Production Test Program (PTP) for the LPC4088 Experiment Base Board
Dependencies: EALib I2S LM75B SDFileSystem mbed
TestAudio.cpp@3:7ef908e84ae1, 2014-09-08 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Sep 08 11:34:53 2014 +0000
- Revision:
- 3:7ef908e84ae1
- Parent:
- 2:2f4b7535ceb3
- Child:
- 4:aa34674b6afb
Added audio test. Shortened RGB LED startup sequence and added message for user when uSD card not inserted to explain the long delay.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 2:2f4b7535ceb3 | 1 | /* |
embeddedartists | 2:2f4b7535ceb3 | 2 | * Copyright 2013 Embedded Artists AB |
embeddedartists | 2:2f4b7535ceb3 | 3 | * |
embeddedartists | 2:2f4b7535ceb3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 2:2f4b7535ceb3 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 2:2f4b7535ceb3 | 6 | * You may obtain a copy of the License at |
embeddedartists | 2:2f4b7535ceb3 | 7 | * |
embeddedartists | 2:2f4b7535ceb3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 2:2f4b7535ceb3 | 9 | * |
embeddedartists | 2:2f4b7535ceb3 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 2:2f4b7535ceb3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 2:2f4b7535ceb3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 2:2f4b7535ceb3 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 2:2f4b7535ceb3 | 14 | * limitations under the License. |
embeddedartists | 2:2f4b7535ceb3 | 15 | */ |
embeddedartists | 2:2f4b7535ceb3 | 16 | |
embeddedartists | 2:2f4b7535ceb3 | 17 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 18 | * Includes |
embeddedartists | 2:2f4b7535ceb3 | 19 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 20 | |
embeddedartists | 2:2f4b7535ceb3 | 21 | #include "mbed.h" |
embeddedartists | 2:2f4b7535ceb3 | 22 | #include "TestAudio.h" |
embeddedartists | 2:2f4b7535ceb3 | 23 | #include "WM8731.h" |
embeddedartists | 3:7ef908e84ae1 | 24 | #include "I2S.h" |
embeddedartists | 3:7ef908e84ae1 | 25 | #include "sound.h" |
embeddedartists | 2:2f4b7535ceb3 | 26 | |
embeddedartists | 2:2f4b7535ceb3 | 27 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 28 | * Defines and typedefs |
embeddedartists | 2:2f4b7535ceb3 | 29 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 30 | |
embeddedartists | 3:7ef908e84ae1 | 31 | #define SAMPLERATE 32000 |
embeddedartists | 3:7ef908e84ae1 | 32 | |
embeddedartists | 3:7ef908e84ae1 | 33 | /****************************************************************************** |
embeddedartists | 3:7ef908e84ae1 | 34 | * Private Functions |
embeddedartists | 3:7ef908e84ae1 | 35 | *****************************************************************************/ |
embeddedartists | 3:7ef908e84ae1 | 36 | |
embeddedartists | 3:7ef908e84ae1 | 37 | void TestAudio::echo(void) { |
embeddedartists | 3:7ef908e84ae1 | 38 | int to_read = _i2sRx.fifo_points(); //Find out how many stereo samples to read |
embeddedartists | 3:7ef908e84ae1 | 39 | |
embeddedartists | 3:7ef908e84ae1 | 40 | //Read 'to_read' number of stereo samples. |
embeddedartists | 3:7ef908e84ae1 | 41 | _i2sRx.read(_rxBuf, to_read); |
embeddedartists | 3:7ef908e84ae1 | 42 | |
embeddedartists | 3:7ef908e84ae1 | 43 | //Loop through all stereo samples |
embeddedartists | 3:7ef908e84ae1 | 44 | for(int i = 0; i < to_read; i+=2) { |
embeddedartists | 3:7ef908e84ae1 | 45 | // Check if wave-file shall be output |
embeddedartists | 3:7ef908e84ae1 | 46 | if (_waveIdx > 0) |
embeddedartists | 3:7ef908e84ae1 | 47 | { |
embeddedartists | 3:7ef908e84ae1 | 48 | _txBuf[i] = sound_8k[_waveIdx/4] << 5; |
embeddedartists | 3:7ef908e84ae1 | 49 | _txBuf[i+1] = sound_8k[_waveIdx/4] << 5; |
embeddedartists | 3:7ef908e84ae1 | 50 | |
embeddedartists | 3:7ef908e84ae1 | 51 | //Increment wave samples pointer and check if all samples have been read, if so, set pointer to zero |
embeddedartists | 3:7ef908e84ae1 | 52 | _waveIdx++; |
embeddedartists | 3:7ef908e84ae1 | 53 | if (_waveIdx/4 > sound_sz) |
embeddedartists | 3:7ef908e84ae1 | 54 | { |
embeddedartists | 3:7ef908e84ae1 | 55 | _waveIdx = 0; |
embeddedartists | 3:7ef908e84ae1 | 56 | } |
embeddedartists | 3:7ef908e84ae1 | 57 | } |
embeddedartists | 3:7ef908e84ae1 | 58 | //Output delayed version of audio input |
embeddedartists | 3:7ef908e84ae1 | 59 | else |
embeddedartists | 3:7ef908e84ae1 | 60 | { |
embeddedartists | 3:7ef908e84ae1 | 61 | //Echo buffer only contains right side samples (since MIC is used as input, which is a mono input) |
embeddedartists | 3:7ef908e84ae1 | 62 | //Output is however stereo, so just copy echo bugger to both right and left side for output samples |
embeddedartists | 3:7ef908e84ae1 | 63 | _txBuf[i] = _echoBuf[_echoBufPtr]; |
embeddedartists | 3:7ef908e84ae1 | 64 | _txBuf[i+1] = _echoBuf[_echoBufPtr]; |
embeddedartists | 3:7ef908e84ae1 | 65 | |
embeddedartists | 3:7ef908e84ae1 | 66 | //Only fill echo buffer with right side samples, i.e., ignore rxBuf[i+1] content |
embeddedartists | 3:7ef908e84ae1 | 67 | _echoBuf[_echoBufPtr] = _rxBuf[i]; |
embeddedartists | 3:7ef908e84ae1 | 68 | } |
embeddedartists | 3:7ef908e84ae1 | 69 | |
embeddedartists | 3:7ef908e84ae1 | 70 | //Increment echo buffer write pointer and check for wrap-around |
embeddedartists | 3:7ef908e84ae1 | 71 | _echoBufPtr++; |
embeddedartists | 3:7ef908e84ae1 | 72 | if (_echoBufPtr >= ECHOLENGTH) |
embeddedartists | 3:7ef908e84ae1 | 73 | { |
embeddedartists | 3:7ef908e84ae1 | 74 | _echoBufPtr = 0; |
embeddedartists | 3:7ef908e84ae1 | 75 | } |
embeddedartists | 3:7ef908e84ae1 | 76 | } |
embeddedartists | 3:7ef908e84ae1 | 77 | |
embeddedartists | 3:7ef908e84ae1 | 78 | //Write samples to output/codec |
embeddedartists | 3:7ef908e84ae1 | 79 | _i2sTx.write(_txBuf, to_read); |
embeddedartists | 3:7ef908e84ae1 | 80 | } |
embeddedartists | 3:7ef908e84ae1 | 81 | |
embeddedartists | 2:2f4b7535ceb3 | 82 | /****************************************************************************** |
embeddedartists | 2:2f4b7535ceb3 | 83 | * Public Functions |
embeddedartists | 2:2f4b7535ceb3 | 84 | *****************************************************************************/ |
embeddedartists | 2:2f4b7535ceb3 | 85 | |
embeddedartists | 2:2f4b7535ceb3 | 86 | /* |
embeddedartists | 2:2f4b7535ceb3 | 87 | Prerequisites: |
embeddedartists | 2:2f4b7535ceb3 | 88 | |
embeddedartists | 2:2f4b7535ceb3 | 89 | - For this test to work jumpers JP8 and JP9 on the LPC4088 Experiment Base Board |
embeddedartists | 2:2f4b7535ceb3 | 90 | must both be in positions 1-2 |
embeddedartists | 2:2f4b7535ceb3 | 91 | |
embeddedartists | 2:2f4b7535ceb3 | 92 | - MIC cable, Line OUT, Headphone... |
embeddedartists | 2:2f4b7535ceb3 | 93 | */ |
embeddedartists | 2:2f4b7535ceb3 | 94 | |
embeddedartists | 3:7ef908e84ae1 | 95 | TestAudio::TestAudio() : _codec(P0_27, P0_28), _i2sTx(I2S_TRANSMIT, p11, p12, p13), |
embeddedartists | 3:7ef908e84ae1 | 96 | _i2sRx(I2S_RECEIVE, p14, p33, p34),_aIn(p15),_waveIdx(0),_echoBufPtr(0) { |
embeddedartists | 3:7ef908e84ae1 | 97 | } |
embeddedartists | 3:7ef908e84ae1 | 98 | |
embeddedartists | 2:2f4b7535ceb3 | 99 | bool TestAudio::runTest() { |
embeddedartists | 2:2f4b7535ceb3 | 100 | printf("Testing audio...\n"); |
embeddedartists | 3:7ef908e84ae1 | 101 | |
embeddedartists | 3:7ef908e84ae1 | 102 | // joystick used for audio selection |
embeddedartists | 3:7ef908e84ae1 | 103 | DigitalIn up(p32); |
embeddedartists | 3:7ef908e84ae1 | 104 | DigitalIn down(p38); |
embeddedartists | 3:7ef908e84ae1 | 105 | |
embeddedartists | 3:7ef908e84ae1 | 106 | _codec.power(true); |
embeddedartists | 3:7ef908e84ae1 | 107 | _codec.frequency(SAMPLERATE); |
embeddedartists | 3:7ef908e84ae1 | 108 | _codec.wordsize(16); |
embeddedartists | 3:7ef908e84ae1 | 109 | _codec.master(true); |
embeddedartists | 3:7ef908e84ae1 | 110 | _codec.headphone_volume(0.1); |
embeddedartists | 3:7ef908e84ae1 | 111 | _codec.input_select(WM8731_MIC); |
embeddedartists | 3:7ef908e84ae1 | 112 | _codec.microphone_boost(false); |
embeddedartists | 3:7ef908e84ae1 | 113 | _codec.input_mute(false); |
embeddedartists | 3:7ef908e84ae1 | 114 | _codec.output_mute(false); |
embeddedartists | 3:7ef908e84ae1 | 115 | _codec.input_power(true); |
embeddedartists | 3:7ef908e84ae1 | 116 | _codec.output_power(true); |
embeddedartists | 3:7ef908e84ae1 | 117 | // _codec.sidetone(0.99); |
embeddedartists | 3:7ef908e84ae1 | 118 | _codec.linein_volume(0.7); |
embeddedartists | 3:7ef908e84ae1 | 119 | _codec.bypass(true); |
embeddedartists | 3:7ef908e84ae1 | 120 | _codec.start(); |
embeddedartists | 3:7ef908e84ae1 | 121 | |
embeddedartists | 3:7ef908e84ae1 | 122 | _i2sTx.frequency(SAMPLERATE); |
embeddedartists | 3:7ef908e84ae1 | 123 | _i2sTx.wordsize(16); |
embeddedartists | 3:7ef908e84ae1 | 124 | _i2sTx.stereomono(I2S_STEREO); |
embeddedartists | 3:7ef908e84ae1 | 125 | _i2sTx.masterslave(I2S_SLAVE); |
embeddedartists | 3:7ef908e84ae1 | 126 | _i2sTx.start(); |
embeddedartists | 3:7ef908e84ae1 | 127 | |
embeddedartists | 3:7ef908e84ae1 | 128 | _i2sRx.frequency(SAMPLERATE); |
embeddedartists | 3:7ef908e84ae1 | 129 | _i2sRx.wordsize(16); |
embeddedartists | 3:7ef908e84ae1 | 130 | _i2sRx.stereomono(I2S_STEREO); |
embeddedartists | 3:7ef908e84ae1 | 131 | _i2sRx.masterslave(I2S_SLAVE); |
embeddedartists | 3:7ef908e84ae1 | 132 | _i2sRx.attach(this, &TestAudio::echo); |
embeddedartists | 3:7ef908e84ae1 | 133 | _echoBufPtr = 0; |
embeddedartists | 3:7ef908e84ae1 | 134 | _waveIdx = 0; |
embeddedartists | 3:7ef908e84ae1 | 135 | _i2sRx.start(); |
embeddedartists | 3:7ef908e84ae1 | 136 | |
embeddedartists | 3:7ef908e84ae1 | 137 | do |
embeddedartists | 3:7ef908e84ae1 | 138 | { |
embeddedartists | 3:7ef908e84ae1 | 139 | //check if joystick-down pressed = play wave-file |
embeddedartists | 3:7ef908e84ae1 | 140 | if ((down.read() == 0) && (_waveIdx == 0)) |
embeddedartists | 3:7ef908e84ae1 | 141 | _waveIdx = 1; |
embeddedartists | 3:7ef908e84ae1 | 142 | |
embeddedartists | 3:7ef908e84ae1 | 143 | _codec.headphone_volume(_aIn); |
embeddedartists | 3:7ef908e84ae1 | 144 | wait(0.05); |
embeddedartists | 3:7ef908e84ae1 | 145 | } while (up.read() != 0); |
embeddedartists | 3:7ef908e84ae1 | 146 | |
embeddedartists | 2:2f4b7535ceb3 | 147 | return true; |
embeddedartists | 2:2f4b7535ceb3 | 148 | } |
embeddedartists | 2:2f4b7535ceb3 | 149 | |
embeddedartists | 2:2f4b7535ceb3 | 150 |