I'm a PD newbie and I'm trying to figure out how to speed up or slow down a song file similar to speeding up and slowing down a record. I did some searches on the forums but didn't find exactly what I was looking for. I discovered the help file for readsf~ and that enabled me to get a song file playing through PD and from what I can tell the next step is simply adding something to change the sample rate dynamically. I tried block~ but that was giving me artifacts. Is there a simple patch somewhere that I can use for this?
-
Slowing down / speeding up a song
-
ShankarBaba, thanks for pointing me in the right direction. I've been playing around B09 and I think I understand a lot of it - the sound file is being read into a table and that table information is being manipulated before being sent back out to the speakers, but I can't seem to find what's controlling the length of the clip being played - right now it's extremely short. What do I modify to play a continuous file instead of a short loop of the file?
-
The frequency is the speed, the higher it is the faster it'll loop. The chunk size is the size of the file to loop. For its example set it to 100 to play the whole file. The chunk size should be the filesize divided by 441 to play the whole file. You get the file's size through soundfiler's output.
-
Thanks saturno, but I can't seem to get it working yet. The length of my file as output by soundfiler is 44103. When I set the chunk size to 44103, the output volume to 100, and play with the frequency (1 - 500) all I hear is a hum which seems to be a bit of the sound file looping extremely quickly. However, if I set the frequency to 1 and the chunk size to 100 I hear the first second of the song at the correct speed. When I fiddle with the chunk size, setting it to 150 for instance, it seems to just speed up the first second rather than increase the length. I tried setting chunk to around 500, which is chipmunk speed at a frequency of 1, and decreasing the frequency to a fraction using a /10 object in between the number and phasor but other than slowing the song back down that only seemed to add empty space before the beginning of the loop. Any ideas?
-
The chunk size is in 100th of a second, soundfiler's output is in sample size. You have to divide that by 441 to get it in 100th of a second. Your sound file is about 100 100th of a second long. So it really is just one second long. Perhaps your sound file is actually longer than that but without telling soundfiler to resize the array it will only load enough of your file to fill up the array (which happens to be set at 44103). Try setting the message to:
open -resize yourfile.wav table17
That will resize the array to contain the entire file up to 91 seconds (Array's can't be bigger than 4000000 elements in PD).
-
saturno - perfect! That worked. So what are my options in terms of getting around the 91 sec limit? And why is it so roundabout to change the sample rate? Is there no way to do that coming out of readsf instead of feeding it into a table first?
-
> And why is it so roundabout to change the sample rate?
I'm not sure I understand the question
> Is there no way to do that coming out of readsf instead of feeding it into a table first?
Not that I now of. You need to use tabread4~ in order to change the speed of signal, and that requires an array.
> So what are my options in terms of getting around the 91 sec limit?
Using more than one array and changing which array it's playing back at the end of the loop.
-
> And why is it so roundabout to change the sample rate?
I think what I meant was that from what I've read about MAX/MSP modifying the sample rate of an audio file is a little bit easier for a beginner and I was hoping PD would function similarly.>Using more than one array and changing which array it's playing back at the end of the loop.
What would this look like? Could I do it with two arrays, reading back to the audio file and swapping the next set of data into one of them while the other is playing? Or would I want to build out a series of arrays at the initial file load so that I only need to load the sound file once? -
> And why is it so roundabout to change the sample rate?
Now I understand. The best way to change the sample rate of a digital signal without loosing too much quality and being able to do so efficiently in a real-time system is to use 4 point interpolation. That's what tabread4~ does.tabread4~ accepts an input signal which tells it the index to look up in its table. Since it's a signal, it could receive a non integer value (like 3.25) and that's why it does 4 point interpolation. In our example here it would need to figure out what's a 4th of the way between the index 3 and index 4.
Lets assume a table that's 1 second long. In order to play through tabread4~ without modifying its speed we would have to generate a signal which is a straight line that goes from 0 to 44099 in 1 second. If you generate the line in 0.5 seconds it would play it twice as fast and an octave up. You could try this with the line~ object, but for a loop program it is better to use the phasor~ object which generates a saw tooth wave (a straight line that repeats).
Why is it so roundabout? because this way we can do a lot more than just play loops at different speeds. Check out B08 - B14 to see what I mean.
> What would this look like? ...
It would be better to load it once since loading 91 seconds of data per array would cause an IO block generating pauses in your program.In order to hide the implementation detail of how it works you can create an abstraction. I've added here a playloop~ abstraction. Open playloop~-help.pd
You can create as many as you like. I've used $0 in the table name so each instance will get its own array. You can change it to make it work in stereo or to let you set start and end points.
-
Nice! Thanks for the example. It's working wonderfully for me so I'm going to dig into it and see if I can extend it beyond the 91 second limit given your instructions.
-
you can overwrite the maximum limit:
open -maxsize 100000000 yourfile.wav table17
just put some silly big number in where 100000000 is.
-
>>And why is it so roundabout to change the sample rate? Is there no way to do that coming out of readsf instead of feeding it into a table first?<<
i wish this were possible too. it's annoyng in pd that everything needs to be fixed to multiples of a single samplerate.
-
> open -maxsize 100000000 yourfile.wav table17
Did not now that, should prove useful!
But be careful when loading large files since it will cause an IO BLOCK (PD will stutter while loading the file).
> it's annoying in pd that everything needs to be fixed to multiples of a single samplerate
That's not exactly true. If it were than we would only be able to change the speed of signals up by multiples of the the samplerate and we would never be able to slow anything down. The whole point of objects like tabread4~ and tabosc4~ is to allow us to change the samplerate arbitrarily.
It is true about objects like del, metro and line~ but if it weren't then PD would only be useful on the most power computers around.
>i wish this were possible too
An object like readsf~ that buffers and allows for arbitrary samplerate changes sound like an interesting external project. Wonder if anyone is working on it, or has.
-
An object like readsf~ that buffers and allows for arbitrary samplerate changes sound like an interesting external project. Wonder if anyone is working on it, or has.
[readanysf~]
-
ClaudiusMaximus, readanysf sounds like exactly what I've been looking for and hopefully the dependencies don't prove to be a problem. Seems like most of them should be pretty easy to install on my mac.
Hardoff and Satruno, thanks for all the help - I still want to dig into the essentials of pulling in sound files and manipulating them through tables and if I can't get readanysf up and running I know I'll be back here bugging you guys for help on the more traditional methods.