Commit Graph

216 Commits (01c38c944048a9f65adf9873f1d6b7f4f8b41d7c)

Author SHA1 Message Date
Christopher Snowhill 4906c38827 Align all use of Accelerate vDSP functions
vDSP functions expect their input and output pointers to be aligned to
an even four values. Correct this by aligning all pointers. The
allocated buffers used for one parameter should already be aligned
somewhat, but align the incremented positions used on some of them so
that the vDSP functions don't misbehave. Also align the volume scaler
input by doing scalar math until the pointer is aligned prior to calling
vDSP_vsmul. Also, change 16-bit and 32-bit scale to use vsdiv instead of
vsmul with a really small number already divided into one.

Fixes the test vectors that were sent in extrapolating incorrectly due
to their final blocks having uneven sample counts, resulting in
unaligned pointers.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 22:53:09 -08:00
Christopher Snowhill 25077277b3 Add bad sample cleaner for debugging
A bad sample scanner and cleaner will point out in the log whenever a
bad sample, such as infinity, or Not a Number, or even huge values over
±2.0, in case some piece of code, or a decoder, or even a bad file, has
taken over the output.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 22:48:47 -08:00
Christopher Snowhill 96f2a382ee DSD gaplessness, part 3, mildly pointless
In the rare event that we're somehow playing decimated DSD at full
sample rate instead of resampling, only the start needs to be skipped,
and the end needs the input to the decimator padded to flush it, but
nothing needs to be truncated from the end of the output in that case.
Still, mostly pointless, since next to nobody will be outputting 384 kHz
from their Macs, in any case, much less unprocessed DSD.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 02:29:06 -08:00
Christopher Snowhill bec01b675a DSD gaplessness, part 2
We should be extrapolating right over top of the DSD decimator latency,
rather than in front of it. Yeah, that'll do.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 02:11:53 -08:00
Christopher Snowhill 4b0f6b381f Fix DSD gaplessness handling
DSD files should be properly gapless now.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 02:03:06 -08:00
Christopher Snowhill b8a98e301e Metadata loading: Correctly merge over empty tags
Metadata versus properties merging, correctly merge over empty fields if
they are assigned with empty strings or zeroed numbers, instead of only
merging over completely missing fields.

Fixes emailed bug, CUE Sheet metadata reading, primarily.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-14 20:02:18 -08:00
Christopher Snowhill 6d09b72c1d Dynamic info now pushes to the correct track
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-12 07:29:02 -08:00
Christopher Snowhill c39b7ee96a Converter: Smarter, if less portable, endian swap
For big endian sample formats, endianness can be swapped using Clang
specific byte swap functions, which are present in all supported
versions of Xcode.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-12 00:38:08 -08:00
Christopher Snowhill 5f68131437 Converter: One minor change to double to float
Use Accelerate for this, too.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-12 00:03:25 -08:00
Christopher Snowhill 6b148fef11 Channel Mixer: Rewrite upmixing, changed HRIR
Simple upmixing algorithms now use Accelerate framework functions
instead of complex loops, and the HRIR filter now supports forcing
stereo output to any channel output configuration that has at least
front stereo speakers.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-11 23:51:41 -08:00
Christopher Snowhill 3711999112 Cog Audio: Allocate maximum needed audio memory
The chunk could be any format, up to floating point double samples, and
up to 18 channels.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-11 13:50:26 -08:00
Christopher Snowhill 7f8c19799d Fix a very serious error resampling short files
Files that are so short that they need both pre- and post-extrapolation
at the same time.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-11 07:10:31 -08:00
Christopher Snowhill 0b33fe6dea Don't count output buffering for queue hold
This would count the output duration for every file buffered, rather
than only once.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-11 06:50:58 -08:00
Christopher Snowhill 5ff1f95481 Add decoder open error indicator
When decoder is redirected to the internal silence decoder, show an icon
on the playlist indicating a playback error.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-10 02:15:48 -08:00
Christopher Snowhill df63726128 Track properties take priority over metadata read from tag readers
This allows inputs to override things with self-read tags and such, such
as ReplayGain tags.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-09 21:26:17 -08:00
Christopher Snowhill b1a98139cb Cog Audio: Fix generic upmixer mode
This resulted in horrible things, the generic N to N upmixer was leaving
unmapped channels as uninitialized memory. This fixes horrible things
happening for people with interfaces with more channels than the source
file, frequently when the source file is stereo, or if the file is mono
and a center channel is present.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-09 15:16:19 -08:00
Christopher Snowhill 0012d1b17e Implement dynamic metadata reading for streams
Supported by FFmpeg, FLAC, Ogg Vorbis, and Opus.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-09 13:44:50 -08:00
Christopher Snowhill 7cea254f4c Implement framework for dynamic metadata updates
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-08 21:21:53 -08:00
Christopher Snowhill 0763b28f38 HRIR Filter: Replace deprecated Intel-only code
_mm_malloc and _mm_free are apparently based on intrinsic functions,
and only exist on Intel or older macOS targets. So removing them in
favor of posix_memalign.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-08 00:13:41 -08:00
Christopher Snowhill f4f4f80f64 Restart playback on device or output format change
Now the output is restarted on the current file at the current position
if the output format has changed. This should resolve the issue finally.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 22:44:56 -08:00
Christopher Snowhill 728c44242c Do not reset output sample rate automatically
This was buggy as hell, and resulted in errors. Now the user should
restart playback if they change output device formats.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 22:02:17 -08:00
Christopher Snowhill 477feaab1d Now properly supports sample format changing
Sample format can now change dynamically at play time, and the player
will resample it as necessary, extrapolating edges between changes to
reduce the potential for gaps.

