mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-04-19 20:57:38 +08:00
ggwave-to-file : get input from stdin
This commit is contained in:
@@ -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-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-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-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 |
|
| [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:
|
Other projects using **ggwave** or one of its prototypes:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
## ggwave-to-file
|
## ggwave-to-file
|
||||||
|
|
||||||
Output generated audio to a file.
|
Output generated waveform to a file.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./bin/ggwave-to-file "Hello World!" > example.wav
|
echo "Hello World!" | ./bin/ggwave-to-file > example.wav
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
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, " -pN - select the transmission protocol\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, " Available protocols:\n");
|
fprintf(stderr, " Available protocols:\n");
|
||||||
@@ -20,11 +21,14 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 1) {
|
||||||
return -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) {
|
if (message.size() == 0) {
|
||||||
fprintf(stderr, "Invalid message: size = 0\n");
|
fprintf(stderr, "Invalid message: size = 0\n");
|
||||||
@@ -42,6 +46,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
auto sampleRateOut = GGWave::kBaseSampleRate;
|
auto sampleRateOut = GGWave::kBaseSampleRate;
|
||||||
|
|
||||||
|
fprintf(stderr, "Generating waveform for message '%s' ...\n", message.c_str());
|
||||||
|
|
||||||
GGWave ggWave(GGWave::kBaseSampleRate, sampleRateOut, 1024, 4, 2);
|
GGWave ggWave(GGWave::kBaseSampleRate, sampleRateOut, 1024, 4, 2);
|
||||||
ggWave.init(message.size(), message.data(), ggWave.getTxProtocols()[protocolId], volume);
|
ggWave.init(message.size(), message.data(), ggWave.getTxProtocols()[protocolId], volume);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user