Arduino AudioKit HAL
AudioKitConfig.h
1 #pragma once
2 
3 /**
4  * @brief AUDIOKIT_BOARD selects a specic board:
5  * 1) lyrat_v4_3
6  * 2) lyrat_v4_2
7  * 3) lyrat_mini_v1_1
8  * 4) lyratd_msc_v2_2
9  * 5) lyratd_msc_v2_1
10  * 6) ai_thinker_v2_2
11  * 7) esp32_s2_kaluga_1_v1_2
12  */
13 
14 #define AUDIOKIT_BOARD 1
15 
16 #define AUDIOKIT_DEFAULT_INPUT AUDIO_HAL_ADC_INPUT_LINE1
17 #define AUDIOKIT_DEFAULT_OUTPUT AUDIO_HAL_DAC_OUTPUT_ALL
18 #define AUDIOKIT_DEFAULT_MASTER_SLAVE AUDIO_HAL_MODE_SLAVE
19 #define AUDIOKIT_DEFAULT_RATE AUDIO_HAL_44K_SAMPLES
20 #define AUDIOKIT_DEFAULT_BITSIZE AUDIO_HAL_BIT_LENGTH_16BITS
21 #define AUDIOKIT_DEFAULT_I2S_FMT AUDIO_HAL_I2S_NORMAL
22 
23 /**
24  * @brief Configuation for AudioKit
25  *
26  */
28  int i2s_num = 0;
29 
30  audio_hal_adc_input_t adc_input=AUDIOKIT_DEFAULT_INPUT; /*!< set adc channel with audio_hal_adc_input_t */
31  audio_hal_dac_output_t dac_output=AUDIOKIT_DEFAULT_OUTPUT; /*!< set dac channel */
32  audio_hal_codec_mode_t codec_mode; /*!< select codec mode: adc, dac or both */
33  audio_hal_iface_mode_t master_slave_mode=AUDIOKIT_DEFAULT_MASTER_SLAVE; /*!< audio codec chip mode */
34  audio_hal_iface_format_t fmt=AUDIOKIT_DEFAULT_I2S_FMT; /*!< I2S interface format */
35  audio_hal_iface_samples_t samples = AUDIOKIT_DEFAULT_RATE; /*!< I2S interface samples per second */
36  audio_hal_iface_bits_t bits = AUDIOKIT_DEFAULT_BITSIZE; /*!< i2s interface number of bits per sample */
37 
38  /// Returns true if the CODEC is the master
39  bool isMaster() {
41  }
42 
43  /// provides the bits per sample
45  switch(bits){
47  return 16;
48  case cAUDIO_HAL_BIT_LENGTH_24BITS:
49  return 24;
51  return 32;
52  }
53  return 0;
54  }
55 
56  /// Provides the sample rate in samples per second
57  int sampleRate() {
58  switch(samples){
59  case AUDIO_HAL_08K_SAMPLES: /*!< set to 8k samples per second */
60  return 8000;
61  case AUDIO_HAL_11K_SAMPLES: /*!< set to 11.025k samples per second */
62  return 11000;
63  case AUDIO_HAL_16K_SAMPLES: /*!< set to 16k samples in per second */
64  return 16000;
65  case AUDIO_HAL_22K_SAMPLES: /*!< set to 22.050k samples per second */
66  return 22000;
67  case AUDIO_HAL_24K_SAMPLES: /*!< set to 24k samples in per second */
68  return 24000;
69  case AUDIO_HAL_32K_SAMPLES: /*!< set to 32k samples in per second */
70  return 32000;
71  case AUDIO_HAL_44K_SAMPLES: /*!< set to 44.1k samples per second */
72  return 44000;
73  case AUDIO_HAL_48K_SAMPLES: /*!< set to 48k samples per second */
74  return 48000;
75  }
76  return 0;
77  }
78 
79  /// Provides the ESP32 i2s_config_t
80  i2s_config_t i2sConfig(){
81  int mode = isMaster()? I2S_MODE_MASTER : I2S_MODE_SLAVE;
83  mode = mode | I2S_MODE_TX;
85  mode = mode | I2S_MODE_RX;
87  mode = mode | I2S_MODE_RX | I2S_MODE_TX;
88  }
89 
90  const i2s_config_t i2s_config = {
91  .mode = mode,
92  .sample_rate = sampleRate(),
93  .bits_per_sample = bitsPerSample(),
94  .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
95  .communication_format = I2S_COMM_FORMAT_STAND_I2S,
96  .intr_alloc_flags = 0, // default interrupt priority
97  .dma_buf_count = 8,
98  .dma_buf_len = 64,
99  .use_apll = true
100  };
101  return i2s_config;
102  }
103 
104  i2s_pin_config_t i2sPins(){
105  i2s_pin_config_t result;
106  }
107 
108 };
109 
audio_hal_codec_mode_t
Select media hal codec mode.
Definition: audio_hal.h:45
@ AUDIO_HAL_CODEC_MODE_BOTH
Definition: audio_hal.h:48
@ AUDIO_HAL_CODEC_MODE_ENCODE
Definition: audio_hal.h:46
@ AUDIO_HAL_CODEC_MODE_DECODE
Definition: audio_hal.h:47
audio_hal_iface_bits_t
Select I2S interface number of bits per sample.
Definition: audio_hal.h:104
@ AUDIO_HAL_BIT_LENGTH_16BITS
Definition: audio_hal.h:105
@ AUDIO_HAL_BIT_LENGTH_32BITS
Definition: audio_hal.h:107
audio_hal_iface_mode_t
Select I2S interface operating mode i.e. master or slave for audio codec chip.
Definition: audio_hal.h:82
@ AUDIO_HAL_MODE_MASTER
Definition: audio_hal.h:84
audio_hal_dac_output_t
Select channel for dac output.
Definition: audio_hal.h:65
audio_hal_adc_input_t
Select adc channel for input mic signal.
Definition: audio_hal.h:55
audio_hal_iface_samples_t
Select I2S interface samples per second.
Definition: audio_hal.h:90
@ AUDIO_HAL_08K_SAMPLES
Definition: audio_hal.h:91
@ AUDIO_HAL_16K_SAMPLES
Definition: audio_hal.h:93
@ AUDIO_HAL_24K_SAMPLES
Definition: audio_hal.h:95
@ AUDIO_HAL_32K_SAMPLES
Definition: audio_hal.h:96
@ AUDIO_HAL_11K_SAMPLES
Definition: audio_hal.h:92
@ AUDIO_HAL_22K_SAMPLES
Definition: audio_hal.h:94
@ AUDIO_HAL_44K_SAMPLES
Definition: audio_hal.h:97
@ AUDIO_HAL_48K_SAMPLES
Definition: audio_hal.h:98
audio_hal_iface_format_t
Select I2S interface format for audio codec chip.
Definition: audio_hal.h:113
Configuation for AudioKit.
audio_hal_iface_bits_t bits
audio_hal_iface_samples_t samples
int bitsPerSample()
provides the bits per sample
int sampleRate()
Provides the sample rate in samples per second.
audio_hal_dac_output_t dac_output
bool isMaster()
Returns true if the CODEC is the master.
audio_hal_adc_input_t adc_input
audio_hal_iface_format_t fmt
i2s_config_t i2sConfig()
Provides the ESP32 i2s_config_t.
audio_hal_iface_mode_t master_slave_mode
audio_hal_codec_mode_t codec_mode