arduino-audio-tools
I2SConfigStd.h
1 #pragma once
2 #include "AudioConfig.h"
3 #include "AudioTools/AudioTypes.h"
4 
5 #ifndef PIN_I2S_MCK
6 # define PIN_I2S_MCK -1
7 #endif
8 
9 namespace audio_tools {
10 
17 class I2SConfigStd : public AudioInfo {
18  public:
19 
20  I2SConfigStd() {
21  channels = DEFAULT_CHANNELS;
22  sample_rate = DEFAULT_SAMPLE_RATE;
23  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
24  }
25 
27  I2SConfigStd(const I2SConfigStd &cfg) = default;
28 
31  channels = DEFAULT_CHANNELS;
32  sample_rate = DEFAULT_SAMPLE_RATE;
33  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
34  rx_tx_mode = mode;
35  switch(mode){
36  case RX_MODE:
37  pin_data = PIN_I2S_DATA_IN;
38  break;
39  case TX_MODE:
40  pin_data = PIN_I2S_DATA_OUT;
41  break;
42  default:
43  pin_data = PIN_I2S_DATA_OUT;
44  pin_data_rx = PIN_I2S_DATA_IN;
45  break;
46  }
47  }
48 
50  RxTxMode rx_tx_mode = TX_MODE;
51  bool is_master = true;
52  //int port_no = 0; // processor dependent port
53  int pin_ws = PIN_I2S_WS;
54  int pin_bck = PIN_I2S_BCK;
55  int pin_data; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
56  int pin_data_rx; // rx pin for RXTX_MODE
57  int pin_mck = PIN_I2S_MCK;
58  I2SFormat i2s_format = I2S_STD_FORMAT;
59 
60  int buffer_count = I2S_BUFFER_COUNT;
61  int buffer_size = I2S_BUFFER_SIZE;
62 
63 #if defined(RP2040_HOWER)
65  int mck_multiplier = 64;
66  I2SSignalType signal_type = Digital; // e.g. the RP2040 supports digial or PDM
67 #endif
68 
69 #if defined(USE_ALT_PIN_SUPPORT)
70  bool is_arduino_pin_numbers = true;
71 #endif
72 
73  void logInfo(const char* source="") {
74  AudioInfo::logInfo(source);
75  LOGI("rx/tx mode: %s", RxTxModeNames[rx_tx_mode]);
76  //LOGI("port_no: %d", port_no);
77  LOGI("is_master: %s", is_master ? "Master":"Slave");
78  LOGI("sample rate: %d", sample_rate);
79  LOGI("bits per sample: %d", bits_per_sample);
80  LOGI("number of channels: %d", channels);
81  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
82  LOGI("buffer_count:%d",buffer_count);
83  LOGI("buffer_size:%d",buffer_size);
84  if (pin_mck!=-1)
85  LOGI("pin_mck: %d", pin_mck);
86  if (pin_bck!=-1)
87  LOGI("pin_bck: %d", pin_bck);
88  if (pin_ws!=-1)
89  LOGI("pin_ws: %d", pin_ws);
90  if (pin_data!=-1)
91  LOGI("pin_data: %d", pin_data);
92  if (pin_data_rx!=-1 && rx_tx_mode==RXTX_MODE){
93  LOGI("pin_data_rx: %d", pin_data_rx);
94  }
95  }
96 
97 };
98 
99 using I2SConfig = I2SConfigStd;
100 
101 }
102 
Configuration for i2s.
Definition: I2SConfigStd.h:17
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigStd.h:50
I2SConfigStd(const I2SConfigStd &cfg)=default
Default Copy Constructor.
I2SConfigStd(RxTxMode mode)
Constructor.
Definition: I2SConfigStd.h:30
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:26
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10
I2SSignalType
I2S Signal Types: Digital, Analog, PDM.
Definition: AudioTypes.h:405
I2SFormat
I2S Formats.
Definition: AudioTypes.h:390
static const char * RxTxModeNames[]
Text string (description) for RxTxMode.
Definition: AudioTypes.h:38
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:50
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:53
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:55
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:57