2014-02-18 8 views
0

샘플에서 피치 쉬프트를 시도하고 있습니다. 선형 보간 방법을 사용하고 있습니다.선형 보간 - 오디오 피치 쉬프트

피치가 전체 정수 값이면 피치가 깨끗하게 이동합니다. 피치 시프트되는 양이 합리적이면 사운드가 심하게 왜곡됩니다. 구현이 효과가있는 것처럼 보입니다.

여기 내 코드입니다. 나는 잘 말하려고했습니다.

public void generateOutTrack() 
{ 
    Note currNote; 
    float[] output=new float[pattern.getPlayTimeInSmps()];//returns total play time of pattern in #samples. 


    float[] currSample=sample.getData();//the pcm data of the sample to be used 
    int currPeriod=0;//length of next note in number of samples 
    int outputPtr=0;//points to next sample in output buffer array 
    float pitch;//amount to pitch sample by 
    float linInt=0;//linear interpolater 
    float phasePtr=0;//floating point index in sample 
    int ptr=0;//integer index into sample 

    JavAud.checkRange(currSample); 

    while((currNote=pattern.nextNote())!=null)//each iteration plays one note 
    { 

     currPeriod=currNote.getPeriodInSmps();//length of current note in samples 
     pitch=currNote.getPitch();//pitch of current note 

     for(int i=0;i<currPeriod;i++)//run for length of note 
     { 
      ptr=(int)phasePtr;//floor of floating point index 
      linInt=phasePtr-ptr; 

      //if we are not at end of sample copy data to output 
      if(ptr<currSample.length*(1/pitch)-1) 
      { 

       //linear interpolation pitch shifting 
       output[outputPtr]=(currSample[ptr+1]*linInt)+(currSample[ptr]*(1-linInt)); 

       //alternate pitch shifting by simple sample dropping(has less distortion) 
       //output[outputPtr]=currSample[ptr]; 

      } 
      else//else silent 
      { 
       output[outputPtr]=0; 
      } 

      outputPtr++; 
      phasePtr=phasePtr+pitch; 
     } 

     phasePtr=0; 

    } 
    JavAud.checkRange(output); 
    WavFileWriter writer = new WavFileWriter(); 
    writer.writeWave(new WavFile(1, JavAud.GLB_SMP_RATE, output), "outputTone.wav"); 

} 
+1

안녕하세요. 코드에서 오류를 발견하도록 사람들에게 요청하는 것은 특히 생산적이지 않습니다. 디버거를 사용하거나 인쇄 문을 추가하여 프로그램의 진행 상황을 추적하고 발생할 것으로 예상되는 것과 비교하여 문제를 격리해야합니다. 이 둘이 갈라지면 문제를 발견했습니다. (그리고 필요하다면, [최소 테스트 케이스] (http : // sscce/org)를 구성해야합니다. –

답변

1

리샘플링으로 피치 이동을하는 것처럼 보입니다. 선형 보간보다 더 나은 품질 리샘플링을 수행하는 일반적인 방법 중 하나는 보간 커널로 윈도우 Sinc 저역 통과 필터를 사용하는 것입니다. 윈도우 화 된 Sinc 리샘플링의 한 (느린) 방법에 대한 의사 코드는 다음과 같습니다. http://www.nicholson.com/rhn/dsp.html#3

+0

알고리즘 선택 때문에 나쁜 품질을 얻지는 않습니다. 코드 어딘가에 버그로 인해 나쁜 품질을 얻고 있습니다. 나는 무거운 왜곡을 얻고 있으며, 골치 아픈 것에서 벗어난다. – ScottF