Arduino wave shield – speed up – slow down demo from adafruit industries on Vimeo.
One of the reasons I made the Wave Shield kit is that I wanted to be able to play with audio clips and make strange effects. When every sample passes thru the Arduino, it becomes quite easy. For example, the Arduino has an interrupt that goes off 22,050 times a second (for 22kHz audio)…by simply changing the interrupt timing now you’ve changed the playback rate!
Here is the new code for the procedure that plays back the audio. Basically, it checks the analog pin and uses that value to generate a new sample rate scaled off of the original. Then it sets the new sample rate. There’s a little hysteresis code in there to make sure it only updates it when the pot is turned. As collin mentions, you can use any sort of analog sensor, such as a photo cell, bend sensor, etc!
int16_t lastpotval = 0;
#define HYSTERESIS 3
void playcomplete(char *name) {
int16_t potval;
uint32_t newsamplerate;
playfile(name);
while (wave.isplaying) {
potval = analogRead(0);
if ( ((potval - lastpotval) > HYSTERESIS) || ((lastpotval - potval) > HYSTERESIS)) {
newsamplerate = wave.dwSamplesPerSec; // get the original sample rate
newsamplerate *= potval; // scale it by the analog value
newsamplerate /= 512; // we want to 'split' between 2x sped up and slowed down.
wave.setSampleRate(newsamplerate); // set it immediately!
Serial.println(newsamplerate, DEC); // for debugging
lastpotval = potval;
}
delay(100);
}
card.close_file(f);
}

Printable catalog (PDF)
FEED
I’m a bit confused about int16_t and uint32_t. I gather that they are integer data types and that u indicates unsigned and the digits 8,16,32 represent the number of bits. But how are they different from byte,int, unsigned int, long and unsigned long?
Comment by myuserid — May 21, 2008 @ 2:22 pm
they are completely identical. i use uint8_t, etc because that way it is extraordinarily clear what type it is. “int” varies on platforms, from 2 to 4 bytes, which makes code less portable. if you say uint32_t then there is no confusion!
Comment by ladyada — May 21, 2008 @ 2:39 pm
There may be no confusion with the other platforms. But I’ll bet its confusing to some of other Arduino users, who, like myself, aren’t adept C programmers and have only studied the Arduino programming reference (and your excellent tutorials, of course).
Comment by myuserid — May 21, 2008 @ 3:28 pm
Can it play backwards too? (I assume it’s technically possible, but I mean do the the current libraries easily support that.)
Comment by cinco — May 23, 2008 @ 2:01 pm
it cant play backwards, but thats due to FAT16 format…each cluster points only to the -next- cluster. so to play backwards you have to fastforward thru the file to the point you want, each time. computers have tons of ram so they just buffer it all!
Comment by ladyada — May 23, 2008 @ 2:04 pm
So would that also mean you can only loop the entire file, and not set loop points in the middle?
Comment by cinco — May 24, 2008 @ 12:47 pm
This might be a dumb question, since I’m a beginner with the arduino, but what is the resistance of the pot and which pins is it connected to.
Comment by Christian — October 5, 2008 @ 4:43 am
When I run this scetch, I get this error:
In function ‘void playcomplete(char*)’:
error: ‘playfile’ was not declared in this scope
What is wrong?
Comment by Christian — November 2, 2008 @ 11:14 am
This is so cool. It works great.
Comment by Christian — December 10, 2008 @ 9:26 am
tryin to speed uo play back what resistance is the pot and witch pins is it connected to please
Comment by KING LEVI — January 2, 2010 @ 2:11 am