1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 12:55:16 +00:00

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.
This commit is contained in:
Marcoen Hirschberg 2014-05-27 08:21:18 +02:00 committed by wm4
parent 434242adb5
commit 31a10f7c38
13 changed files with 28 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -94,7 +94,7 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
sh_audio->channels = channels;
w->nChannels = sh_audio->channels.num;
w->nSamplesPerSec = sh_audio->samplerate = samplerate;
int samplesize = (af_fmt2bits(aformat) + 7) / 8;
int samplesize = af_fmt2bps(aformat);
w->nAvgBytesPerSec = samplerate * samplesize * w->nChannels;
w->nBlockAlign = w->nChannels * samplesize;
w->wBitsPerSample = 8 * samplesize;

View File

@ -802,7 +802,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
sh_a->codec = "mp-pcm";
sh_a->format = audio_format;
int samplesize = af_fmt2bits(audio_format) / 8;
int samplesize = af_fmt2bps(audio_format);
int block_align = samplesize * sh_audio->channels.num;
int bytes_per_second = sh_audio->samplerate * block_align;