Currently supported formats for this:

- FLAC
- Ogg Vorbis
- Any format supported by FFmpeg, such as MP3 or AAC

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 19:18:45 -08:00
Christopher Snowhill 91da112e35 Cog Audio: Fix potential hang on stop
The ChunkList wasn't clearing the remover entered flag when the chain
was empty. Now it does, so it will shut down correctly.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 15:31:57 -08:00
Christopher Snowhill 08da31f96c Cog Audio: Fix generic downmix to stereo
Code ordering was wrong, it was writing the output samples repeatedly
for each input speaker, now it will only write them once.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 04:17:53 -08:00
Christopher Snowhill acb1dd75d3 Cog Audio: Fix memory leaks with new buffering
By applying copious amounts of autorelease pools, memory is freed in a
timely manner. Prior to this, buffer objects were freed, but not being
released, and thus accumulating in memory indefinitely, as the original
threads and functions had autorelease pools that scoped the entire
thread, rather than individual function blocks that utilized the new
buffering system. This fixes memory growth caused by playback.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 04:06:36 -08:00
Christopher Snowhill 1ef8df675f Cog Audio: Implement support for channel config
This implements the basic output and mixing support for channel config
bits, optionally set by the input plugin.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-07 01:10:05 -08:00
Christopher Snowhill b0b1446aa7 HRIR Filter: Corrected scale math, fixing volume
The volume should have been twice what it was, because I got this scale
wrong. The correct scale for Accelerate inverse FFT is 1/4 per sample,
not 1/8 like I accidentally misread while rewriting a convolver for the
umpteenth time from scratch.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-06 21:53:42 -08:00
Christopher Snowhill 85c7073649 Reformat my own source code with clang-format
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-06 21:49:27 -08:00
Christopher Snowhill 62edb39761 Cog Audio: Major rewrite of audio buffering
Rewrite attempt number two. Now using array lists of audio chunks, with
each chunk having its format and optionally losslessness stashed along
with it. This replaces the old virtual ring buffer method. As a result
of this, the HRIR toggle now works instantaneously.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-06 03:08:34 -08:00
Christopher Snowhill 0131f7c925 Revert "Core Audio output: Rewrote major portions"
This reverts commit 637ea4efe1.
2022-02-05 04:14:03 -08:00
Christopher Snowhill 4cdca2f5f8 Converter: Fix DSD gaplessness
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-05 04:03:40 -08:00
Christopher Snowhill 637ea4efe1 Core Audio output: Rewrote major portions
After all this rewriting, down or upmixing the audio is now handled with
the lowest latency possible, meaning that toggling the HRIR option now
takes effect immediately.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-05 03:45:02 -08:00
Christopher Snowhill 39cc33cac4 Converter: Remove no longer necessary includes
These were only needed when I wasn't using Accelerate framework.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-04 19:53:17 -08:00
Christopher Snowhill d6760c823a HRIR Filter: Change resampler to use soxr oneshot
This should use the oneshot method, which takes care of flushing for us.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-01 22:54:27 -08:00
Christopher Snowhill 074e4115dd sox resampler: Perform post file flush
Flush the resampler when the source file terminates, so that it outputs
delayed samples properly. This fixes gapless decoding of resampled
files.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-01 22:47:11 -08:00
Christopher Snowhill d4990de7f3 Adopt the sox resampler instead of RetroArch
Removing RetroArch code from my project.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-01 18:55:39 -08:00
Christopher Snowhill 641f6390c5 HRIR Filter: Quality of life improvements
The memory allocation is now nicer, and only allocates what is needed.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-01 15:28:24 -08:00
Christopher Snowhill 61a30c959c Bundled resources: Use NSBundle interface
These methods should use NSBundle, rather than CF* C functions

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-01 14:40:02 -08:00
Christopher Snowhill 9e5a70c9ae Cog Audio: Dealt with a major retain cycle leak
This seals up a major memory leak of the playback state whenever a chain
is released on stop or on manual track change. CogAudioMulti was
retaining the input node due to its listeners, and InputNode was not
releasing the listeners when asked to stop running. This is fixed now.

