Shop OBEX P1 Docs P2 Docs Learn Events
How would I slow down audio? — Parallax Forums

How would I slow down audio?

tim1986tim1986 Posts: 41
edited 2011-07-01 01:24 in Propeller 1
I don't know if I need to use a propeller for this, but I want to take an stereo (analog) audio signal and slow it down depending on a voltage input or the number of times a switch is closed per minute. So the higher the voltage or more times the switch is closed the faster and closer to normal speed the audio is played. I want it to sound like a cassette/tape player/walkmen's battery dieing.

How can I do this?? Any ideas are appreciated.

Thanks in advance.
-Tim
«1

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-28 17:09
    Simply slowing down audio requires a lot of memory and a way to start and stop the source. To see what I'm talking about, imagine a tape supply reel running at 7.5 ips and the take-up reel running at 3.75 ips. Where does the ever-increasing loop of tape between them go? That's where the memory comes in. The Propeller doesn't have nearly enough memory internally to do something like this, but it may be possible to accomplish with external memory or fast storage. It would still be quite an ambitious project, though, especially if you also needed to preserve the original source's pitch.

    -Phil
  • LeonLeon Posts: 7,620
    edited 2011-06-28 17:19
    The simplest way to do that is to use a Microchip dsPIC and a suitable codec. This dsPIC board I designed for speech processing should be suitable:

    http://www.leonheller.com/Audio%20Processor/AP.pdf

    A different codec would be needed for music (stereo or mono).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-28 17:25
    Leon,

    What kind of memory were you planning to use to buffer the incoming stream? Simply stretching the audio or chopping it up and replicating the pieces is probably within the Propeller's capability. The big problem is that data is coming in faster than it goes out.

    Here's a classic example of the need for buffering when the input is faster than the output:

    -Phil
  • LeonLeon Posts: 7,620
    edited 2011-06-28 17:29
    The dsPIC30F4013 I used has 2k of RAM:

    http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010345

    There are others with a lot more.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-28 17:32
    Leon wrote:
    The dsPIC I used has 2k of RAM. There are others with a lot more.

    It would take megabytes to do what the OP wants, unless his audio snippets are very short or he has a way to interrupt the input.

    -Phil
  • LeonLeon Posts: 7,620
    edited 2011-06-28 17:38
    Yes, if he wants to do it on a continuous basis. I think I could come up with a solution using external memory.
  • AntoineDoinelAntoineDoinel Posts: 312
    edited 2011-06-28 18:15
    I recall reading up about a technique for pitch shifting that didn't seem too complicated or memory consuming... found the link, here it is: http://www.wavefrontsemi.com/UserFiles/File/AL_Info/AL32/AppNotes/WavefrontAN3201-02%20Pitch%20Shifting.pdf

    I think it's used in low end effect processors from Alesis, like the Microverb, which is probably based the same AL3201BG IC.

    Regards
    Alessandro
  • LeonLeon Posts: 7,620
    edited 2011-06-28 18:19
    I've got some of those Alesis DSP chips.
  • AntoineDoinelAntoineDoinel Posts: 312
    edited 2011-06-28 18:42
    Leon wrote: »
    I've got some of those Alesis DSP chips.

    Nice :smile: Have you built something using that?
    I thought about getting a DRE chip mostly because it has a ready made leslie effect. And the SOIC package should be not too hard to solder by hand.
  • tim1986tim1986 Posts: 41
    edited 2011-06-29 01:10
    Would the 1MB Flash chip on the Propeller C3 be enough for a buffer chip or what would be needed?

    -Tim
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2011-06-29 01:43
    More "wrong processor" I am afraid, but a simular sort of thing:-

    http://elm-chan.org/works/vp/report.html
  • LeonLeon Posts: 7,620
    edited 2011-06-29 02:18
    Nice :smile: Have you built something using that?
    I thought about getting a DRE chip mostly because it has a ready made leslie effect. And the SOIC package should be not too hard to solder by hand.

    I designed a little four-layer PCB to try one out, with the companion ADC and DAC chips, but couldn't get it to work. Here is the schematic:

    http://www.leonheller.com/Audio%20Processor/Alesis%20DSP.pdf

    I used a small AVR as the controller.

    I've attached an image of the PCB layout. It's rather dense.
    1024 x 575 - 79K
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2011-06-29 05:54
    The big unknown here is how long the OP wants to slows things down for and what quality he is after.
  • ericballericball Posts: 774
    edited 2011-06-29 06:21
    As the walkman battery dies the motor slows down which both slows the playback and shifts the pitch. This is easy to accomplish, just play back the audio samples at a lower rate than they are taken. The difficulty is you're trying to do it in real-time. As PhiPi has said, you need to store the data in some kind of memory. How long you can record is dependent on your input sample rate and how much memory you have.

    It all gets much easier if the audio data is stored on an SD card.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-29 07:41
    tim1986 wrote: »
    Would the 1MB Flash chip on the Propeller C3 be enough for a buffer chip or what would be needed?

    -Tim

    Tim, I doubt you'd want to use flash for this application. Flash can be written to a limited number of times.

    I think this is probably an application where you'd want to use SRAM. There are several multi-bit bus SRAM projects on the Propeller forum. I even did a cheap version by stacking eight DIP chips to make up a 256KByte "module."

    You'll need to decide on the sound quality you want and how long you want a buffer to last. Then you can figure out how much memory you need. Or, as often is the case, you could work backward and figure out what quality and time you could get from a set about of memory.

    Have you tried the "microphone_to_headphones" demo? It's in the "_Demos" folder of the Propeller Tool. The program uses the microphone and headphone jack on the Demo board. The program can help you quantify the quality you're after.

    As others have mentioned, if you don't need to preserve the pitch of the original sound the problem is a lot easier.

    Duane
  • LeonLeon Posts: 7,620
    edited 2011-06-29 07:51
    The OP doesn't want pitch preserved, he wants it to sound like a cassette player with the batteries running down.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-29 07:56
    Tim,

    Let's do the math. If your audio source is speech, for example, you will need to acquire at least 8000 samples per second, 16,000 for stereo. For speech 8 bits per sample is probably adequate, especially with companding. Say you want to slow it down to as little as 50%. That means you've got as many as 8000 samples per second coming in that you can't send out right away. If you want to handle an incoming stream that lasts 15 minutes, that's 8000 x 15 x 60 = 7.2MB of memory required. If your source is something besides speech or if you need more than 15 minutes of input, the memory requirements go up from there.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-29 08:10
    Phil,

    If Tim only wants to slow down a sentence at a time then he only needs to store a few seconds. 8000 x 6 = 48000 = 48KB.
    Or lets assume he's using 256KB SRAM. 256000 / 8000 = 32 seconds of speech could be stored. Could be fun.

    Duane
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-29 08:15
    Duane,

    You're right. A lot depends on his requirements, which he's not yet stated. The memory reqirement is also relaxed if the minimum speed ratio is more than 50%.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-29 08:19
    The C3's 64K of SRAM would be enough for 8 seconds of storage. I don't think 8KB/s should be a problem with SPI.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-29 08:25
    I just realized 8KB/s isn't the speed needed. The SRAM will need to be both written to and read from simultaneously. I still think the SPI SRAM on the C3 could do it but it's not a trivial problem (at least for me) to record and vary the playback at the same time.

    It would be easier to record a sentence and then play it back (at variable speed) after the entire sentence has been recorded.
  • Jack BuffingtonJack Buffington Posts: 115
    edited 2011-06-29 09:55
    I made a pitch shifter on a PIC once. The way that I implemented it was to create a ring buffer that is filled at the full sample rate. The buffer is never considered full and continues to overwrite older data forever. The out pointer moves around the ring buffer at a different rate. There was a little artifacting due to the hard transitions where the out pointer meets with the in pointer. You might be able to limit this somewhat by implementing some sort of low pass filter or slew rate limiter.

    If all you will be putting through the device will be speech, you could get fancier and do a best guess of the speaker's pitch and then look for zero crossings that roughly meet the timing. Take that waveform, stretch it to a standard length and put it into a temporary buffer. There would be a main buffer that held the actual waveform that was output. When the out pointer reached the end of the main buffer, you could swap buffers. That would take care of glitching. This should be in the realm of possible on a propeller.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-29 10:29
    I don't think a pitch shifter is what the OP wants, though. He wants to slow down the overall rate of the input. IOW, if the input is speech, the output will be the same speech, only slower with, possibly, a lower pitch.

    Tim, it would be nice if you could clarify exactly what specs (bandwidth, duration, whether the output has to be simultaneous with input, whether you want the pitch to shift with rate, etc.) you're after. Otherwise, we're just spinning our wheels here.

    Thanks,
    -Phil
  • RaymanRayman Posts: 14,876
    edited 2011-06-29 12:24
    I think the usual way we play stereo is from the SD card with audio stored in .wav format.
    You can find examples of that in OBEX.
    They could be easily modified to play back at different speed.

    But, if you mean you want to record in real time and playback slower, then you need a lot of memory as has been discussed.
    Maybe you could do it with SD card, I think it has enough bandwidth, but I haven't seen it done yet.
  • lonesocklonesock Posts: 917
    edited 2011-06-29 13:57
    Rayman wrote: »
    I think the usual way we play stereo is from the SD card with audio stored in .wav format.
    You can find examples of that in OBEX.
    They could be easily modified to play back at different speed.

    But, if you mean you want to record in real time and playback slower, then you need a lot of memory as has been discussed.
    Maybe you could do it with SD card, I think it has enough bandwidth, but I haven't seen it done yet.
    I've done it: huge circular buffer on a SD card using the raw access block driver from the FSRW project (naturally ;-). I still needed a decent buffer on the prop, since you get some lag switching from read to write and back. I'll see if I can dig up the files when I get home. Of course, no matter how big the buffer, you will run out of space eventually if this is always on.

    Jonathan
  • tim1986tim1986 Posts: 41
    edited 2011-06-29 23:31
    Ok. The thought that I originally had was an exercise bike that you could plug your ipod into and if you didn't keep up speed the audio would slow down(pitch to shift with rate). Since it's an ipod you could set it up as a remote with the dock connector to pause to allow the buffer to catch up. Thank you all for the info!

    -Tim
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2011-06-30 04:13
    tim1986 wrote: »
    ... if you didn't keep up speed the audio would slow down(pitch to shift with rate).

    Ok. But that's not slowing it down. Simulating a tape player slowing down involves delaying the signal by an increasing amount and dropping its pitch. That's why you need a decent sized chunk of memory. For the effect you want I'd suggest that just pitch shifting will be enough. You should be able to do that just using Hub Ram.
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-06-30 08:28
    "slow down(pitch to shift with rate)."

    But he does want the audio to slow down.
    And that the side effect of pitch going down is OK.

    I would use some spi sram, make a circular buffer,
    if it's OK that the audio skips if the buffer overflows?
    Or use the pause function on the ipod.
  • RaymanRayman Posts: 14,876
    edited 2011-06-30 08:58
    Instead of using an Ipod to play the music, you could convert it to .wav files, put it on SD card and use a Prop to play it.
    Then, you could do some simple changes to the wav player code to vary the speed as desired.
  • AleAle Posts: 2,363
    edited 2011-07-01 01:24
    He can also compress the audio and gain some space... Of course using interpolation between samples could be a good idea (and avoiding compression...) :). The defining factor here is real-time or prerecorded. Real time needs buffering memory, prerecorded does not because you just read your sample slower :).
Sign In or Register to comment.