Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBAudioPlayback by
Revision 3:762585288ed5, committed 2015-12-01
- Comitter:
- K_O_Carnivist
- Date:
- Tue Dec 01 09:10:31 2015 +0000
- Parent:
- 2:6d4dcaa2c065
- Commit message:
- First publish
Changed in this revision
--- a/USBDevice.lib Fri Mar 01 13:22:17 2013 +0000 +++ b/USBDevice.lib Tue Dec 01 09:10:31 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/USBDevice/#335f2506f422 +http://mbed.org/users/mbed_official/code/USBDevice/#2af474687369
--- a/main.cpp Fri Mar 01 13:22:17 2013 +0000 +++ b/main.cpp Tue Dec 01 09:10:31 2015 +0000 @@ -1,40 +1,34 @@ -// Playback example with the USBAUDIO library - #include "mbed.h" #include "USBAudio.h" -// frequency: 48 kHz -#define FREQ_SPK 48000 -#define FREQ_MIC 48000 +#define FREQ 48000 +#define NUMBER_CHANNEL 2 +#define LENGTH_AUDIO_PACKET (FREQ / 500) * NUMBER_CHANNEL + +// USB Audio object +USBAudio audio(FREQ, NUMBER_CHANNEL, FREQ, NUMBER_CHANNEL, 0xab45, 0x0378); -// 2channels: stereo -#define NB_CHA_SPK 2 -#define NB_CHA_MIC 2 +// Analog input objects +AnalogIn pot0(p17); +AnalogIn pot1(p18); -// length computed: each ms, we receive 48 * 16bits ->48 * 2 bytes. as there are two channels, the length will be 48 * 2 * 2 -#define LENGTH_AUDIO_PACKET_SPK (FREQ_SPK / 500) * NB_CHA_SPK -#define LENGTH_AUDIO_PACKET_MIC (FREQ_MIC / 500) * NB_CHA_MIC - -// USBAudio object -USBAudio audio(FREQ_SPK, NB_CHA_SPK, FREQ_MIC, NB_CHA_MIC, 0xab45, 0x0378); +// Input and output buffers +int16_t buf_in[LENGTH_AUDIO_PACKET/sizeof(int16_t)][2]; +int16_t buf_out[LENGTH_AUDIO_PACKET/sizeof(int16_t)][2]; -int main() { - // buffer of int - int buf_in[LENGTH_AUDIO_PACKET_SPK/sizeof(int)]; - int buf_out[LENGTH_AUDIO_PACKET_MIC/sizeof(int)]; - int * stream_out = buf_in; - int * stream_in = buf_out; - int * tmp = NULL; +int main() +{ + while (1) + { + // read and write one audio packet each frame + audio.readWrite((uint8_t *)buf_in, (uint8_t *)buf_out); + + int16_t analog_input[2] = {pot0.read_u16() / 64, pot1.read_u16() / 64}; - while (1) { - // read and write one audio packet each frame - audio.readWrite((uint8_t *)stream_in, (uint8_t *)stream_out); - - // swap the buffers - tmp = stream_in; - stream_in = stream_out; - stream_out = tmp; + for (int i = 0; i < LENGTH_AUDIO_PACKET/sizeof(int16_t); i++) + { + buf_out[i][0] = analog_input[0]; + buf_out[i][1] = analog_input[1]; + } } } - -
--- a/mbed.bld Fri Mar 01 13:22:17 2013 +0000 +++ b/mbed.bld Tue Dec 01 09:10:31 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file