문제

I have raw audio data in the form of

vector<short> m_shorts;

The audio data is 22050 kHz mono.

Does anybody have any idea how I can (without any third party library) quickly convert the short vector to 48000 Hz mono?

I know it will not improve the sound. This is only for passing the audio data to an effect (which sounds better with higher sample rate).

Thank you for the help.

도움이 되었습니까?

해결책

If you want to double the sampling frequency from 22050Hz to 44100Hz (which is the double of 22050) you might do some linear interpolation:

vector<short> m_shorts;
vector<short> outputs;
unsigned inplen = m_shorts.length();
output.resize(2*inplen+1);
for (unsigned ix = 0; ix < inplen; ix++) { // not sure of the bounds
  output[2*ix] = m_shorts[ix];
  output[2*ix+1] = (m_shorts[ix] + m_shorts[ix+1])/2;
}

But I am not an audio or signal processing expert. There could be more clever ways... (perhaps a Fourier transform then an inverse Fourier).

And I am not sure that "would sounds better".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top