Skip to content

Commit

Permalink
examples : ggwave-to-file Fixes (#98)
Browse files Browse the repository at this point in the history
* examples : Fix output device on Windows, instead of stdout, write to a file instead.

* Update examples/ggwave-to-file/main.cpp

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
  • Loading branch information
guilt and ggerganov authored Jul 23, 2023
1 parent 614bcb3 commit c2716d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/ggwave-to-file/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
#include <iostream>

int main(int argc, char** argv) {

#if defined(_WIN32)
const std::string & defaultFile = "audio.wav";
#else
const std::string & defaultFile = "/dev/stdout";
#endif

fprintf(stderr, "Usage: %s [-vN] [-sN] [-pN] [-lN] [-d]\n", argv[0]);
fprintf(stderr, " -fF - output filename, (default: %s)\n", defaultFile.c_str());
fprintf(stderr, " -vN - output volume, N in (0, 100], (default: 50)\n");
fprintf(stderr, " -sN - output sample rate, N in [%d, %d], (default: %d)\n", (int) GGWave::kSampleRateMin, (int) GGWave::kSampleRateMax, (int) GGWave::kDefaultSampleRate);
fprintf(stderr, " -pN - select the transmission protocol id (default: 1)\n");
Expand Down Expand Up @@ -40,6 +48,7 @@ int main(int argc, char** argv) {
}

const int volume = argm.count("v") == 0 ? 50 : std::stoi(argm.at("v"));
const std::string & file = argm.count("f") == 0 ? defaultFile : argm.at("f");
const float sampleRateOut = argm.count("s") == 0 ? GGWave::kDefaultSampleRate : std::stof(argm.at("s"));
const int protocolId = argm.count("p") == 0 ? 1 : std::stoi(argm.at("p"));
const int payloadLength = argm.count("l") == 0 ? -1 : std::stoi(argm.at("l"));
Expand Down Expand Up @@ -107,6 +116,7 @@ int main(int argc, char** argv) {
std::vector<char> bufferPCM(nBytes);
std::memcpy(bufferPCM.data(), ggWave.txWaveform(), nBytes);

fprintf(stderr, "Output file = %s\n", file.c_str());
fprintf(stderr, "Output size = %d bytes\n", (int) bufferPCM.size());

drwav_data_format format;
Expand All @@ -119,7 +129,7 @@ int main(int argc, char** argv) {
fprintf(stderr, "Writing WAV data ...\n");

drwav wav;
drwav_init_file_write(&wav, "/dev/stdout", &format, NULL);
drwav_init_file_write(&wav, file.c_str(), &format, NULL);
drwav_uint64 framesWritten = drwav_write_pcm_frames(&wav, bufferPCM.size()/2, bufferPCM.data());

fprintf(stderr, "WAV frames written = %d\n", (int) framesWritten);
Expand Down

0 comments on commit c2716d8

Please sign in to comment.