mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-05-10 02:47:39 +08:00
ggwave : compute Tx amplitudes always
This commit is contained in:
@@ -333,16 +333,6 @@ public:
|
|||||||
int bytesPerTx; // number of bytes in a chunk of data
|
int bytesPerTx; // number of bytes in a chunk of data
|
||||||
|
|
||||||
int nDataBitsPerTx() const { return 8*bytesPerTx; }
|
int nDataBitsPerTx() const { return 8*bytesPerTx; }
|
||||||
|
|
||||||
bool operator==(const TxProtocol & other) const {
|
|
||||||
return freqStart == other.freqStart &&
|
|
||||||
framesPerTx == other.framesPerTx &&
|
|
||||||
bytesPerTx == other.bytesPerTx;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const TxProtocol & other) const {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using RxProtocol = TxProtocol;
|
using RxProtocol = TxProtocol;
|
||||||
|
|||||||
@@ -410,7 +410,6 @@ struct GGWave::Tx {
|
|||||||
|
|
||||||
TxRxData txData;
|
TxRxData txData;
|
||||||
TxProtocol txProtocol;
|
TxProtocol txProtocol;
|
||||||
TxProtocol txProtocolLast;
|
|
||||||
|
|
||||||
AmplitudeData outputBlock;
|
AmplitudeData outputBlock;
|
||||||
AmplitudeData outputBlockResampled;
|
AmplitudeData outputBlockResampled;
|
||||||
@@ -543,8 +542,6 @@ GGWave::GGWave(const Parameters & parameters) :
|
|||||||
if (m_isTxEnabled) {
|
if (m_isTxEnabled) {
|
||||||
m_tx = std::unique_ptr<Tx>(new Tx());
|
m_tx = std::unique_ptr<Tx>(new Tx());
|
||||||
|
|
||||||
m_tx->txProtocolLast = {};
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const int maxDataBits = 2*16*maxBytesPerTx();
|
const int maxDataBits = 2*16*maxBytesPerTx();
|
||||||
|
|
||||||
@@ -703,36 +700,33 @@ bool GGWave::encode(const CBWaveformOut & cbWaveformOut) {
|
|||||||
m_resampler->reset();
|
m_resampler->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_tx->txProtocol != m_tx->txProtocolLast) {
|
for (int k = 0; k < (int) m_tx->phaseOffsets.size(); ++k) {
|
||||||
for (int k = 0; k < (int) m_tx->phaseOffsets.size(); ++k) {
|
m_tx->phaseOffsets[k] = (M_PI*k)/(m_tx->txProtocol.nDataBitsPerTx());
|
||||||
m_tx->phaseOffsets[k] = (M_PI*k)/(m_tx->txProtocol.nDataBitsPerTx());
|
}
|
||||||
|
|
||||||
|
// note : what is the purpose of this shuffle ? I forgot .. :(
|
||||||
|
//std::random_device rd;
|
||||||
|
//std::mt19937 g(rd());
|
||||||
|
|
||||||
|
//std::shuffle(phaseOffsets.begin(), phaseOffsets.end(), g);
|
||||||
|
|
||||||
|
for (int k = 0; k < (int) m_tx->dataBits.size(); ++k) {
|
||||||
|
const double freq = bitFreq(m_tx->txProtocol, k);
|
||||||
|
|
||||||
|
const double phaseOffset = m_tx->phaseOffsets[k];
|
||||||
|
const double curHzPerSample = m_hzPerSample;
|
||||||
|
const double curIHzPerSample = 1.0/curHzPerSample;
|
||||||
|
|
||||||
|
for (int i = 0; i < m_samplesPerFrame; i++) {
|
||||||
|
const double curi = i;
|
||||||
|
m_tx->bit1Amplitude[k][i] = std::sin((2.0*M_PI)*(curi*m_isamplesPerFrame)*(freq*curIHzPerSample) + phaseOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// note : what is the purpose of this shuffle ? I forgot .. :(
|
for (int i = 0; i < m_samplesPerFrame; i++) {
|
||||||
//std::random_device rd;
|
const double curi = i;
|
||||||
//std::mt19937 g(rd());
|
m_tx->bit0Amplitude[k][i] = std::sin((2.0*M_PI)*(curi*m_isamplesPerFrame)*((freq + m_hzPerSample*m_freqDelta_bin)*curIHzPerSample) + phaseOffset);
|
||||||
|
|
||||||
//std::shuffle(phaseOffsets.begin(), phaseOffsets.end(), g);
|
|
||||||
|
|
||||||
for (int k = 0; k < (int) m_tx->dataBits.size(); ++k) {
|
|
||||||
const double freq = bitFreq(m_tx->txProtocol, k);
|
|
||||||
|
|
||||||
const double phaseOffset = m_tx->phaseOffsets[k];
|
|
||||||
const double curHzPerSample = m_hzPerSample;
|
|
||||||
const double curIHzPerSample = 1.0/curHzPerSample;
|
|
||||||
|
|
||||||
for (int i = 0; i < m_samplesPerFrame; i++) {
|
|
||||||
const double curi = i;
|
|
||||||
m_tx->bit1Amplitude[k][i] = std::sin((2.0*M_PI)*(curi*m_isamplesPerFrame)*(freq*curIHzPerSample) + phaseOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < m_samplesPerFrame; i++) {
|
|
||||||
const double curi = i;
|
|
||||||
m_tx->bit0Amplitude[k][i] = std::sin((2.0*M_PI)*(curi*m_isamplesPerFrame)*((freq + m_hzPerSample*m_freqDelta_bin)*curIHzPerSample) + phaseOffset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_tx->txProtocolLast = m_tx->txProtocol;
|
|
||||||
|
|
||||||
const int nECCBytesPerTx = getECCBytesForLength(m_tx->txDataLength);
|
const int nECCBytesPerTx = getECCBytesForLength(m_tx->txDataLength);
|
||||||
const int sendDataLength = m_tx->txDataLength + m_encodedDataOffset;
|
const int sendDataLength = m_tx->txDataLength + m_encodedDataOffset;
|
||||||
|
|||||||
Reference in New Issue
Block a user