Writing new Audio Filter - Lots of Noise

For questions and discussion that is NOT (I repeat NOT) specific to a certain Operating System.
bryguy1299
New Cone
New Cone
Posts: 1
Joined: 20 Sep 2008 21:43

Writing new Audio Filter - Lots of Noise

Postby bryguy1299 » 20 Sep 2008 23:59

Hello,

I'm developing an audio filter that makes changes to the audio based on external events that occur at specific times. I wanted to start off by just passing the audio through the filter (not making any changes to the content). When I play an MP3 file with my audio filter enabled, I hear extremely distorted audio. I had originally been printing the start_time and end_time from the input buffer in DoWork(), and thought that maybe printing messages was bogging the system down, causing the distorted sound. I still get the same behavior even after commenting out the print statement.

I'm wondering if there is something fundamentally wrong with my code. Here goes:

/*****************************************************************************
* Preamble
*****************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_aout.h>

/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Create ( vlc_object_t * );
static void Destroy ( vlc_object_t * );
static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
aout_buffer_t * );

/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( N_("Simple audio content filter for modifying audio when events occur.") );
set_shortname( N_("Audio Event Filter") );
set_category( CAT_AUDIO );
set_subcategory( SUBCAT_AUDIO_AFILTER );
set_capability( "audio filter", 5 );
set_callbacks( Create, Destroy );
vlc_module_end();

/*****************************************************************************
* Internal data structures
*****************************************************************************/
struct event_t
{
mtime_t start;
mtime_t end;
struct event_T *next;
};

struct aout_filter_sys_t
{
struct event_t *events;
};


/*****************************************************************************
* Create
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
aout_filter_t * p_filter = (aout_filter_t *)p_this;
msg_Info ( p_filter, "Greetings! NJB - Mute Audio Content Filter Welcomes you!");

/* Allocate the memory needed to store the module's structure */
p_filter->p_sys = malloc( sizeof(struct aout_filter_sys_t) );
if ( p_filter->p_sys == NULL )
{
msg_Err( p_filter, "out of memory" );
return VLC_EGENERIC;
}

p_filter->p_sys->events = malloc(sizeof(struct event_t));
if ( p_filter->p_sys->events == NULL )
{
msg_Err( p_filter, "out of memory" );
return VLC_EGENERIC;
}

p_filter->p_sys->events->start = 0;
p_filter->p_sys->events->end = 0;
p_filter->p_sys->events->next = NULL;

p_filter->pf_do_work = DoWork;
p_filter->b_in_place = 0;

return VLC_SUCCESS;
}

/*****************************************************************************
* Destroy
*****************************************************************************/
static void Destroy( vlc_object_t *p_this )
{
aout_filter_t * p_filter = (aout_filter_t *)p_this;

if ( p_filter->p_sys != NULL )
{
//TODO: this function should be recursive once we have more than 1 event
if ( p_filter->p_sys->events != NULL )
{
free ( p_filter->p_sys->events );
p_filter->p_sys->events = NULL;
}
free ( p_filter->p_sys );
p_filter->p_sys = NULL;
}

}

/*****************************************************************************
* DoWork
*****************************************************************************/
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
VLC_UNUSED(p_aout);
if ( p_filter->p_sys != NULL )
{
struct aout_filter_sys_t * p_sys = p_filter->p_sys;

/* first attempt at trying to pass the data straight thru...
size_t samples = p_in_buf->i_nb_samples;
size_t bytes = p_in_buf->i_nb_bytes;
memcpy(p_out_buf->p_buffer, p_in_buf->p_buffer, p_in_buf->i_nb_bytes);
p_out_buf->i_nb_bytes = bytes;
p_out_buf->i_nb_samples = samples;
*/
//second attempt...
memcpy(p_out_buf, p_in_buf, sizeof(aout_buffer_t));

if (p_sys->events != NULL)
{
//msg_Info (p_aout , "Buffer Start=[%lld], End=[%lld]", p_in_buf->start_date, p_in_buf->end_date );

}
}

}

Thanks in advance...

Return to “General VLC media player Troubleshooting”

Who is online

Users browsing this forum: No registered users and 46 guests