ggwave-to-file : get input from stdin

This commit is contained in:
Georgi Gerganov
2021-01-09 14:39:05 +02:00
parent 0cf5da1a4d
commit a25ad60da4
3 changed files with 12 additions and 6 deletions

View File

@@ -72,7 +72,7 @@ The [examples](https://github.com/ggerganov/ggwave/blob/master/examples/) folder
| [ggwave-rx](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-rx) | Very basic receive-only program | SDL |
| [ggwave-cli](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-cli) | Command line tool for sending/receiving data through sound | SDL |
| [ggwave-wasm](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-wasm) | WebAssembly module for web applications | SDL |
| [ggwave-to-file](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-to-file) | Output generated audio to a file | - |
| [ggwave-to-file](https://github.com/ggerganov/ggwave/blob/master/examples/ggwave-to-file) | Output generated waveform to a file | - |
| [waver](https://github.com/ggerganov/ggwave/blob/master/examples/waver) | GUI tool for sending/receiving data through sound | SDL |
Other projects using **ggwave** or one of its prototypes:

View File

@@ -1,7 +1,7 @@
## ggwave-to-file
Output generated audio to a file.
Output generated waveform to a file.
```bash
./bin/ggwave-to-file "Hello World!" > example.wav
echo "Hello World!" | ./bin/ggwave-to-file > example.wav
```

View File

@@ -7,9 +7,10 @@
#include <cstdio>
#include <cstring>
#include <iostream>
int main(int argc, char** argv) {
fprintf(stderr, "Usage: %s \"message\" output.wav [-pN]\n", argv[0]);
fprintf(stderr, "Usage: %s [-pN]\n", argv[0]);
fprintf(stderr, " -pN - select the transmission protocol\n");
fprintf(stderr, "\n");
fprintf(stderr, " Available protocols:\n");
@@ -20,11 +21,14 @@ int main(int argc, char** argv) {
}
fprintf(stderr, "\n");
if (argc < 2) {
if (argc < 1) {
return -1;
}
std::string message = argv[1];
fprintf(stderr, "Enter a text message:\n");
std::string message;
std::getline(std::cin, message);
if (message.size() == 0) {
fprintf(stderr, "Invalid message: size = 0\n");
@@ -42,6 +46,8 @@ int main(int argc, char** argv) {
auto sampleRateOut = GGWave::kBaseSampleRate;
fprintf(stderr, "Generating waveform for message '%s' ...\n", message.c_str());
GGWave ggWave(GGWave::kBaseSampleRate, sampleRateOut, 1024, 4, 2);
ggWave.init(message.size(), message.data(), ggWave.getTxProtocols()[protocolId], volume);