From bff03a181f8c4102a75144f818ea15ea53165170 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 23 May 2013 21:23:32 +0200 Subject: core: add a spsc ringbuffer implementation Currently every single AO was implementing it's own ringbuffer, many times with slightly different semantics. This is an attempt to fix the problem. I stole some good ideas from ao_portaudio's ringbuffer and went from there. The main difference is this one stores wpos and rpos which are absolute positions in an "infinite" buffer. To find the actual position for writing / reading just apply modulo size. The producer only modifies wpos while the consumer only modifies rpos. This makes it pretty easy to reason about and make the operations thread safe by using barriers (thread safety is guaranteed only in the Single-Producer/Single- Consumer case). Also adapted ao_coreaudio to use this ringbuffer. --- audio/format.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'audio/format.c') diff --git a/audio/format.c b/audio/format.c index 5b1262956c..f9bfcb5ba8 100644 --- a/audio/format.c +++ b/audio/format.c @@ -110,6 +110,16 @@ static bool af_fmt_valid(int format) return (format & AF_FORMAT_MASK) == format; } +int af_fmt_seconds_to_bytes(int format, float seconds, int channels) +{ + int bps = (af_fmt2bits(format) / 8); + int framelen = channels * bps; + int bytes = seconds * bps; + if (bytes % framelen) + bytes += framelen - (bytes % framelen); + return bytes; +} + int af_str2fmt_short(bstr str) { if (bstr_startswith0(str, "0x")) { -- cgit v1.2.3