diff --git a/examples/ggwave-common-sdl2.cpp b/examples/ggwave-common-sdl2.cpp index 088a2b6..ba85651 100644 --- a/examples/ggwave-common-sdl2.cpp +++ b/examples/ggwave-common-sdl2.cpp @@ -227,7 +227,7 @@ bool GGWave_init( g_ggWave = new GGWave( g_obtainedSpecIn.freq, g_obtainedSpecOut.freq, - 1024, + GGWave::kDefaultSamplesPerFrame, sampleSizeBytesIn, sampleSizeBytesOut); } diff --git a/include/ggwave/ggwave.h b/include/ggwave/ggwave.h index 7403441..8cc27b5 100644 --- a/include/ggwave/ggwave.h +++ b/include/ggwave/ggwave.h @@ -7,6 +7,7 @@ class GGWave { public: static constexpr auto kBaseSampleRate = 48000.0; + static constexpr auto kDefaultSamplesPerFrame = 1024; static constexpr auto kMaxSamplesPerFrame = 1024; static constexpr auto kMaxDataBits = 256; static constexpr auto kMaxDataSize = 256; @@ -54,6 +55,7 @@ public: int samplesPerFrame, int sampleSizeBytesIn, int sampleSizeBytesOut); + ~GGWave(); bool init(int textLength, const char * stext, const TxProtocol & aProtocol, const int volume); diff --git a/src/ggwave.cpp b/src/ggwave.cpp index e4b6c55..2509aee 100644 --- a/src/ggwave.cpp +++ b/src/ggwave.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace { @@ -163,6 +164,10 @@ GGWave::GGWave( m_outputBlock(kMaxSamplesPerFrame), m_outputBlock16(kMaxRecordedFrames*kMaxSamplesPerFrame) { + if (samplesPerFrame > kMaxSamplesPerFrame) { + throw std::runtime_error("Invalid samples per frame"); + } + init(0, "", getDefultTxProtocol(), 0); }