Skip to content

Commit

Permalink
Add an option to control halving DSD volume level
Browse files Browse the repository at this point in the history
And default it to disabled. As was pointed out to me by a user, DSD is
apparently mastered to a level of -6 dB, so double its level on output
by default.

Also reorder all preferences dialog controls so they are instantiated in
display order, which should help screen readers, maybe.

Fixes #368

Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed Jul 15, 2023
1 parent 09aa0d9 commit 2d7a748
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 177 deletions.
2 changes: 2 additions & 0 deletions Audio/Chain/ChunkList.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
int dsd2pcmLatency;
#endif

BOOL halveDSDVolume;

void *hdcd_decoder;

BOOL formatRead;
Expand Down
30 changes: 28 additions & 2 deletions Audio/Chain/ChunkList.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#import "BadSampleCleaner.h"
#endif

static void *kChunkListContext = &kChunkListContext;

#if DSD_DECIMATE
/**
* DSD 2 PCM: Stage 1:
Expand Down Expand Up @@ -392,6 +394,10 @@ - (id)initWithMaximumDuration:(double)duration {
dsd2pcmCount = 0;
dsd2pcmLatency = 0;
#endif

halveDSDVolume = NO;

[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.halveDSDVolume" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kChunkListContext];
}

return self;
Expand Down Expand Up @@ -419,6 +425,19 @@ - (void)dealloc {
if(tempData) {
free(tempData);
}

[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.halveDSDVolume" context:kChunkListContext];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if(context != kChunkListContext) {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
return;
}

if([keyPath isEqualToString:@"values.halveDSDVolume"]) {
halveDSDVolume = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"halveDSDVolume"];
}
}

- (void)reset {
Expand Down Expand Up @@ -648,8 +667,15 @@ - (AudioChunk *)convertChunk:(AudioChunk *)inChunk {
inputBuffer = &tempData[buffer_adder];
inputChanged = YES;
#if DSD_DECIMATE
float scaleFactor = 2.0f;
vDSP_vsdiv((float *)inputBuffer, 1, &scaleFactor, (float *)inputBuffer, 1, bytesReadFromInput / sizeof(float));
if(halveDSDVolume) {
float scaleFactor = 2.0f;
vDSP_vsdiv((float *)inputBuffer, 1, &scaleFactor, (float *)inputBuffer, 1, bytesReadFromInput / sizeof(float));
}
#else
if(!halveDSDVolume) {
float scaleFactor = 2.0f;
vDSP_vsmul((float *)inputBuffer, 1, &scaleFactor, (float *)inputBuffer, 1, bytesReadFromInput / sizeof(float));
}
#endif
} else if(bitsPerSample <= 8) {
samplesRead = bytesReadFromInput;
Expand Down
8 changes: 4 additions & 4 deletions Preferences/Preferences/Base.lproj/PathSuggester.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22138.1" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22138.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -84,11 +84,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="Myn-dz-D1X">
<rect key="frame" x="87" y="0.0" width="333.5" height="24"/>
<rect key="frame" x="87" y="0.0" width="334" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3sg-yr-7pE">
<rect key="frame" x="0.0" y="4" width="334" height="16"/>
<rect key="frame" x="0.0" y="4" width="335" height="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="xFm-ed-yBb">
<font key="font" usesAppearanceFont="YES"/>
Expand Down
Loading

0 comments on commit 2d7a748

Please sign in to comment.