diff --git a/examples/arduino-rx/arduino-rx.ino b/examples/arduino-rx/arduino-rx.ino index 637bb7c..9cad340 100644 --- a/examples/arduino-rx/arduino-rx.ino +++ b/examples/arduino-rx/arduino-rx.ino @@ -6,7 +6,7 @@ static const char channels = 1; // default PCM output frequency -static const int frequency = 10000; +static const int frequency = GGWave::kBaseSampleRate; const int qmax = 1024; volatile int qhead = 0; @@ -52,7 +52,7 @@ void loop() { auto p = GGWave::getDefaultParameters(); p.sampleRateInp = frequency; p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16; - p.payloadLength = 4; + p.payloadLength = 16; GGWave instance(p); static GGWave::CBWaveformInp cbWaveformInp = [&](void * data, uint32_t nMaxBytes) { diff --git a/examples/arduino-rx/ggwave/ggwave.h b/examples/arduino-rx/ggwave/ggwave.h index 0066b45..b620958 100644 --- a/examples/arduino-rx/ggwave/ggwave.h +++ b/examples/arduino-rx/ggwave/ggwave.h @@ -286,15 +286,15 @@ extern "C" { class GGWave { public: - static constexpr auto kBaseSampleRate = 10000.0f; - static constexpr auto kSampleRateMin = 6000.0f; + static constexpr auto kBaseSampleRate = 6000.0f; + static constexpr auto kSampleRateMin = 1000.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 kDefaultSoundMarkerThreshold = 3.0f; static constexpr auto kDefaultMarkerFrames = 16; static constexpr auto kDefaultEncodedDataOffset = 3; - static constexpr auto kMaxSamplesPerFrame = 256; + static constexpr auto kMaxSamplesPerFrame = 128; static constexpr auto kMaxDataBits = 256; static constexpr auto kMaxDataSize = 256; static constexpr auto kMaxLengthVarible = 140; @@ -324,15 +324,15 @@ public: static const TxProtocols & getTxProtocols() { static const TxProtocols kTxProtocols { - { GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL, { "Normal", 40, 9, 3, } }, - { GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, { "Fast", 40, 6, 3, } }, - { GGWAVE_TX_PROTOCOL_AUDIBLE_FASTEST, { "Fastest", 40, 3, 3, } }, + //{ GGWAVE_TX_PROTOCOL_AUDIBLE_NORMAL, { "Normal", 40, 9, 3, } }, + //{ GGWAVE_TX_PROTOCOL_AUDIBLE_FAST, { "Fast", 40, 6, 3, } }, + //{ GGWAVE_TX_PROTOCOL_AUDIBLE_FASTEST, { "Fastest", 40, 3, 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_FASTEST, { "[U] Fastest", 320, 3, 3, } }, //{ GGWAVE_TX_PROTOCOL_DT_NORMAL, { "[DT] Normal", 24, 9, 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; @@ -430,7 +430,7 @@ public: // 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 & getTxProtocol(int id) { return getTxProtocols().at(TxProtocolId(id)); } static const TxProtocol & getTxProtocol(TxProtocolId id) { return getTxProtocols().at(id); } diff --git a/examples/ggwave-common-sdl2.cpp b/examples/ggwave-common-sdl2.cpp index c68321b..c6bcc03 100644 --- a/examples/ggwave-common-sdl2.cpp +++ b/examples/ggwave-common-sdl2.cpp @@ -122,7 +122,7 @@ bool GGWave_init( playbackSpec.freq = GGWave::kBaseSampleRate + sampleRateOffset; playbackSpec.format = AUDIO_S16SYS; playbackSpec.channels = 1; - playbackSpec.samples = 16*1024; + playbackSpec.samples = (16*1024*GGWave::kBaseSampleRate)/48000; playbackSpec.callback = NULL; SDL_zero(g_obtainedSpecOut); diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index e6b5687..1af5e04 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -287,14 +287,14 @@ extern "C" { class GGWave { public: 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 kDefaultSamplesPerFrame = 1024; static constexpr auto kDefaultVolume = 10; static constexpr auto kDefaultSoundMarkerThreshold = 3.0f; static constexpr auto kDefaultMarkerFrames = 16; static constexpr auto kDefaultEncodedDataOffset = 3; - static constexpr auto kMaxSamplesPerFrame = 2048; + static constexpr auto kMaxSamplesPerFrame = 1024; static constexpr auto kMaxDataBits = 256; static constexpr auto kMaxDataSize = 256; static constexpr auto kMaxLengthVarible = 140; diff --git a/src/ggwave.cpp b/src/ggwave.cpp index fa8f6d5..aed64e2 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -1294,6 +1294,10 @@ void GGWave::decode_fixed() { const int binStart = rxProtocol.freqStart; const int binDelta = 16; + if (binStart > kMaxSamplesPerFrame) { + continue; + } + const int totalLength = m_payloadLength + getECCBytesForLength(m_payloadLength); const int totalTxs = (totalLength + rxProtocol.bytesPerTx - 1)/rxProtocol.bytesPerTx;