summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/format.c4
-rw-r--r--audio/format.h2
-rw-r--r--audio/out/ao_coreaudio.c12
-rw-r--r--audio/out/ao_portaudio.c3
4 files changed, 13 insertions, 8 deletions
diff --git a/audio/format.c b/audio/format.c
index f9bfcb5ba8..a65c10472d 100644
--- a/audio/format.c
+++ b/audio/format.c
@@ -110,11 +110,11 @@ 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 af_fmt_seconds_to_bytes(int format, float seconds, int channels, int samplerate)
{
int bps = (af_fmt2bits(format) / 8);
int framelen = channels * bps;
- int bytes = seconds * bps;
+ int bytes = seconds * bps * samplerate;
if (bytes % framelen)
bytes += framelen - (bytes % framelen);
return bytes;
diff --git a/audio/format.h b/audio/format.h
index d7b3b34c42..f3aa3d8af0 100644
--- a/audio/format.h
+++ b/audio/format.h
@@ -133,7 +133,7 @@ int af_str2fmt_short(bstr str);
int af_fmt2bits(int format);
// Amount of bytes that contain audio of the given duration, aligned to frames.
-int af_fmt_seconds_to_bytes(int format, float seconds, int channels);
+int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int samplerate);
char* af_fmt2str(int format, char* str, int size);
const char* af_fmt2str_short(int format);
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index d3491f17f8..ea9e431535 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -94,6 +94,12 @@ struct priv
struct mp_ring *buffer;
};
+static int get_ring_size(struct ao *ao)
+{
+ return af_fmt_seconds_to_bytes(
+ ao->format, 0.5, ao->channels.num, ao->samplerate);
+}
+
static OSStatus theRenderProc(void *inRefCon,
AudioUnitRenderActionFlags *inActionFlags,
const AudioTimeStamp *inTimeStamp,
@@ -621,8 +627,7 @@ static int init(struct ao *ao, char *params)
ao->bps = ao->samplerate * inDesc.mBytesPerFrame;
ao->buffersize = ao->bps;
- int bufbytes = af_fmt_seconds_to_bytes(ao->format, 0.5, ao->channels.num);
- p->buffer = mp_ring_new(p, bufbytes);
+ p->buffer = mp_ring_new(p, get_ring_size(ao));
ao->outburst = maxFrames;
print_buffer(p->buffer);
@@ -859,8 +864,7 @@ static int OpenSPDIF(struct ao *ao)
/* For ac3/dts, just use packet size 6144 bytes as chunk size. */
int chunk_size = p->stream_format.mBytesPerPacket;
ao->buffersize = ao->bps;
- int bufbytes = af_fmt_seconds_to_bytes(ao->format, 0.5, ao->channels.num);
- p->buffer = mp_ring_new(p, bufbytes);
+ p->buffer = mp_ring_new(p, get_ring_size(ao));
ao->outburst = chunk_size;
print_buffer(p->buffer);
diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c
index 62a58c0fed..d51d01ed9b 100644
--- a/audio/out/ao_portaudio.c
+++ b/audio/out/ao_portaudio.c
@@ -91,7 +91,8 @@ static bool check_pa_ret(int ret)
static int seconds_to_bytes(struct ao *ao, double seconds)
{
- return af_fmt_seconds_to_bytes(ao->format, seconds, ao->channels.num);
+ return af_fmt_seconds_to_bytes(ao->format, seconds, ao->channels.num,
+ ao->samplerate);
}
static int to_int(const char *s, int return_on_error)