summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/audio.c6
-rw-r--r--audio/audio.h2
-rw-r--r--audio/filter/af.c4
-rw-r--r--audio/filter/af_lavcac3enc.c2
-rw-r--r--audio/filter/af_lavrresample.c2
-rw-r--r--audio/filter/af_volume.c2
-rw-r--r--audio/format.c47
-rw-r--r--audio/format.h16
-rw-r--r--audio/out/ao.c4
-rw-r--r--audio/out/ao_alsa.c18
-rw-r--r--audio/out/ao_coreaudio.c2
-rw-r--r--audio/out/ao_coreaudio_exclusive.c2
-rw-r--r--audio/out/ao_coreaudio_utils.c10
-rw-r--r--audio/out/ao_dsound.c10
-rw-r--r--audio/out/ao_lavc.c6
-rw-r--r--audio/out/ao_oss.c10
-rw-r--r--audio/out/ao_pcm.c6
-rw-r--r--audio/out/ao_pulse.c2
-rwxr-xr-xaudio/out/ao_wasapi_utils.c16
-rw-r--r--audio/out/push.c2
20 files changed, 83 insertions, 86 deletions
diff --git a/audio/audio.c b/audio/audio.c
index c4ffc233a1..f84d6054bc 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -34,8 +34,8 @@ 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_fmt2bps(mpa->format);
- if (AF_FORMAT_IS_PLANAR(mpa->format)) {
+ mpa->bps = af_fmt_to_bytes(mpa->format);
+ if (af_fmt_is_planar(mpa->format)) {
mpa->spf = 1;
mpa->num_planes = mpa->nch;
mpa->sstride = mpa->bps;
@@ -105,7 +105,7 @@ char *mp_audio_config_to_str_buf(char *buf, size_t buf_sz, struct mp_audio *mpa)
void mp_audio_force_interleaved_format(struct mp_audio *mpa)
{
- if (AF_FORMAT_IS_PLANAR(mpa->format))
+ if (af_fmt_is_planar(mpa->format))
mp_audio_set_format(mpa, af_fmt_from_planar(mpa->format));
}
diff --git a/audio/audio.h b/audio/audio.h
index a221b126ac..a0ecb2d7bf 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_fmt2bps(format))
+ int bps; // size of sub-samples (af_fmt_to_bytes(format))
// --- private
// These do not necessarily map directly to planes[]. They can have
diff --git a/audio/filter/af.c b/audio/filter/af.c
index 3e7fdf045a..f37a47697e 100644
--- a/audio/filter/af.c
+++ b/audio/filter/af.c
@@ -493,8 +493,8 @@ static int af_reinit(struct af_stream *s)
int fmt_in1 = af->prev->data->format;
int fmt_in2 = in.format;
if (af_fmt_is_valid(fmt_in1) && af_fmt_is_valid(fmt_in2)) {
- bool spd1 = AF_FORMAT_IS_IEC61937(fmt_in1);
- bool spd2 = AF_FORMAT_IS_IEC61937(fmt_in2);
+ bool spd1 = af_fmt_is_spdif(fmt_in1);
+ bool spd2 = af_fmt_is_spdif(fmt_in2);
if (spd1 != spd2 && af->next) {
MP_WARN(af, "Filter %s apparently cannot be used due to "
"spdif passthrough - removing it.\n",
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index 5695bfd8c6..8d403a7f12 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -75,7 +75,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
struct mp_audio *in = arg;
struct mp_audio orig_in = *in;
- if (AF_FORMAT_IS_SPECIAL(in->format) || in->nch < s->cfg_min_channel_num)
+ if (!af_fmt_is_pcm(in->format) || in->nch < s->cfg_min_channel_num)
return AF_DETACH;
mp_audio_set_format(in, s->in_sampleformat);
diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c
index f811dfaeb9..38fd84c901 100644
--- a/audio/filter/af_lavrresample.c
+++ b/audio/filter/af_lavrresample.c
@@ -497,7 +497,7 @@ static int filter(struct af_instance *af, struct mp_audio *in)
mp_audio_copy_config(out, &s->avrctx_fmt);
if (out->samples && !mp_audio_config_equals(out, &s->pre_out_fmt)) {
- assert(AF_FORMAT_IS_PLANAR(out->format) && out->format == real_out.format);
+ assert(af_fmt_is_planar(out->format) && out->format == real_out.format);
reorder_planes(out, s->reorder_out, &s->pool_fmt.channels);
if (!mp_audio_config_equals(out, &s->pre_out_fmt)) {
struct mp_audio *new = mp_audio_pool_get(s->reorder_buffer,
diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c
index d66e38c0e1..1b564f0983 100644
--- a/audio/filter/af_volume.c
+++ b/audio/filter/af_volume.c
@@ -68,7 +68,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
} else {
mp_audio_set_format(af->data, AF_FORMAT_FLOAT);
}
- if (AF_FORMAT_IS_PLANAR(in->format))
+ if (af_fmt_is_planar(in->format))
mp_audio_set_format(af->data, af_fmt_to_planar(af->data->format));
s->rgain = 1.0;
if ((s->rgain_track || s->rgain_album) && af->replaygain_data) {
diff --git a/audio/format.c b/audio/format.c
index 7da99b6a0e..36cfb9be03 100644
--- a/audio/format.c
+++ b/audio/format.c
@@ -27,7 +27,8 @@
#include "common/common.h"
#include "audio/filter/af.h"
-int af_fmt2bps(int format)
+// number of bytes per sample, 0 if invalid/unknown
+int af_fmt_to_bytes(int format)
{
switch (af_fmt_from_planar(format)) {
case AF_FORMAT_U8: return 1;
@@ -42,27 +43,22 @@ int af_fmt2bps(int format)
return 0;
}
-int af_fmt2bits(int format)
+int af_fmt_change_bytes(int format, int bytes)
{
- return af_fmt2bps(format) * 8;
-}
-
-int af_fmt_change_bits(int format, int bits)
-{
- if (!af_fmt_is_valid(format) || !bits)
+ if (!af_fmt_is_valid(format) || !bytes)
return 0;
for (int fmt = 1; fmt < AF_FORMAT_COUNT; fmt++) {
- if (af_fmt2bits(fmt) == bits &&
+ if (af_fmt_to_bytes(fmt) == bytes &&
af_fmt_is_float(fmt) == af_fmt_is_float(format) &&
af_fmt_is_planar(fmt) == af_fmt_is_planar(format) &&
- af_fmt_is_spdif(fmt) == af_fmt_is_planar(format))
+ af_fmt_is_spdif(fmt) == af_fmt_is_spdif(format))
return fmt;
}
return 0;
}
// All formats are considered signed, except explicitly unsigned int formats.
-bool af_fmt_unsigned(int format)
+bool af_fmt_is_unsigned(int format)
{
return format == AF_FORMAT_U8 || format == AF_FORMAT_U8P;
}
@@ -90,6 +86,11 @@ bool af_fmt_is_spdif(int format)
return af_format_sample_alignment(format) > 1;
}
+bool af_fmt_is_pcm(int format)
+{
+ return af_fmt_is_valid(format) && !af_fmt_is_spdif(format);
+}
+
static const int planar_formats[][2] = {
{AF_FORMAT_U8P, AF_FORMAT_U8},
{AF_FORMAT_S16P, AF_FORMAT_S16},
@@ -156,8 +157,8 @@ const char *af_fmt_to_str(int format)
int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int samplerate)
{
- assert(!AF_FORMAT_IS_PLANAR(format));
- int bps = af_fmt2bps(format);
+ assert(!af_fmt_is_planar(format));
+ int bps = af_fmt_to_bytes(format);
int framelen = channels * bps;
int bytes = seconds * bps * samplerate;
if (bytes % framelen)
@@ -167,7 +168,7 @@ int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int sampler
void af_fill_silence(void *dst, size_t bytes, int format)
{
- memset(dst, af_fmt_unsigned(format) ? 0x80 : 0, bytes);
+ memset(dst, af_fmt_is_unsigned(format) ? 0x80 : 0, bytes);
}
#define FMT_DIFF(type, a, b) (((a) & type) - ((b) & type))
@@ -183,28 +184,28 @@ int af_format_conversion_score(int dst_format, int src_format)
if (dst_format == src_format)
return 1024;
// Can't be normally converted
- if (AF_FORMAT_IS_SPECIAL(dst_format) || AF_FORMAT_IS_SPECIAL(src_format))
+ if (!af_fmt_is_pcm(dst_format) || !af_fmt_is_pcm(src_format))
return INT_MIN;
int score = 1024;
if (af_fmt_is_planar(dst_format) != af_fmt_is_planar(src_format))
score -= 1; // has to (de-)planarize
if (af_fmt_is_float(dst_format) != af_fmt_is_float(src_format)) {
- int dst_bits = af_fmt2bits(dst_format);
+ int dst_bytes = af_fmt_to_bytes(dst_format);
if (af_fmt_is_float(dst_format)) {
// For int->float, always prefer 32 bit float.
- score -= dst_bits == 32 ? 8 : 0;
+ score -= dst_bytes == 4 ? 1 : 0;
} else {
// For float->int, always prefer highest bit depth int
- score -= 8 * (64 - dst_bits);
+ score -= 8 - dst_bytes;
}
// Has to convert float<->int - Consider this the worst case.
score -= 2048;
} else {
- int bits = af_fmt2bits(dst_format) - af_fmt2bits(src_format);
- if (bits > 0) {
- score -= 8 * bits; // has to add padding
- } else if (bits < 0) {
- score -= 1024 - 8 * bits; // has to reduce bit depth
+ int bytes = af_fmt_to_bytes(dst_format) - af_fmt_to_bytes(src_format);
+ if (bytes > 0) {
+ score -= bytes; // has to add padding
+ } else if (bytes < 0) {
+ score -= 1024 - bytes; // has to reduce bit depth
}
}
return score;
diff --git a/audio/format.h b/audio/format.h
index 83da59cf61..ea17a44766 100644
--- a/audio/format.h
+++ b/audio/format.h
@@ -54,22 +54,18 @@ enum af_format {
AF_FORMAT_COUNT
};
-#define AF_FORMAT_IS_IEC61937(f) af_fmt_is_spdif(f)
-#define AF_FORMAT_IS_SPECIAL(f) af_fmt_is_spdif(f)
-#define AF_FORMAT_IS_FLOAT(f) af_fmt_is_float(f)
-#define AF_FORMAT_IS_PLANAR(f) af_fmt_is_planar(f)
-
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);
+int af_fmt_to_bytes(int format);
+int af_fmt_change_bytes(int format, int bytes);
-bool af_fmt_unsigned(int format);
+bool af_fmt_is_valid(int format);
+bool af_fmt_is_unsigned(int format);
bool af_fmt_is_float(int format);
bool af_fmt_is_int(int format);
bool af_fmt_is_planar(int format);
bool af_fmt_is_spdif(int format);
+bool af_fmt_is_pcm(int format);
int af_fmt_to_planar(int format);
int af_fmt_from_planar(int format);
@@ -77,8 +73,6 @@ int af_fmt_from_planar(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 samplerate);
-bool af_fmt_is_valid(int format);
-
void af_fill_silence(void *dst, size_t bytes, int format);
int af_format_conversion_score(int dst_format, int src_format);
diff --git a/audio/out/ao.c b/audio/out/ao.c
index c1333ab584..abf50b6b81 100644
--- a/audio/out/ao.c
+++ b/audio/out/ao.c
@@ -196,9 +196,9 @@ static struct ao *ao_init(bool probing, struct mpv_global *global,
goto fail;
}
- ao->sstride = af_fmt2bps(ao->format);
+ ao->sstride = af_fmt_to_bytes(ao->format);
ao->num_planes = 1;
- if (AF_FORMAT_IS_PLANAR(ao->format)) {
+ if (af_fmt_is_planar(ao->format)) {
ao->num_planes = ao->channels.num;
} else {
ao->sstride *= ao->channels.num;
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index fddc637e53..d81df23f9d 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -101,7 +101,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
long get_vol, set_vol;
float f_multi;
- if (AF_FORMAT_IS_SPECIAL(ao->format))
+ if (!af_fmt_is_pcm(ao->format))
return CONTROL_FALSE;
snd_mixer_selem_id_alloca(&sid);
@@ -376,7 +376,7 @@ static int try_open_device(struct ao *ao, const char *device)
struct priv *p = ao->priv;
int err;
- if (AF_FORMAT_IS_IEC61937(ao->format)) {
+ if (af_fmt_is_spdif(ao->format)) {
void *tmp = talloc_new(NULL);
char *params = talloc_asprintf(tmp,
"AES0=%d,AES1=%d,AES2=0,AES3=%d",
@@ -453,7 +453,7 @@ static int init_device(struct ao *ao, bool second_try)
err = snd_pcm_hw_params_any(p->alsa, alsa_hwparams);
CHECK_ALSA_ERROR("Unable to get initial parameters");
- if (AF_FORMAT_IS_IEC61937(ao->format)) {
+ if (af_fmt_is_spdif(ao->format)) {
if (ao->format == AF_FORMAT_S_MP3) {
p->alsa_fmt = SND_PCM_FORMAT_MPEG;
} else {
@@ -469,7 +469,7 @@ static int init_device(struct ao *ao, bool second_try)
err = snd_pcm_hw_params_test_format(p->alsa, alsa_hwparams, p->alsa_fmt);
if (err < 0) {
- if (AF_FORMAT_IS_IEC61937(ao->format))
+ if (af_fmt_is_spdif(ao->format))
CHECK_ALSA_ERROR("Unable to set IEC61937 format");
MP_INFO(ao, "Format %s is not supported by hardware, trying default.\n",
af_fmt_to_str(ao->format));
@@ -480,11 +480,11 @@ static int init_device(struct ao *ao, bool second_try)
err = snd_pcm_hw_params_set_format(p->alsa, alsa_hwparams, p->alsa_fmt);
CHECK_ALSA_ERROR("Unable to set format");
- snd_pcm_access_t access = AF_FORMAT_IS_PLANAR(ao->format)
+ snd_pcm_access_t access = af_fmt_is_planar(ao->format)
? SND_PCM_ACCESS_RW_NONINTERLEAVED
: SND_PCM_ACCESS_RW_INTERLEAVED;
err = snd_pcm_hw_params_set_access(p->alsa, alsa_hwparams, access);
- if (err < 0 && AF_FORMAT_IS_PLANAR(ao->format)) {
+ if (err < 0 && af_fmt_is_planar(ao->format)) {
ao->format = af_fmt_from_planar(ao->format);
access = SND_PCM_ACCESS_RW_INTERLEAVED;
err = snd_pcm_hw_params_set_access(p->alsa, alsa_hwparams, access);
@@ -492,7 +492,7 @@ static int init_device(struct ao *ao, bool second_try)
CHECK_ALSA_ERROR("Unable to set access type");
struct mp_chmap dev_chmap = ao->channels;
- if (AF_FORMAT_IS_IEC61937(ao->format) || p->cfg_ignore_chmap) {
+ if (af_fmt_is_spdif(ao->format) || p->cfg_ignore_chmap) {
dev_chmap.num = 0; // disable chmap API
} else if (dev_chmap.num == 1 && dev_chmap.speaker[0] == MP_SPEAKER_ID_FC) {
// As yet another ALSA API inconsistency, mono is not reported correctly.
@@ -597,7 +597,7 @@ static int init_device(struct ao *ao, bool second_try)
if (p->cfg_ignore_chmap) {
MP_VERBOSE(ao, "user set ignore-chmap; ignoring the channel map.\n");
- } else if (AF_FORMAT_IS_IEC61937(ao->format)) {
+ } else if (af_fmt_is_spdif(ao->format)) {
MP_VERBOSE(ao, "using spdif passthrough; ignoring the channel map.\n");
} else if (mp_chmap_is_valid(&chmap)) {
// Is it one that contains NA channels?
@@ -849,7 +849,7 @@ static int play(struct ao *ao, void **data, int samples, int flags)
return 0;
do {
- if (AF_FORMAT_IS_PLANAR(ao->format)) {
+ if (af_fmt_is_planar(ao->format)) {
res = snd_pcm_writen(p->alsa, data, samples);
} else {
res = snd_pcm_writei(p->alsa, data[0], samples);
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index b424e66661..3585c1d9d3 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -151,7 +151,7 @@ static int init(struct ao *ao)
{
struct priv *p = ao->priv;
- if (AF_FORMAT_IS_IEC61937(ao->format)) {
+ if (af_fmt_is_spdif(ao->format)) {
MP_WARN(ao, "detected IEC61937, redirecting to coreaudio_exclusive\n");
ao->redirect = "coreaudio_exclusive";
return CONTROL_ERROR;
diff --git a/audio/out/ao_coreaudio_exclusive.c b/audio/out/ao_coreaudio_exclusive.c
index b16641483d..e62ccee2ba 100644
--- a/audio/out/ao_coreaudio_exclusive.c
+++ b/audio/out/ao_coreaudio_exclusive.c
@@ -169,7 +169,7 @@ static int init(struct ao *ao)
ao->format = af_fmt_from_planar(ao->format);
- if (!AF_FORMAT_IS_IEC61937(ao->format)) {
+ if (!af_fmt_is_spdif(ao->format)) {
MP_ERR(ao, "Only compressed formats are supported.\n");
goto coreaudio_error_nounlock;
}
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 96382512e8..77e87b7c23 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -168,22 +168,22 @@ static void ca_fill_asbd_raw(AudioStreamBasicDescription *asbd, int mp_format,
{
asbd->mSampleRate = samplerate;
// Set "AC3" for other spdif formats too - unknown if that works.
- asbd->mFormatID = AF_FORMAT_IS_IEC61937(mp_format) ?
+ asbd->mFormatID = af_fmt_is_spdif(mp_format) ?
kAudioFormat60958AC3 :
kAudioFormatLinearPCM;
asbd->mChannelsPerFrame = num_channels;
- asbd->mBitsPerChannel = af_fmt2bits(mp_format);
+ asbd->mBitsPerChannel = af_fmt_to_bytes(mp_format) * 8;
asbd->mFormatFlags = kAudioFormatFlagIsPacked;
int channels_per_buffer = num_channels;
- if (AF_FORMAT_IS_PLANAR(mp_format)) {
+ if (af_fmt_is_planar(mp_format)) {
asbd->mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
channels_per_buffer = 1;
}
- if (AF_FORMAT_IS_FLOAT(mp_format)) {
+ if (af_fmt_is_float(mp_format)) {
asbd->mFormatFlags |= kAudioFormatFlagIsFloat;
- } else if (!af_fmt_unsigned(mp_format)) {
+ } else if (!af_fmt_is_unsigned(mp_format)) {
asbd->mFormatFlags |= kAudioFormatFlagIsSignedInteger;
}
diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c
index 8b1e10a10b..c581bf512e 100644
--- a/audio/out/ao_dsound.c
+++ b/audio/out/ao_dsound.c
@@ -444,7 +444,7 @@ static int init(struct ao *ao)
int format = af_fmt_from_planar(ao->format);
int rate = ao->samplerate;
- if (!AF_FORMAT_IS_IEC61937(format)) {
+ if (!af_fmt_is_spdif(format)) {
struct mp_chmap_sel sel = {0};
mp_chmap_sel_add_waveext(&sel);
if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels))
@@ -456,7 +456,7 @@ static int init(struct ao *ao)
case AF_FORMAT_U8:
break;
default:
- if (AF_FORMAT_IS_IEC61937(format))
+ if (af_fmt_is_spdif(format))
break;
MP_VERBOSE(ao, "format %s not supported defaulting to Signed 16-bit Little-Endian\n",
af_fmt_to_str(format));
@@ -465,7 +465,7 @@ static int init(struct ao *ao)
//set our audio parameters
ao->samplerate = rate;
ao->format = format;
- ao->bps = ao->channels.num * rate * af_fmt2bps(format);
+ ao->bps = ao->channels.num * rate * af_fmt_to_bytes(format);
int buffersize = ao->bps * p->cfg_buffersize / 1000;
MP_VERBOSE(ao, "Samplerate:%iHz Channels:%i Format:%s\n", rate,
ao->channels.num, af_fmt_to_str(format));
@@ -478,7 +478,7 @@ static int init(struct ao *ao)
? sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) : 0;
wformat.Format.nChannels = ao->channels.num;
wformat.Format.nSamplesPerSec = rate;
- if (AF_FORMAT_IS_IEC61937(format)) {
+ if (af_fmt_is_spdif(format)) {
// Whether it also works with e.g. DTS is unknown, but probably does.
wformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF;
wformat.Format.wBitsPerSample = 16;
@@ -486,7 +486,7 @@ static int init(struct ao *ao)
} else {
wformat.Format.wFormatTag = (ao->channels.num > 2)
? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
- int bps = af_fmt2bps(format);
+ int bps = af_fmt_to_bytes(format);
wformat.Format.wBitsPerSample = bps * 8;
wformat.Format.nBlockAlign = wformat.Format.nChannels * bps;
}
diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c
index b322982566..0106a64475 100644
--- a/audio/out/ao_lavc.c
+++ b/audio/out/ao_lavc.c
@@ -136,7 +136,7 @@ static int init(struct ao *ao)
select_format(ao, codec);
- ac->sample_size = af_fmt2bps(ao->format);
+ ac->sample_size = af_fmt_to_bytes(ao->format);
ac->stream->codec->sample_fmt = af_to_avformat(ao->format);
ac->stream->codec->bits_per_raw_sample = ac->sample_size * 8;
@@ -241,7 +241,7 @@ static int encode(struct ao *ao, double apts, void **data)
frame->format = af_to_avformat(ao->format);
frame->nb_samples = ac->aframesize;
- size_t num_planes = AF_FORMAT_IS_PLANAR(ao->format) ? ao->channels.num : 1;
+ size_t num_planes = af_fmt_is_planar(ao->format) ? ao->channels.num : 1;
assert(num_planes <= AV_NUM_DATA_POINTERS);
for (int n = 0; n < num_planes; n++)
frame->extended_data[n] = data[n];
@@ -350,7 +350,7 @@ static int play(struct ao *ao, void **data, int samples, int flags)
double pts = ectx->last_audio_in_pts;
pts += ectx->samples_since_last_pts / (double)ao->samplerate;
- size_t num_planes = AF_FORMAT_IS_PLANAR(ao->format) ? ao->channels.num : 1;
+ size_t num_planes = af_fmt_is_planar(ao->format) ? ao->channels.num : 1;
void *tempdata = NULL;
void *padded[MP_NUM_CHANNELS];
diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c
index bcb21aeffd..32190877f6 100644
--- a/audio/out/ao_oss.c
+++ b/audio/out/ao_oss.c
@@ -184,7 +184,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
return CONTROL_OK;
#endif
- if (AF_FORMAT_IS_SPECIAL(ao->format))
+ if (!af_fmt_is_pcm(ao->format))
return CONTROL_TRUE;
if ((fd = open(p->oss_mixer_device, O_RDONLY)) != -1) {
@@ -247,7 +247,7 @@ static bool try_format(struct ao *ao, int *format)
struct priv *p = ao->priv;
int oss_format = format2oss(*format);
- if (oss_format == -1 && AF_FORMAT_IS_IEC61937(*format))
+ if (oss_format == -1 && af_fmt_is_spdif(*format))
oss_format = AFMT_AC3;
if (oss_format == -1) {
@@ -303,7 +303,7 @@ static int reopen_device(struct ao *ao, bool allow_format_changes)
fcntl(p->audio_fd, F_SETFD, FD_CLOEXEC);
#endif
- if (AF_FORMAT_IS_IEC61937(format)) {
+ if (af_fmt_is_spdif(format)) {
if (ioctl(p->audio_fd, SNDCTL_DSP_SPEED, &samplerate) == -1)
goto fail;
// Probably could be fixed by setting number of channels; needs testing.
@@ -327,7 +327,7 @@ static int reopen_device(struct ao *ao, bool allow_format_changes)
MP_VERBOSE(ao, "sample format: %s\n", af_fmt_to_str(format));
- if (!AF_FORMAT_IS_IEC61937(format)) {
+ if (!af_fmt_is_spdif(format)) {
struct mp_chmap_sel sel = {0};
for (int n = 0; n < MP_NUM_CHANNELS + 1; n++)
mp_chmap_sel_add_map(&sel, &oss_layouts[n]);
@@ -392,7 +392,7 @@ static int reopen_device(struct ao *ao, bool allow_format_changes)
}
}
- p->outburst -= p->outburst % (channels.num * af_fmt2bps(format)); // round down
+ p->outburst -= p->outburst % (channels.num * af_fmt_to_bytes(format)); // round down
return 0;
diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c
index 5b9d61b450..76f0315bef 100644
--- a/audio/out/ao_pcm.c
+++ b/audio/out/ao_pcm.c
@@ -73,7 +73,7 @@ static void fput32le(uint32_t val, FILE *fp)
static void write_wave_header(struct ao *ao, FILE *fp, uint64_t data_length)
{
uint16_t fmt = ao->format == AF_FORMAT_FLOAT ? WAV_ID_FLOAT_PCM : WAV_ID_PCM;
- int bits = af_fmt2bits(ao->format);
+ int bits = af_fmt_to_bytes(ao->format) * 8;
// Master RIFF chunk
fput32le(WAV_ID_RIFF, fp);
@@ -135,7 +135,7 @@ static int init(struct ao *ao)
case AF_FORMAT_FLOAT:
break;
default:
- if (!AF_FORMAT_IS_IEC61937(ao->format))
+ if (!af_fmt_is_spdif(ao->format))
ao->format = AF_FORMAT_S16;
break;
}
@@ -146,7 +146,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_fmt2bps(ao->format);
+ ao->bps = ao->channels.num * ao->samplerate * af_fmt_to_bytes(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_pulse.c b/audio/out/ao_pulse.c
index f797802797..78d8ac2561 100644
--- a/audio/out/ao_pulse.c
+++ b/audio/out/ao_pulse.c
@@ -210,7 +210,7 @@ static pa_encoding_t map_digital_format(int format)
case AF_FORMAT_S_AAC: return PA_ENCODING_MPEG2_AAC_IEC61937;
#endif
default:
- if (AF_FORMAT_IS_IEC61937(format))
+ if (af_fmt_is_spdif(format))
return PA_ENCODING_ANY;
return PA_ENCODING_PCM;
}
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index b0b0c10575..d7dc3ad07f 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -85,13 +85,13 @@ const struct wasapi_fmt_mapping wasapi_fmt_table[] = {
static const GUID *format_to_subtype(int format)
{
- if (AF_FORMAT_IS_SPECIAL(format)) {
+ if (af_fmt_is_spdif(format)) {
for (int i = 0; wasapi_fmt_table[i].format; i++) {
if (wasapi_fmt_table[i].format == format)
return wasapi_fmt_table[i].subtype;
}
return &KSDATAFORMAT_SPECIFIER_NONE;
- } else if (AF_FORMAT_IS_FLOAT(format)) {
+ } else if (af_fmt_is_float(format)) {
return &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
}
return &KSDATAFORMAT_SUBTYPE_PCM;
@@ -229,7 +229,7 @@ static void set_waveformat(WAVEFORMATEXTENSIBLE *wformat,
wformat->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wformat->Format.nChannels = channels->num;
wformat->Format.nSamplesPerSec = samplerate;
- wformat->Format.wBitsPerSample = af_fmt2bits(format);
+ wformat->Format.wBitsPerSample = af_fmt_to_bytes(format) * 8;
wformat->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
wformat->SubFormat = *format_to_subtype(format);
@@ -306,9 +306,11 @@ static int format_from_waveformat(WAVEFORMATEX *wf)
// Since mpv doesn't have the notion of "valid bits", we just specify a
// format with the container size. The least significant, "invalid"
// bits will be excess precision ignored by wasapi.
- // The change_bits operations should be a no-op for properly
+ // The change_bytes operations should be a no-op for properly
// configured "special" formats, otherwise it will return 0.
- return af_fmt_change_bits(format, wf->wBitsPerSample);
+ if (wf->wBitsPerSample % 8)
+ return 0;
+ return af_fmt_change_bytes(format, wf->wBitsPerSample / 8) * 8;
}
static bool chmap_from_waveformat(struct mp_chmap *channels, const WAVEFORMATEX *wf)
@@ -365,7 +367,7 @@ static bool set_ao_format(struct ao *ao, WAVEFORMATEX *wf, AUDCLNT_SHAREMODE sha
}
// Do not touch the ao for passthrough, just assume that we set WAVEFORMATEX correctly.
- if (!AF_FORMAT_IS_SPECIAL(format)) {
+ if (af_fmt_is_pcm(format)) {
struct mp_chmap channels;
if (!chmap_from_waveformat(&channels, wf)) {
MP_ERR(ao, "Unable to construct channel map from WAVEFORMAT %s\n",
@@ -575,7 +577,7 @@ static bool find_formats(struct ao *ao)
// might be passthrough). If that fails, do a pcm format
// search.
return find_formats_exclusive(ao, true);
- } else if (AF_FORMAT_IS_SPECIAL(ao->format)) {
+ } else if (af_fmt_is_spdif(ao->format)) {
// If a passthrough format is requested, but exclusive mode
// was not explicitly set, try only the requested passthrough
// format in exclusive mode. Fall back on shared mode if that
diff --git a/audio/out/push.c b/audio/out/push.c
index beafd36a13..301004bd99 100644
--- a/audio/out/push.c
+++ b/audio/out/push.c
@@ -438,7 +438,7 @@ const struct ao_driver ao_api_push = {
int ao_play_silence(struct ao *ao, int samples)
{
assert(ao->api == &ao_api_push);
- if (samples <= 0 || AF_FORMAT_IS_SPECIAL(ao->format) || !ao->driver->play)
+ if (samples <= 0 || !af_fmt_is_pcm(ao->format) || !ao->driver->play)
return 0;
char *p = talloc_size(NULL, samples * ao->sstride);
af_fill_silence(p, samples * ao->sstride, ao->format);