arduino-audio-tools
AnalogConfigStd.h
1 #pragma once
2 #include "AudioConfig.h"
3 #include "AudioTools/CoreAudio/AudioTypes.h"
4 
5 #ifndef PIN_ANALOG_START
6 # define PIN_ANALOG_START -1
7 #endif
8 
9 #ifndef ANALOG_BUFFERS
10 # define ANALOG_BUFFERS 10
11 #endif
12 
13 #ifndef ANALOG_MAX_OUT_CHANNELS
14 # define ANALOG_MAX_OUT_CHANNELS 10
15 #endif
16 
17 
18 namespace audio_tools {
19 
20 class AnalogAudioArduino;
21 
29 class AnalogConfigStd : public AudioInfo {
30  friend class AnalogAudioArduino;
31  public:
32  int buffer_count = ANALOG_BUFFERS;
33  int buffer_size = ANALOG_BUFFER_SIZE;
34  RxTxMode rx_tx_mode = RX_MODE;
35  bool is_blocking_write = true;
36  bool is_auto_center_read = true;
37  int max_sample_rate = ANALOG_MAX_SAMPLE_RATE;
38  int start_pin = PIN_ANALOG_START;
39 
40  AnalogConfigStd() = default;
41  AnalogConfigStd(RxTxMode rxtxMode) : AudioInfo() {
42  rx_tx_mode = rxtxMode;
43  }
44 
46  template <typename T, int N>
47  void setPins(T (&a)[N]) {
48  pins_data.clear();
49  pins_data.resize(N);
50  for (int i = 0; i < N; ++i) {
51  pins_data[i] = a[i]; // reset all elements
52  }
53  }
54 
55  // /// Defines the pins and the corresponding number of channels (=number of
56  // /// pins)
57  // void setPins(Pins &pins) {
58  // pins_data.clear();
59  // for (int i = 0; i < pins.size(); i++) {
60  // pins_data.push_back(pins[i]);
61  // }
62  // }
63 
65  Pins &pins() {
66  if (pins_data.size() == 0 && start_pin >= 0) {
67  pins_data.resize(channels);
68  for (int j = 0; j < channels; j++) {
69  pins_data[j] = start_pin + j;
70  }
71  }
72  return pins_data;
73  }
74 
75  protected:
76  Pins pins_data{0};
77 
78 };
79 
80 #ifndef ANALOG_CONFIG
81 #define ANALOG_CONFIG
82 using AnalogConfig = AnalogConfigStd;
83 #endif
84 
85 } // ns
86 #//endif
Analog Data IO using a timer and the Arduino analogRead() method and writing using analogWrite();.
Definition: AnalogAudioArduino.h:22
Generic ADC and DAC configuration.
Definition: AnalogConfigStd.h:29
Pins & pins()
Determines the pins (for all channels)
Definition: AnalogConfigStd.h:65
void setPins(T(&a)[N])
support assignament of int array
Definition: AnalogConfigStd.h:47
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:28
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
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:57
AudioInfo()=default
Default constructor.