Make audio ring buffer size a multiple of 3,5,7,8.

This commit is contained in:
Johns 2012-04-22 17:17:54 +02:00
parent ebe0beb400
commit 207871fd9b
4 changed files with 31 additions and 13 deletions

View File

@ -1,6 +1,8 @@
User johns User johns
Date: Date:
Make audio ring buffer size a multiple of 3,5,7,8.
Add reset ring buffer support.
Fix bug: alloca wrong size for audio buffer. Fix bug: alloca wrong size for audio buffer.
Handle jump in stream like stream start. Handle jump in stream like stream start.
Always compile audio drift correction. Always compile audio drift correction.

13
audio.c
View File

@ -178,8 +178,8 @@ static int AudioVolume; ///< current volume (0 .. 1000)
extern int VideoAudioDelay; ///< import audio/video delay extern int VideoAudioDelay; ///< import audio/video delay
/// default ring buffer size ~2s 8ch 16bit /// default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)
static const unsigned AudioRingBufferSize = 2 * 48000 * 8 * 2; static const unsigned AudioRingBufferSize = 3 * 5 * 7 * 8 * 2 * 1000;
static int AudioChannelsInHw[9]; ///< table which channels are supported static int AudioChannelsInHw[9]; ///< table which channels are supported
enum _audio_rates enum _audio_rates
@ -684,9 +684,7 @@ static int AudioRingAdd(unsigned sample_rate, int channels, int use_ac3)
AudioRing[AudioRingWrite].HwSampleRate = sample_rate; AudioRing[AudioRingWrite].HwSampleRate = sample_rate;
AudioRing[AudioRingWrite].HwChannels = AudioChannelMatrix[u][channels]; AudioRing[AudioRingWrite].HwChannels = AudioChannelMatrix[u][channels];
AudioRing[AudioRingWrite].PTS = INT64_C(0x8000000000000000); AudioRing[AudioRingWrite].PTS = INT64_C(0x8000000000000000);
// reset ring-buffer RingBufferReset(AudioRing[AudioRingWrite].RingBuffer);
RingBufferReadAdvance(AudioRing[AudioRingWrite].RingBuffer,
RingBufferUsedBytes(AudioRing[AudioRingWrite].RingBuffer));
atomic_inc(&AudioRingFilled); atomic_inc(&AudioRingFilled);
@ -856,6 +854,11 @@ static int AlsaPlayRingbuffer(void)
// FIXME: if not all are written, we double amplify them // FIXME: if not all are written, we double amplify them
} }
frames = snd_pcm_bytes_to_frames(AlsaPCMHandle, avail); frames = snd_pcm_bytes_to_frames(AlsaPCMHandle, avail);
if (avail != snd_pcm_frames_to_bytes(AlsaPCMHandle, frames)) {
Error(_("audio/alsa: bytes lost -> out of sync\n"));
}
#ifdef DEBUG
#endif
for (;;) { for (;;) {
if (AlsaUseMmap) { if (AlsaUseMmap) {

View File

@ -48,6 +48,18 @@ struct _ring_buffer_
atomic_t Filled; ///< how many of the buffer is used atomic_t Filled; ///< how many of the buffer is used
}; };
/**
** Reset ring buffer pointers.
**
** @param rb Ring buffer to reset read/write pointers.
*/
void RingBufferReset(RingBuffer * rb)
{
rb->ReadPointer = rb->Buffer;
rb->WritePointer = rb->Buffer;
atomic_set(&rb->Filled, 0);
}
/** /**
** Allocate a new ring buffer. ** Allocate a new ring buffer.
** **
@ -69,10 +81,8 @@ RingBuffer *RingBufferNew(size_t size)
} }
rb->Size = size; rb->Size = size;
rb->ReadPointer = rb->Buffer;
rb->WritePointer = rb->Buffer;
rb->BufferEnd = rb->Buffer + size; rb->BufferEnd = rb->Buffer + size;
atomic_set(&rb->Filled, 0); RingBufferReset(rb);
return rb; return rb;
} }
@ -89,7 +99,7 @@ void RingBufferDel(RingBuffer * rb)
/** /**
** Advance write pointer in ring buffer. ** Advance write pointer in ring buffer.
** **
** @param rb Ring buffer to adance write pointer. ** @param rb Ring buffer to advance write pointer.
** @param cnt Number of bytes to be adavanced. ** @param cnt Number of bytes to be adavanced.
** **
** @returns Number of bytes that could be advanced in ring buffer. ** @returns Number of bytes that could be advanced in ring buffer.
@ -198,7 +208,7 @@ size_t RingBufferGetWritePointer(RingBuffer * rb, void **wp)
/** /**
** Advance read pointer in ring buffer. ** Advance read pointer in ring buffer.
** **
** @param rb Ring buffer to adance read pointer. ** @param rb Ring buffer to advance read pointer.
** @param cnt Number of bytes to be advanced. ** @param cnt Number of bytes to be advanced.
** **
** @returns Number of bytes that could be advanced in ring buffer. ** @returns Number of bytes that could be advanced in ring buffer.

View File

@ -23,13 +23,16 @@
/// @addtogroup Ringbuffer /// @addtogroup Ringbuffer
/// @{ /// @{
///< ring buffer typedef /// ring buffer typedef
typedef struct _ring_buffer_ RingBuffer; typedef struct _ring_buffer_ RingBuffer;
///< create new ring buffer /// reset ring buffer pointers
extern void RingBufferReset(RingBuffer *);
/// create new ring buffer
extern RingBuffer *RingBufferNew(size_t); extern RingBuffer *RingBufferNew(size_t);
///< free ring buffer /// free ring buffer
extern void RingBufferDel(RingBuffer *); extern void RingBufferDel(RingBuffer *);
/// write into ring buffer /// write into ring buffer