Fixes #221

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-29 21:31:19 -08:00
Christopher Snowhill d239b58ab1 HRIR Filter: Fix 7.0 downmix and WAV files
7.0 downmix was passing parameters to cblas_scopy backwards, and WAV
files report "host" endian, not "native".

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-27 23:02:04 -08:00
Christopher Snowhill 600c447531 Virtual Surround: Further cleanup
Quick changes I missed. Oops.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-26 01:03:12 -08:00
Christopher Snowhill 7b5925d7d2 Virtual Surround: General cleanup
This should fix some coding issues, and also fix some potential memory
leaks in the file verifier, assuming it didn't already release the
files it was pulling the stats from.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-26 01:00:28 -08:00
Christopher Snowhill 778ac0699e Virtual Surround: Cleanup properly
The filter wasn't properly freeing its FFT setup state, and also was
unnecessarily null checking the pointers before passing them to the
aligned free function, which already does null checking.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-25 22:06:53 -08:00
Christopher Snowhill 708c7dc721 Headphone Virtualization: Implement customization
Implement the ability to configure and select an HRIR preset to use with
the HRIR filter, or remove the preset. It will validate the file's
usefulness before setting it for the player to use.

Also, fixed back center channel filtering for 7.0 format audio.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-01-25 21:30:33 -08:00
Christopher Snowhill bb029757fd
Headphone Virtualization: Fix an oops
The previous commit was not sound. Now it is.
2022-01-25 17:45:32 -08:00
Christopher Snowhill e53144acfa Headphone Virtualization: Implement 7ch impulses
This is needed for HeSuVi no-echo impulses, which are only one channel
per input channel, and mapping uses symmetrical mirroring of the input
set to create the surround effect, since there's no side-to-side delay
in these impulses.
2022-01-25 17:23:34 -08:00
Christopher Snowhill e7b78085ca New feature: Implemented headphone virtualization
This new virtualizer uses the Accelerate framework to process samples.
I've bundled a HeSuVi impulse for now, and will add an option to select
an impulse in the future. It will validate the selection before sending
it to the actual filter, which outright fails if it receives invalid
input. Impulses will be supported in any arbitrary format that Cog
supports, but let's not go too hog wild, it requires HeSuVi 14 channel
presets.
2022-01-25 16:50:42 -08:00
Christopher Snowhill 51caf3f4e3 Cog Audio: Don't overfill the output buffer when asked to reset the buffers 2022-01-23 19:53:50 -08:00
Christopher Snowhill 494ad84ea7 Cog Audio: Made ring buffer locking mechanism more secure and/or smarter 2022-01-23 19:36:33 -08:00
Christopher Snowhill 502e52d699 Core Audio output: Hopefully stop buffer looping on device stop 2022-01-22 14:37:37 -08:00
Christopher Snowhill 9d1fd08574 HDCD Decoder: Only process lossless tracks 2022-01-21 22:47:11 -08:00
Christopher Snowhill 26e0e0cead HDCD Decoding: Add HDCD indicator 2022-01-20 23:53:45 -08:00
Christopher Snowhill 6f0a737123 Cog Audio: Implement HDCD decoding 2022-01-19 02:08:57 -08:00
Christopher Snowhill de193b70e2 Converter: Improve extrapolation for resampler, and also pad decimated DSD, even if not resampling it 2022-01-19 00:40:40 -08:00
Christopher Snowhill c4c29be35a Output converter: Limit extrapolation to only be trained on twice as many samples as the extrapolation order 2022-01-18 16:43:10 -08:00
Christopher Snowhill 83ad969d9b Equalizer: Add option for presets to track the music genre tags 2022-01-17 20:43:08 -08:00
Christopher Snowhill 71b2f7a4f2 Implement graphic equalizer 2022-01-16 07:32:47 -08:00
Christopher Snowhill c640481c25 Add SIMD optimized volume scaling 2022-01-16 00:46:21 -08:00
Christopher Snowhill 72453ba05a Cog Audio: Converter now rounds up sample counts affected by resamlping ratio 2022-01-15 23:41:31 -08:00
Christopher Snowhill fbef034903 Cog Audio: Further overhaul output buffering and track queue code 2022-01-15 02:09:26 -08:00
Christopher Snowhill 5ab728b205 Cog Audio: Overhaul output buffering yet again, adding an extra buffer stage between the converter and the output thread 2022-01-14 22:46:41 -08:00
Christopher Snowhill 6315377eaf Cog Audio: Fix extrapolator to use signed type for sample delta 2022-01-14 11:37:52 -08:00
Christopher Snowhill af6677cf34 Cog Audio: Keep track of last resampler quality used so we don't reinitialize when not necessary, and also keep track of DSD decimated sample rate separately, so the input format remains unmodified 2022-01-14 11:18:50 -08:00
Christopher Snowhill 3ce3edde88 Cog Audio: Fix track end extrapolator used by resampler 2022-01-14 07:39:55 -08:00
Christopher Snowhill 748891f285 Cog Audio / WavPack input: Add DSD decimation to converter, and change WavPack input to emit only raw DSD 2022-01-14 06:26:09 -08:00
Christopher Snowhill 903b457a28 Cog Audio: Make it possible to play obscene sample rate files without major failures 2022-01-14 02:00:32 -08:00
Christopher Snowhill c8d2864862 Cog Audio: Enhance playback queue handler, so it always halts buffering when there are at least 30 seconds worth of buffers filled, possibly spanning multiple files. Also improve the chain reset function so that playlist changes and playback order control reset the queue properly when the queue refill function is currently entered in another thread. 2022-01-13 23:05:32 -08:00
Christopher Snowhill 7cc89c9f92 Cog Audio: Enhance track end extrapolator so it will always have a reasonable amount of buffered data for extrapolation 2022-01-13 23:03:53 -08:00
Christopher Snowhill 92d29e7acf Cog Audio: Now preserves already resampled output when switching output formats 2022-01-13 19:43:18 -08:00
Christopher Snowhill 73348b1616 Cog Audio: Implement play position skip ahead when output format changes, based on how much converter output is being discarded 2022-01-12 23:17:07 -08:00
Christopher Snowhill d1b519d59d Cog Audio: Only declare end of stream on read when previous node has declared end of stream and the buffer has actually run empty. This prevents the case where the buffer may terminate early due to the read pointer hitting the end of the ring buffer and wrapping. 2022-01-12 23:15:23 -08:00
Christopher Snowhill ec7ac74fcd Cog Audio: Fix input chain to reset its buffers when seeking properly 2022-01-12 23:13:49 -08:00
Christopher Snowhill cc134ce293 Cog Audio: Converter node actually pauses when it is being reconfigured, and resets its buffer when the output format is changed 2022-01-12 23:13:00 -08:00
Christopher Snowhill b0f5a37e85 Cog Audio: Only proceed to the next track when the current track has actually finished 2022-01-12 21:53:58 -08:00
Christopher Snowhill 5fef62dd03 Cog Audio: Implemented device output and input file format changing support 2022-01-12 21:31:22 -08:00
Christopher Snowhill 9feaffc92d Cog Audio: Made RetroArch resampler safer 2022-01-12 18:45:43 -08:00
Christopher Snowhill f1d70aaa54 Cog Audio: Add explanatory comment to source code 2022-01-12 03:36:27 -08:00
Christopher Snowhill 84d445cffe Cog Audio: Fix converter so that seeking on startup playback position resume works properly 2022-01-12 03:01:55 -08:00
Christopher Snowhill f8e3b0e1ee Core Audio output: Some more minor changes 2022-01-11 22:06:41 -08:00
Christopher Snowhill 557e0bd399 Core Audio output: Fix so it stops properly 2022-01-11 20:38:17 -08:00
Christopher Snowhill 91c3feac2e Cog Audio converter: Fix handling signed versus unsigned for 8 bit samples 2022-01-11 19:37:47 -08:00
Christopher Snowhill f44e4e793b Cog Audio converter: Fix end of track flush and extrapolation 2022-01-11 19:37:17 -08:00
Christopher Snowhill ed882e25cb Cog Audio: Resampler now extrapolates into latency padding for better gapless playback 2022-01-11 18:19:30 -08:00
Christopher Snowhill ee05fe9e44 Core Audio output: Add sanity checking for supported formats, and support 64 bit float input data, in case anything actually uses that 2022-01-11 17:09:06 -08:00
Christopher Snowhill 72210c67e4 Replaced AudioQueue output with AUAudioUnit 2022-01-11 07:06:40 -08:00
Christopher Snowhill c4c9a741ef Replaced AudioToolbox converter process with homebrew solution, using the RetroArch sinc resampler 2022-01-11 04:09:19 -08:00
Christopher Snowhill dfe92ffedc Audio Player: Fix so ReplayGain isn't reset on seek 2021-12-28 21:05:25 -08:00
Christopher Snowhill c1c21ec84f Hopefully fix glitching on seeking 2021-12-28 16:04:16 -08:00
Christopher Snowhill ba3746fcff Remove blank line 2021-12-28 15:40:53 -08:00
Christopher Snowhill 38c530043d Output converter: Add more upmixing modes 2021-12-28 15:39:23 -08:00
Christopher Snowhill b13235ec5f Fix 6.1 stereo downmix mapping 2021-12-28 00:10:44 -08:00
Christopher Snowhill 258a56a276 Audio Output: Implement more upmixing modes, and correct some upmixing behavior 2021-12-28 00:09:57 -08:00
Christopher Snowhill 25a43a9083 Audio Output: Fix converter to always emit trailing samples on end of track 2021-12-27 17:04:16 -08:00
Christopher Snowhill 8435416cd7 Core Audio output: Default device setting now tracks system device changes, and output assigns a speaker mapping depending on the channel count 2021-12-26 21:27:26 -08:00
Christopher Snowhill 1cc34ea7d4 Audio Output: Made converter cleanup atomic, to wait on any threads that are still running 2021-12-26 04:34:33 -08:00
Christopher Snowhill dfeca7aa97 Seeking now takes the true nuclear approach to output, and should no longer have glitches 2021-12-26 02:01:02 -08:00
Christopher Snowhill d22ee14a36 Audio Output: Take a more nuclear approach to output resetting when seeking 2021-12-25 23:41:45 -08:00
Christopher Snowhill 1278b64afd Audio Output: Fixed converter so it won't loop endlessly when it either reaches the end of a stream or is otherwise supposed to terminate 2021-12-25 22:47:17 -08:00
Christopher Snowhill 5246731189 Core Audio: Overhauled audio output to use AudioQueue instead of AudioUnit, fixed downmixing to mono, and implemented upmixing mono or other formats to more channels if the device requests them 2021-12-25 22:32:43 -08:00
Christopher Snowhill 9c9d71cd9c Overhaul CoreAudio output code: Downmix properly from 8 channels, redo converter process, and no longer crash when forced to output to a low quality device. Switchover to stereo from mono isn't perfect, however. 2021-12-25 15:02:13 -08:00