1

I have a program which reads

4096 frames (16384 bytes)
16bit LE
48000 Hz
PCM

into a 16384 bytes large buffer per "read" from a kernel module (= read from ALSA's ring-buffer).

After each "read" I have to downsample the 48 kHz to 44.1 kHz and the output must be smaller/equal 4096 frames (streaming to Apple's Airport Express).

It already works, but the output sounds "too fast" and is "flickering" (I think due to lost frames in the "read", described below), then stops sometimes (I think "too fast" causes "wait for data").

For the resampling I use src_process from libsamplerate (aka Secret Rabbit Code):

int src_process (SRC_STATE *state, SRC_DATA *data) ;

with following parameters:

  data_in       : A pointer to the input data samples.
  input_frames  : 4096
  data_out      : A pointer to the output data samples.
  output_frames : 4096
  src_ratio     : 44100 / 48000 -> 0,91875

My kernel module tells me when I missed some frames in ALSA's ring-buffer inside and this happens.

I'am missing about 100 frames / "read".

Maybe someone understands the problem and can say something like "4096 frames-buffer is too small" or something else.

Meanwhile I will re-check my code.

Martin L.
  • 3,006
  • 6
  • 36
  • 60
  • If you're re-sampling the number of input frame won't be equal to the number of output frames, in this case you should have like ~4458 frames as input and 4096 frames as output – Musa Jun 29 '12 at 07:12
  • Yes, that was also my first thought. But then I re-checked the docs and saw "output_frames" is the maximum frame-amount of output. I have to check the real amount this evening, I'm remembering something like 3000-4000 frames for my 4096 input-frames. – Martin L. Jun 29 '12 at 07:16
  • You may need to do multiple passes to fill your output buffer as 4096 in will generate < 4096 out. Use `output_frames_gen ` to determine how to set `data_out` to fill the rest of the buffer – Musa Jun 29 '12 at 07:29
  • This is maybe the problem. I will check this. – Martin L. Jun 29 '12 at 07:34

0 Answers0