mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-02-07 17:54:39 +08:00
wip : remove param ecc bytes
This commit is contained in:
@@ -24,6 +24,7 @@ public:
|
||||
static constexpr auto kMaxSpectrumHistory = 4;
|
||||
static constexpr auto kMaxRecordedFrames = 1024;
|
||||
static constexpr auto kDefaultFixedLength = 82;
|
||||
static constexpr auto kDefaultFixedECCBytes = 32;
|
||||
|
||||
struct TxProtocol {
|
||||
const char * name;
|
||||
@@ -31,7 +32,6 @@ public:
|
||||
int paramFreqStart;
|
||||
int paramFramesPerTx;
|
||||
int paramBytesPerTx;
|
||||
int paramECCBytesPerTx;
|
||||
int paramVolume;
|
||||
};
|
||||
|
||||
@@ -92,10 +92,10 @@ public:
|
||||
|
||||
private:
|
||||
const TxProtocols txProtocols {
|
||||
{ "Normal", 40, 9, 3, 32, 50 },
|
||||
{ "Fast", 40, 6, 3, 32, 50 },
|
||||
{ "Fastest", 40, 3, 3, 32, 50 },
|
||||
{ "Ultrasonic", 320, 9, 3, 32, 50 },
|
||||
{ "Normal", 40, 9, 3, 50 },
|
||||
{ "Fast", 40, 6, 3, 50 },
|
||||
{ "Fastest", 40, 3, 3, 50 },
|
||||
{ "Ultrasonic", 320, 9, 3, 50 },
|
||||
};
|
||||
|
||||
int maxFramesPerTx() const {
|
||||
@@ -114,14 +114,6 @@ private:
|
||||
return res;
|
||||
}
|
||||
|
||||
int maxECCBytesPerTx() const {
|
||||
int res = 0;
|
||||
for (const auto & protocol : txProtocols) {
|
||||
res = std::max(res, protocol.paramECCBytesPerTx);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int nIterations;
|
||||
|
||||
// Rx
|
||||
|
||||
@@ -148,7 +148,7 @@ bool GGWave::init(int textLength, const char * stext, const TxProtocol & aProtoc
|
||||
ihzPerSample = 1.0/hzPerSample;
|
||||
|
||||
nDataBitsPerTx = 8*txProtocol.paramBytesPerTx;
|
||||
nECCBytesPerTx = (txMode == TxMode::FixedLength) ? txProtocol.paramECCBytesPerTx : getECCBytesForLength(textLength);
|
||||
nECCBytesPerTx = (txMode == TxMode::FixedLength) ? kDefaultFixedECCBytes : getECCBytesForLength(textLength);
|
||||
|
||||
framesToAnalyze = 0;
|
||||
framesLeftToAnalyze = 0;
|
||||
@@ -199,7 +199,7 @@ bool GGWave::init(int textLength, const char * stext, const TxProtocol & aProtoc
|
||||
if (rsLength) delete rsLength;
|
||||
|
||||
if (txMode == TxMode::FixedLength) {
|
||||
rsData = new RS::ReedSolomon(kDefaultFixedLength, nECCBytesPerTx);
|
||||
rsData = new RS::ReedSolomon(kDefaultFixedLength, kDefaultFixedLength);
|
||||
rsLength = nullptr;
|
||||
} else {
|
||||
rsData = new RS::ReedSolomon(textLength, nECCBytesPerTx);
|
||||
@@ -501,20 +501,31 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) {
|
||||
}
|
||||
|
||||
if (knownLength) {
|
||||
int decodedLength = rxData[0];
|
||||
if (rsData->Decode(txDataEncoded.data() + encodedOffset, rxData.data()) == 0) {
|
||||
if (txMode == TxMode::FixedLength && rxData[0] == 'A') {
|
||||
printf("[ANSWER] Received sound data successfully!\n");
|
||||
} else if (txMode == TxMode::FixedLength && rxData[0] == 'O') {
|
||||
printf("[OFFER] Received sound data successfully!\n");
|
||||
} else if (rxData[0] != 0) {
|
||||
printf("Decoded length = %d\n", decodedLength);
|
||||
std::string s((char *) rxData.data(), decodedLength);
|
||||
printf("Received sound data successfully: '%s'\n", s.c_str());
|
||||
if (txMode == FixedLength) {
|
||||
if (rsData->Decode(txDataEncoded.data() + encodedOffset, rxData.data()) == 0) {
|
||||
if (rxData[0] == 'A') {
|
||||
printf("[ANSWER] Received sound data successfully!\n");
|
||||
} else if (rxData[0] == 'O') {
|
||||
printf("[OFFER] Received sound data successfully!\n");
|
||||
}
|
||||
|
||||
isValid = true;
|
||||
hasNewRxData = true;
|
||||
lastRxDataLength = decodedLength;
|
||||
lastRxDataLength = kDefaultFixedLength;
|
||||
}
|
||||
} else {
|
||||
int decodedLength = rxData[0];
|
||||
if (rsData->Decode(txDataEncoded.data() + encodedOffset, rxData.data()) == 0) {
|
||||
if (rxData[0] != 0) {
|
||||
std::string s((char *) rxData.data(), decodedLength);
|
||||
|
||||
printf("Decoded length = %d\n", decodedLength);
|
||||
printf("Received sound data successfully: '%s'\n", s.c_str());
|
||||
|
||||
isValid = true;
|
||||
hasNewRxData = true;
|
||||
lastRxDataLength = decodedLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -577,7 +588,7 @@ void GGWave::receive(const CBDequeueAudio & CBDequeueAudio) {
|
||||
rxData.fill(0);
|
||||
receivingData = true;
|
||||
if (txMode == TxMode::FixedLength) {
|
||||
recvDuration_frames = 2*nMarkerFrames + nPostMarkerFrames + maxFramesPerTx()*((kDefaultFixedLength + maxECCBytesPerTx())/minBytesPerTx() + 1);
|
||||
recvDuration_frames = 2*nMarkerFrames + nPostMarkerFrames + maxFramesPerTx()*((kDefaultFixedLength + kDefaultFixedECCBytes)/minBytesPerTx() + 1);
|
||||
} else {
|
||||
recvDuration_frames = 2*nMarkerFrames + nPostMarkerFrames + maxFramesPerTx()*((kMaxLength + ::getECCBytesForLength(kMaxLength))/minBytesPerTx() + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user