Streams USB audio with sound effects applied. Sound effect selected by joystick and intensity altered by tilting the mbed. Output to the mbed-application-board phono jack.

Dependencies:   C12832_lcd MMA7660 USBDevice mbed

/media/uploads/bw/img_1293.jpg

/* Uses the mbed LPC1768 and mbed-application-board to create a USB audio device
 * that streams audio from a host computer to headphones or powered speakers. 
 * A couple different sound effects can be applied to the stream in real-time,
 * and tilting the mbed alters intensity of the effect.
 *
 *                                               ECHO
 *       The joystick selects )                   |
 *       one of three effect  )       STRAIGHT -  o  - STRAIGHT
 *       modes.               )                   |
 *                                              REVERB   
 * 
 *
 *
 *                                               \\           ||    
 *       Tilting the mbed     )      ======       \\          ||
 *       determines intensity )                    \\         ||
 *       of the effect.       )
 *                                     0%         50%         100%  
 *
 * The LCD display shows the current effect mode, intesity and buffer level.
*/
Committer:
bw
Date:
Thu Mar 27 21:43:41 2014 +0000
Revision:
2:9429f84ea165
Parent:
0:bbf6cf0eab95
Clean up comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bw 0:bbf6cf0eab95 1 /*******************************************************************************
bw 0:bbf6cf0eab95 2 * Implements delay lines for audio samples.
bw 0:bbf6cf0eab95 3 * Bryan Wade
bw 0:bbf6cf0eab95 4 * 27 MAR 2014
bw 0:bbf6cf0eab95 5 ******************************************************************************/
bw 0:bbf6cf0eab95 6 #include "delay.h"
bw 0:bbf6cf0eab95 7 #include "string.h"
bw 0:bbf6cf0eab95 8
bw 0:bbf6cf0eab95 9 struct delay_t { // Implementation of opaque type.
bw 0:bbf6cf0eab95 10 int16_t *base;
bw 0:bbf6cf0eab95 11 int16_t *head;
bw 0:bbf6cf0eab95 12 size_t len;
bw 0:bbf6cf0eab95 13 };
bw 0:bbf6cf0eab95 14
bw 0:bbf6cf0eab95 15 /*
bw 0:bbf6cf0eab95 16 * Create a delay object given a ptr and size of available RAM.
bw 0:bbf6cf0eab95 17 * This is only allocating memory for the metadata. The location of
bw 0:bbf6cf0eab95 18 * the buffer memory is passed in.
bw 0:bbf6cf0eab95 19 * @return Ptr to the new delay.
bw 0:bbf6cf0eab95 20 */
bw 0:bbf6cf0eab95 21 delay_t *Delay_Create(void)
bw 0:bbf6cf0eab95 22 {
bw 0:bbf6cf0eab95 23 return (delay_t *)malloc(sizeof(delay_t));
bw 0:bbf6cf0eab95 24 }
bw 0:bbf6cf0eab95 25
bw 0:bbf6cf0eab95 26 /*
bw 0:bbf6cf0eab95 27 * Configure delay buffer location and size.
bw 0:bbf6cf0eab95 28 * @return True if successful.
bw 0:bbf6cf0eab95 29 */
bw 0:bbf6cf0eab95 30 bool Delay_Configure(delay_t *delay, void *ram, size_t size)
bw 0:bbf6cf0eab95 31 {
bw 0:bbf6cf0eab95 32 if (delay) {
bw 0:bbf6cf0eab95 33 delay->base = delay->head = (int16_t *)ram;
bw 0:bbf6cf0eab95 34 delay->len = size / sizeof(int16_t);
bw 0:bbf6cf0eab95 35 memset(ram, 0, size);
bw 0:bbf6cf0eab95 36 return true;
bw 0:bbf6cf0eab95 37 }
bw 0:bbf6cf0eab95 38
bw 0:bbf6cf0eab95 39 return false;
bw 0:bbf6cf0eab95 40 }
bw 0:bbf6cf0eab95 41
bw 0:bbf6cf0eab95 42 /*
bw 0:bbf6cf0eab95 43 * Push a new sample with feedback into the delay while simulateously retieving the output sample.
bw 0:bbf6cf0eab95 44 * @return Output data.
bw 0:bbf6cf0eab95 45 */
bw 0:bbf6cf0eab95 46 int16_t Delay_WriteWithFeedback(delay_t *delay, int16_t dataIn, uint16_t gain)
bw 0:bbf6cf0eab95 47 {
bw 0:bbf6cf0eab95 48 int16_t dataOut = *delay->head;
bw 0:bbf6cf0eab95 49
bw 0:bbf6cf0eab95 50 // Feedback gain is fixed-point Q16 format.
bw 0:bbf6cf0eab95 51 *delay->head = dataIn + ((gain * dataOut ) >> 16);
bw 0:bbf6cf0eab95 52
bw 0:bbf6cf0eab95 53 if (++delay->head >= delay->base + delay->len)
bw 0:bbf6cf0eab95 54 delay->head = delay->base;
bw 0:bbf6cf0eab95 55
bw 0:bbf6cf0eab95 56 return dataOut;
bw 0:bbf6cf0eab95 57 }
bw 0:bbf6cf0eab95 58