Production Test Program (PTP) for the LPC4088 Experiment Base Board
Dependencies: EALib I2S LM75B SDFileSystem mbed
Diff: TestAudio.cpp
- Revision:
- 4:aa34674b6afb
- Parent:
- 3:7ef908e84ae1
- Child:
- 5:3eb61b96b6ac
--- a/TestAudio.cpp Mon Sep 08 11:34:53 2014 +0000 +++ b/TestAudio.cpp Tue Sep 09 09:57:11 2014 +0000 @@ -17,6 +17,7 @@ /****************************************************************************** * Includes *****************************************************************************/ +//#define SOUND_8KHZ #include "mbed.h" #include "TestAudio.h" @@ -45,8 +46,11 @@ // Check if wave-file shall be output if (_waveIdx > 0) { - _txBuf[i] = sound_8k[_waveIdx/4] << 5; - _txBuf[i+1] = sound_8k[_waveIdx/4] << 5; +#if SOUND_8KHZ + int sample = sound_8k[_waveIdx/4] << 5 + _txBuf[i] = sample; + _txBuf[i+1] = sample; + _echoBuf[_echoBufPtr] = _rxBuf[i]; //Increment wave samples pointer and check if all samples have been read, if so, set pointer to zero _waveIdx++; @@ -54,6 +58,19 @@ { _waveIdx = 0; } +#else + int sample = (unsigned int)sound_32k[_waveIdx] | (((unsigned int)sound_32k[_waveIdx+1]) << 8); + _txBuf[i] = sample; + _txBuf[i+1] = sample; + _echoBuf[_echoBufPtr] = _rxBuf[i]; + + //Increment wave samples pointer and check if all samples have been read, if so, set pointer to zero + _waveIdx += 2; + if (_waveIdx > sound_sz) + { + _waveIdx = 0; + } +#endif } //Output delayed version of audio input else @@ -97,11 +114,14 @@ } bool TestAudio::runTest() { - printf("Testing audio...\n"); + printf("Testing audio... Exit by pressing joystick up\n"); + printf("Joystick down = play short wave-file. Youstick right/left = tunr microhone boost on/off\n"); // joystick used for audio selection DigitalIn up(p32); DigitalIn down(p38); + DigitalIn left(p39); + DigitalIn right(p37); _codec.power(true); _codec.frequency(SAMPLERATE); @@ -109,41 +129,63 @@ _codec.master(true); _codec.headphone_volume(0.1); _codec.input_select(WM8731_MIC); - _codec.microphone_boost(false); + _codec.microphone_boost(true); _codec.input_mute(false); _codec.output_mute(false); _codec.input_power(true); _codec.output_power(true); -// _codec.sidetone(0.99); _codec.linein_volume(0.7); _codec.bypass(true); _codec.start(); + _i2sRx.frequency(SAMPLERATE); + _i2sRx.wordsize(16); + _i2sRx.stereomono(I2S_STEREO); + _i2sRx.masterslave(I2S_SLAVE); + _i2sRx.attach(this, &TestAudio::echo); + _i2sRx.set_interrupt_fifo_level(1); + _echoBufPtr = 0; + _waveIdx = 0; + _i2sRx.start(); + _i2sTx.frequency(SAMPLERATE); _i2sTx.wordsize(16); _i2sTx.stereomono(I2S_STEREO); _i2sTx.masterslave(I2S_SLAVE); _i2sTx.start(); - _i2sRx.frequency(SAMPLERATE); - _i2sRx.wordsize(16); - _i2sRx.stereomono(I2S_STEREO); - _i2sRx.masterslave(I2S_SLAVE); - _i2sRx.attach(this, &TestAudio::echo); - _echoBufPtr = 0; - _waveIdx = 0; - _i2sRx.start(); do { //check if joystick-down pressed = play wave-file if ((down.read() == 0) && (_waveIdx == 0)) - _waveIdx = 1; + _waveIdx = 2; + + //check if joystick-left pressed = turn off microphone boost + if (left.read() == 0) + { + _codec.input_mute(true); + wait(0.2); + _codec.microphone_boost(false); + wait(0.2); + _codec.input_mute(false); + } + + //check if joystick-right pressed = turn on microphone boost + if (right.read() == 0) + { + _codec.input_mute(true); + wait(0.2); + _codec.microphone_boost(true); + wait(0.2); + _codec.input_mute(false); + } _codec.headphone_volume(_aIn); - wait(0.05); + wait(0.25); } while (up.read() != 0); - + + _codec.power(false); return true; }