![](/media/cache/profiles/564127c03caab942e503ee6f810f54fd.50x50_q85.png)
Added Function to power down magic USB interface chip with new firmware Download firmware here http://mbed.org/users/simon/notebook/interface-powerdown/ http://mbed.org/media/uploads/simon/mbedmicrocontroller_experimentalpowerdown.if You need to power the mbed by vin or usb board such as cool components http://mbed.org/cookbook/Cool-Components-Workshop-Board Hello my name is guitar reverse me and it is karaoke time
Revision 0:f2733793d0fd, committed 2011-07-20
- Comitter:
- mbed2f
- Date:
- Wed Jul 20 05:45:03 2011 +0000
- Commit message:
- Added Function to power down magic USB interface chip with new firmware
Hello my name is guitar reverse me and it is karaoke time
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r f2733793d0fd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 20 05:45:03 2011 +0000 @@ -0,0 +1,98 @@ +#include <mbed.h> + +// Function to power down magic USB interface chip with new firmware +#define USR_POWERDOWN (0x104) +int semihost_powerdown() { + uint32_t arg; + return __semihost(USR_POWERDOWN, &arg); +} + +// If you don't need the PC host USB interface.... +// Power down magic USB interface chip - saves around 150mW +// Needs new firmware (URL below) and USB cable not connected +// http://mbed.org/users/simon/notebook/interface-powerdown/ +// Supply power to mbed using Vin pin + + +// Boolean types +#define TRUE 1 +#define FALSE 0 + +//#define NUM_SAMPLES 48000 +/* ADC for the microphone/input, DAC for the speaker/output */ +AnalogIn mic(p19); +AnalogOut speaker(p18); + +// Allocate a buffer to be used for the audio recording +static const size_t BufferSize = 15 * 1066; +static unsigned short Buffer[BufferSize]; + //int16_t Buffer[ 32768]; + //unsigned short Buffer[NUM_SAMPLES]; + + +int main(void) +{ + + int result; + result = semihost_powerdown(); + //int i; + // for (i = 0; ; ) + + { unsigned short ReadSample = 0xFFFF; + // Indices to track where the playback and recording should take place in the + // audio buffer. The recording can occur one sample behind the current playback + // index since it is no longer required. + int Index = 0; + // Reverse the direction the buffer is walked between each iteration to save memory + int Direction = 1; + // Have audio to playback + int Playback = FALSE; + // The amount of data to be recorded before starting reverse playback + // NOTE: Probably want this to be configured at runtime via a knob, etc. + //int ChunkSize = 9024; + int ChunkSize = BufferSize; + // Infinite loop of recording and reverse playback + for (;;) + { + unsigned short PlaySample; + + // Read out the sample from the buffer to be played back + if (Playback) + { + PlaySample = Buffer[Index]; + speaker.write_u16(PlaySample); + //i = (i+0) % NUM_SAMPLES; + + //wait(0.2f); + } + + // Obtain current audio sample from the A/D converter. + // NOTE: I am just faking these values in this sample with an incrementing value + ReadSample = mic.read_u16(); + + // Record the sample into the buffer right where a space was freed up from the PlaySample read above + Buffer[Index] = ReadSample += mic.read_u16(); + + // Increment the buffer pointer + Index += Direction; + + // Check to see if the chunk has been filled + if (Index < 0) + { + // Now have a chunk to be played back + Playback = TRUE; + // Reverse the direction of playback and recording + Direction *= -1; + Index = 0; + } + else if (Index >= ChunkSize) + { + // Now have a chunk to be played back + Playback = TRUE; + // Reverse the direction of playback and recording + Direction *= -1; + Index = ChunkSize - 1; + } + } +} +} \ No newline at end of file
diff -r 000000000000 -r f2733793d0fd mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 20 05:45:03 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912