1

In a C++ Program, I am trying to downsample blocks of 8192 audio samples (-32768...32767). The original Sampling Rate is 48kHz, and I'd like to have 16kHz.

The ratio 16/48 should yield roughly 2731 samples if the original number of samples is 8192.

I tried to use libav for this, using this code for every block of 8192 input samples:

struct AVResampleContext* ctx = av_resample_init(16000,48000,16,10,1,1.0)
av_resample(ctx,dataIn,dataOut,&samplesConsumed,8192,2731,0)

This seems to work to a certain degree, however - the last 30 samples or so are zeros in each output block of 2731 samples, so one can always here an "audible click"

What am I doing wrong here?

Thank you very much for any help!

Nox997
  • 71
  • 5
  • I'm not familiar with the library, but I think you need to check the return value to see how many samples were actually produced. – Mike Seymour Mar 06 '12 at 17:25
  • How many samples output does av_resample return? – Joachim Isaksson Mar 06 '12 at 17:27
  • Thank you for your help! I've checked the samplesConsumed variable, at it's only consuming 8142 values of the original 8192 values. Do you have any clue why this might be the case? – Nox997 Mar 06 '12 at 18:09
  • Looking at the doxygen: http://libav.org/doxygen/master/avcodec_8h.html#af5c7cb29680ca6710ef3bd7e8aaeac0b Haven't you got the second and third args the wrong way round? – cmannett85 Mar 06 '12 at 18:20
  • Sorry, that was only wrong in the post above. The actual code is correct... – Nox997 Mar 06 '12 at 18:33
  • so, is there a "more sane" documentation of libav than just the doxygen one? – Nox997 Mar 06 '12 at 19:17

0 Answers0