This commit is contained in:
Georgi Gerganov
2022-05-28 19:41:56 +03:00
parent 8b4a651e19
commit 7c2312d784
5 changed files with 18 additions and 14 deletions

View File

@@ -6,7 +6,7 @@
static const char channels = 1; static const char channels = 1;
// default PCM output frequency // default PCM output frequency
static const int frequency = 10000; static const int frequency = GGWave::kBaseSampleRate;
const int qmax = 1024; const int qmax = 1024;
volatile int qhead = 0; volatile int qhead = 0;
@@ -52,7 +52,7 @@ void loop() {
auto p = GGWave::getDefaultParameters(); auto p = GGWave::getDefaultParameters();
p.sampleRateInp = frequency; p.sampleRateInp = frequency;
p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16; p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16;
p.payloadLength = 4; p.payloadLength = 16;
GGWave instance(p); GGWave instance(p);
static GGWave::CBWaveformInp cbWaveformInp = [&](void * data, uint32_t nMaxBytes) { static GGWave::CBWaveformInp cbWaveformInp = [&](void * data, uint32_t nMaxBytes) {

View File

@@ -286,15 +286,15 @@ extern "C" {
class GGWave { class GGWave {
public: public:
static constexpr auto kBaseSampleRate = 10000.0f; static constexpr auto kBaseSampleRate = 6000.0f;
static constexpr auto kSampleRateMin = 6000.0f; static constexpr auto kSampleRateMin = 1000.0f;
static constexpr auto kSampleRateMax = 10000.0f; static constexpr auto kSampleRateMax = 10000.0f;
static constexpr auto kDefaultSamplesPerFrame = 256; static constexpr auto kDefaultSamplesPerFrame = 128;
static constexpr auto kDefaultVolume = 10; static constexpr auto kDefaultVolume = 10;
static constexpr auto kDefaultSoundMarkerThreshold = 3.0f; static constexpr auto kDefaultSoundMarkerThreshold = 3.0f;
static constexpr auto kDefaultMarkerFrames = 16; static constexpr auto kDefaultMarkerFrames = 16;
static constexpr auto kDefaultEncodedDataOffset = 3; static constexpr auto kDefaultEncodedDataOffset = 3;
static constexpr auto kMaxSamplesPerFrame = 256; static constexpr auto kMaxSamplesPerFrame = 128;
static constexpr auto kMaxDataBits = 256; static constexpr auto kMaxDataBits = 256;
static constexpr auto kMaxDataSize = 256; static constexpr auto kMaxDataSize = 256;
static constexpr auto kMaxLengthVarible = 140; static constexpr auto kMaxLengthVarible = 140;
@@ -324,15 +324,15 @@ public:
static const TxProtocols & getTxProtocols() { static const TxProtocols & getTxProtocols() {
static const TxProtocols kTxProtocols { static const TxProtocols kTxProtocols {
{ GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL, { "Normal", 40, 9, 3, } }, //{ GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL, { "Normal", 40, 9, 3, } },
{ GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, { "Fast", 40, 6, 3, } }, //{ GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, { "Fast", 40, 6, 3, } },
{ GGWAVE_TX_PROTOCOL_AUDIBLE_FASTEST, { "Fastest", 40, 3, 3, } }, //{ GGWAVE_TX_PROTOCOL_AUDIBLE_FASTEST, { "Fastest", 40, 3, 3, } },
//{ GGWAVE_TX_PROTOCOL_ULTRASOUND_NORMAL, { "[U] Normal", 320, 9, 3, } }, //{ GGWAVE_TX_PROTOCOL_ULTRASOUND_NORMAL, { "[U] Normal", 320, 9, 3, } },
//{ GGWAVE_TX_PROTOCOL_ULTRASOUND_FAST, { "[U] Fast", 320, 6, 3, } }, //{ GGWAVE_TX_PROTOCOL_ULTRASOUND_FAST, { "[U] Fast", 320, 6, 3, } },
//{ GGWAVE_TX_PROTOCOL_ULTRASOUND_FASTEST, { "[U] Fastest", 320, 3, 3, } }, //{ GGWAVE_TX_PROTOCOL_ULTRASOUND_FASTEST, { "[U] Fastest", 320, 3, 3, } },
//{ GGWAVE_TX_PROTOCOL_DT_NORMAL, { "[DT] Normal", 24, 9, 1, } }, //{ GGWAVE_TX_PROTOCOL_DT_NORMAL, { "[DT] Normal", 24, 9, 1, } },
//{ GGWAVE_TX_PROTOCOL_DT_FAST, { "[DT] Fast", 24, 6, 1, } }, //{ GGWAVE_TX_PROTOCOL_DT_FAST, { "[DT] Fast", 24, 6, 1, } },
//{ GGWAVE_TX_PROTOCOL_DT_FASTEST, { "[DT] Fastest", 24, 3, 1, } }, { GGWAVE_TX_PROTOCOL_DT_FASTEST, { "[DT] Fastest", 24, 3, 1, } },
}; };
return kTxProtocols; return kTxProtocols;
@@ -430,7 +430,7 @@ public:
// Tx // Tx
static TxProtocolId getDefaultTxProtocolId() { return GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL; } static TxProtocolId getDefaultTxProtocolId() { return getTxProtocols().begin()->first; }
static const TxProtocol & getDefaultTxProtocol() { return getTxProtocols().at(getDefaultTxProtocolId()); } static const TxProtocol & getDefaultTxProtocol() { return getTxProtocols().at(getDefaultTxProtocolId()); }
static const TxProtocol & getTxProtocol(int id) { return getTxProtocols().at(TxProtocolId(id)); } static const TxProtocol & getTxProtocol(int id) { return getTxProtocols().at(TxProtocolId(id)); }
static const TxProtocol & getTxProtocol(TxProtocolId id) { return getTxProtocols().at(id); } static const TxProtocol & getTxProtocol(TxProtocolId id) { return getTxProtocols().at(id); }

View File

@@ -122,7 +122,7 @@ bool GGWave_init(
playbackSpec.freq = GGWave::kBaseSampleRate + sampleRateOffset; playbackSpec.freq = GGWave::kBaseSampleRate + sampleRateOffset;
playbackSpec.format = AUDIO_S16SYS; playbackSpec.format = AUDIO_S16SYS;
playbackSpec.channels = 1; playbackSpec.channels = 1;
playbackSpec.samples = 16*1024; playbackSpec.samples = (16*1024*GGWave::kBaseSampleRate)/48000;
playbackSpec.callback = NULL; playbackSpec.callback = NULL;
SDL_zero(g_obtainedSpecOut); SDL_zero(g_obtainedSpecOut);

View File

@@ -287,14 +287,14 @@ extern "C" {
class GGWave { class GGWave {
public: public:
static constexpr auto kBaseSampleRate = 48000.0f; static constexpr auto kBaseSampleRate = 48000.0f;
static constexpr auto kSampleRateMin = 6000.0f; static constexpr auto kSampleRateMin = 1000.0f;
static constexpr auto kSampleRateMax = 96000.0f; static constexpr auto kSampleRateMax = 96000.0f;
static constexpr auto kDefaultSamplesPerFrame = 1024; static constexpr auto kDefaultSamplesPerFrame = 1024;
static constexpr auto kDefaultVolume = 10; static constexpr auto kDefaultVolume = 10;
static constexpr auto kDefaultSoundMarkerThreshold = 3.0f; static constexpr auto kDefaultSoundMarkerThreshold = 3.0f;
static constexpr auto kDefaultMarkerFrames = 16; static constexpr auto kDefaultMarkerFrames = 16;
static constexpr auto kDefaultEncodedDataOffset = 3; static constexpr auto kDefaultEncodedDataOffset = 3;
static constexpr auto kMaxSamplesPerFrame = 2048; static constexpr auto kMaxSamplesPerFrame = 1024;
static constexpr auto kMaxDataBits = 256; static constexpr auto kMaxDataBits = 256;
static constexpr auto kMaxDataSize = 256; static constexpr auto kMaxDataSize = 256;
static constexpr auto kMaxLengthVarible = 140; static constexpr auto kMaxLengthVarible = 140;

View File

@@ -1294,6 +1294,10 @@ void GGWave::decode_fixed() {
const int binStart = rxProtocol.freqStart; const int binStart = rxProtocol.freqStart;
const int binDelta = 16; const int binDelta = 16;
if (binStart > kMaxSamplesPerFrame) {
continue;
}
const int totalLength = m_payloadLength + getECCBytesForLength(m_payloadLength); const int totalLength = m_payloadLength + getECCBytesForLength(m_payloadLength);
const int totalTxs = (totalLength + rxProtocol.bytesPerTx - 1)/rxProtocol.bytesPerTx; const int totalTxs = (totalLength + rxProtocol.bytesPerTx - 1)/rxProtocol.bytesPerTx;