1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-20 10:17:31 +00:00

audio: fix af_fmt_seconds_to_bytes

Was missing samplerate
This commit is contained in:
Stefano Pigozzi 2013-06-16 19:25:10 +02:00
parent b24bb7076d
commit c8c70dce57
4 changed files with 13 additions and 8 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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)