Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // Playback example with the USBAUDIO library 00002 00003 #include "mbed.h" 00004 #include "USBAudio.h" 00005 00006 // frequency: 48 kHz 00007 #define FREQ_SPK 48000 00008 #define FREQ_MIC 48000 00009 00010 // 2channels: stereo 00011 #define NB_CHA_SPK 2 00012 #define NB_CHA_MIC 2 00013 00014 // length computed: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there are two channels, the length will be 48 * 2 * 2 00015 #define LENGTH_AUDIO_PACKET_SPK (FREQ_SPK / 500) * NB_CHA_SPK 00016 #define LENGTH_AUDIO_PACKET_MIC (FREQ_MIC / 500) * NB_CHA_MIC 00017 00018 // USBAudio object 00019 USBAudio audio(FREQ_SPK, NB_CHA_SPK, FREQ_MIC, NB_CHA_MIC, 0xab45, 0x0378); 00020 00021 int main() { 00022 // buffer of int 00023 int buf_in[LENGTH_AUDIO_PACKET_SPK/sizeof(int)]; 00024 int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)]; 00025 int * stream_out = buf_in; 00026 int * stream_in = buf_out; 00027 int * tmp = NULL; 00028 00029 while (1) { 00030 // read and write one audio packet each frame 00031 audio.readWrite((uint8_t *)stream_in, (uint8_t *)stream_out); 00032 00033 // swap the buffers 00034 tmp = stream_in; 00035 stream_in = stream_out; 00036 stream_out = tmp; 00037 } 00038 } 00039 00040
Generated on Sun Jul 17 2022 08:25:26 by 1.7.2