+ sync->next_pts += duration;
+
+ if( audio->config.in.samplerate == audio->config.out.samplerate ||
+ audio->config.out.codec == HB_ACODEC_AC3 ||
+ audio->config.out.codec == HB_ACODEC_DCA )
+ {
+ /*
+ * If we don't have to do sample rate conversion or this audio is
+ * pass-thru just send the input buffer downstream after adjusting
+ * its timestamps to make the output stream continuous.
+ */
+ }
+ else
+ {
+ /* Not pass-thru - do sample rate conversion */
+ int count_in, count_out;
+ hb_buffer_t * buf_raw = buf;
+ int channel_count = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown) *
+ sizeof( float );
+
+ count_in = buf_raw->size / channel_count;
+ /*
+ * When using stupid rates like 44.1 there will always be some
+ * truncation error. E.g., a 1536 sample AC3 frame will turn into a
+ * 1536*44.1/48.0 = 1411.2 sample frame. If we just truncate the .2
+ * the error will build up over time and eventually the audio will
+ * substantially lag the video. libsamplerate will keep track of the
+ * fractional sample & give it to us when appropriate if we give it
+ * an extra sample of space in the output buffer.
+ */
+ count_out = ( duration * audio->config.out.samplerate ) / 90000 + 1;
+
+ sync->data.input_frames = count_in;
+ sync->data.output_frames = count_out;
+ sync->data.src_ratio = (double)audio->config.out.samplerate /
+ (double)audio->config.in.samplerate;
+
+ buf = hb_buffer_init( count_out * channel_count );
+ sync->data.data_in = (float *) buf_raw->data;
+ sync->data.data_out = (float *) buf->data;
+ if( src_process( sync->state, &sync->data ) )
+ {
+ /* XXX If this happens, we're screwed */
+ hb_log( "sync: audio %d src_process failed", i );
+ }
+ hb_buffer_close( &buf_raw );
+
+ buf->size = sync->data.output_frames_gen * channel_count;
+ duration = ( sync->data.output_frames_gen * 90000 ) /
+ audio->config.out.samplerate;
+ }
+ buf->frametype = HB_FRAME_AUDIO;
+ buf->start = start;
+ buf->stop = start + duration;
+ sync->next_start = start + duration;
+ hb_fifo_push( fifo, buf );