2 * filter_volume.c -- adjust audio volume
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "filter_volume.h"
23 #include <framework/mlt_frame.h>
31 static int filter_get_audio( mlt_frame frame
, int16_t **buffer
, mlt_audio_format
*format
, int *frequency
, int *channels
, int *samples
)
33 // Get the properties of the a frame
34 mlt_properties properties
= mlt_frame_properties( frame
);
35 double volume
= mlt_properties_get_double( properties
, "volume" );
37 // Restore the original get_audio
38 frame
->get_audio
= mlt_properties_get_data( properties
, "volume.get_audio", NULL
);
40 // Get the producer's audio
41 mlt_frame_get_audio( frame
, buffer
, format
, frequency
, channels
, samples
);
45 for ( i
= 0; i
< ( *channels
* *samples
); i
++ )
46 (*buffer
)[i
] *= volume
;
51 /** Filter processing.
54 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
56 mlt_properties properties
= mlt_frame_properties( frame
);
58 // Propogate the level property
59 if ( mlt_properties_get( mlt_filter_properties( this ), "volume" ) != NULL
)
60 mlt_properties_set_double( properties
, "volume",
61 mlt_properties_get_double( mlt_filter_properties( this ), "volume" ) );
63 // Backup the original get_audio (it's still needed)
64 mlt_properties_set_data( properties
, "volume.get_audio", frame
->get_audio
, 0, NULL
, NULL
);
66 // Override the get_audio method
67 frame
->get_audio
= filter_get_audio
;
72 /** Constructor for the filter.
75 mlt_filter
filter_volume_init( char *arg
)
77 mlt_filter
this = calloc( sizeof( struct mlt_filter_s
), 1 );
78 if ( this != NULL
&& mlt_filter_init( this, NULL
) == 0 )
80 this->process
= filter_process
;
82 mlt_properties_set_double( mlt_filter_properties( this ), "volume", atof( arg
) );