⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headphone.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        ComputeChannelOperations ( p_data , i_rate                , i_next_atomic_operation , i_source_channel_offset                , d_x , d_z_rear , d_min , 1.5 / i_nb_channels );        i_next_atomic_operation += 2;        i_source_channel_offset++;    }    if ( i_physical_channels & AOUT_CHAN_REARCENTER )    {        ComputeChannelOperations ( p_data , i_rate                , i_next_atomic_operation , i_source_channel_offset                , 0 , -d_z , d_min , 1.5 / i_nb_channels );        i_next_atomic_operation += 2;        i_source_channel_offset++;    }    if ( i_physical_channels & AOUT_CHAN_CENTER )    {        /* having two center channels increases the spatialization effect */        ComputeChannelOperations ( p_data , i_rate                , i_next_atomic_operation , i_source_channel_offset                , d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );        i_next_atomic_operation += 2;        ComputeChannelOperations ( p_data , i_rate                , i_next_atomic_operation , i_source_channel_offset                , -d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );        i_next_atomic_operation += 2;        i_source_channel_offset++;    }    if ( i_physical_channels & AOUT_CHAN_LFE )    {        ComputeChannelOperations ( p_data , i_rate                , i_next_atomic_operation , i_source_channel_offset                , 0 , d_z_rear , d_min , 5.0 / i_nb_channels );        i_next_atomic_operation += 2;        i_source_channel_offset++;    }    /* Initialize the overflow buffer     * we need it because the process induce a delay in the samples */    p_data->i_overflow_buffer_size = 0;    for ( i = 0 ; i < p_data->i_nb_atomic_operations ; i++ )    {        if ( p_data->i_overflow_buffer_size                < p_data->p_atomic_operations[i].i_delay * 2 * sizeof (float) )        {            p_data->i_overflow_buffer_size                = p_data->p_atomic_operations[i].i_delay * 2 * sizeof (float);        }    }    p_data->p_overflow_buffer = malloc ( p_data->i_overflow_buffer_size );    if ( p_data->p_atomic_operations == NULL )    {        msg_Err( p_filter, "out of memory" );        return -1;    }    memset ( p_data->p_overflow_buffer , 0 , p_data->i_overflow_buffer_size );    /* end */    return 0;}/***************************************************************************** * Create: allocate headphone downmixer *****************************************************************************/static int Create( vlc_object_t *p_this ){    aout_filter_t * p_filter = (aout_filter_t *)p_this;    vlc_bool_t b_fit = VLC_TRUE;    /* Activate this filter only with stereo devices */    if ( p_filter->output.i_physical_channels            != (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT) )    {        msg_Dbg( p_filter, "filter discarded (incompatible format)" );        return VLC_EGENERIC;    }    /* Request a specific format if not already compatible */    if ( p_filter->input.i_original_channels            != p_filter->output.i_original_channels )    {        b_fit = VLC_FALSE;        p_filter->input.i_original_channels =                                        p_filter->output.i_original_channels;    }    if ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2')          || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )    {        b_fit = VLC_FALSE;        p_filter->input.i_format = VLC_FOURCC('f','l','3','2');        p_filter->output.i_format = VLC_FOURCC('f','l','3','2');    }    if ( p_filter->input.i_rate != p_filter->output.i_rate )    {        b_fit = VLC_FALSE;        p_filter->input.i_rate = p_filter->output.i_rate;    }    if ( p_filter->input.i_physical_channels == (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT)          && ( p_filter->input.i_original_channels & AOUT_CHAN_DOLBYSTEREO )          && ! config_GetInt ( p_filter , "headphone-dolby" ) )    {        b_fit = VLC_FALSE;        p_filter->input.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |                                              AOUT_CHAN_CENTER |                                              AOUT_CHAN_REARLEFT |                                              AOUT_CHAN_REARRIGHT;    }    if ( ! b_fit )    {        msg_Dbg( p_filter, "requesting specific format" );        return VLC_EGENERIC;    }    /* 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->i_overflow_buffer_size = 0;    p_filter->p_sys->p_overflow_buffer = NULL;    p_filter->p_sys->i_nb_atomic_operations = 0;    p_filter->p_sys->p_atomic_operations = NULL;    if ( Init( p_filter , p_filter->p_sys                , aout_FormatNbChannels ( &p_filter->input )                , p_filter->input.i_physical_channels                , p_filter->input.i_rate ) < 0 )    {        return VLC_EGENERIC;    }    p_filter->pf_do_work = DoWork;    p_filter->b_in_place = 0;    return VLC_SUCCESS;}/***************************************************************************** * Destroy: deallocate resources associated with headphone downmixer *****************************************************************************/static void Destroy( vlc_object_t *p_this ){    aout_filter_t * p_filter = (aout_filter_t *)p_this;    if ( p_filter->p_sys != NULL )    {        if ( p_filter->p_sys->p_overflow_buffer != NULL )        {            free ( p_filter->p_sys->p_overflow_buffer );        }        if ( p_filter->p_sys->p_atomic_operations != NULL )        {            free ( p_filter->p_sys->p_atomic_operations );        }        free ( p_filter->p_sys );        p_filter->p_sys = NULL;    }}/***************************************************************************** * DoWork: convert a buffer *****************************************************************************/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 ){    int i_input_nb = aout_FormatNbChannels( &p_filter->input );    int i_output_nb = aout_FormatNbChannels( &p_filter->output );    float * p_in = (float*) p_in_buf->p_buffer;    byte_t * p_out;    byte_t * p_overflow;    byte_t * p_slide;    size_t i_overflow_size;     /* in bytes */    size_t i_out_size;          /* in bytes */    unsigned int i, j;    int i_source_channel_offset;    int i_dest_channel_offset;    unsigned int i_delay;    double d_amplitude_factor;    /* out buffer characterisitcs */    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;    p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb;    p_out = p_out_buf->p_buffer;    i_out_size = p_out_buf->i_nb_bytes;    if ( p_filter->p_sys != NULL )    {        /* Slide the overflow buffer */        p_overflow = p_filter->p_sys->p_overflow_buffer;        i_overflow_size = p_filter->p_sys->i_overflow_buffer_size;        memset ( p_out , 0 , i_out_size );        if ( i_out_size > i_overflow_size )            memcpy ( p_out , p_overflow , i_overflow_size );        else            memcpy ( p_out , p_overflow , i_out_size );        p_slide = p_filter->p_sys->p_overflow_buffer;        while ( p_slide < p_overflow + i_overflow_size )        {            if ( p_slide + i_out_size < p_overflow + i_overflow_size )            {                memset ( p_slide , 0 , i_out_size );                if ( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )                    memcpy ( p_slide , p_slide + i_out_size , i_out_size );                else                    memcpy ( p_slide , p_slide + i_out_size                      , p_overflow + i_overflow_size - ( p_slide + i_out_size ) );            }            else            {                memset ( p_slide , 0 , p_overflow + i_overflow_size - p_slide );            }            p_slide += i_out_size;        }        /* apply the atomic operations */        for ( i = 0 ; i < p_filter->p_sys->i_nb_atomic_operations ; i++ )        {            /* shorter variable names */            i_source_channel_offset                = p_filter->p_sys->p_atomic_operations[i].i_source_channel_offset;            i_dest_channel_offset                = p_filter->p_sys->p_atomic_operations[i].i_dest_channel_offset;            i_delay = p_filter->p_sys->p_atomic_operations[i].i_delay;            d_amplitude_factor                = p_filter->p_sys->p_atomic_operations[i].d_amplitude_factor;            if ( p_out_buf->i_nb_samples > i_delay )            {                /* current buffer coefficients */                for ( j = 0 ; j < p_out_buf->i_nb_samples - i_delay ; j++ )                {                    ((float*)p_out)[ (i_delay+j)*i_output_nb + i_dest_channel_offset ]                        += p_in[ j * i_input_nb + i_source_channel_offset ]                           * d_amplitude_factor;                }                /* overflow buffer coefficients */                for ( j = 0 ; j < i_delay ; j++ )                {                    ((float*)p_overflow)[ j*i_output_nb + i_dest_channel_offset ]                        += p_in[ (p_out_buf->i_nb_samples - i_delay + j)                           * i_input_nb + i_source_channel_offset ]                           * d_amplitude_factor;                }            }            else            {                /* overflow buffer coefficients only */                for ( j = 0 ; j < p_out_buf->i_nb_samples ; j++ )                {                    ((float*)p_overflow)[ (i_delay - p_out_buf->i_nb_samples + j)                        * i_output_nb + i_dest_channel_offset ]                        += p_in[ j * i_input_nb + i_source_channel_offset ]                           * d_amplitude_factor;                }            }        }    }    else    {        memset ( p_out , 0 , i_out_size );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -