diff options
| author | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2007-08-15 13:42:38 +0100 |
|---|---|---|
| committer | Darren Salt <linux@youmustbejoking.demon.co.uk> | 2007-08-15 13:42:38 +0100 |
| commit | 7047d9e5acf97c91a523c99ccc4b008a35a3e094 (patch) | |
| tree | 80a7a22b47640a7b97f4f027797abf2d704d07e5 /src/xine-engine/audio_out.c | |
| parent | 27aeb069aa930c0c8fa0e0f41885bbedc69d0bcb (diff) | |
| download | xine-lib-7047d9e5acf97c91a523c99ccc4b008a35a3e094.tar.gz xine-lib-7047d9e5acf97c91a523c99ccc4b008a35a3e094.tar.bz2 | |
Fix an audio resampling problem which was causing regular clicking.
The cause was that the resampling code was using only the samples in the buffer
but not really handling the transition between two buffers (which it would
handle completely independently). The new code remembers the last sample from
the previous buffer and uses it in the resampling. We therefore end up one
sample behind and without the clicks.
Diffstat (limited to 'src/xine-engine/audio_out.c')
| -rw-r--r-- | src/xine-engine/audio_out.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 6f5351986..93768224b 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -251,6 +251,7 @@ typedef struct { * sure nobody will change speed without going through xine.c:set_speed_internal */ int slow_fast_audio; /* play audio even on slow/fast speeds */ + int16_t last_sample[RESAMPLE_MAX_CHANNELS]; audio_buffer_t *frame_buf[2]; /* two buffers for "stackable" conversions */ int16_t *zero_space; @@ -746,19 +747,19 @@ static audio_buffer_t* prepare_samples( aos_t *this, audio_buffer_t *buf) { switch (this->input.mode) { case AO_CAP_MODE_MONO: ensure_buffer_size(this->frame_buf[1], (this->output.bits>>3), num_output_frames); - _x_audio_out_resample_mono (buf->mem, buf->num_frames, + _x_audio_out_resample_mono (this->last_sample, buf->mem, buf->num_frames, this->frame_buf[1]->mem, num_output_frames); buf = swap_frame_buffers(this); break; case AO_CAP_MODE_STEREO: ensure_buffer_size(this->frame_buf[1], (this->output.bits>>3)*2, num_output_frames); - _x_audio_out_resample_stereo (buf->mem, buf->num_frames, + _x_audio_out_resample_stereo (this->last_sample, buf->mem, buf->num_frames, this->frame_buf[1]->mem, num_output_frames); buf = swap_frame_buffers(this); break; case AO_CAP_MODE_4CHANNEL: ensure_buffer_size(this->frame_buf[1], (this->output.bits>>3)*4, num_output_frames); - _x_audio_out_resample_4channel (buf->mem, buf->num_frames, + _x_audio_out_resample_4channel (this->last_sample, buf->mem, buf->num_frames, this->frame_buf[1]->mem, num_output_frames); buf = swap_frame_buffers(this); break; @@ -766,7 +767,7 @@ static audio_buffer_t* prepare_samples( aos_t *this, audio_buffer_t *buf) { case AO_CAP_MODE_5CHANNEL: case AO_CAP_MODE_5_1CHANNEL: ensure_buffer_size(this->frame_buf[1], (this->output.bits>>3)*6, num_output_frames); - _x_audio_out_resample_6channel (buf->mem, buf->num_frames, + _x_audio_out_resample_6channel (this->last_sample, buf->mem, buf->num_frames, this->frame_buf[1]->mem, num_output_frames); buf = swap_frame_buffers(this); break; @@ -775,6 +776,25 @@ static audio_buffer_t* prepare_samples( aos_t *this, audio_buffer_t *buf) { /* pass-through modes: no resampling */ break; } + } else { + /* maintain last_sample in case we need it */ + switch (this->input.mode) { + case AO_CAP_MODE_MONO: + memcpy (this->last_sample, &buf->mem[buf->num_frames - 1], sizeof (this->last_sample[0])); + break; + case AO_CAP_MODE_STEREO: + memcpy (this->last_sample, &buf->mem[(buf->num_frames - 1) * 2], 2 * sizeof (this->last_sample[0])); + break; + case AO_CAP_MODE_4CHANNEL: + memcpy (this->last_sample, &buf->mem[(buf->num_frames - 1) * 4], 4 * sizeof (this->last_sample[0])); + break; + case AO_CAP_MODE_4_1CHANNEL: + case AO_CAP_MODE_5CHANNEL: + case AO_CAP_MODE_5_1CHANNEL: + memcpy (this->last_sample, &buf->mem[(buf->num_frames - 1) * 6], 6 * sizeof (this->last_sample[0])); + break; + default:; + } } /* mode conversion */ @@ -2160,6 +2180,8 @@ xine_audio_port_t *_x_ao_new_port (xine_t *xine, ao_driver_t *driver, fifo_append (this->free_fifo, buf); } + + memset (this->last_sample, 0, sizeof (this->last_sample)); /* buffers used for audio conversions */ for (i=0; i<2; i++) { |
