mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
0042735d7a
commit
f7a427676c
1
Makefile
1
Makefile
|
@ -122,6 +122,7 @@ ifeq ($(HAVE_AVUTIL_REFCOUNTING),no)
|
|||
endif
|
||||
|
||||
SOURCES = talloc.c \
|
||||
audio/audio.c \
|
||||
audio/chmap.c \
|
||||
audio/fmt-conversion.c \
|
||||
audio/format.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;
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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++){
|
||||
|
|
|
@ -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;
|
||||
mp_audio_copy_config(af->data, (struct mp_audio*)arg);
|
||||
|
||||
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;
|
||||
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:{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() :-/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue