Arduino STK  4.6.2
ArdI2SOut.h
1 #include "ArdConfig.h"
2 #ifdef __I2S__
3 
4 #ifndef ARDI2SOUT_H
5 #define ARDI2SOUT_H
6 
7 #include "Stk.h"
8 #include "WvOut.h"
9 #include "ArdCommonOut.h"
10 #ifdef ESP32
11 #include "driver/i2s.h"
12 #endif
13 #ifdef ESP8266
14 #include "I2S.h"
15 #endif
16 
17 #define SAMPLE_RATE (36000)
18 #define I2S_NUM (0)
19 #define I2S_BCK_IO (GPIO_NUM_13)
20 #define I2S_WS_IO (GPIO_NUM_15)
21 #define I2S_DO_IO (GPIO_NUM_21)
22 #define I2S_DI_IO (-1)
23 
24 
25 typedef int (*RtESPAudioCallback)( void *outputBuffer,
26  unsigned int nFrames,
27  void *userData );
28 
29  static i2s_config_t default_i2s_config = {
30  .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
31  .sample_rate = SAMPLE_RATE, // corrected by info from bluetooth
32  .bits_per_sample = (i2s_bits_per_sample_t) sizeof(stk::StkFloat),
33  .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
34  .communication_format = I2S_COMM_FORMAT_I2S_MSB,
35  .intr_alloc_flags = 0, // default interrupt priority
36  .dma_buf_count = 8,
37  .dma_buf_len = 64,
38  .use_apll = false
39 };
40 
41 static i2s_pin_config_t default_pin_config = {
42  .bck_io_num = I2S_BCK_IO,
43  .ws_io_num = I2S_WS_IO,
44  .data_out_num = I2S_DO_IO,
45  .data_in_num = I2S_DI_IO
46 };
47 
48 namespace stk {
49 
50 /***************************************************/
67 /***************************************************/
68 
69 class ArdI2SOut: public ArdCommonOut {
70  public:
71  ArdI2SOut(unsigned channels=1, i2s_port_t i2s_number=(i2s_port_t)0);
72  void begin();
73  void setPinConfig(i2s_pin_config_t& pin_config);
74  void setI2SConfig(i2s_config_t& i2s_config);
75 
76  protected:
77  int byteCount;
78  i2s_config_t& i2s_config=default_i2s_config;
79  i2s_pin_config_t& pin_config = default_pin_config;
80  i2s_port_t i2s_number;
81  bool active = false;
82 
83  virtual void write(StkFloat value) override;
84  virtual void write(int16_t value) override;
85 
86 };
87 
88 }; //stk
89 #endif
90 #endif
STK Common Output for Arduiono.
Definition: ArdCommonOut.h:23
Output of sound to the I2S pins of the ESP32.
Definition: ArdI2SOut.h:69
The STK namespace.
Definition: ADSR.h:8