From 31a10f7c38887294af758d21a19596b7772f328a Mon Sep 17 00:00:00 2001 From: Marcoen Hirschberg Date: Tue, 27 May 2014 08:21:18 +0200 Subject: af_fmt2bits: change to af_fmt2bps (bytes/sample) where appropriate In most places where af_fmt2bits is called to get the bits/sample, the result is immediately converted to bytes/sample. Avoid this by getting bytes/sample directly by introducing af_fmt2bps. --- audio/audio.c | 2 +- audio/audio.h | 2 +- audio/decode/ad_mpg123.c | 2 +- audio/format.c | 21 +++++++++++++-------- audio/format.h | 1 + audio/out/ao.c | 2 +- audio/out/ao_dsound.c | 8 ++++---- audio/out/ao_lavc.c | 2 +- audio/out/ao_oss.c | 2 +- audio/out/ao_pcm.c | 2 +- audio/out/ao_portaudio.c | 2 +- 11 files changed, 26 insertions(+), 20 deletions(-) (limited to 'audio') diff --git a/audio/audio.c b/audio/audio.c index 57096eaa38..8589104137 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -31,7 +31,7 @@ static void update_redundant_info(struct mp_audio *mpa) assert(mp_chmap_is_empty(&mpa->channels) || mp_chmap_is_valid(&mpa->channels)); mpa->nch = mpa->channels.num; - mpa->bps = af_fmt2bits(mpa->format) / 8; + mpa->bps = af_fmt2bps(mpa->format); if (af_fmt_is_planar(mpa->format)) { mpa->spf = 1; mpa->num_planes = mpa->nch; diff --git a/audio/audio.h b/audio/audio.h index 8dbdc4e710..2fe4da92b1 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -35,7 +35,7 @@ struct mp_audio { int nch; // number of channels (redundant with chmap) int spf; // sub-samples per sample on each plane int num_planes; // number of planes - int bps; // size of sub-samples (af_fmt2bits(format) / 8) + int bps; // size of sub-samples (af_fmt2bps(format)) // private int allocated[MP_NUM_CHANNELS]; // use mp_audio_get_allocated_size() diff --git a/audio/decode/ad_mpg123.c b/audio/decode/ad_mpg123.c index 7b174aa0d6..ec4dc04485 100644 --- a/audio/decode/ad_mpg123.c +++ b/audio/decode/ad_mpg123.c @@ -160,7 +160,7 @@ static int set_format(struct dec_audio *da) return MPG123_ERR; } mp_audio_set_format(&da->decoded, af); - con->sample_size = channels * (af_fmt2bits(af) / 8); + con->sample_size = channels * af_fmt2bps(af); con->new_format = 0; } return ret; diff --git a/audio/format.c b/audio/format.c index e343ca36db..9b14fd167b 100644 --- a/audio/format.c +++ b/audio/format.c @@ -28,21 +28,26 @@ #include "common/common.h" #include "audio/filter/af.h" -int af_fmt2bits(int format) +int af_fmt2bps(int format) { - if (AF_FORMAT_IS_AC3(format)) return 16; + if (AF_FORMAT_IS_AC3(format)) return 2; if (format == AF_FORMAT_UNKNOWN) return 0; switch (format & AF_FORMAT_BITS_MASK) { - case AF_FORMAT_8BIT: return 8; - case AF_FORMAT_16BIT: return 16; - case AF_FORMAT_24BIT: return 24; - case AF_FORMAT_32BIT: return 32; - case AF_FORMAT_64BIT: return 64; + case AF_FORMAT_8BIT: return 1; + case AF_FORMAT_16BIT: return 2; + case AF_FORMAT_24BIT: return 3; + case AF_FORMAT_32BIT: return 4; + case AF_FORMAT_64BIT: return 8; } return 0; } +int af_fmt2bits(int format) +{ + return af_fmt2bps(format) * 8; +} + static int bits_to_mask(int bits) { switch (bits) { @@ -159,7 +164,7 @@ const char *af_fmt_to_str(int format) int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int samplerate) { assert(!af_fmt_is_planar(format)); - int bps = (af_fmt2bits(format) / 8); + int bps = af_fmt2bps(format); int framelen = channels * bps; int bytes = seconds * bps * samplerate; if (bytes % framelen) diff --git a/audio/format.h b/audio/format.h index 6fcf923624..6821f27ab6 100644 --- a/audio/format.h +++ b/audio/format.h @@ -151,6 +151,7 @@ extern const struct af_fmt_entry af_fmtstr_table[]; int af_str2fmt_short(bstr str); const char *af_fmt_to_str(int format); +int af_fmt2bps(int format); int af_fmt2bits(int format); int af_fmt_change_bits(int format, int bits); diff --git a/audio/out/ao.c b/audio/out/ao.c index 313f4f7554..358762b73c 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -171,7 +171,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, if (ao->driver->init(ao) < 0) goto error; - ao->sstride = af_fmt2bits(ao->format) / 8; + ao->sstride = af_fmt2bps(ao->format); ao->num_planes = 1; if (af_fmt_is_planar(ao->format)) { ao->num_planes = ao->channels.num; diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c index da0c14cdc2..e8d37e48f7 100644 --- a/audio/out/ao_dsound.c +++ b/audio/out/ao_dsound.c @@ -402,7 +402,7 @@ static int init(struct ao *ao) //set our audio parameters ao->samplerate = rate; ao->format = format; - ao->bps = ao->channels.num * rate * (af_fmt2bits(format) >> 3); + ao->bps = ao->channels.num * rate * af_fmt2bps(format); int buffersize = ao->bps; // space for 1 sec MP_VERBOSE(ao, "Samplerate:%iHz Channels:%i Format:%s\n", rate, ao->channels.num, af_fmt_to_str(format)); @@ -422,9 +422,9 @@ static int init(struct ao *ao) } else { wformat.Format.wFormatTag = (ao->channels.num > 2) ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM; - wformat.Format.wBitsPerSample = af_fmt2bits(format); - wformat.Format.nBlockAlign = wformat.Format.nChannels * - (wformat.Format.wBitsPerSample >> 3); + int bps = af_fmt2bps(format); + wformat.Format.wBitsPerSample = bps * 8; + wformat.Format.nBlockAlign = wformat.Format.nChannels * bps; } // fill in primary sound buffer descriptor diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 0bfe2eb9cb..7eb81f1d4e 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -137,7 +137,7 @@ static int init(struct ao *ao) select_format(ao, codec); - ac->sample_size = af_fmt2bits(ao->format) / 8; + ac->sample_size = af_fmt2bps(ao->format); ac->stream->codec->sample_fmt = af_to_avformat(ao->format); ac->stream->codec->bits_per_raw_sample = ac->sample_size * 8; diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index ca7539b590..545ddca3f8 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -419,7 +419,7 @@ ac3_retry: #endif } - ao->bps = ao->channels.num * (af_fmt2bits(ao->format) / 8); + ao->bps = ao->channels.num * af_fmt2bps(ao->format); p->outburst -= p->outburst % ao->bps; // round down ao->bps *= ao->samplerate; diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c index ab5faf6173..1e8a0adf75 100644 --- a/audio/out/ao_pcm.c +++ b/audio/out/ao_pcm.c @@ -143,7 +143,7 @@ static int init(struct ao *ao) if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) return -1; - ao->bps = ao->channels.num * ao->samplerate * (af_fmt2bits(ao->format) / 8); + ao->bps = ao->channels.num * ao->samplerate * af_fmt2bps(ao->format); MP_INFO(ao, "File: %s (%s)\nPCM: Samplerate: %d Hz Channels: %d Format: %s\n", priv->outputfilename, diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c index ae8b76e830..52c67d2a3c 100644 --- a/audio/out/ao_portaudio.c +++ b/audio/out/ao_portaudio.c @@ -204,7 +204,7 @@ static int init(struct ao *ao) ao->format = fmt->mp_format; sp.sampleFormat = fmt->pa_format; - int framelen = ao->channels.num * (af_fmt2bits(ao->format) / 8); + int framelen = ao->channels.num * af_fmt2bps(ao->format); ao->bps = ao->samplerate * framelen; if (!CHECK_PA_RET(Pa_IsFormatSupported(NULL, &sp, ao->samplerate))) -- cgit v1.2.3