Menu

Change tempo in non realtime context without time offset

Help
2023-05-03
2023-05-05
  • Regis Houde

    Regis Houde - 2023-05-03

    I try to use Soundtouch to change the tempo of a recording without introducing a time offset. As a matter of fact, I noticed that the output is always shift left (sounds starts before what is expected). For example, if a recording is at tempo 120 Bpm and the sounds starts at sample 1000, I would expect that the sound would start at sample 2000 if I change the tempo to 60 Bpm but it´s not the case, the sound starts before that.

    Is it possible to avoid that? If not, is it possible to know the exact value of the offset?

    thank you

     
  • oparviai

    oparviai - 2023-05-05

    Hello. Given that you leave a message here, please verify that you have the latest version of SoundTouch available nowadays in here: https://codeberg.org/soundtouch/soundtouch

     
  • Regis Houde

    Regis Houde - 2023-05-05

    I have the latest version. I am using the files from the tar release (https://www.surina.net/soundtouch/soundtouch-2.3.2.tar.gz)

    I did more tests and here are the result.

    Initial data : 120 BPM
    Guitar starting at 7,894034 bar

    Converting to following BPM, the Guitar start is offset as follow :

    Tempo (bpm) Event (bar) Delta
    60 7,8188 -0,0752
    75 7,8521 -0,0419
    90 7,8414 -0,0526
    105 7,8588 -0,0353
    120 7,8940 0,0000
    135 7,8880 -0,0060
    150 7,8801 -0,0139
    165 7,9195 0,0254
    180 7,9086 0,0146

    Maybe, I am doing something wrong. Here is my code:

    HANDLE stProcessor = soundtouch_createInstance();
    try {
    
            soundtouch_setChannels(stProcessor, nbChannels);
            soundtouch_setSampleRate(stProcessor, asioDriverInfo.sampleRate);
            soundtouch_setTempo(stProcessor, newTempo/oldTempo);
    
    
            soundtouch_putSamples(stProcessor, oldData, oldNumSamples);
    
            soundtouch_flush(stProcessor); // To make sure we have everything!
    
            int index  = 0;
            int nReceived;
    
            do
            {
                nReceived = soundtouch_receiveSamples(stProcessor, newData + nbChannels*index, bufs.numSamples - index);
                index += nReceived;
                qInfo("nReceived = %d nReceived/nbChannels = %d", nReceived, nReceived/nbChannels);
            }
            while((nReceived > 0) && (index < bufs.numSamples));
    
            soundtouch_clear(stProcessor);
    
            }
    
    }
    catch (const std::exception& e)
    {
        qInfo("ERROR Catch! %s", e.what());
    }
    
    soundtouch_destroyInstance(stProcessor);
    
    std::free(oldData);
    std::free(newData);
    
     

Log in to post a comment.