I can't change the speed of a music file without avoiding that a disturbing noise appear

后端 未结 1 1672
生来不讨喜
生来不讨喜 2021-01-26 10:28

I am trying to change the speed of an audio file, if I do it with unsigned values all is all right, but once I start using double values things get messy, for instance, my code

相关标签:
1条回答
  • 2021-01-26 11:07

    Your reading-from falls on odd barriers: that is because of truncation the read-from byte starts at an odd location. Use the following to start from even location:

    for (i=0; i<(b2.length/frameSize); i++) {
          int ind=(int)((i*frameSize*playBackSpeed));
          if((ind%2)==1) ind++;
        for (j=0; j<frameSize; j++) {
            b2[(i*frameSize)+j] = b1[ind+j];
        }
    }
    

    Or you can change the jump to 4:

        if((ind%4)>0) ind+=(4-(ind%4));
    
    0 讨论(0)
提交回复
热议问题