summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorHector Martin <marcan@marcan.st>2016-09-19 21:22:58 +0900
committerwm4 <wm4@nowhere>2016-09-19 14:55:58 +0200
commited8540c38effa1713fb066bab2771e5efae53ba4 (patch)
tree9da51f7e692ef1f5dcd32c3b0e81024d43c94ed2 /audio
parent0525f5fa93f9d997fd3d0037be17c3350823704e (diff)
downloadmpv-ed8540c38effa1713fb066bab2771e5efae53ba4.tar.bz2
mpv-ed8540c38effa1713fb066bab2771e5efae53ba4.tar.xz
af_pan: add af-command support to change the matrix
This allows for seamless changes in the downmixing matrix without having to reinitialize the filter chain.
Diffstat (limited to 'audio')
-rw-r--r--audio/filter/af_pan.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c
index ad4d31df29..c27f4bd07c 100644
--- a/audio/filter/af_pan.c
+++ b/audio/filter/af_pan.c
@@ -43,6 +43,27 @@ static void set_channels(struct mp_audio *mpa, int num)
mp_audio_set_channels(mpa, &map);
}
+static void parse_matrix(struct af_instance *af, const char *cp)
+{
+ af_pan_t *s = af->priv;
+ int j = 0, k = 0, n;
+ while (cp && k < AF_NCH) {
+ sscanf(cp, "%f%n" , &s->level[j][k], &n);
+ MP_VERBOSE(af, "Pan level from channel %i to"
+ " channel %i = %f\n", k, j, s->level[j][k]);
+ cp = &cp[n];
+ j++;
+ if (j >= s->nch) {
+ j = 0;
+ k++;
+ }
+ if (*cp != ',')
+ break;
+ cp++;
+ }
+
+}
+
// Initialization and runtime control
static int control(struct af_instance *af, int cmd, void *arg)
{
@@ -102,6 +123,15 @@ static int control(struct af_instance *af, int cmd, void *arg)
return AF_ERROR;
*(float*)arg = s->level[0][1] - s->level[1][0];
return AF_OK;
+ case AF_CONTROL_COMMAND: {
+ char **args = arg;
+ if (!strcmp(args[0], "set-matrix")) {
+ parse_matrix(af, args[1]);
+ return CONTROL_OK;
+ } else {
+ return CONTROL_ERROR;
+ }
+ }
}
return AF_UNKNOWN;
}
@@ -151,30 +181,12 @@ static int af_open(struct af_instance *af)
af->control = control;
af->filter_frame = filter_frame;
af_pan_t *s = af->priv;
- int n = 0;
- int j, k;
-
int nch = s->nch;
if (nch && AF_OK != control(af, AF_CONTROL_SET_PAN_NOUT, &nch))
return AF_ERROR;
// Read pan values
- char *cp = s->matrixstr;
- j = 0; k = 0;
- while (cp && k < AF_NCH) {
- sscanf(cp, "%f%n" , &s->level[j][k], &n);
- MP_VERBOSE(af, "Pan level from channel %i to"
- " channel %i = %f\n", k, j, s->level[j][k]);
- cp = &cp[n];
- j++;
- if (j >= nch) {
- j = 0;
- k++;
- }
- if (*cp != ',')
- break;
- cp++;
- }
+ parse_matrix(af, s->matrixstr);
return AF_OK;
}