Hi,
I am testing speed effect using soxlib APIs. Test is based on the example0 but flanger is just replaced by speed and with proper argument.
Code executes with no error notice but the speed effect is not effective when playing the result audio file.
cd src/
make examples
./example0 kick_drum.wav kick_drum_out.wav
./play kick_drum_out.wav # is played at same speed than input sample. No change but Volume is effective however.
./play kick_drum.wav speed 3 # Using shell command is actually works
Using soxlib API, speed seems being by-passed when sox flows the effect chain.
Using shell command, it is working good.
It is expected ?
Attached code example0 with mods.
Hi! I've had a look at this and it seems that the reason is that "speed" changes the sample rate but the call to sox_open_write() specifies the sample rate of the output file as a copy of that of the input file.
It is sox.c, which is "just" another client of libsox, that automatically inserts effects in the chain to adapt the sample rate at the end, make the number of channels match, not libsox, which is why it works from the command line as you expected.
If you add a "rate 48000" (or whatever the sample rate of the output file is) after the "speed", you get the output you expected, or you can achieve the "speed" effect you wanted simply by multiplying or dividing in->signal.rate by the factor in question before copying it into out->signal.rate without any "speed" effect at all.
https://codeberg.org/sox_ng/sox_ng/issues/442
Last edit: Martin Guy 2025-12-27