Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 17 of 17

Thread: SD Audio playback speed

  1. #1
    Junior Member
    Join Date
    May 2017
    Posts
    3

    SD Audio playback speed

    Hello

    Trying to find out if it is possible to play audio files from an sd card while adjusting the speed of which the audio files are played at. I would only need to change the speed by -10% / +10%. This seems like a bit of a grey area atm so any guidance would be greatly appreciated. I am using a teensy 3.6 with a teensy audio adapter.

    Cheers!

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,145
    Quote Originally Posted by Geroge View Post
    Hello

    Trying to find out if it is possible to play audio files from an sd card while adjusting the speed of which the audio files are played at. I would only need to change the speed by -10% / +10%. This seems like a bit of a grey area atm so any guidance would be greatly appreciated. I am using a teensy 3.6 with a teensy audio adapter.

    Cheers!
    Reading from SD card is independent from playing audio. As audio sampling rate is fixed, you could insert a resampling filter between sd card read and audio output. However, I do not know if there are examples available.

  3. #3
    Junior Member
    Join Date
    May 2017
    Posts
    3
    Quote Originally Posted by WMXZ View Post
    Reading from SD card is independent from playing audio. As audio sampling rate is fixed, you could insert a resampling filter between sd card read and audio output. However, I do not know if there are examples available.
    Hmmm massive over-sight on my behalf, should have noticed on that one. I am trying to make a small beatmatching tool, kind of based off cdj 500s. Forgive me as I am pretty new to this, but is there a way of slowing down / speeding up the sd card read rate? Doesn't exactly need to sound good. I noticed that with the flash memory chip installed on the audio board you can get about 8 sec of delay, perhaps this could be used for a re-sampling filter?
    Cheers

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,914
    Quote Originally Posted by Geroge View Post
    is there a way of slowing down / speeding up the sd card read rate? Doesn't exactly need to sound good.
    So far nobody has written the code to do this. It's on my todo list, together with *many* other features. I do not have a solid timeframe for when I'll get around to it.

    To specifically answer your "is there a way" question, yes, there most certainly is a way. But that way involves pretty substantial programming effort within the library. If "a way" is restricted to mean only ways that involve using existing audio library features without difficult programming, then no, there isn't currently such a way.

    I noticed that with the flash memory chip installed on the audio board you can get about 8 sec of delay, perhaps this could be used for a re-sampling filter?
    This is purely a matter of software. The extra memory chip is not needed and would not significantly help. In fact, the software would likely be much more difficult to write if it unnecessarily tried to use that chip in some way.
    Last edited by PaulStoffregen; 05-29-2017 at 04:08 PM.

  5. #5
    Junior Member
    Join Date
    May 2017
    Posts
    3
    Great this clears up a lot thank you. Looking forward to this feature being implemented, along with the many others!

    Cheers!

  6. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    I had an unsuccessful go at this a few months ago, the goal was to be able to detune samples for a sample-based keyboard.

    Reading from SD card is independent from playing audio, but the code for AudioPlaySdRaw reads data from the SD card in chunks matching the audio buffer size. Reading at double or half speed is relatively easy, but something like 10% slower/faster would require keeping track of excess data that's already read but doesn't fill an entire audio buffer yet. My attempt just resulted in a lot of terrible noise with a hint of the original sound.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,565
    Quote Originally Posted by floretan View Post
    I had an unsuccessful go at this a few months ago, the goal was to be able to detune samples for a sample-based keyboard.

    Reading from SD card is independent from playing audio, but the code for AudioPlaySdRaw reads data from the SD card in chunks matching the audio buffer size. Reading at double or half speed is relatively easy, but something like 10% slower/faster would require keeping track of excess data that's already read but doesn't fill an entire audio buffer yet. My attempt just resulted in a lot of terrible noise with a hint of the original sound.
    Have you tried to sync the speed-change with the audioblocks (speed-change only when between blocks)

  8. #8
    Member Moo's Avatar
    Join Date
    Oct 2016
    Location
    London
    Posts
    20

    RAW files playback speed

    I was also looking for some kind of playback speed control, and since I didn't find any solutions and quite a few people who seems to have a similar requirements, I thought I'd see if I could hack it... well at least the easy version, which is resampled RAW files...

    I implemented a ResamplingSdReader class which has equivalent methods to File::read(char *buf, long len) but returns a resampled buffer instead of direct buffer from file.

    I've copied play_sd_raw class to play_sd_raw_resampled class and added method setReadRate(float f): where 1 would be regular playback rate, 0.5 half speed, 2 double speed, etc). [Maybe it should be called setPlaybackRate?]

    I've forked https://github.com/PaulStoffregen/Audio -> https://github.com/newdigate/Audio, added this feature, even tested briefly on a teensy, and to my surprise to seemed to work really nicely.

    https://github.com/newdigate/Audio/c...47aecc0c7a1960

    if anybody is interested, I'd be happy to send pull request to PaulStoffregen/Audio

    A nice improvement would be to implement an option to enable linear interpolation on the resampled output.

    It would also be nice to be able to play WAV files at arbitrary rates.

  9. #9
    Member Moo's Avatar
    Join Date
    Oct 2016
    Location
    London
    Posts
    20
    I moved the variable playback rate feature to its own branch here https://github.com/newdigate/Audio/t...-raw-resampled

    I've briefly tested the code, seems to be okay between -1.0 and 1.0, posted quick video https://www.youtube.com/watch?v=rEEJf7q9tRY (apologies - its pretty raw)

    If anybody has the time and inclination, I'd be interested to know your thoughts/experiences/questions...

    Im planning on using this feature with a tempo synch'ed teensy audio recorder/looper... Also like to see if I can get it to work with .wav files

  10. #10
    Junior Member
    Join Date
    Jan 2017
    Posts
    14
    This looks cool, I'll try this at some point. Were there any artefacts above 1.0 or -1.0 values as you have only tested that?

  11. #11
    Member Moo's Avatar
    Join Date
    Oct 2016
    Location
    London
    Posts
    20
    Subsequently Iíve tested it between -4.0 and 4.0... works successfully. beyond that Iíve not tested.

  12. #12
    Member propa's Avatar
    Join Date
    Apr 2018
    Location
    UK
    Posts
    93
    Quote Originally Posted by Moo View Post
    Subsequently Iíve tested it between -4.0 and 4.0... works successfully. beyond that Iíve not tested.
    Hi Moo,

    Is there any reason your code only works with Teensy 3.6? Can't seem to get it to compile for 3.2 sadly. Will buy a 3.6, but wondering what the issue is with 3.2 compatibility.

    Great work, can't wait to try it out. And sounds like wobbly glitch hop in the video, nice work!

  13. #13
    Member Moo's Avatar
    Join Date
    Oct 2016
    Location
    London
    Posts
    20
    Oh... I didn't realise it wasn't compiling for teensy 3.2 - Im sure it should be able to - I'll have a look when I get a moment, thanks for letting me know...

    I got alot of satisfaction from turning that knob back and forth, it sounds just like an old vinyl being scratched....

  14. #14
    Member propa's Avatar
    Join Date
    Apr 2018
    Location
    UK
    Posts
    93
    Quote Originally Posted by Moo View Post
    Oh... I didn't realise it wasn't compiling for teensy 3.2 - Im sure it should be able to - I'll have a look when I get a moment, thanks for letting me know...

    I got alot of satisfaction from turning that knob back and forth, it sounds just like an old vinyl being scratched....
    I got it to compile a while ago, the mistake was all my fault not realising you code was using the built in SD card and not the SD care from the audio shield.

    From my test so far I'm not getting great quality results on 3.2, very crakly/bitty, I think talking to the audio SD card over SPI may be causing some performance issues. Not sure if accessing the built in one on 3.6 performs a load quicker and therefore gets better quality results.

    Will get my hands on a 3.6 soon enough and test!

  15. #15
    Junior Member
    Join Date
    Jan 2017
    Posts
    14
    Quote Originally Posted by propa View Post
    I got it to compile a while ago, the mistake was all my fault not realising you code was using the built in SD card and not the SD care from the audio shield.

    From my test so far I'm not getting great quality results on 3.2, very crakly/bitty,
    I also got it to work on a 3.2 using audio shield SD card. I'm also getting some crackly sound, but weirdly enough I cannot change the 'rate' when the file is playing. It seems to poll the analogread at startup but once it plays it almost seems like the sketch gets stuck?

    Any clue as to where I should be looking to solve this? I am using the entire forked audio folder and can compile without errors.

  16. #16
    Member propa's Avatar
    Join Date
    Apr 2018
    Location
    UK
    Posts
    93
    Quote Originally Posted by bobkruijer View Post
    I also got it to work on a 3.2 using audio shield SD card. I'm also getting some crackly sound, but weirdly enough I cannot change the 'rate' when the file is playing. It seems to poll the analogread at startup but once it plays it almost seems like the sketch gets stuck?

    Any clue as to where I should be looking to solve this? I am using the entire forked audio folder and can compile without errors.
    Yes that sounds like my experience too, checked the serial monitor and the sensor data looked like it was being dragged through the monitor, wouldn't rest when pot was at 1. and I couldn't get it to change rate either. I think it's due to the SD card, from what I've read now the 3.6 card has 6 dedicated wires, nothing is shared with the card, the audio shield SD card uses four wire SPI communication which is slower than the dedicated one on 3.6 or 3.5.

    After a whole bunch of research yesterday Moo's seems like one of the more robust solutions, maybe bite the bullet and grab a better teensy? (apologies if that's not what you want to hear)

  17. #17
    Junior Member
    Join Date
    Jan 2017
    Posts
    14
    Hmm, I kinda see how the speed access speed could be slower, but then I would expect a slower response- not no response at all to be honest. From what I understand it is not an official audio lib, so maybe it just doesn't work well across different teensy models? Be that as it may, I'll probably will grab a 3.6 just to try if it works for my purposes, would be keen to hear your experience on it as well!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •