arduino-audio-tools
StdioStream.h
1 #pragma once
2 #include <unistd.h>
3 #include "AudioTools/CoreAudio/AudioStreams.h"
4 
5 namespace audio_tools {
6 
14 class StdioStream : public BaseStream {
15 public:
16  AudioInfo defaultConfig() {
17  AudioInfo def;
18  def.bits_per_sample = 16;
19  def.sample_rate = 44100;
20  def.channels = 2;
21  return def;
22  }
23 
24  bool begin() {
25  is_open = true;
26  return true;
27  }
28 
29 
30  int available() override { return DEFAULT_BUFFER_SIZE; }
31 
32  size_t readBytes(uint8_t* data, size_t len) override {
33  // read from stdin
34  return ::read(0, data, len);
35  }
36 
37  int availableForWrite() override { return DEFAULT_BUFFER_SIZE; }
38 
39  size_t write(const uint8_t *data, size_t len) override {
40  if (!is_open)
41  return 0;
42  // write to stdout
43  return ::write(1, data, len);
44  }
45 
46  void end() {
47  is_open = false;
48  }
49 
50 protected:
51  bool is_open = false;
52 };
53 
54 } // namespace audio_tools
Base class for all Streams. It relies on write(const uint8_t *buffer, size_t size) and readBytes(uint...
Definition: BaseStream.h:34
Direct binary Audio Output to stdout. On linux you can hear the audio e.g. with ./generator | aplay -...
Definition: StdioStream.h:14
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:823
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:52
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:55
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:57
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:59