-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathI2SMaster.h
89 lines (70 loc) · 1.88 KB
/
I2SMaster.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Created by Evixar Inc.
// Copyright © 2018 Evixar Inc. All rights reserved.
//
#ifndef __I2SMASTER_H__
#define __I2SMASTER_H__
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2s.h"
#include <vector>
using namespace std;
#define AUDIO_CHANNELS (2)
#define AUDIO_CHANNEL_LEFT (0)
#define AUDIO_CHANNEL_RIGHT (1)
#define AUDIO_CHANNEL_NONE (2)
#ifndef I2S_BCLK
#define I2S_BCLK (25)
#endif
#ifndef I2S_ADC_DATA
#define I2S_ADC_DATA (27)
#endif
#ifndef I2S_DAC_DATA
#define I2S_DAC_DATA (17)
#endif
#ifndef I2S_ADC_LRCLK
#define I2S_ADC_LRCLK (26)
#endif
#ifdef OLD_GOOYA
#define I2S_ADC_DATA (2)
#endif
#ifndef I2S_BITS_PER_SAMPLE
#define I2S_BITS_PER_SAMPLE I2S_BITS_PER_SAMPLE_16BIT
#endif
#ifndef DMA_AUDIO_FRAMES
#define DMA_AUDIO_FRAMES (256)
#endif
#define DMA_BUFFER_SIZE (I2S_BITS_PER_SAMPLE/8*DMA_AUDIO_FRAMES*AUDIO_CHANNELS)
#ifndef DMA_BUFFER_COUNT
#define DMA_BUFFER_COUNT (2)
#endif
#define DMA_TOTAL_BUFFER_SIZE (DMA_BUFFER_SIZE*DMA_BUFFER_COUNT)
typedef void (* I2S_AUDIOCALLBACK)(int16_t* buffer, int8_t chs, int32_t frames, void* param);
class I2SMaster
{
public:
// cpu_number: 0 or 1
I2SMaster();
void initialize(int sample_rate, int cpu_number,
I2S_AUDIOCALLBACK inputcallback,
I2S_AUDIOCALLBACK outputcallback,
void* param);
void start();
void stop();
static void audio_input_task(void* pvParameters);
static void audio_output_task(void* pvParameters);
private:
i2s_pin_config_t i2s_pin_config;
i2s_config_t i2s_config;
bool started;
void* param;
uint8_t inputbuffer[DMA_TOTAL_BUFFER_SIZE];
uint8_t outputbuffer[DMA_TOTAL_BUFFER_SIZE];
I2S_AUDIOCALLBACK inputcallback;
I2S_AUDIOCALLBACK outputcallback;
// task
int cpu_number;
TaskHandle_t input_task;
TaskHandle_t output_task;
};
#endif//