샘플에서 피치 쉬프트를 시도하고 있습니다. 선형 보간 방법을 사용하고 있습니다.선형 보간 - 오디오 피치 쉬프트
피치가 전체 정수 값이면 피치가 깨끗하게 이동합니다. 피치 시프트되는 양이 합리적이면 사운드가 심하게 왜곡됩니다. 구현이 효과가있는 것처럼 보입니다.
여기 내 코드입니다. 나는 잘 말하려고했습니다.
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");
}
안녕하세요. 코드에서 오류를 발견하도록 사람들에게 요청하는 것은 특히 생산적이지 않습니다. 디버거를 사용하거나 인쇄 문을 추가하여 프로그램의 진행 상황을 추적하고 발생할 것으로 예상되는 것과 비교하여 문제를 격리해야합니다. 이 둘이 갈라지면 문제를 발견했습니다. (그리고 필요하다면, [최소 테스트 케이스] (http : // sscce/org)를 구성해야합니다. –