summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-05 19:47:51 +0200
committerwm4 <wm4@nowhere>2013-05-12 21:24:54 +0200
commitf7a427676c0fe3c12509e3d9a243301f93626b0a (patch)
tree8dc8a2371a3e561ebb03f0bd17c2d59135c9f872 /audio
parent0042735d7aefb2f05a79ba2eae741a63f22ea0c9 (diff)
downloadmpv-f7a427676c0fe3c12509e3d9a243301f93626b0a.tar.bz2
mpv-f7a427676c0fe3c12509e3d9a243301f93626b0a.tar.xz
audio: add some setters for mp_audio, and require filters to use them
mp_audio has some redundant fields. Setters like mp_audio_set_format() initialize these properly. Also move the mp_audio struct to a the file audio.c. We can remove a mysterious line of code from af.c: in.format |= af_bits2fmt(in.bps * 8); I'm not sure if this was ever actually needed, or if it was some kind of "make it work" quick-fix that works against the way things were supposed to work. All filters etc. now set the format correctly, so if there ever was a need for this code, it's definitely gone.
Diffstat (limited to 'audio')
-rw-r--r--audio/audio.c38
-rw-r--r--audio/audio.h38
-rw-r--r--audio/decode/dec_audio.c20
-rw-r--r--audio/filter/af.c20
-rw-r--r--audio/filter/af.h21
-rw-r--r--audio/filter/af_bs2b.c8
-rw-r--r--audio/filter/af_center.c5
-rw-r--r--audio/filter/af_channels.c7
-rw-r--r--audio/filter/af_delay.c5
-rw-r--r--audio/filter/af_drc.c13
-rw-r--r--audio/filter/af_equalizer.c6
-rw-r--r--audio/filter/af_export.c6
-rw-r--r--audio/filter/af_extrastereo.c11
-rw-r--r--audio/filter/af_format.c19
-rw-r--r--audio/filter/af_hrtf.c11
-rw-r--r--audio/filter/af_karaoke.c6
-rw-r--r--audio/filter/af_ladspa.c6
-rw-r--r--audio/filter/af_lavcac3enc.c16
-rw-r--r--audio/filter/af_lavrresample.c16
-rw-r--r--audio/filter/af_pan.c10
-rw-r--r--audio/filter/af_scaletempo.c17
-rw-r--r--audio/filter/af_sinesuppress.c7
-rw-r--r--audio/filter/af_sub.c5
-rw-r--r--audio/filter/af_surround.c12
-rw-r--r--audio/filter/af_sweep.c8
-rw-r--r--audio/filter/af_volume.c9
-rw-r--r--audio/format.c2
-rw-r--r--audio/out/ao.h2
28 files changed, 166 insertions, 178 deletions
diff --git a/audio/audio.c b/audio/audio.c
new file mode 100644
index 0000000000..04ebe390b8
--- /dev/null
+++ b/audio/audio.c
@@ -0,0 +1,38 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+
+#include "audio.h"
+
+void mp_audio_set_format(struct mp_audio *mpa, int format)
+{
+ mpa->format = format;
+ mpa->bps = af_fmt2bits(format) / 8;
+}
+
+void mp_audio_set_num_channels(struct mp_audio *mpa, int num_channels)
+{
+ mpa->nch = num_channels;
+}
+
+void mp_audio_copy_config(struct mp_audio *dst, const struct mp_audio *src)
+{
+ mp_audio_set_format(dst, src->format);
+ mp_audio_set_num_channels(dst, src->nch);
+ dst->rate = src->rate;
+}
diff --git a/audio/audio.h b/audio/audio.h
new file mode 100644
index 0000000000..f39069cf73
--- /dev/null
+++ b/audio/audio.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MP_AUDIO_H
+#define MP_AUDIO_H
+
+#include "format.h"
+
+// Audio data chunk
+struct mp_audio {
+ void *audio; // data buffer
+ int len; // buffer length (in bytes)
+ int rate; // sample rate
+ int nch; // number of channels, use mp_audio_set_channels() to set
+ int format; // format (AF_FORMAT_...), use mp_audio_set_format() to set
+ // Redundant fields, for convenience
+ int bps; // bytes per sample (redundant with format)
+};
+
+void mp_audio_set_format(struct mp_audio *mpa, int format);
+void mp_audio_set_num_channels(struct mp_audio *mpa, int num_channels);
+void mp_audio_copy_config(struct mp_audio *dst, const struct mp_audio *src);
+
+#endif
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index c7ae3155ed..6c8804eec9 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -205,16 +205,14 @@ int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate,
if (!afs)
afs = af_new(sh_audio->opts);
// input format: same as codec's output format:
- afs->input.rate = in_samplerate;
- afs->input.nch = sh_audio->channels;
- afs->input.format = sh_audio->sample_format;
- af_fix_parameters(&(afs->input));
+ afs->input.rate = in_samplerate;
+ mp_audio_set_num_channels(&afs->input, sh_audio->channels);
+ mp_audio_set_format(&afs->input, sh_audio->sample_format);
// output format: same as ao driver's input format (if missing, fallback to input)
- afs->output.rate = *out_samplerate;
- afs->output.nch = *out_channels;
- afs->output.format = *out_format;
- af_fix_parameters(&(afs->output));
+ afs->output.rate = *out_samplerate;
+ mp_audio_set_num_channels(&afs->output, *out_channels);
+ mp_audio_set_format(&afs->output, *out_format);
// filter config:
memcpy(&afs->cfg, &af_cfg, sizeof(struct af_cfg));
@@ -284,10 +282,10 @@ static int filter_n_bytes(sh_audio_t *sh, struct bstr *outbuf, int len)
.audio = sh->a_buffer,
.len = len,
.rate = sh->samplerate,
- .nch = sh->channels,
- .format = sh->sample_format
};
- af_fix_parameters(&filter_input);
+ mp_audio_set_format(&filter_input, sh->sample_format);
+ mp_audio_set_num_channels(&filter_input, sh->channels);
+
struct mp_audio *filter_output = af_play(sh->afilter, &filter_input);
if (!filter_output)
return -1;
diff --git a/audio/filter/af.c b/audio/filter/af.c
index 9f534ad2fb..4d2e5e3ac3 100644
--- a/audio/filter/af.c
+++ b/audio/filter/af.c
@@ -84,17 +84,14 @@ static struct af_info* filter_list[] = {
static bool af_config_equals(struct mp_audio *a, struct mp_audio *b)
{
return a->format == b->format
- && a->bps == b->bps
&& a->nch == b->nch
&& a->rate == b->rate;
}
static void af_copy_unset_fields(struct mp_audio *dst, struct mp_audio *src)
{
- if (dst->format == AF_FORMAT_UNKNOWN) {
- dst->format = src->format;
- dst->bps = src->bps;
- }
+ if (dst->format == AF_FORMAT_UNKNOWN)
+ mp_audio_set_format(dst, src->format);
if (dst->nch == 0)
dst->nch = src->nch;
if (dst->rate == 0)
@@ -459,9 +456,6 @@ int af_reinit(struct af_stream *s)
af = af->next;
break;
case AF_FALSE: { // Configuration filter is needed
- // Set output bits per sample (unknown why this would be needed)
- in.format |= af_bits2fmt(in.bps * 8);
-
if (af_fix_channels(s, &af, in) == AF_OK) {
retry++;
continue;
@@ -743,13 +737,3 @@ void af_help(void)
i++;
}
}
-
-void af_fix_parameters(struct mp_audio *data)
-{
- if (data->nch < 0 || data->nch > AF_NCH) {
- mp_msg(MSGT_AFILTER, MSGL_ERR,
- "Invalid number of channels %i, assuming 2.\n", data->nch);
- data->nch = 2;
- }
- data->bps = af_fmt2bits(data->format) / 8;
-}
diff --git a/audio/filter/af.h b/audio/filter/af.h
index 96e5c66607..4ccc70792f 100644
--- a/audio/filter/af.h
+++ b/audio/filter/af.h
@@ -27,6 +27,7 @@
#include "core/options.h"
#include "audio/format.h"
#include "audio/chmap.h"
+#include "audio/audio.h"
#include "control.h"
#include "core/mp_msg.h"
@@ -35,17 +36,6 @@ struct af_instance;
// Number of channels
#define AF_NCH MP_NUM_CHANNELS
-// Audio data chunk
-struct mp_audio {
- void *audio; // data buffer
- int len; // buffer length
- int rate; // sample rate
- int nch; // number of channels
- int format; // format
- int bps; // bytes per sample
-};
-
-
// Flags used for defining the behavior of an audio filter
#define AF_FLAGS_REENTRANT 0x00000000
#define AF_FLAGS_NOT_REENTRANT 0x00000001
@@ -295,15 +285,6 @@ float af_softclip(float a);
/** Print a list of all available audio filters */
void af_help(void);
-/**
- * \brief fill the missing parameters in the struct mp_audio structure
- * \param data structure to fill
- * \ingroup af_filter
- *
- * Currently only sets bps based on format
- */
-void af_fix_parameters(struct mp_audio *data);
-
/** Memory reallocation macro: if a local buffer is used (i.e. if the
filter doesn't operate on the incoming buffer this macro must be
called to ensure the buffer is big enough.
diff --git a/audio/filter/af_bs2b.c b/audio/filter/af_bs2b.c
index aebcc3b201..f8003a70a3 100644
--- a/audio/filter/af_bs2b.c
+++ b/audio/filter/af_bs2b.c
@@ -105,9 +105,8 @@ static int control(struct af_instance *af, int cmd, void *arg)
format = ((struct mp_audio*)arg)->format;
af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = 2; // bs2b is useful only for 2ch audio
- af->data->bps = ((struct mp_audio*)arg)->bps;
- af->data->format = format;
+ mp_audio_set_num_channels(af->data, 2); // bs2b is useful only for 2ch audio
+ mp_audio_set_format(af->data, format);
/* check for formats supported by libbs2b
and assign corresponding handlers */
@@ -162,8 +161,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
break;
default:
af->play = play_f;
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
break;
}
diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c
index aa9aae8514..f92cefd335 100644
--- a/audio/filter/af_center.c
+++ b/audio/filter/af_center.c
@@ -48,9 +48,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!arg) return AF_ERROR;
af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = max(s->ch+1,((struct mp_audio*)arg)->nch);
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_set_num_channels(af->data, max(s->ch+1,((struct mp_audio*)arg)->nch));
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
return af_test_output(af,(struct mp_audio*)arg);
}
diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c
index ac396a51cd..f6369936d6 100644
--- a/audio/filter/af_channels.c
+++ b/audio/filter/af_channels.c
@@ -164,8 +164,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
}
af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->format = ((struct mp_audio*)arg)->format;
- af->data->bps = ((struct mp_audio*)arg)->bps;
+ mp_audio_set_format(af->data, ((struct mp_audio*)arg)->format);
af->mul = (double)af->data->nch / ((struct mp_audio*)arg)->nch;
return check_routes(s,((struct mp_audio*)arg)->nch,af->data->nch);
case AF_CONTROL_COMMAND_LINE:{
@@ -208,7 +207,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
return AF_ERROR;
}
- af->data->nch=((int*)arg)[0];
+ mp_audio_set_num_channels(af->data, ((int*)arg)[0]);
if(!s->router)
mp_msg(MSGT_AFILTER, MSGL_V, "[channels] Changing number of channels"
" to %i\n",af->data->nch);
@@ -248,7 +247,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
// Set output data
c->audio = l->audio;
c->len = c->len / c->nch * l->nch;
- c->nch = l->nch;
+ mp_audio_set_num_channels(c, l->nch);
return c;
}
diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c
index ce8d71980b..eb3e9e19cb 100644
--- a/audio/filter/af_delay.c
+++ b/audio/filter/af_delay.c
@@ -52,10 +52,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
for(i=0;i<af->data->nch;i++)
free(s->q[i]);
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
- af->data->format = ((struct mp_audio*)arg)->format;
- af->data->bps = ((struct mp_audio*)arg)->bps;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
// Allocate new delay queues
for(i=0;i<af->data->nch;i++){
diff --git a/audio/filter/af_drc.c b/audio/filter/af_drc.c
index ba1e10c0a7..e293f7f616 100644
--- a/audio/filter/af_drc.c
+++ b/audio/filter/af_drc.c
@@ -87,15 +87,10 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Sanity check
if(!arg) return AF_ERROR;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
-
- if(((struct mp_audio*)arg)->format == (AF_FORMAT_S16_NE)){
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
- }else{
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+
+ if(((struct mp_audio*)arg)->format != (AF_FORMAT_S16_NE)){
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
}
return af_test_output(af,(struct mp_audio*)arg);
case AF_CONTROL_COMMAND_LINE:{
diff --git a/audio/filter/af_equalizer.c b/audio/filter/af_equalizer.c
index a05b2df399..6441b9b116 100644
--- a/audio/filter/af_equalizer.c
+++ b/audio/filter/af_equalizer.c
@@ -96,10 +96,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Sanity check
if(!arg) return AF_ERROR;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
// Calculate number of active filters
s->K=KM;
diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c
index 5e3a1869ee..ea0aa938ca 100644
--- a/audio/filter/af_export.c
+++ b/audio/filter/af_export.c
@@ -85,10 +85,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
close(s->fd);
// Accept only int16_t as input format (which sucks)
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
// If buffer length isn't set, set it to the default value
if(s->sz == 0)
diff --git a/audio/filter/af_extrastereo.c b/audio/filter/af_extrastereo.c
index d9120fb8d9..ed1fd27898 100644
--- a/audio/filter/af_extrastereo.c
+++ b/audio/filter/af_extrastereo.c
@@ -47,17 +47,14 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Sanity check
if(!arg) return AF_ERROR;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = 2;
- if (((struct mp_audio*)arg)->format == AF_FORMAT_FLOAT_NE)
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_num_channels(af->data, 2);
+ if (af->data->format == AF_FORMAT_FLOAT_NE)
{
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
af->play = play_float;
}// else
{
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
af->play = play_s16;
}
diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c
index 720cff0bf0..5988d25118 100644
--- a/audio/filter/af_format.c
+++ b/audio/filter/af_format.c
@@ -94,8 +94,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
int supported_ac3 = 0;
// Make sure this filter isn't redundant
- if(af->data->format == data->format &&
- af->data->bps == data->bps)
+ if(af->data->format == data->format)
return AF_DETACH;
// A bit complex because we can convert AC3
@@ -121,7 +120,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
buf1, buf2);
af->data->rate = data->rate;
- af->data->nch = data->nch;
+ mp_audio_set_num_channels(af->data, data->nch);
af->mul = (double)af->data->bps / data->bps;
af->play = play; // set default
@@ -164,8 +163,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!AF_FORMAT_IS_AC3(*(int*)arg) && AF_OK != check_format(*(int*)arg))
return AF_ERROR;
- af->data->format = *(int*)arg;
- af->data->bps = af_fmt2bits(af->data->format)/8;
+ mp_audio_set_format(af->data, *(int*)arg);
return AF_OK;
}
@@ -194,7 +192,7 @@ static struct mp_audio* play_swapendian(struct af_instance* af, struct mp_audio*
endian(c->audio,l->audio,len,c->bps);
c->audio = l->audio;
- c->format = l->format;
+ mp_audio_set_format(c, l->format);
return c;
}
@@ -211,9 +209,8 @@ static struct mp_audio* play_float_s16(struct af_instance* af, struct mp_audio*
float2int(c->audio, l->audio, len, 2);
c->audio = l->audio;
+ mp_audio_set_format(c, l->format);
c->len = len*2;
- c->bps = 2;
- c->format = l->format;
return c;
}
@@ -230,9 +227,8 @@ static struct mp_audio* play_s16_float(struct af_instance* af, struct mp_audio*
int2float(c->audio, l->audio, len, 2);
c->audio = l->audio;
+ mp_audio_set_format(c, l->format);
c->len = len*4;
- c->bps = 4;
- c->format = l->format;
return c;
}
@@ -284,9 +280,8 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
// Set output data
c->audio = l->audio;
+ mp_audio_set_format(c, l->format);
c->len = len*l->bps;
- c->bps = l->bps;
- c->format = l->format;
return c;
}
diff --git a/audio/filter/af_hrtf.c b/audio/filter/af_hrtf.c
index 72e2ec7c66..1e3244e2eb 100644
--- a/audio/filter/af_hrtf.c
+++ b/audio/filter/af_hrtf.c
@@ -301,7 +301,7 @@ static int control(struct af_instance *af, int cmd, void* arg)
af->data->rate);
return AF_ERROR;
}
- af->data->nch = ((struct mp_audio*)arg)->nch;
+ mp_audio_set_num_channels(af->data, ((struct mp_audio*)arg)->nch);
if(af->data->nch == 2) {
/* 2 channel input */
if(s->decode_mode != HRTF_MIX_MATRIX2CH) {
@@ -310,13 +310,12 @@ static int control(struct af_instance *af, int cmd, void* arg)
}
}
else if (af->data->nch < 5)
- af->data->nch = 5;
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
+ mp_audio_set_num_channels(af->data, 5);
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
test_output_res = af_test_output(af, (struct mp_audio*)arg);
af->mul = 2.0 / af->data->nch;
// after testing input set the real output format
- af->data->nch = 2;
+ mp_audio_set_num_channels(af->data, 2);
s->print_flag = 1;
return test_output_res;
case AF_CONTROL_COMMAND_LINE:
@@ -574,7 +573,7 @@ static struct mp_audio* play(struct af_instance *af, struct mp_audio *data)
/* Set output data */
data->audio = af->data->audio;
data->len = data->len / data->nch * 2;
- data->nch = 2;
+ mp_audio_set_num_channels(data, 2);
return data;
}
diff --git a/audio/filter/af_karaoke.c b/audio/filter/af_karaoke.c
index 965eb8f40d..faed389625 100644
--- a/audio/filter/af_karaoke.c
+++ b/audio/filter/af_karaoke.c
@@ -34,10 +34,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
{
switch(cmd){
case AF_CONTROL_REINIT:
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
- af->data->format= AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
return af_test_output(af,(struct mp_audio*)arg);
}
return AF_UNKNOWN;
diff --git a/audio/filter/af_ladspa.c b/audio/filter/af_ladspa.c
index c1b3f24360..f7ec0d278f 100644
--- a/audio/filter/af_ladspa.c
+++ b/audio/filter/af_ladspa.c
@@ -498,10 +498,8 @@ static int control(struct af_instance *af, int cmd, void *arg) {
/* accept FLOAT, let af_format do conversion */
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
/* arg->len is not set here yet, so init of buffers and connecting the
* filter, has to be done in play() :-/
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index 94d59a11ca..5be8df2b51 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -75,16 +75,15 @@ static int control(struct af_instance *af, int cmd, void *arg)
if (AF_FORMAT_IS_AC3(data->format) || data->nch < s->min_channel_num)
return AF_DETACH;
- af->data->format = s->in_sampleformat;
- af->data->bps = af_fmt2bits(s->in_sampleformat) / 8;
+ mp_audio_set_format(af->data, s->in_sampleformat);
if (data->rate == 48000 || data->rate == 44100 || data->rate == 32000)
af->data->rate = data->rate;
else
af->data->rate = 48000;
if (data->nch > AC3_MAX_CHANNELS)
- af->data->nch = AC3_MAX_CHANNELS;
+ mp_audio_set_num_channels(af->data, AC3_MAX_CHANNELS);
else
- af->data->nch = data->nch;
+ mp_audio_set_num_channels(af->data, data->nch);
test_output_res = af_test_output(af, data);
s->pending_len = 0;
@@ -123,9 +122,8 @@ static int control(struct af_instance *af, int cmd, void *arg)
"encoder frame size %d\n", s->lavc_actx->frame_size);
return AF_ERROR;
}
- af->data->format = AF_FORMAT_AC3_BE;
- af->data->bps = 2;
- af->data->nch = 2;
+ mp_audio_set_format(af->data, AF_FORMAT_AC3_BE);
+ mp_audio_set_num_channels(af->data, 2);
return test_output_res;
case AF_CONTROL_COMMAND_LINE:
mp_msg(MSGT_AFILTER, MSGL_DBG2, "af_lavcac3enc cmdline: %s.\n", (char*)arg);
@@ -316,8 +314,8 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
buf += len;
}
c->audio = l->audio;
- c->nch = 2;
- c->bps = 2;
+ mp_audio_set_num_channels(c, 2);
+ mp_audio_set_format(c, af->data->format);
c->len = outsize;
mp_msg(MSGT_AFILTER, MSGL_DBG2, "play return size %d, pending %d\n",
outsize, s->pending_len);
diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c
index 2dd2c613c7..1f142792df 100644
--- a/audio/filter/af_lavrresample.c
+++ b/audio/filter/af_lavrresample.c
@@ -137,21 +137,19 @@ static int control(struct af_instance *af, int cmd, void *arg)
out->rate = in->rate;
if (out->nch == 0)
- out->nch = in->nch;
+ mp_audio_set_num_channels(out, in->nch);
enum AVSampleFormat in_samplefmt = af_to_avformat(in->format);
if (in_samplefmt == AV_SAMPLE_FMT_NONE) {
- in->format = AF_FORMAT_FLOAT_NE;
+ mp_audio_set_format(in, AF_FORMAT_FLOAT_NE);
in_samplefmt = af_to_avformat(in->format);
}
enum AVSampleFormat out_samplefmt = af_to_avformat(out->format);
if (out_samplefmt == AV_SAMPLE_FMT_NONE) {
- out->format = in->format;
+ mp_audio_set_format(out, in->format);
out_samplefmt = in_samplefmt;
}
- out->bps = af_fmt2bits(out->format) / 8;
- in->bps = af_fmt2bits(in->format) / 8;
af->mul = (double) (out->rate * out->nch) / (in->rate * in->nch);
af->delay = out->nch * s->opts.filter_size / FFMIN(af->mul, 1);
@@ -196,16 +194,14 @@ static int control(struct af_instance *af, int cmd, void *arg)
}
return ((in->format == orig_in.format) &&
- (in->bps == orig_in.bps) &&
- (in->nch == orig_in.nch))
+ (in->nch == orig_in.nch))
? AF_OK : AF_FALSE;
}
case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET: {
if (af_to_avformat(*(int*)arg) == AV_SAMPLE_FMT_NONE)
return AF_FALSE;
- af->data->format = *(int*)arg;
- af->data->bps = af_fmt2bits(af->data->format)/8;
+ mp_audio_set_format(af->data, *(int*)arg);
return AF_OK;
}
case AF_CONTROL_CHANNELS | AF_CONTROL_SET: {
@@ -214,7 +210,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
if (nch < 1 || nch > AF_NCH)
return AF_ERROR;
- af->data->nch = nch;
+ mp_audio_set_num_channels(af->data, nch);
return AF_OK;
}
case AF_CONTROL_COMMAND_LINE: {
diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c
index 6468d14042..398ffe3b33 100644
--- a/audio/filter/af_pan.c
+++ b/audio/filter/af_pan.c
@@ -45,15 +45,13 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!arg) return AF_ERROR;
af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
- af->data->nch = s->nch ? s->nch: ((struct mp_audio*)arg)->nch;
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
+ mp_audio_set_num_channels(af->data, s->nch ? s->nch: ((struct mp_audio*)arg)->nch);
af->mul = (double)af->data->nch / ((struct mp_audio*)arg)->nch;
if((af->data->format != ((struct mp_audio*)arg)->format) ||
(af->data->bps != ((struct mp_audio*)arg)->bps)){
- ((struct mp_audio*)arg)->format = af->data->format;
- ((struct mp_audio*)arg)->bps = af->data->bps;
+ mp_audio_set_format((struct mp_audio*)arg, af->data->format);
return AF_FALSE;
}
return AF_OK;
@@ -178,7 +176,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
// Set output data
c->audio = l->audio;
c->len = c->len / c->nch * l->nch;
- c->nch = l->nch;
+ mp_audio_set_num_channels(c, l->nch);
return c;
}
diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c
index 657fd7f712..5cf0f3b082 100644
--- a/audio/filter/af_scaletempo.c
+++ b/audio/filter/af_scaletempo.c
@@ -302,29 +302,22 @@ static int control(struct af_instance* af, int cmd, void* arg)
"[scaletempo] %.3f speed * %.3f scale_nominal = %.3f\n",
s->speed, s->scale_nominal, s->scale);
+ mp_audio_copy_config(af->data, data);
+
if (s->scale == 1.0) {
if (s->speed_tempo && s->speed_pitch)
return AF_DETACH;
- af->data->format = data->format;
- af->data->nch = data->nch;
- af->data->rate = data->rate;
- af->data->bps = data->bps;
af->delay = 0;
af->mul = 1;
return af_test_output(af, data);
}
- af->data->rate = data->rate;
- af->data->nch = data->nch;
- if ( data->format == AF_FORMAT_S16_LE
- || data->format == AF_FORMAT_S16_BE ) {
+ if (data->format == AF_FORMAT_S16_NE) {
use_int = 1;
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = bps = 2;
} else {
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = bps = 4;
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
}
+ bps = af->data->bps;
frames_stride = srate * s->ms_stride;
s->bytes_stride = frames_stride * bps * nch;
diff --git a/audio/filter/af_sinesuppress.c b/audio/filter/af_sinesuppress.c
index c9a77ab498..10f0b650ec 100644
--- a/audio/filter/af_sinesuppress.c
+++ b/audio/filter/af_sinesuppress.c
@@ -54,8 +54,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Sanity check
if(!arg) return AF_ERROR;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = 1;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_num_channels(af->data, 1);
#if 0
if (((struct mp_audio*)arg)->format == AF_FORMAT_FLOAT_NE)
{
@@ -65,8 +65,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
}// else
#endif
{
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
af->play = play_s16;
}
diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c
index 4af28d9141..1ae65a0d11 100644
--- a/audio/filter/af_sub.c
+++ b/audio/filter/af_sub.c
@@ -70,9 +70,8 @@ static int control(struct af_instance* af, int cmd, void* arg)
if(!arg) return AF_ERROR;
af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = max(s->ch+1,((struct mp_audio*)arg)->nch);
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_set_num_channels(af->data, max(s->ch+1,((struct mp_audio*)arg)->nch));
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
// Design low-pass filter
s->k = 1.0;
diff --git a/audio/filter/af_surround.c b/audio/filter/af_surround.c
index 57288d6ba2..c63105481f 100644
--- a/audio/filter/af_surround.c
+++ b/audio/filter/af_surround.c
@@ -92,10 +92,9 @@ static int control(struct af_instance* af, int cmd, void* arg)
switch(cmd){
case AF_CONTROL_REINIT:{
float fc;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch*2;
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
+ mp_audio_set_num_channels(af->data, ((struct mp_audio*)arg)->nch*2);
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
if (af->data->nch != 4){
mp_msg(MSGT_AFILTER, MSGL_ERR, "[surround] Only stereo input is supported.\n");
@@ -125,8 +124,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
if((af->data->format != ((struct mp_audio*)arg)->format) ||
(af->data->bps != ((struct mp_audio*)arg)->bps)){
- ((struct mp_audio*)arg)->format = af->data->format;
- ((struct mp_audio*)arg)->bps = af->data->bps;
+ mp_audio_set_format((struct mp_audio*)arg, af->data->format);
return AF_FALSE;
}
return AF_OK;
@@ -244,7 +242,7 @@ static struct mp_audio* play(struct af_instance* af, struct mp_audio* data){
// Set output data
data->audio = af->data->audio;
data->len *= 2;
- data->nch = af->data->nch;
+ mp_audio_set_num_channels(data, af->data->nch);
return data;
}
diff --git a/audio/filter/af_sweep.c b/audio/filter/af_sweep.c
index 6d1106fefc..6cc099f2d8 100644
--- a/audio/filter/af_sweep.c
+++ b/audio/filter/af_sweep.c
@@ -41,12 +41,10 @@ static int control(struct af_instance* af, int cmd, void* arg)
switch(cmd){
case AF_CONTROL_REINIT:
- af->data->nch = data->nch;
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
- af->data->rate = data->rate;
+ mp_audio_copy_config(af->data, data);
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
- return AF_OK;
+ return af_test_output(af, data);
case AF_CONTROL_COMMAND_LINE:
sscanf((char*)arg,"%lf", &s->delta);
return AF_OK;
diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c
index 5664443f03..82c31eaa12 100644
--- a/audio/filter/af_volume.c
+++ b/audio/filter/af_volume.c
@@ -66,12 +66,10 @@ static int control(struct af_instance* af, int cmd, void* arg)
// Sanity check
if(!arg) return AF_ERROR;
- af->data->rate = ((struct mp_audio*)arg)->rate;
- af->data->nch = ((struct mp_audio*)arg)->nch;
+ mp_audio_copy_config(af->data, (struct mp_audio*)arg);
if(s->fast && (((struct mp_audio*)arg)->format != (AF_FORMAT_FLOAT_NE))){
- af->data->format = AF_FORMAT_S16_NE;
- af->data->bps = 2;
+ mp_audio_set_format(af->data, AF_FORMAT_S16_NE);
}
else{
// Cutoff set to 10Hz for forgetting factor
@@ -79,8 +77,7 @@ static int control(struct af_instance* af, int cmd, void* arg)
float t = 2.0-cos(x);
s->time = 1.0 - (t - sqrt(t*t - 1));
mp_msg(MSGT_AFILTER, MSGL_DBG2, "[volume] Forgetting factor = %0.5f\n",s->time);
- af->data->format = AF_FORMAT_FLOAT_NE;
- af->data->bps = 4;
+ mp_audio_set_format(af->data, AF_FORMAT_FLOAT_NE);
}
return af_test_output(af,(struct mp_audio*)arg);
case AF_CONTROL_COMMAND_LINE:{
diff --git a/audio/format.c b/audio/format.c
index 9625857ada..012d24b010 100644
--- a/audio/format.c
+++ b/audio/format.c
@@ -29,6 +29,8 @@
int af_fmt2bits(int format)
{
if (AF_FORMAT_IS_AC3(format)) return 16;
+ if (format == AF_FORMAT_UNKNOWN)
+ return 0;
return (format & AF_FORMAT_BITS_MASK)+8;
// return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8;
#if 0
diff --git a/audio/out/ao.h b/audio/out/ao.h
index 4a7c928824..e57fff7a95 100644
--- a/audio/out/ao.h
+++ b/audio/out/ao.h
@@ -88,7 +88,7 @@ struct ao {
int samplerate;
int channels;
int format;
- int bps;
+ int bps; // bytes per second
int outburst;
int buffersize;
double pts;