Resending to include the list.
> 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 > > Wrong description. > + * Copyright (C) 2009-2015 Meltytech, LLC > > Copyright year is only 2015. > + * > + * 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 */ > +}; > > Use instead mlt_audio_format_size(). > +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]; > > Use instead mlt_audio_format_size( *format, 1, 1 ); > + > + /* pcm samples buffer */ > + uint8_t *pcm = *buffer; > + > + mlt_service_lock(MLT_FILTER_SERVICE(filter)); > > The lock is not necessary since we are not modifying the service. > + > + /* 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 ) ) > ) > > "if ( mlt_properties_get( ... ) )" for reason in the next comment. > + { > + j = atoi( prop_val ); > > Do not use atoi(); use mlt_properties_get_int( properties, prop_name ). > + if( j >= 0 && j < MAX_CHANNELS ) > + m[i] = j; > + } > + } > > The mapping does need to mutable. We could compute this once on the first call to process_filter(). In that case, you would need to malloc() the memory and use mlt_properties_set_data(). Then, on each call to process_frame, push the map pointer instead of the filter onto the audio stack and pop it here instead of mlt_filter and remove the properties variable. See below. > + > + /* 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)); > > Remove the corresponding unlock. > + > + return 0; > +} > + > +/** Filter processing. > +*/ > + > +static mlt_frame filter_process( mlt_filter filter, mlt_frame frame ) > +{ > + mlt_frame_push_audio(frame, filter); > > Something like, remove above line and add here: int *map = mlt_properties_get_data( MLT_FILTER_PROPERTIES(filter), "map", NULL ); if ( !map) { map = malloc( sizeof(*map) * MAX_CHANNELS ); mlt_properties_set_data( MLT_FILTER_PROPERTIES(filter), "map", sizeof(*map) * MAX_CHANNELS, (mlt_destructor) free, NULL ); // Build map here } mlt_frame_push( frame, map ); > + 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 > > wrong identifier > +title: Copy/swap Channels accoring to given matrix > > Too long and redundant with description. Shorten it to "Remap Channels" > +version: 1 > +copyright: Meltytech, LLC > +creator: Maksym Veremeyenko > +license: LGPLv2.1 > +language: en > +tags: > + - Audio > +description: Copy/swap Channels accoring to given matrix. > > Hmm, we already have channelcopy that can do simple copy and swaps; maybe "reorganize audio channels" is better. According is misspelled. Call it a mapping because people tend to think 2- or 3-D when they read matrix. > +parameters: > + - identifier: <number> > > identifier: 0 > + title: number of source channel > > title: Source of channel 0 > + type: integer > + minimum: 0 > + maximum: 31 > + default: 0 > > That is only the default for property "0". Make 32 of these. Yeah, it seems kind of stupid, but we do not have a good way to express patterns. This verbose, literal approach should make it understandable - especially with correct default values.
------------------------------------------------------------------------------
_______________________________________________ Mlt-devel mailing list Mlt-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mlt-devel