00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <string.h>
00029
00030 #include <vlc/vlc.h>
00031 #include "audio_output.h"
00032 #include "aout_internal.h"
00033
00034
00035
00036
00037 static int Create ( vlc_object_t * );
00038
00039 static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00040 aout_buffer_t * );
00041
00042
00043
00044
00045 vlc_module_begin();
00046 set_category( CAT_AUDIO );
00047 set_subcategory( SUBCAT_AUDIO_MISC );
00048 set_description( _("audio filter for float32->s16 conversion") );
00049 set_capability( "audio filter", 1 );
00050 set_callbacks( Create, NULL );
00051 vlc_module_end();
00052
00053
00054
00055
00056 static int Create( vlc_object_t *p_this )
00057 {
00058 aout_filter_t * p_filter = (aout_filter_t *)p_this;
00059
00060 if ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2')
00061 || p_filter->output.i_format != AOUT_FMT_S16_NE )
00062 {
00063 return -1;
00064 }
00065
00066 if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
00067 {
00068 return -1;
00069 }
00070
00071 p_filter->pf_do_work = DoWork;
00072 p_filter->b_in_place = 1;
00073
00074 return 0;
00075 }
00076
00077
00078
00079
00080 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00081 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00082 {
00083 int i;
00084 float * p_in = (float *)p_in_buf->p_buffer;
00085 int16_t * p_out = (int16_t *)p_out_buf->p_buffer;
00086
00087 for ( i = p_in_buf->i_nb_samples
00088 * aout_FormatNbChannels( &p_filter->input ); i-- ; )
00089 {
00090 #if 0
00091
00092 if ( *p_in >= 1.0 ) *p_out = 32767;
00093 else if ( *p_in < -1.0 ) *p_out = -32768;
00094 else *p_out = *p_in * 32768.0;
00095 #else
00096
00097 union { float f; int32_t i; } u;
00098 u.f = *p_in + 384.0;
00099 if ( u.i > 0x43c07fff ) *p_out = 32767;
00100 else if ( u.i < 0x43bf8000 ) *p_out = -32768;
00101 else *p_out = u.i - 0x43c00000;
00102 #endif
00103 p_in++; p_out++;
00104 }
00105
00106 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00107 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes / 2;
00108 }
00109