]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/usb/device/audio/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / usb / device / audio / main.cpp
1 // Playback example with the USBAUDIO library
2
3 #include "mbed.h"
4 #include "USBAudio.h"
5
6 // frequency: 48 kHz
7 #define FREQ_SPK 48000
8 #define FREQ_MIC 48000
9
10 // 2channels: stereo
11 #define NB_CHA_SPK 2
12 #define NB_CHA_MIC 2
13
14 // length computed: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there are two channels, the length will be 48 * 2 * 2
15 #define LENGTH_AUDIO_PACKET_SPK (FREQ_SPK / 500) * NB_CHA_SPK
16 #define LENGTH_AUDIO_PACKET_MIC (FREQ_MIC / 500) * NB_CHA_MIC
17
18 // USBAudio object
19 USBAudio audio(FREQ_SPK, NB_CHA_SPK, FREQ_MIC, NB_CHA_MIC, 0xab45, 0x0378);
20
21 int main() {
22     // buffer of int
23     int buf_in[LENGTH_AUDIO_PACKET_SPK/sizeof(int)];
24     int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)];
25     int * stream_out = buf_in;
26     int * stream_in = buf_out;
27     int * tmp = NULL;
28
29     while (1) {
30         // read and write one audio packet each frame
31         audio.readWrite((uint8_t *)stream_in, (uint8_t *)stream_out);
32
33         // swap the buffers
34         tmp = stream_in;
35         stream_in = stream_out;
36         stream_out = tmp;
37     }
38 }
39
40