Limits with setting the speed of playback with ofSoundPlayer

I’m trying to get really slow playback of a sound file using ofSoundPlayer. My understanding is that to set the speed in ofSoundPlayer you set the speed with setSpeed(float x). I had thought that the value of x would be multiplied by the sample rate.

For example normal playback would be:

1*44100 = 44,100 Hz

If I try to go for really slow back like 0.1 speed (0.1 * 44100 = 4410 Hz). I see no difference in the audio playback comparing 0.1 speed to 0.0001. I should expect to see a sample rate of 4.41Hz (0.0001*44100). However I think 0.1 is the slowest it will go to. I also noticed if you put 0 as the value it will sound the same as 0.1.

Is my understanding correct here and 0.1 playback would be the lowest possible for ofSoundPlayer? Is it possible to get slower playback with ofSoundPlayer?

I found that I had better luck with using ofxSoundObjects. There is a ofxSoundPlayerObject class in the add-on which allows you to set speed in a similar way to ofSoundPlayer but allows smaller values to be set.

I came across ofxSoundTouch which is a wrapper for the c++ library Sound Touch. I didn’t get that set up as it doesn’t have a file loader. But I guess you can load it as an audio buffer using ofxSoundObjects as it is described in this post.

glad that you are using ofxSoundObjects. :slight_smile:
ofSoundPlayer relies on several different implementations depending on the platform being compiled for. As such, there might be some limitations with some of these. Which platform are you using?
ofxSoundPlayerObject just loads the audio data through a third party library and plays it back, which allows you to manipulate the sound signal. The set speed function should work, although there are some bugs in the implementation of ofSoundBuffer's resampling algorithm. Take a look at this issue.
For loading a sound file into an ofSoundBuffer just do:

//add the ofxSoundObjects addon
#include "ofxSoundObjects.h"

ofSoundBuffer buffer;
if(ofxLoadSound(buffer, "path/to/the/sound/file")){
    //the sound file loaded successfully.
   //the sound file was not loaded.

hope this helps.

Thanks for your reply.

I’ve been trying on Mac OS and on Raspbian but both seem to not produce lower speeds than 0.1 with ofSoundPlayer

I did get the set speed to work with ofxSoundPlayerObject however I noticed some bad distortion when the audio was played at a speed of 0.05 or lower do you know why this would be? Would there be a way around this?

With the method you describe, you can load audio in to the ofSoundBuffer, this would just be modified as a ofSoundBuffer. What would be the best way of accessing the actual audio buffer? I notice there is getBuffer() however this just seems to be a vector of type ofSoundBuffer.

well that quite slow and I would suspect that some heavy artifacts might appear just because of the interpolation that is going on. The interpolation that is implemented in ofSoundBuffer is quite basic, so some other fancier algorithms might work better. Just think of reducing speed like stretching a digital image, you’ll begin to notice some weird arttifacts when you stretch it too much. This is pretty much the same.
Maybe using some other library for audio resampling or slowing down, such as ofxSoundTouch might work better.

This is how you access the sound buffer. the getBuffer() method returns a vector of floats, which is the audio data. Notice that the audio data is interleaved. Take a look at ofSoundBuffer documentation and ofBook´s sound chapter

A good way of doing this would be through ofxPd and using a granular sampler patch on the PD end…