Repository navigation
Make the player's output sample rate configurable - #146
Open
MathieuDubart wants to merge 1 commit into
Open
MathieuDubart wants to merge 1 commit into
MathieuDubart wants to merge 1 commit into
Conversation
`outputAudioFormat` was pinned to 44100 Hz, so decoded audio was always converted to that rate before reaching the engine. When the output hardware runs at another rate the system then resamples a second time, and a 48 kHz source makes a full round trip for nothing: down to 44100 by the converter and back up to 48000 by the output unit. On iOS the built-in speaker runs at 48 kHz, so this affects the default route on current devices. Add `outputSampleRate` to `AudioPlayerConfiguration`, defaulting to 44100 so existing behaviour and every existing call site are unchanged. Callers that know their hardware rate — on iOS, `AVAudioSession.sharedInstance().sampleRate` — can now match it and drop one conversion. The per-entry converter is created from the source format to the output format already, so nothing else needs to change. `normalizeValues()` clamps a non-positive rate to the default, which is what makes the `AVAudioFormat` initialiser in `AudioPlayer` safe. `outputAudioFormat` also becomes a `let`, as it was never reassigned.
Owner
|
Hey, thanks for raising this, I need to double check this as it might cause incorrect progress for files that at 44.1k but the output is specified as 48k - most likely there will be more places to include the new output... |
Author
|
hey, thanks for your quick repsonse and for checking this :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
outputAudioFormatwas pinned to 44100 Hz, so decoded audio was always converted to that rate before reaching the engine. When the output hardware runs at another rate the system then resamples a second time, and a 48 kHz source makes a full round trip for nothing: down to 44100 by the converter and back up to 48000 by the output unit. On iOS the built-in speaker runs at 48 kHz, so this affects the default route on current devices.Add
outputSampleRatetoAudioPlayerConfiguration, defaulting to 44100 so existing behaviour and every existing call site are unchanged. Callers that know their hardware rate — on iOS,AVAudioSession.sharedInstance().sampleRate— can now match it and drop one conversion. The per-entry converter is created from the source format to the output format already, so nothing else needs to change.normalizeValues()clamps a non-positive rate to the default, which is what makes theAVAudioFormatinitialiser inAudioPlayersafe.outputAudioFormatalso becomes alet, as it was never reassigned.