Equalizer: Bring it back to the quality it had
The quality of the equalizer dialog is now up to par with what we had before, minus all the crashes. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
344ceb173d
commit
41efc22096
|
@ -56,6 +56,7 @@
|
|||
BOOL observersapplied;
|
||||
|
||||
float volume;
|
||||
float eqPreamp;
|
||||
|
||||
AVAudioFormat *_deviceFormat;
|
||||
|
||||
|
|
|
@ -152,6 +152,10 @@ static OSStatus renderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioAct
|
|||
volumeScale = 0.5;
|
||||
}
|
||||
|
||||
if(_self->eqEnabled) {
|
||||
volumeScale *= _self->eqPreamp;
|
||||
}
|
||||
|
||||
scaleBuffersByVolume(ioData, _self->volume * volumeScale);
|
||||
|
||||
if(amountRead < amountToRead) {
|
||||
|
@ -216,6 +220,9 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
|||
BOOL enabled = [[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue];
|
||||
|
||||
[self setEqualizerEnabled:enabled];
|
||||
} else if([keyPath isEqualToString:@"values.eqPreamp"]) {
|
||||
float preamp = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] floatForKey:@"eqPreamp"];
|
||||
eqPreamp = pow(10.0, preamp / 20.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -746,6 +753,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
|||
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.outputDevice" options:0 context:NULL];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.GraphicEQenable" options:0 context:NULL];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.eqPreamp" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:NULL];
|
||||
observersapplied = YES;
|
||||
|
||||
return (err == nil);
|
||||
|
@ -777,6 +785,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
|||
observersapplied = NO;
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice"];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.GraphicEQenable"];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.eqPreamp"];
|
||||
}
|
||||
if(stopNext && started && !paused) {
|
||||
while(![[outputController buffer] isEmpty]) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -339,6 +339,8 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) {
|
|||
[super windowDidLoad];
|
||||
|
||||
[self changePreset:presetSelector];
|
||||
|
||||
[self handleMouseEvents];
|
||||
}
|
||||
|
||||
- (void)setEQ:(AudioUnit)au {
|
||||
|
@ -453,27 +455,25 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) {
|
|||
|
||||
[eqPreamp setFloatValue:-maxValue];
|
||||
[[NSUserDefaults standardUserDefaults] setFloat:-maxValue forKey:[cog_equalizer_band_settings objectAtIndex:0]];
|
||||
|
||||
if(au)
|
||||
equalizerLoadPreset(au);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)adjustSlider:(id)sender {
|
||||
NSInteger tag = [sender tag];
|
||||
|
||||
NSInteger count = [equalizer_presets_processed count];
|
||||
if([presetSelector indexOfSelectedItem] != count) {
|
||||
[presetSelector selectItemAtIndex:count];
|
||||
}
|
||||
|
||||
if(tag == 0) {
|
||||
float preamp = [eqPreamp floatValue];
|
||||
[[NSUserDefaults standardUserDefaults] setFloat:preamp forKey:[cog_equalizer_band_settings objectAtIndex:0]];
|
||||
|
||||
equalizerLoadPreset(au);
|
||||
} else if(tag < [cog_equalizer_band_settings count]) {
|
||||
float preamp = [eqPreamp floatValue];
|
||||
|
||||
float value = [sender floatValue];
|
||||
[[NSUserDefaults standardUserDefaults] setFloat:value forKey:[cog_equalizer_band_settings objectAtIndex:tag]];
|
||||
if(au)
|
||||
AudioUnitSetParameter(au, (int)(tag - 1), kAudioUnitScope_Global, 0, value + preamp, 0);
|
||||
AudioUnitSetParameter(au, (int)(tag - 1), kAudioUnitScope_Global, 0, value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,6 +481,8 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) {
|
|||
NSInteger index = [sender indexOfSelectedItem];
|
||||
|
||||
if(index >= 0 && index < [equalizer_presets_processed count]) {
|
||||
[[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"GraphicEQpreset"];
|
||||
|
||||
NSDictionary *preset = [equalizer_presets_processed objectAtIndex:index];
|
||||
|
||||
equalizerApplyPreset(au, preset);
|
||||
|
@ -502,4 +504,26 @@ void equalizerApplyPreset(AudioUnit au, const NSDictionary *preset) {
|
|||
}
|
||||
}
|
||||
|
||||
- (void)handleMouseEvents {
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskRightMouseDown | NSEventMaskRightMouseDragged
|
||||
handler:^NSEvent *_Nullable(NSEvent *_Nonnull theEvent) {
|
||||
if([theEvent window] == [self window]) {
|
||||
NSPoint event_location = [theEvent locationInWindow];
|
||||
NSPoint local_point = [self.window.contentView convertPoint:event_location fromView:nil];
|
||||
|
||||
for(NSInteger i = 0; i < [cog_equalizer_band_settings count]; ++i) {
|
||||
NSSlider *slider = [self sliderForIndex:i];
|
||||
if(NSPointInRect(local_point, [slider frame])) {
|
||||
float sliderPosition = (MAX(MIN(local_point.y, 344.0), 40.0) - 40.0) / 152.0 - 1.0;
|
||||
[slider setFloatValue:sliderPosition * 20.0];
|
||||
[self adjustSlider:slider];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return theEvent;
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue