mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-03-17 16:06:00 +08:00
ggwave : add default constructor
This commit is contained in:
@@ -293,7 +293,7 @@ bool GGWave_mainLoop() {
|
||||
SDL_PauseAudioDevice(g_devIdInp, SDL_TRUE);
|
||||
|
||||
const auto nBytes = g_ggWave->encode();
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txData(), nBytes);
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txWaveform(), nBytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -5,28 +5,29 @@
|
||||
const int kPinSpeaker = 10;
|
||||
|
||||
using TSample = int16_t;
|
||||
static const size_t kSampleSize_bytes = sizeof(TSample);
|
||||
const size_t kSampleSize_bytes = sizeof(TSample);
|
||||
|
||||
// default number of output channels
|
||||
static const char channels = 1;
|
||||
const char channels = 1;
|
||||
|
||||
// default PCM output frequency
|
||||
static const int frequency = 6000;
|
||||
static const int samplesPerFrame = 128;
|
||||
const int frequency = 6000;
|
||||
const int samplesPerFrame = 128;
|
||||
|
||||
static const int qpow = 9;
|
||||
static const int qmax = 1 << qpow;
|
||||
const int qpow = 9;
|
||||
const int qmax = 1 << qpow;
|
||||
|
||||
volatile int qhead = 0;
|
||||
volatile int qtail = 0;
|
||||
volatile int qsize = 0;
|
||||
|
||||
// Buffer to read samples into, each sample is 16-bits
|
||||
// buffer to read samples into, each sample is 16-bits
|
||||
TSample sampleBuffer[qmax];
|
||||
|
||||
volatile int err = 0;
|
||||
|
||||
GGWave * g_ggwave = nullptr;
|
||||
// global GGwave instance
|
||||
GGWave ggwave;
|
||||
|
||||
// helper function to output the generated GGWave waveform via a buzzer
|
||||
void send_text(GGWave & ggwave, uint8_t pin, const char * text, GGWave::TxProtocolId protocolId) {
|
||||
@@ -57,6 +58,8 @@ void setup() {
|
||||
|
||||
Serial.println(F("Trying to create ggwave instance"));
|
||||
|
||||
ggwave.setLogFile(nullptr);
|
||||
|
||||
auto p = GGWave::getDefaultParameters();
|
||||
|
||||
p.payloadLength = 16;
|
||||
@@ -84,17 +87,12 @@ void setup() {
|
||||
GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_FAST, true);
|
||||
GGWave::Protocols::rx().toggle(GGWAVE_PROTOCOL_MT_FASTEST, true);
|
||||
|
||||
delay(1000);
|
||||
|
||||
static GGWave ggwave(p);
|
||||
ggwave.prepare(p);
|
||||
Serial.println(ggwave.heapSize());
|
||||
|
||||
delay(1000);
|
||||
|
||||
ggwave.setLogFile(nullptr);
|
||||
|
||||
g_ggwave = &ggwave;
|
||||
|
||||
Serial.println(F("Instance initialized"));
|
||||
|
||||
// Configure the data receive callback
|
||||
@@ -115,8 +113,6 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
auto & ggwave = *g_ggwave;
|
||||
|
||||
int nr = 0;
|
||||
int niter = 0;
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ const int kPinButton1 = 4;
|
||||
const int samplesPerFrame = 128;
|
||||
const int sampleRate = 6000;
|
||||
|
||||
GGWave * g_ggwave = nullptr;
|
||||
// global GGwave instance
|
||||
GGWave ggwave;
|
||||
|
||||
char txt[64];
|
||||
#define P(str) (strcpy_P(txt, PSTR(str)), txt)
|
||||
@@ -36,6 +37,7 @@ void send_text(GGWave & ggwave, uint8_t pin, const char * text, GGWave::TxProtoc
|
||||
|
||||
void setup() {
|
||||
Serial.begin(57600);
|
||||
while (!Serial);
|
||||
|
||||
pinMode(kPinLed0, OUTPUT);
|
||||
pinMode(kPinSpeaker, OUTPUT);
|
||||
@@ -55,12 +57,10 @@ void setup() {
|
||||
p.operatingMode = (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES | GGWAVE_OPERATING_MODE_USE_DSS);
|
||||
|
||||
GGWave::Protocols::tx().only(GGWAVE_PROTOCOL_MT_FASTEST);
|
||||
static GGWave ggwave(p);
|
||||
ggwave.prepare(p);
|
||||
ggwave.setLogFile(nullptr);
|
||||
Serial.println(ggwave.heapSize());
|
||||
|
||||
g_ggwave = &ggwave;
|
||||
|
||||
Serial.println(F("Instance initialized"));
|
||||
}
|
||||
|
||||
@@ -68,8 +68,6 @@ int pressed = 0;
|
||||
bool isDown = false;
|
||||
|
||||
void loop() {
|
||||
auto & ggwave = *g_ggwave;
|
||||
|
||||
delay(1000);
|
||||
|
||||
digitalWrite(kPinLed0, HIGH);
|
||||
|
||||
@@ -275,7 +275,7 @@ bool GGWave_mainLoop() {
|
||||
SDL_PauseAudioDevice(g_devIdInp, SDL_TRUE);
|
||||
|
||||
const auto nBytes = g_ggWave->encode();
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txData(), nBytes);
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txWaveform(), nBytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -102,7 +102,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
std::vector<char> bufferPCM(nBytes);
|
||||
std::memcpy(bufferPCM.data(), ggWave.txData(), nBytes);
|
||||
std::memcpy(bufferPCM.data(), ggWave.txWaveform(), nBytes);
|
||||
|
||||
fprintf(stderr, "Output size = %d bytes\n", (int) bufferPCM.size());
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ bool GGWave_mainLoop() {
|
||||
SDL_PauseAudioDevice(g_devIdInp, SDL_TRUE);
|
||||
|
||||
const auto nBytes = g_ggWave->encode();
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txData(), nBytes);
|
||||
SDL_QueueAudio(g_devIdOut, g_ggWave->txWaveform(), nBytes);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user