USB Audio Oscilloscope

Dependencies:   USBDevice mbed

Fork of USBAudioPlayback by Samuel Mokrani

Committer:
K_O_Carnivist
Date:
Tue Dec 01 09:10:31 2015 +0000
Revision:
3:762585288ed5
Parent:
0:eb53799c0b97
First publish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:eb53799c0b97 1 #include "mbed.h"
samux 0:eb53799c0b97 2 #include "USBAudio.h"
samux 0:eb53799c0b97 3
K_O_Carnivist 3:762585288ed5 4 #define FREQ 48000
K_O_Carnivist 3:762585288ed5 5 #define NUMBER_CHANNEL 2
K_O_Carnivist 3:762585288ed5 6 #define LENGTH_AUDIO_PACKET (FREQ / 500) * NUMBER_CHANNEL
K_O_Carnivist 3:762585288ed5 7
K_O_Carnivist 3:762585288ed5 8 // USB Audio object
K_O_Carnivist 3:762585288ed5 9 USBAudio audio(FREQ, NUMBER_CHANNEL, FREQ, NUMBER_CHANNEL, 0xab45, 0x0378);
samux 0:eb53799c0b97 10
K_O_Carnivist 3:762585288ed5 11 // Analog input objects
K_O_Carnivist 3:762585288ed5 12 AnalogIn pot0(p17);
K_O_Carnivist 3:762585288ed5 13 AnalogIn pot1(p18);
samux 0:eb53799c0b97 14
K_O_Carnivist 3:762585288ed5 15 // Input and output buffers
K_O_Carnivist 3:762585288ed5 16 int16_t buf_in[LENGTH_AUDIO_PACKET/sizeof(int16_t)][2];
K_O_Carnivist 3:762585288ed5 17 int16_t buf_out[LENGTH_AUDIO_PACKET/sizeof(int16_t)][2];
samux 0:eb53799c0b97 18
K_O_Carnivist 3:762585288ed5 19 int main()
K_O_Carnivist 3:762585288ed5 20 {
K_O_Carnivist 3:762585288ed5 21 while (1)
K_O_Carnivist 3:762585288ed5 22 {
K_O_Carnivist 3:762585288ed5 23 // read and write one audio packet each frame
K_O_Carnivist 3:762585288ed5 24 audio.readWrite((uint8_t *)buf_in, (uint8_t *)buf_out);
K_O_Carnivist 3:762585288ed5 25
K_O_Carnivist 3:762585288ed5 26 int16_t analog_input[2] = {pot0.read_u16() / 64, pot1.read_u16() / 64};
samux 0:eb53799c0b97 27
K_O_Carnivist 3:762585288ed5 28 for (int i = 0; i < LENGTH_AUDIO_PACKET/sizeof(int16_t); i++)
K_O_Carnivist 3:762585288ed5 29 {
K_O_Carnivist 3:762585288ed5 30 buf_out[i][0] = analog_input[0];
K_O_Carnivist 3:762585288ed5 31 buf_out[i][1] = analog_input[1];
K_O_Carnivist 3:762585288ed5 32 }
samux 0:eb53799c0b97 33 }
samux 0:eb53799c0b97 34 }