![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
USB Audio Oscilloscope
Fork of USBAudioPlayback by
main.cpp@0:eb53799c0b97, 2012-03-22 (annotated)
- Committer:
- samux
- Date:
- Thu Mar 22 14:02:07 2012 +0000
- Revision:
- 0:eb53799c0b97
- Child:
- 3:762585288ed5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:eb53799c0b97 | 1 | // Playback example with the USBAUDIO library |
samux | 0:eb53799c0b97 | 2 | |
samux | 0:eb53799c0b97 | 3 | #include "mbed.h" |
samux | 0:eb53799c0b97 | 4 | #include "USBAudio.h" |
samux | 0:eb53799c0b97 | 5 | |
samux | 0:eb53799c0b97 | 6 | // frequency: 48 kHz |
samux | 0:eb53799c0b97 | 7 | #define FREQ_SPK 48000 |
samux | 0:eb53799c0b97 | 8 | #define FREQ_MIC 48000 |
samux | 0:eb53799c0b97 | 9 | |
samux | 0:eb53799c0b97 | 10 | // 2channels: stereo |
samux | 0:eb53799c0b97 | 11 | #define NB_CHA_SPK 2 |
samux | 0:eb53799c0b97 | 12 | #define NB_CHA_MIC 2 |
samux | 0:eb53799c0b97 | 13 | |
samux | 0:eb53799c0b97 | 14 | // length computed: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there are two channels, the length will be 48 * 2 * 2 |
samux | 0:eb53799c0b97 | 15 | #define LENGTH_AUDIO_PACKET_SPK (FREQ_SPK / 500) * NB_CHA_SPK |
samux | 0:eb53799c0b97 | 16 | #define LENGTH_AUDIO_PACKET_MIC (FREQ_MIC / 500) * NB_CHA_MIC |
samux | 0:eb53799c0b97 | 17 | |
samux | 0:eb53799c0b97 | 18 | // USBAudio object |
samux | 0:eb53799c0b97 | 19 | USBAudio audio(FREQ_SPK, NB_CHA_SPK, FREQ_MIC, NB_CHA_MIC, 0xab45, 0x0378); |
samux | 0:eb53799c0b97 | 20 | |
samux | 0:eb53799c0b97 | 21 | int main() { |
samux | 0:eb53799c0b97 | 22 | // buffer of int |
samux | 0:eb53799c0b97 | 23 | int buf_in[LENGTH_AUDIO_PACKET_SPK/sizeof(int)]; |
samux | 0:eb53799c0b97 | 24 | int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)]; |
samux | 0:eb53799c0b97 | 25 | int * stream_out = buf_in; |
samux | 0:eb53799c0b97 | 26 | int * stream_in = buf_out; |
samux | 0:eb53799c0b97 | 27 | int * tmp = NULL; |
samux | 0:eb53799c0b97 | 28 | |
samux | 0:eb53799c0b97 | 29 | while (1) { |
samux | 0:eb53799c0b97 | 30 | // read and write one audio packet each frame |
samux | 0:eb53799c0b97 | 31 | audio.readWrite((uint8_t *)stream_in, (uint8_t *)stream_out); |
samux | 0:eb53799c0b97 | 32 | |
samux | 0:eb53799c0b97 | 33 | // swap the buffers |
samux | 0:eb53799c0b97 | 34 | tmp = stream_in; |
samux | 0:eb53799c0b97 | 35 | stream_in = stream_out; |
samux | 0:eb53799c0b97 | 36 | stream_out = tmp; |
samux | 0:eb53799c0b97 | 37 | } |
samux | 0:eb53799c0b97 | 38 | } |
samux | 0:eb53799c0b97 | 39 | |
samux | 0:eb53799c0b97 | 40 |