Menu

Output Garbled

Help
2018-04-03
2018-04-03
  • herdian ferdianto

    Hi

    I am using SoundTouch with QT to do some pitch shifting. And currently using SOUNDTOUCH_INTEGER_SAMPLES instead of the float samples. Please see the code below

        const unsigned char *ptr = reinterpret_cast<const unsigned char*>(data.data());
        SAMPLETYPE sampleBuffer[BUFF_SIZE];
        int nSamples = BUFF_SIZE / nChannels;
        for(int i=0; i<BUFF_SIZE; i++){
            sampleBuffer[i] = reinterpret_cast<SAMPLETYPE>(ptr);
            ptr+=sampleSize;
        }
        soundTouch.putSamples(&sampleBuffer[0], nSamples);
        do
        {
            SAMPLETYPE outputSamples[BUFF_SIZE*2];
            nSamples = soundTouch.receiveSamples(&outputSamples[0], BUFF_SIZE/nChannels);
            if (nSamples>0) 
            {
                int sampleByteOut = nSamples * nChannels * sizeof(SAMPLETYPE);
                QByteArray out( sampleByteOut, 0 );
                short *data_s = reinterpret_cast<short *>(out.data());
                for(int i=0,len=nSamples*nChannels; i<len; i++) {
                    data_s[i] = outputSamples[i];
                }
                outputBuffer->write(out, sampleByteOut);
            }
        } while (nSamples != 0);
    

    Anything I missed out? I was trying to use the SoundStretch but still not working.

     
  • herdian ferdianto

    I got the issues covered by using float buffer
    now the issue is stutter. I will look for another solution for this.

     
  • oparviai

    oparviai - 2018-04-03

    Check these:
    How does your code know how many input samples it gets? If it has different amount of input samples than it expects, it surely stutters
    Casting between types. Your code has quite many castings between data type and it's difficult to say from the source code if they are correct.

     

Log in to post a comment.