mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-04-18 20:17:29 +08:00
remove-stl : almost complete - only <initializer_list> remains
This commit is contained in:
@@ -339,26 +339,27 @@ private:
|
|||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
ggvector();
|
ggvector() : m_data(nullptr), m_size(0) {}
|
||||||
ggvector(T * data, int size);
|
ggvector(T * data, int size) : m_data(data), m_size(size) {}
|
||||||
|
|
||||||
ggvector(const ggvector<T> & other) = default;
|
ggvector(const ggvector<T> & other) = default;
|
||||||
|
|
||||||
// delete operator=
|
// delete operator=
|
||||||
ggvector & operator=(const ggvector &) = delete;
|
ggvector & operator=(const ggvector &) = delete;
|
||||||
ggvector & operator=(ggvector &&) = delete;
|
ggvector & operator=(ggvector &&) = delete;
|
||||||
|
|
||||||
T & operator[](int i);
|
T & operator[](int i) { return m_data[i]; }
|
||||||
const T & operator[](int i) const;
|
const T & operator[](int i) const { return m_data[i]; }
|
||||||
|
|
||||||
|
int size() const { return m_size; }
|
||||||
|
T * data() const { return m_data; }
|
||||||
|
|
||||||
|
T * begin() const { return m_data; }
|
||||||
|
T * end() const { return m_data + m_size; }
|
||||||
|
|
||||||
void assign(const ggvector & other);
|
void assign(const ggvector & other);
|
||||||
void copy(const ggvector & other);
|
void copy(const ggvector & other);
|
||||||
|
|
||||||
int size() const;
|
|
||||||
T * data() const;
|
|
||||||
|
|
||||||
T * begin() const;
|
|
||||||
T * end() const;
|
|
||||||
|
|
||||||
void zero();
|
void zero();
|
||||||
void zero(int n);
|
void zero(int n);
|
||||||
};
|
};
|
||||||
@@ -373,14 +374,14 @@ private:
|
|||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
ggmatrix();
|
ggmatrix() : m_data(nullptr), m_size0(0), m_size1(0) {}
|
||||||
ggmatrix(T * data, int size0, int size1);
|
ggmatrix(T * data, int size0, int size1) : m_data(data), m_size0(size0), m_size1(size1) {}
|
||||||
|
|
||||||
ggvector<T> operator[](int i);
|
ggvector<T> operator[](int i) {
|
||||||
|
return ggvector<T>(m_data + i*m_size1, m_size1);
|
||||||
|
}
|
||||||
|
|
||||||
T & operator()(int i, int j);
|
int size() const { return m_size0; }
|
||||||
|
|
||||||
int size() const;
|
|
||||||
|
|
||||||
void zero();
|
void zero();
|
||||||
};
|
};
|
||||||
|
|||||||
121
src/ggwave.cpp
121
src/ggwave.cpp
@@ -9,9 +9,8 @@
|
|||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
#include "reed-solomon/rs.hpp"
|
#include "reed-solomon/rs.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <math.h>
|
||||||
#include <ctime>
|
#include <stdio.h>
|
||||||
#include <cstdio>
|
|
||||||
//#include <random>
|
//#include <random>
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
@@ -285,22 +284,6 @@ int bytesForSampleFormat(GGWave::SampleFormat sampleFormat) {
|
|||||||
// ggvector
|
// ggvector
|
||||||
//
|
//
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ggvector<T>::ggvector() : m_data(nullptr), m_size(0) {}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
ggvector<T>::ggvector(T * data, int size) : m_data(data), m_size(size) {}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T & ggvector<T>::operator[](int i) {
|
|
||||||
return m_data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
const T & ggvector<T>::operator[](int i) const {
|
|
||||||
return m_data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ggvector<T>::assign(const ggvector & other) {
|
void ggvector<T>::assign(const ggvector & other) {
|
||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
@@ -316,26 +299,6 @@ void ggvector<T>::copy(const ggvector & other) {
|
|||||||
memcpy(m_data, other.m_data, GG_MIN(m_size, other.m_size)*sizeof(T));
|
memcpy(m_data, other.m_data, GG_MIN(m_size, other.m_size)*sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
int ggvector<T>::size() const {
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T * ggvector<T>::data() const {
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T * ggvector<T>::begin() const {
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T * ggvector<T>::end() const {
|
|
||||||
return m_data + m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void ggvector<T>::zero() {
|
void ggvector<T>::zero() {
|
||||||
memset(m_data, 0, m_size*sizeof(T));
|
memset(m_data, 0, m_size*sizeof(T));
|
||||||
@@ -346,37 +309,12 @@ void ggvector<T>::zero(int n) {
|
|||||||
memset(m_data, 0, n*sizeof(T));
|
memset(m_data, 0, n*sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
template struct ggvector<uint8_t>;
|
|
||||||
template struct ggvector<int8_t>;
|
|
||||||
template struct ggvector<float>;
|
|
||||||
template struct ggvector<int16_t>;
|
template struct ggvector<int16_t>;
|
||||||
|
|
||||||
//
|
//
|
||||||
// ggmatrix
|
// ggmatrix
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ggmatrix<T>::ggmatrix() : m_data(nullptr), m_size0(0), m_size1(0) {}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ggmatrix<T>::ggmatrix(T * data, int size0, int size1) : m_data(data), m_size0(size0), m_size1(size1) {}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ggvector<T> ggmatrix<T>::operator[](int i) {
|
|
||||||
return ggvector<T>(m_data + i*m_size1, m_size1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T & ggmatrix<T>::operator()(int i, int j) {
|
|
||||||
return m_data[i*m_size1 + j];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
int ggmatrix<T>::size() const {
|
|
||||||
return m_size0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ggmatrix<T>::zero() {
|
void ggmatrix<T>::zero() {
|
||||||
memset(m_data, 0, m_size0*m_size1*sizeof(T));
|
memset(m_data, 0, m_size0*m_size1*sizeof(T));
|
||||||
@@ -436,30 +374,66 @@ GGWave::RxProtocols & GGWave::Protocols::rx() {
|
|||||||
return protocols;
|
return protocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this probably does not matter, but adding it anyway
|
||||||
|
#ifdef ARDUINO
|
||||||
|
const int kAlignment = 1;
|
||||||
|
#else
|
||||||
|
const int kAlignment = 8;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//template <typename T>
|
||||||
|
//void ggalloc(std::vector<T> & v, int n, void * buf, int & bufSize) {
|
||||||
|
// if (buf == nullptr) {
|
||||||
|
// bufSize += n*sizeof(T);
|
||||||
|
// bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// v.resize(n);
|
||||||
|
// bufSize += n*sizeof(T);
|
||||||
|
// bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//template <typename T>
|
||||||
|
//void ggalloc(std::vector<std::vector<T>> & v, int n, int m, void * buf, int & bufSize) {
|
||||||
|
// if (buf == nullptr) {
|
||||||
|
// bufSize += n*m*sizeof(T);
|
||||||
|
// bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// v.resize(n);
|
||||||
|
// for (int i = 0; i < n; i++) {
|
||||||
|
// v[i].resize(m);
|
||||||
|
// }
|
||||||
|
// bufSize += n*m*sizeof(T);
|
||||||
|
// bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
|
//}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ggalloc(ggvector<T> & v, int n, void * buf, int & bufSize) {
|
void ggalloc(ggvector<T> & v, int n, void * buf, int & bufSize) {
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
bufSize += n*sizeof(T);
|
bufSize += n*sizeof(T);
|
||||||
bufSize = ((bufSize + 7)/8)*8;
|
bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v.assign(ggvector<T>((T *)((char *) buf + bufSize), n));
|
v.assign(ggvector<T>((T *)((char *) buf + bufSize), n));
|
||||||
bufSize += n*sizeof(T);
|
bufSize += n*sizeof(T);
|
||||||
bufSize = ((bufSize + 7)/8)*8;
|
bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ggalloc(ggmatrix<T> & v, int n, int m, void * buf, int & bufSize) {
|
void ggalloc(ggmatrix<T> & v, int n, int m, void * buf, int & bufSize) {
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
bufSize += n*m*sizeof(T);
|
bufSize += n*m*sizeof(T);
|
||||||
bufSize = ((bufSize + 7)/8)*8;
|
bufSize = ((bufSize + kAlignment - 1) / kAlignment)*kAlignment;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = ggmatrix<T>((T *)((char *) buf + bufSize), n, m);
|
v = ggmatrix<T>((T *)((char *) buf + bufSize), n, m);
|
||||||
bufSize += n*m*sizeof(T);
|
bufSize += n*m*sizeof(T);
|
||||||
bufSize = ((bufSize + 7)/8)*8;
|
bufSize = ((bufSize + kAlignment - 1)/kAlignment)*kAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -538,7 +512,10 @@ bool GGWave::prepare(const Parameters & parameters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto heapSize0 = m_heapSize;
|
const auto heapSize0 = m_heapSize;
|
||||||
m_heap = malloc(m_heapSize);
|
|
||||||
|
// not sure if allocating alligned memory makes any difference
|
||||||
|
//m_heap = malloc(m_heapSize);
|
||||||
|
m_heap = aligned_alloc(kAlignment, m_heapSize);
|
||||||
|
|
||||||
m_heapSize = 0;
|
m_heapSize = 0;
|
||||||
if (this->alloc(m_heap, m_heapSize) == false) {
|
if (this->alloc(m_heap, m_heapSize) == false) {
|
||||||
@@ -1720,8 +1697,7 @@ void GGWave::decode_variable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isReceiving) {
|
if (isReceiving) {
|
||||||
std::time_t timestamp = std::time(nullptr);
|
ggprintf("Receiving sound data ...\n");
|
||||||
ggprintf("%sReceiving sound data ...\n", std::asctime(std::localtime(×tamp)));
|
|
||||||
|
|
||||||
m_rx.receiving = true;
|
m_rx.receiving = true;
|
||||||
m_rx.data.zero();
|
m_rx.data.zero();
|
||||||
@@ -1775,9 +1751,8 @@ void GGWave::decode_variable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isEnded && m_rx.framesToRecord > 1) {
|
if (isEnded && m_rx.framesToRecord > 1) {
|
||||||
std::time_t timestamp = std::time(nullptr);
|
|
||||||
m_rx.recvDuration_frames -= m_rx.framesLeftToRecord - 1;
|
m_rx.recvDuration_frames -= m_rx.framesLeftToRecord - 1;
|
||||||
ggprintf("%sReceived end marker. Frames left = %d, recorded = %d\n", std::asctime(std::localtime(×tamp)), m_rx.framesLeftToRecord, m_rx.recvDuration_frames);
|
ggprintf("Received end marker. Frames left = %d, recorded = %d\n", m_rx.framesLeftToRecord, m_rx.recvDuration_frames);
|
||||||
m_rx.nMarkersSuccess = 0;
|
m_rx.nMarkersSuccess = 0;
|
||||||
m_rx.framesLeftToRecord = 1;
|
m_rx.framesLeftToRecord = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user