]> git.sesse.net Git - vlc/blob - modules/gui/macosx/AudioEffects.m
ASF: help stupid compiler
[vlc] / modules / gui / macosx / AudioEffects.m
1 /*****************************************************************************
2  * AudioEffects.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2004-2011 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *          Jérôme Decoodt <djc@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # import "config.h"
27 #endif
28
29 #import "intf.h"
30 #import "AudioEffects.h"
31 #import "../../audio_filter/equalizer_presets.h"
32 #import "CompatibilityFixes.h"
33
34 #import <vlc_common.h>
35 #import <vlc_aout_intf.h>
36
37 #import <math.h>
38
39 #pragma mark -
40 #pragma mark Initialization & Generic code
41
42 @implementation VLCAudioEffects
43 static VLCAudioEffects *_o_sharedInstance = nil;
44
45 + (VLCAudioEffects *)sharedInstance
46 {
47     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
48 }
49
50 - (id)init
51 {
52     if (_o_sharedInstance) {
53         [self dealloc];
54     } else {
55         p_intf = VLCIntf;
56         _o_sharedInstance = [super init];
57     }
58     
59     return _o_sharedInstance;
60 }
61
62 - (void)awakeFromNib
63 {
64     /* setup the user's language */
65     /* Equalizer */
66     [o_eq_enable_ckb setTitle:_NS("Enable")];
67     [o_eq_twopass_ckb setTitle:_NS("2 Pass")];
68     [o_eq_preamp_lbl setStringValue:_NS("Preamp")];
69     [o_eq_presets_popup removeAllItems];
70     for( int i = 0; i < NB_PRESETS ; i++ )
71     {
72         [o_eq_presets_popup addItemWithTitle: _NS(preset_list_text[i])];
73         [[o_eq_presets_popup lastItem] setTag: i];
74     }
75
76     /* Compressor */
77     [o_comp_enable_ckb setTitle:_NS("Enable dynamic range compressor")];
78     [o_comp_reset_btn setTitle:_NS("Reset")];
79     [o_comp_band1_lbl setStringValue:_NS("RMS/peak")];;
80     [o_comp_band2_lbl setStringValue:_NS("Attack")];
81     [o_comp_band3_lbl setStringValue:_NS("Release")];
82     [o_comp_band4_lbl setStringValue:_NS("Threshold")];
83     [o_comp_band5_lbl setStringValue:_NS("Ratio")];
84     [o_comp_band6_lbl setStringValue:_NS("Knee radius")];
85     [o_comp_band7_lbl setStringValue:_NS("Makeup gain")];
86     
87     /* Spatializer */
88     [o_spat_enable_ckb setTitle:_NS("Enable Spatializer")];
89     [o_spat_reset_btn setTitle:_NS("Reset")];
90     [o_spat_band1_lbl setStringValue:_NS("Size")];
91     [o_spat_band2_lbl setStringValue:_NS("Width")];
92     [o_spat_band3_lbl setStringValue:_NS("Wet")];
93     [o_spat_band4_lbl setStringValue:_NS("Dry")];
94     [o_spat_band5_lbl setStringValue:_NS("Dump")];
95     
96     /* Filter */
97     [o_filter_headPhone_ckb setTitle:_NS("Headphone virtualization")];
98     [o_filter_normLevel_ckb setTitle:_NS("Volume normalization")];
99     [o_filter_normLevel_lbl setStringValue:_NS("Maximum level")];
100     
101     /* generic */
102     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"equalizer"]] setLabel:_NS("Equalizer")];
103     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"compressor"]] setLabel:_NS("Compressor")];
104     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"spatializer"]] setLabel:_NS("Spatializer")];
105     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"filter"]] setLabel:_NS("Filter")];
106     [o_window setTitle:_NS("Audio Effects")];
107     [o_window setExcludedFromWindowsMenu:YES];
108     if (OSX_LION)
109         [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
110
111     [self setupEqualizer];
112     [self resetCompressor];
113     [self resetSpatializer];
114     [self resetAudioFilters];
115 }
116
117 - (IBAction)toggleWindow:(id)sender
118 {
119     if( [o_window isVisible] )
120         [o_window orderOut:sender];
121     else
122         [o_window makeKeyAndOrderFront:sender];
123 }
124
125 - (void)setAudioFilter: (char *)psz_name on:(BOOL)b_on
126 {
127     char *psz_tmp;
128     audio_output_t * p_aout = getAout();
129     if( p_aout )
130         psz_tmp = var_GetNonEmptyString( p_aout, "audio-filter" );
131     else
132         psz_tmp = config_GetPsz( p_intf, "audio-filter" );        
133     
134     if( b_on )
135     {
136         if(! psz_tmp)
137             config_PutPsz( p_intf, "audio-filter", psz_name );
138         else if( (NSInteger)strstr( psz_tmp, psz_name ) == NO )
139         {
140             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:%s", psz_tmp, psz_name] UTF8String];
141             config_PutPsz( p_intf, "audio-filter", psz_tmp );
142         }
143     } else {
144         if( psz_tmp )
145         {
146             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@":%s",psz_name]]] UTF8String];
147             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%s:",psz_name]]] UTF8String];
148             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithUTF8String:psz_name]]] UTF8String];
149             config_PutPsz( p_intf, "audio-filter", psz_tmp );
150         }
151     }
152
153     if( p_aout ) {
154         aout_EnableFilter( pl_Get( p_intf ), psz_name, b_on );
155         vlc_object_release( p_aout );
156     }
157 }
158
159 #pragma mark -
160 #pragma mark Equalizer
161 static bool GetEqualizerStatus( intf_thread_t *p_custom_intf,
162                              char *psz_name )
163 {
164     char *psz_parser, *psz_string = NULL;
165     vlc_object_t *p_object = VLC_OBJECT(getAout());
166     if( p_object == NULL )
167         p_object = vlc_object_hold(pl_Get( p_custom_intf ));
168     
169     psz_string = config_GetPsz( p_custom_intf, "audio-filter" );
170     
171     if(! psz_string )
172         psz_string = var_GetNonEmptyString( p_object, "audio-filter" );
173     
174     vlc_object_release( p_object );
175     
176     if( !psz_string ) return false;
177     
178     psz_parser = strstr( psz_string, psz_name );
179     
180     free( psz_string );
181     
182     if ( psz_parser )
183         return true;
184     else
185         return false;
186 }
187
188 - (void)setupEqualizer
189 {
190     vlc_object_t *p_object= VLC_OBJECT(getAout());
191     if( p_object == NULL )
192         p_object = pl_Get( VLCIntf );
193
194     if( p_object )
195     {
196         char *psz_preset;
197
198         var_Create( p_object, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
199         psz_preset = var_GetNonEmptyString( p_object, "equalizer-preset" );
200
201         for( int i = 0 ; i < NB_PRESETS ; i++ )
202         {
203             if( strcmp( preset_list[i], psz_preset ) )
204                 continue;
205
206             [o_eq_presets_popup selectItemWithTag:i];
207
208             [o_eq_preamp_sld setFloatValue: eqz_preset_10b[i].f_preamp];
209             [self setBandSlidersValues: (float *)eqz_preset_10b[i].f_amp];
210
211             if( strcmp( psz_preset, "flat" ) )
212             {
213                 char psz_bands[100];
214
215                 snprintf( psz_bands, sizeof( psz_bands ),
216                          "%.1f %.1f %.1f %.1f %.1f %.1f %.1f "
217                          "%.1f %.1f %.1f",
218                          eqz_preset_10b[i].f_amp[0],
219                          eqz_preset_10b[i].f_amp[1],
220                          eqz_preset_10b[i].f_amp[2],
221                          eqz_preset_10b[i].f_amp[3],
222                          eqz_preset_10b[i].f_amp[4],
223                          eqz_preset_10b[i].f_amp[5],
224                          eqz_preset_10b[i].f_amp[6],
225                          eqz_preset_10b[i].f_amp[7],
226                          eqz_preset_10b[i].f_amp[8],
227                          eqz_preset_10b[i].f_amp[9] );
228                 
229                 var_Create( p_object, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
230                 var_Create( p_object, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
231                 var_SetFloat( p_object, "equalizer-preamp", eqz_preset_10b[i].f_preamp );
232                 var_SetString( p_object, "equalizer-bands", psz_bands );
233             }
234         }
235         free( psz_preset );
236     }
237
238     [self equalizerUpdated];
239 }
240
241 - (void)equalizerUpdated
242 {
243     float f_preamp, f_band[10];
244     char *psz_bands, *psz_bands_init, *p_next;
245     bool b_2p;
246     bool b_enabled = GetEqualizerStatus( p_intf, (char *)"equalizer" );
247     vlc_object_t *p_object = VLC_OBJECT(getAout());
248     
249     if( p_object == NULL )
250         p_object = vlc_object_hold(pl_Get( p_intf ));
251     
252     var_Create( p_object, "equalizer-preamp", VLC_VAR_FLOAT |
253                VLC_VAR_DOINHERIT );
254     var_Create( p_object, "equalizer-bands", VLC_VAR_STRING |
255                VLC_VAR_DOINHERIT );
256     
257     psz_bands = var_GetNonEmptyString( p_object, "equalizer-bands" );
258     
259     if( psz_bands == NULL )
260         psz_bands = strdup( "0 0 0 0 0 0 0 0 0 0" );
261
262     b_2p = (BOOL)config_GetInt( p_object, "equalizer-2pass" );
263     f_preamp = config_GetFloat( p_object, "equalizer-preamp" );
264
265     vlc_object_release( p_object );
266     
267     /* Set the preamp slider */
268     [o_eq_preamp_sld setFloatValue: f_preamp];
269
270     /* Set the bands slider */
271     psz_bands_init = psz_bands;
272     
273     for( int i = 0; i < 10; i++ )
274     {
275         /* Read dB -20/20 */
276         f_band[i] = strtof( psz_bands, &p_next );
277         if( !p_next || p_next == psz_bands ) break; /* strtof() failed */
278         
279         if( !*psz_bands ) break; /* end of line */
280         psz_bands = p_next+1;
281     }
282     free( psz_bands_init );
283     [self setBandSlidersValues:f_band];
284     
285     /* Set the the checkboxes */
286     [o_eq_enable_ckb setState: b_enabled];
287     [o_eq_twopass_ckb setState: b_2p];
288 }
289
290 - (id)sliderByIndex:(int)index
291 {
292     switch(index)
293     {
294         case 0 : return o_eq_band1_sld;
295         case 1 : return o_eq_band2_sld;
296         case 2 : return o_eq_band3_sld;
297         case 3 : return o_eq_band4_sld;
298         case 4 : return o_eq_band5_sld;
299         case 5 : return o_eq_band6_sld;
300         case 6 : return o_eq_band7_sld;
301         case 7 : return o_eq_band8_sld;
302         case 8 : return o_eq_band9_sld;
303         case 9 : return o_eq_band10_sld;
304         default : return nil;
305     }
306 }
307
308 - (void)setBandSlidersValues:(float *)values
309 {
310     for (int i = 0 ; i<= 9 ; i++)
311         [self setValue:values[i] forSlider:i];
312 }
313
314 - (void)initBandSliders
315 {
316     for (int i = 0 ; i< 9 ; i++)
317         [self setValue:0.0 forSlider:i];
318 }
319
320 - (void)setValue:(float)value forSlider:(int)index
321 {
322     id slider = [self sliderByIndex:index];
323     
324     if (slider != nil)
325         [slider setFloatValue:value];
326 }
327
328 - (IBAction)eq_enable:(id)sender
329 {
330     [self setAudioFilter: "equalizer" on:[sender state]];
331 }
332
333 - (IBAction)eq_bandSliderUpdated:(id)sender
334 {
335     vlc_object_t *p_object = VLC_OBJECT(getAout());
336     
337     if( p_object == NULL )
338         p_object = vlc_object_hold(pl_Get( p_intf ));
339     
340     const char *psz_values;
341     NSString *preset = [NSString stringWithFormat:@"%.1f ", [o_eq_band1_sld floatValue] ];
342     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band2_sld floatValue] ];
343     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band3_sld floatValue] ];
344     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band4_sld floatValue] ];
345     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band5_sld floatValue] ];
346     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band6_sld floatValue] ];
347     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band7_sld floatValue] ];
348     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band8_sld floatValue] ];
349     preset = [preset stringByAppendingFormat:@"%.1f ", [o_eq_band9_sld floatValue] ];
350     preset = [preset stringByAppendingFormat:@"%.1f", [o_eq_band10_sld floatValue] ];
351
352     psz_values = [preset UTF8String];
353     var_SetString( p_object, "equalizer-bands", psz_values );
354
355     /* save changed to config */
356     config_PutPsz( p_intf, "equalizer-bands", psz_values );
357
358     vlc_object_release( p_object );
359 }
360 - (IBAction)eq_changePreset:(id)sender
361 {
362     vlc_object_t *p_object= VLC_OBJECT(getAout());
363     if( p_object == NULL )
364         p_object = vlc_object_hold(pl_Get( p_intf ));
365     NSInteger numberOfChosenPreset = [[sender selectedItem] tag];
366
367     var_SetString( p_object , "equalizer-preset" , preset_list[numberOfChosenPreset] );
368
369     NSString *preset = @"";
370     const char *psz_values;
371     for( int i = 0; i < EQZ_BANDS_MAX; i++ )
372     {
373         preset = [preset stringByAppendingFormat:@"%.1f ", eqz_preset_10b[numberOfChosenPreset].f_amp[i] ];
374     }
375     psz_values = [preset UTF8String];
376     var_SetString( p_object, "equalizer-bands", psz_values );
377     var_SetFloat( p_object, "equalizer-preamp", eqz_preset_10b[[[sender selectedItem] tag]].f_preamp);
378
379     [o_eq_preamp_sld setFloatValue: eqz_preset_10b[numberOfChosenPreset].f_preamp];
380
381     [self setBandSlidersValues:(float *)eqz_preset_10b[numberOfChosenPreset].f_amp];
382
383     /* save changed to config */
384     config_PutPsz( p_intf, "equalizer-bands", psz_values );
385     config_PutFloat( p_intf, "equalizer-preamp", eqz_preset_10b[numberOfChosenPreset].f_preamp );
386     config_PutPsz( p_intf, "equalizer-preset", preset_list[numberOfChosenPreset] );
387
388     vlc_object_release( p_object );
389 }
390 - (IBAction)eq_preampSliderUpdated:(id)sender
391 {
392     float f_preamp = [sender floatValue] ;
393
394     vlc_object_t *p_object = VLC_OBJECT(getAout());
395     if( p_object == NULL )
396         p_object = vlc_object_hold(pl_Get( p_intf ));
397
398     var_SetFloat( p_object, "equalizer-preamp", f_preamp );
399
400     /* save changed to config */
401     config_PutFloat( p_intf, "equalizer-preamp", f_preamp );
402
403     vlc_object_release( p_object );
404 }
405 - (IBAction)eq_twopass:(id)sender
406 {
407     bool b_2p = [sender state] ? true : false;
408     audio_output_t *p_aout = getAout();
409     vlc_object_t *p_object= VLC_OBJECT(p_aout);
410     if( p_object == NULL )
411         p_object = vlc_object_hold(pl_Get( p_intf ));
412
413     var_SetBool( p_object, "equalizer-2pass", b_2p );
414
415     /* save changed to config */
416     config_PutInt( p_intf, "equalizer-2pass", (int)b_2p );
417
418     vlc_object_release( p_object );
419 }
420
421 #pragma mark -
422 #pragma mark Compressor
423 - (void)resetCompressor
424 {
425     char * psz_afilters;
426     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
427     if( psz_afilters ) {
428         [o_comp_enable_ckb setState: (NSInteger)strstr( psz_afilters, "compressor" ) ];
429         free( psz_afilters );
430     } 
431     else
432         [o_comp_enable_ckb setState: NSOffState];
433
434     [o_comp_band1_sld setFloatValue: config_GetFloat( p_intf, "compressor-rms-peak" )];
435     [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_comp_band1_sld floatValue]]];
436     [o_comp_band2_sld setFloatValue: config_GetFloat( p_intf, "compressor-attack" )];
437     [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [o_comp_band2_sld floatValue]]];
438     [o_comp_band3_sld setFloatValue: config_GetFloat( p_intf, "compressor-release" )];
439     [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [o_comp_band3_sld floatValue]]];
440     [o_comp_band4_sld setFloatValue: config_GetFloat( p_intf, "compressor-threshold" )];
441     [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [o_comp_band4_sld floatValue]]];
442     [o_comp_band5_sld setFloatValue: config_GetFloat( p_intf, "compressor-ratio" )];
443     [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [o_comp_band5_sld floatValue]]];
444     [o_comp_band6_sld setFloatValue: config_GetFloat( p_intf, "compressor-knee" )];
445     [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band6_sld floatValue]]];
446     [o_comp_band7_sld setFloatValue: config_GetFloat( p_intf, "compressor-makeup-gain" )];
447     [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [o_comp_band7_sld floatValue]]];
448 }
449
450 - (IBAction)resetCompressorValues:(id)sender
451 {
452     config_PutFloat( p_intf, "compressor-rms-peak", 0.000000 );
453     config_PutFloat( p_intf, "compressor-attack", 25.000000 );
454     config_PutFloat( p_intf, "compressor-release", 100.000000 );
455     config_PutFloat( p_intf, "compressor-threshold", -11.000000 );
456     config_PutFloat( p_intf, "compressor-ratio", 8.000000 );
457     config_PutFloat( p_intf, "compressor-knee", 2.500000 );
458     config_PutFloat( p_intf, "compressor-makeup-gain", 7.000000 );
459
460     audio_output_t * p_aout = getAout();
461     if (p_aout) {
462         var_SetFloat( p_aout, "compressor-rms-peak", 0.000000 );
463         var_SetFloat( p_aout, "compressor-attack", 25.000000 );
464         var_SetFloat( p_aout, "compressor-release", 100.000000 );
465         var_SetFloat( p_aout, "compressor-threshold", -11.000000 );
466         var_SetFloat( p_aout, "compressor-ratio", 8.000000 );
467         var_SetFloat( p_aout, "compressor-knee", 2.500000 );
468         var_SetFloat( p_aout, "compressor-makeup-gain", 7.000000 );
469         vlc_object_release( p_aout );
470     }
471     [self resetCompressor];
472 }
473
474 - (IBAction)comp_enable:(id)sender
475 {
476     [self setAudioFilter:"compressor" on:[sender state]];
477 }
478
479 - (IBAction)comp_sliderUpdated:(id)sender
480 {
481     audio_output_t * p_aout = getAout();
482     char * value;
483     if( sender == o_comp_band1_sld )
484         value = "compressor-rms-peak";
485     else if( sender == o_comp_band2_sld )
486         value = "compressor-attack";
487     else if( sender == o_comp_band3_sld )
488         value = "compressor-release";
489     else if( sender == o_comp_band4_sld )
490         value = "compressor-threshold";
491     else if( sender == o_comp_band5_sld )
492         value = "compressor-ratio";
493     else if( sender == o_comp_band6_sld )
494         value = "compressor-knee";
495     else if( sender == o_comp_band7_sld )
496         value = "compressor-makeup-gain";
497
498     if( p_aout ) {
499         var_SetFloat( p_aout, value, [sender floatValue] );
500         vlc_object_release( p_aout );
501     }
502     config_PutFloat( p_intf, value, [sender floatValue] );
503
504     if( sender == o_comp_band1_sld )
505         [o_comp_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
506     else if( sender == o_comp_band2_sld )
507         [o_comp_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f ms", [sender floatValue]]];
508     else if( sender == o_comp_band3_sld )
509         [o_comp_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%3.1f ms", [sender floatValue]]];
510     else if( sender == o_comp_band4_sld )
511         [o_comp_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%2.1f dB", [sender floatValue]]];
512     else if( sender == o_comp_band5_sld )
513         [o_comp_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f:1", [sender floatValue]]];
514     else if( sender == o_comp_band6_sld )
515         [o_comp_band6_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
516     else if( sender == o_comp_band7_sld )
517         [o_comp_band7_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f dB", [sender floatValue]]];
518 }
519
520 #pragma mark -
521 #pragma mark Spatializer
522 - (void)resetSpatializer
523 {
524     char * psz_afilters;
525     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
526     if( psz_afilters ) {
527         [o_spat_enable_ckb setState: (NSInteger)strstr( psz_afilters, "spatializer" ) ];
528         free( psz_afilters );
529     } 
530     else
531         [o_spat_enable_ckb setState: NSOffState];
532     
533     [o_spat_band1_sld setFloatValue: config_GetFloat( p_intf, "spatializer-roomsize" )];
534     [o_spat_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_spat_band1_sld floatValue]]];
535     [o_spat_band2_sld setFloatValue: config_GetFloat( p_intf, "spatializer-width" )];
536     [o_spat_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_spat_band2_sld floatValue]]];
537     [o_spat_band3_sld setFloatValue: config_GetFloat( p_intf, "spatializer-wet" )];
538     [o_spat_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_spat_band3_sld floatValue]]];
539     [o_spat_band4_sld setFloatValue: config_GetFloat( p_intf, "spatializer-dry" )];
540     [o_spat_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_spat_band4_sld floatValue]]];
541     [o_spat_band5_sld setFloatValue: config_GetFloat( p_intf, "spatializer-damp" )];
542     [o_spat_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [o_spat_band5_sld floatValue]]];
543 }
544
545 - (IBAction)resetSpatializerValues:(id)sender
546 {
547     config_PutFloat( p_intf, "spatializer-roomsize", 1.050000 );
548     config_PutFloat( p_intf, "spatializer-width", 10.000000 );
549     config_PutFloat( p_intf, "spatializer-wet", 3.000000 );
550     config_PutFloat( p_intf, "spatializer-dry", 2.000000 );
551     config_PutFloat( p_intf, "spatializer-damp", 1.000000 );
552
553     audio_output_t * p_aout = getAout();
554     if (p_aout) {
555         var_SetFloat( p_aout, "spatializer-roomsize", 1.050000 );
556         var_SetFloat( p_aout, "spatializer-width", 10.000000 );
557         var_SetFloat( p_aout, "spatializer-wet", 3.000000 );
558         var_SetFloat( p_aout, "spatializer-dry", 2.000000 );
559         var_SetFloat( p_aout, "spatializer-damp", 1.000000 );
560         vlc_object_release( p_aout );
561     }
562     [self resetSpatializer];
563 }
564
565 - (IBAction)spat_enable:(id)sender
566 {
567     [self setAudioFilter:"spatializer" on:[sender state]];    
568 }
569
570 - (IBAction)spat_sliderUpdated:(id)sender
571 {
572     audio_output_t * p_aout = getAout();
573     char * value;
574     if( sender == o_spat_band1_sld )
575         value = "spatializer-roomsize";
576     else if( sender == o_spat_band2_sld )
577         value = "spatializer-width";
578     else if( sender == o_spat_band3_sld )
579         value = "spatializer-wet";
580     else if( sender == o_spat_band4_sld )
581         value = "spatializer-dry";
582     else if( sender == o_spat_band5_sld )
583         value = "spatializer-damp";
584     
585     if( p_aout ) {
586         var_SetFloat( p_aout, value, [sender floatValue] );
587         vlc_object_release( p_aout );
588     }
589     config_PutFloat( p_intf, value, [sender floatValue] );
590     
591     if( sender == o_spat_band1_sld )
592         [o_spat_band1_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
593     else if( sender == o_spat_band2_sld )
594         [o_spat_band2_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
595     else if( sender == o_spat_band3_sld )
596         [o_spat_band3_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
597     else if( sender == o_spat_band4_sld )
598         [o_spat_band4_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
599     else if( sender == o_spat_band5_sld )
600         [o_spat_band5_fld setStringValue:[NSString localizedStringWithFormat:@"%1.1f", [sender floatValue]]];
601 }
602
603 #pragma mark -
604 #pragma mark Filter
605 - (void)resetAudioFilters
606 {
607     char * psz_afilters;
608     psz_afilters = config_GetPsz( p_intf, "audio-filter" );
609     if( psz_afilters )
610     {
611         [o_filter_headPhone_ckb setState: (NSInteger)strstr( psz_afilters, "headphone" ) ];
612         [o_filter_normLevel_ckb setState: (NSInteger)strstr( psz_afilters, "normvol" ) ];
613         free( psz_afilters );
614     } else {
615         [o_filter_headPhone_ckb setState: NSOffState];
616         [o_filter_normLevel_ckb setState: NSOffState];
617     }
618     [o_filter_normLevel_sld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
619 }
620
621 - (IBAction)filter_enableHeadPhoneVirt:(id)sender
622 {
623     [self setAudioFilter: "headphone" on:[sender state]];
624 }
625
626 - (IBAction)filter_enableVolumeNorm:(id)sender
627 {
628     [self setAudioFilter: "normvol" on:[sender state]];    
629 }
630
631 - (IBAction)filter_volNormSliderUpdated:(id)sender
632 {
633     audio_output_t * p_aout= getAout();
634
635     if( p_aout )
636     {
637         var_SetFloat( p_aout, "norm-max-level", [o_filter_normLevel_sld floatValue] );
638         vlc_object_release( p_aout );
639     }
640
641     config_PutFloat( p_intf, "norm-max-level", [o_filter_normLevel_sld floatValue] );
642 }
643
644 @end