On 09.06.2015 6:04, Dan Dennedy wrote:
Hi Maksym, This would be good. We have channel remap code in the avformat and the linsys sdi consumers. It would be better to have this as a distinct filter. However, you attached the wrong patch.
correct patch attached
the only thing i doubt is mapping style and description of that in yml file..
-- Maksym Veremeyenko
From 21a3ed01d442deccce952df3f29acbd3a740c20e Mon Sep 17 00:00:00 2001 From: Maksym Veremeyenko <ve...@m1.tv> Date: Mon, 8 Jun 2015 20:48:14 +0200 Subject: [PATCH] Implement audiomap filter --- src/modules/core/Makefile | 1 + src/modules/core/factory.c | 2 + src/modules/core/filter_audiomap.c | 116 ++++++++++++++++++++++++++++++++++ src/modules/core/filter_audiomap.yml | 19 ++++++ 4 files changed, 138 insertions(+), 0 deletions(-) create mode 100644 src/modules/core/filter_audiomap.c create mode 100644 src/modules/core/filter_audiomap.yml diff --git a/src/modules/core/Makefile b/src/modules/core/Makefile index d8d2c9b..94c27fd 100644 --- a/src/modules/core/Makefile +++ b/src/modules/core/Makefile @@ -15,6 +15,7 @@ OBJS = factory.o \ producer_noise.o \ producer_tone.o \ filter_audiochannels.o \ + filter_audiomap.o \ filter_audioconvert.o \ filter_audiowave.o \ filter_brightness.o \ diff --git a/src/modules/core/factory.c b/src/modules/core/factory.c index d25f810..266ff6e 100644 --- a/src/modules/core/factory.c +++ b/src/modules/core/factory.c @@ -24,6 +24,7 @@ extern mlt_consumer consumer_multi_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); extern mlt_consumer consumer_null_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); extern mlt_filter filter_audiochannels_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); +extern mlt_filter filter_audiomap_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); extern mlt_filter filter_audioconvert_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); extern mlt_filter filter_audiowave_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); extern mlt_filter filter_brightness_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ); @@ -71,6 +72,7 @@ MLT_REPOSITORY MLT_REGISTER( consumer_type, "multi", consumer_multi_init ); MLT_REGISTER( consumer_type, "null", consumer_null_init ); MLT_REGISTER( filter_type, "audiochannels", filter_audiochannels_init ); + MLT_REGISTER( filter_type, "audiomap", filter_audiomap_init ); MLT_REGISTER( filter_type, "audioconvert", filter_audioconvert_init ); MLT_REGISTER( filter_type, "audiowave", filter_audiowave_init ); MLT_REGISTER( filter_type, "brightness", filter_brightness_init ); diff --git a/src/modules/core/filter_audiomap.c b/src/modules/core/filter_audiomap.c new file mode 100644 index 0000000..6d5e40e --- /dev/null +++ b/src/modules/core/filter_audiomap.c @@ -0,0 +1,116 @@ +/* + * filter_audiomap.c -- convert from one audio format to another + * Copyright (C) 2009-2015 Meltytech, LLC + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <framework/mlt_filter.h> +#include <framework/mlt_frame.h> +#include <framework/mlt_log.h> + +#include <string.h> +#include <stdlib.h> + +#define MAX_CHANNELS 32 + +static const int samples_length[] = +{ + 0, // mlt_audio_none = 0,/**< audio not available */ + 2, // mlt_audio_pcm = 1, /**< \deprecated signed 16-bit interleaved PCM */ + 2, // mlt_audio_s16 = 1, /**< signed 16-bit interleaved PCM */ + 4, // mlt_audio_s32, /**< signed 32-bit non-interleaved PCM */ + 4, // mlt_audio_float, /**< 32-bit non-interleaved floating point */ + 4, // mlt_audio_s32le, /**< signed 32-bit interleaved PCM */ + 4, // mlt_audio_f32le, /**< 32-bit interleaved floating point */ + 1 // mlt_audio_u8 /**< unsigned 8-bit interleaved PCM */ +}; + +static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) +{ + char prop_name[32], *prop_val; + int i, j, l, m[MAX_CHANNELS]; + + mlt_filter filter = mlt_frame_pop_audio(frame); + + // Get the producer's audio + int error = mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples ); + if ( error ) return error; + + mlt_properties properties = MLT_FILTER_PROPERTIES(filter); + + /* find samples length */ + int len = samples_length[*format]; + + /* pcm samples buffer */ + uint8_t *pcm = *buffer; + + mlt_service_lock(MLT_FILTER_SERVICE(filter)); + + /* build matrix */ + for( i = 0; i < MAX_CHANNELS; i++ ) + { + m[i] = i; + + snprintf(prop_name, sizeof(prop_name), "%d", i); + if ( ( prop_val = mlt_properties_get( properties, prop_name ) ) ) + { + j = atoi( prop_val ); + if( j >= 0 && j < MAX_CHANNELS ) + m[i] = j; + } + } + + /* process samples */ + for( i = 0; i < *samples; i++ ) + { + uint8_t tmp[MAX_CHANNELS * 4]; + + for( j = 0; j < MAX_CHANNELS && j < *channels; j++ ) + for(l = 0; l < len; l++) + tmp[j * len + l] = pcm[m[j] * len + l]; + + for(j = 0; j < MAX_CHANNELS && j < *channels; j++) + for(l = 0; l < len; l++) + pcm[j * len + l] = tmp[j * len + l]; + + pcm += len * (*channels); + } + + mlt_service_unlock(MLT_FILTER_SERVICE(filter)); + + return 0; +} + +/** Filter processing. +*/ + +static mlt_frame filter_process( mlt_filter filter, mlt_frame frame ) +{ + mlt_frame_push_audio(frame, filter); + mlt_frame_push_audio( frame, filter_get_audio ); + return frame; +} + +/** Constructor for the filter. +*/ + +mlt_filter filter_audiomap_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) +{ + mlt_filter filter = mlt_filter_new(); + if ( filter ) + filter->process = filter_process; + return filter; +} diff --git a/src/modules/core/filter_audiomap.yml b/src/modules/core/filter_audiomap.yml new file mode 100644 index 0000000..559b642 --- /dev/null +++ b/src/modules/core/filter_audiomap.yml @@ -0,0 +1,19 @@ +schema_version: 0.2 +type: filter +identifier: channelmap +title: Copy/swap Channels accoring to given matrix +version: 1 +copyright: Meltytech, LLC +creator: Maksym Veremeyenko +license: LGPLv2.1 +language: en +tags: + - Audio +description: Copy/swap Channels accoring to given matrix. +parameters: + - identifier: <number> + title: number of source channel + type: integer + minimum: 0 + maximum: 31 + default: 0 -- 1.7.7.6
------------------------------------------------------------------------------
_______________________________________________ Mlt-devel mailing list Mlt-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mlt-devel