]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/channel_mixer/headphone.c
block_t.i_samples -> block_t.i_nb_samples (as aout_buffer_t)
[vlc] / modules / audio_filter / channel_mixer / headphone.c
index c659cdf11d6e96a54aea567799775b62992f74f5..0bcf38654f103246e802dd1ffa4ce65786d28a08 100644 (file)
@@ -7,19 +7,19 @@
  *
  * Authors: Boris Dorès <babal@via.ecp.fr>
  *
- * 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 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.
+ * 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.
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -87,9 +87,9 @@ vlc_module_begin ()
 
     add_integer( "headphone-dim", 10, NULL, HEADPHONE_DIM_TEXT,
                  HEADPHONE_DIM_LONGTEXT, false )
-    add_bool( "headphone-compensate", 0, NULL, HEADPHONE_COMPENSATE_TEXT,
+    add_bool( "headphone-compensate", false, NULL, HEADPHONE_COMPENSATE_TEXT,
               HEADPHONE_COMPENSATE_LONGTEXT, true )
-    add_bool( "headphone-dolby", 0, NULL, HEADPHONE_DOLBY_TEXT,
+    add_bool( "headphone-dolby", false, NULL, HEADPHONE_DOLBY_TEXT,
               HEADPHONE_DOLBY_LONGTEXT, true )
 
     set_capability( "audio filter", 0 )
@@ -354,6 +354,7 @@ static int Init( vlc_object_t *p_this, struct aout_filter_sys_t * p_data
 static int Create( vlc_object_t *p_this )
 {
     aout_filter_t * p_filter = (aout_filter_t *)p_this;
+    aout_filter_sys_t *p_sys;
     bool b_fit = true;
 
     /* Activate this filter only with stereo devices */
@@ -402,20 +403,20 @@ static int Create( vlc_object_t *p_this )
     }
 
     /* 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 )
+    p_sys = p_filter->p_sys = malloc( sizeof(struct aout_filter_sys_t) );
+    if( p_sys == NULL )
         return VLC_ENOMEM;
-    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;
+    p_sys->i_overflow_buffer_size = 0;
+    p_sys->p_overflow_buffer = NULL;
+    p_sys->i_nb_atomic_operations = 0;
+    p_sys->p_atomic_operations = NULL;
 
-    if( Init( VLC_OBJECT(p_filter), p_filter->p_sys
+    if( Init( VLC_OBJECT(p_filter), p_sys
                 , aout_FormatNbChannels ( &p_filter->input )
                 , p_filter->input.i_physical_channels
                 , p_filter->input.i_rate ) < 0 )
     {
-        free( p_filter->p_sys );
+        free( p_sys );
         return VLC_EGENERIC;
     }
 
@@ -432,13 +433,9 @@ static void Destroy( vlc_object_t *p_this )
 {
     aout_filter_t * p_filter = (aout_filter_t *)p_this;
 
-    if( p_filter->p_sys != NULL )
-    {
-        free( p_filter->p_sys->p_overflow_buffer );
-        free( p_filter->p_sys->p_atomic_operations );
-        free( p_filter->p_sys );
-        p_filter->p_sys = NULL;
-    }
+    free( p_filter->p_sys->p_overflow_buffer );
+    free( p_filter->p_sys->p_atomic_operations );
+    free( p_filter->p_sys );
 }
 
 /*****************************************************************************
@@ -448,6 +445,7 @@ 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);
+    aout_filter_sys_t *p_sys = p_filter->p_sys;
     int i_input_nb = aout_FormatNbChannels( &p_filter->input );
     int i_output_nb = aout_FormatNbChannels( &p_filter->output );
 
@@ -472,85 +470,78 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     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;
+    /* Slide the overflow buffer */
+    p_overflow = p_sys->p_overflow_buffer;
+    i_overflow_size = 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 );
+    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_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
-            memcpy( p_out, p_overflow, i_out_size );
+        {
+            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_sys->i_nb_atomic_operations; i++ )
+    {
+        /* shorter variable names */
+        i_source_channel_offset
+            = p_sys->p_atomic_operations[i].i_source_channel_offset;
+        i_dest_channel_offset
+            = p_sys->p_atomic_operations[i].i_dest_channel_offset;
+        i_delay = p_sys->p_atomic_operations[i].i_delay;
+        d_amplitude_factor
+            = p_sys->p_atomic_operations[i].d_amplitude_factor;
 
-        p_slide = p_filter->p_sys->p_overflow_buffer;
-        while( p_slide < p_overflow + i_overflow_size )
+        if( p_out_buf->i_nb_samples > i_delay )
         {
-            if( p_slide + i_out_size < p_overflow + i_overflow_size )
+            /* current buffer coefficients */
+            for( j = 0; j < p_out_buf->i_nb_samples - i_delay; j++ )
             {
-                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 ) );
+                ((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;
             }
-            else
+
+            /* overflow buffer coefficients */
+            for( j = 0; j < i_delay; j++ )
             {
-                memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
+                ((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;
             }
-            p_slide += i_out_size;
         }
-
-        /* apply the atomic operations */
-        for( i = 0; i < p_filter->p_sys->i_nb_atomic_operations; i++ )
+        else
         {
-            /* 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 )
+            /* overflow buffer coefficients only */
+            for( j = 0; j < p_out_buf->i_nb_samples; j++ )
             {
-                /* 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;
-                }
+                ((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 );
-    }
 }
 
 /*
@@ -562,6 +553,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
 static int OpenFilter( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys;
     bool b_fit = true;
 
     /* Activate this filter only with stereo devices */
@@ -609,20 +601,20 @@ static int OpenFilter( vlc_object_t *p_this )
     }
 
     /* Allocate the memory needed to store the module's structure */
-    p_filter->p_sys = malloc( sizeof(struct filter_sys_t) );
-    if( p_filter->p_sys == NULL )
+    p_sys = p_filter->p_sys = malloc( sizeof(struct filter_sys_t) );
+    if( p_sys == NULL )
         return VLC_ENOMEM;
-    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;
+    p_sys->i_overflow_buffer_size = 0;
+    p_sys->p_overflow_buffer = NULL;
+    p_sys->i_nb_atomic_operations = 0;
+    p_sys->p_atomic_operations = NULL;
 
-    if( Init( VLC_OBJECT(p_filter), (struct aout_filter_sys_t *)p_filter->p_sys
+    if( Init( VLC_OBJECT(p_filter), (struct aout_filter_sys_t *)p_sys
                 , aout_FormatNbChannels ( &(p_filter->fmt_in.audio) )
                 , p_filter->fmt_in.audio.i_physical_channels
                 , p_filter->fmt_in.audio.i_rate ) < 0 )
     {
-        free( p_filter->p_sys );
+        free( p_sys );
         return VLC_EGENERIC;
     }
 
@@ -639,13 +631,9 @@ static void CloseFilter( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
 
-    if( p_filter->p_sys != NULL )
-    {
-        free( p_filter->p_sys->p_overflow_buffer );
-        free( p_filter->p_sys->p_atomic_operations );
-        free( p_filter->p_sys );
-        p_filter->p_sys = NULL;
-    }
+    free( p_filter->p_sys->p_overflow_buffer );
+    free( p_filter->p_sys->p_atomic_operations );
+    free( p_filter->p_sys );
 }
 
 static block_t *Convert( filter_t *p_filter, block_t *p_block )
@@ -655,14 +643,14 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     block_t *p_out;
     int i_out_size;
 
-    if( !p_block || !p_block->i_samples )
+    if( !p_block || !p_block->i_nb_samples )
     {
         if( p_block )
             block_Release( p_block );
         return NULL;
     }
 
-    i_out_size = p_block->i_samples *
+    i_out_size = p_block->i_nb_samples *
       p_filter->fmt_out.audio.i_bitspersample/8 *
         aout_FormatNbChannels( &(p_filter->fmt_out.audio) );
 
@@ -674,7 +662,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
         return NULL;
     }
 
-    p_out->i_samples = p_block->i_samples;
+    p_out->i_nb_samples = p_block->i_nb_samples;
     p_out->i_dts = p_block->i_dts;
     p_out->i_pts = p_block->i_pts;
     p_out->i_length = p_block->i_length;
@@ -688,15 +676,15 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
 
     in_buf.p_buffer = p_block->p_buffer;
     in_buf.i_nb_bytes = p_block->i_buffer;
-    in_buf.i_nb_samples = p_block->i_samples;
+    in_buf.i_nb_samples = p_block->i_nb_samples;
     out_buf.p_buffer = p_out->p_buffer;
     out_buf.i_nb_bytes = p_out->i_buffer;
-    out_buf.i_nb_samples = p_out->i_samples;
+    out_buf.i_nb_samples = p_out->i_nb_samples;
 
     DoWork( (aout_instance_t *)p_filter, &aout_filter, &in_buf, &out_buf );
 
     p_out->i_buffer = out_buf.i_nb_bytes;
-    p_out->i_samples = out_buf.i_nb_samples;
+    p_out->i_nb_samples = out_buf.i_nb_samples;
 
     block_Release( p_block );
     return p_out;