<commit_before>/*****************************************************************************
 * fixed.c: Fixed-point audio format conversions
 *****************************************************************************
 * Copyright (C) 2002, 2006-2009 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <jpsaman _at_ videolan _dot_ org>
 *          <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

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

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

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

static int  CreateTo( vlc_object_t * );
static int  CreateFrom( vlc_object_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin ()
    set_description( N_("Fixed point audio format conversions") )
    set_callbacks( CreateTo, NULL )
    set_capability( "audio filter", 15 )
    add_submodule ()
        set_callbacks( CreateFrom, NULL )
        set_capability( "audio filter", 10 )
vlc_module_end ()

/*** Conversion from FI32 to audio output ***/
static block_t *Do_F32ToS16( filter_t *, block_t * );

static int CreateFrom( vlc_object_t *p_this )
{
    filter_t * p_filter = (filter_t *)p_this;

    if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32
     || !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio,
                            &p_filter->fmt_out.audio ) )
        return VLC_EGENERIC;

    /* In fixed-point builds, audio outputs pretty much all use S16N. */
    /* Feel free to add some other format if every needed. */
    switch( p_filter->fmt_out.audio.i_format )
    {
        case VLC_CODEC_S16N:
            p_filter->pf_audio_filter = Do_F32ToS16;
            break;
        default:
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;;
}

union dw
{
    float    f;
    int32_t  s;
    uint32_t u;
};

/*****************************************************************************
 * F32 to S16
 *****************************************************************************/

/*****************************************************************************
 * support routines borrowed from mpg321 (file: mad.c), which is distributed
 * under GPL license
 *
 * mpg321 was written by <NAME> <<EMAIL>>, and based upon 'plaympeg'
 * from the smpeg sources, which was written by various people from Loki Software
 * (http://www.lokigames.com).
 *
 * It also incorporates some source from mad, written by <NAME>
 *****************************************************************************/

/* The following two routines and data structure are from the ever-brilliant<commit_msg>audio/converter/fixed.c: cleanup<commit_after>/*****************************************************************************
 * fixed.c: Fixed-point audio format conversions
 *****************************************************************************
 * Copyright (C) 2002, 2006-2009 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <jpsaman _at_ videolan _dot_ org>
 *          <NAME> <<EMAIL> <EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

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

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

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

static int  CreateTo( vlc_object_t * );
static int  CreateFrom( vlc_object_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin ()
    set_description( N_("Fixed point audio format conversions") )
    set_callbacks( CreateTo, NULL )
    set_capability( "audio filter", 15 )
    add_submodule ()
        set_callbacks( CreateFrom, NULL )
        set_capability( "audio filter", 10 )
vlc_module_end ()

/*** Conversion from FI32 to audio output ***/
static block_t *Do_F32ToS16( filter_t *, block_t * );

static int CreateFrom( vlc_object_t *p_this )
{
    filter_t * p_filter = (filter_t *)p_this;

    if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32
     || !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio,
                            &p_filter->fmt_out.audio ) )
        return VLC_EGENERIC;

    /* In fixed-point builds, audio outputs pretty much all use S16N. */
    /* Feel free to add some other format if every needed. */
    switch( p_filter->fmt_out.audio.i_format )
    {
        case VLC_CODEC_S16N:
            p_filter->pf_audio_filter = Do_F32ToS16;
            break;
        default:
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
}

union dw
{
    float    f;
    int32_t  s;
    uint32_t u;
};

/*****************************************************************************
 * F32 to S16
 *****************************************************************************/

/*****************************************************************************
 * support routines borrowed from mpg321 (file: mad.c), which is distributed
 * under GPL license
 *
 * mpg321 was written by <NAME> <<EMAIL>>, and based upon 'plaympeg'
 * from the smpeg sources, which was written by various people from Loki Software
 * (http://www.lokigames.com).
 *
 * It also incorporates some source from mad, written by <NAME>
 *****************************************************************************/

/* The following two routines and data structure are from the ever-brilliant
{'fraction_non_alphanumeric': 0.30241716458446494, 'fraction_numerical': 0.015752308527973928, 'mean_word_length': 4.306195965417867, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938305', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1849, 'n_words': 629}