Commit Graph

44 Commits (sparkle)

Author SHA1 Message Date
Christopher Snowhill 066ee806dc Only process visualizations when visible
Stop visualization processing when the host window is completely
occluded, thus reducing background CPU usage levels significantly

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-10-15 23:19:22 -07:00
Christopher Snowhill e5aa4287d1 First module converted to swift, but broken 2022-08-05 17:39:19 -07:00
Christopher Snowhill c612994cb2 Move most large stack using buffers to the heap
This should solve most potential future stack overflows.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-07-24 18:41:50 -07:00
Christopher Snowhill c3ca29db0d [Spectrum] Enable switching style at runtime
It is now possible to switch the display style at runtime, while the
views are open.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-07-05 13:54:35 -07:00
Christopher Snowhill c4790af7c0 Reformat spaces to tabs
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-07-05 13:54:17 -07:00
Dzmitry Neviadomski 81c98736fa Add preference to choose between SceneKit and DDB spectrum. 2022-07-05 13:54:10 -07:00
Christopher Snowhill 6f6b5d6986 [Visualization System] Change API a bit
Now the API makes both PCM and FFT data optional, and will do nothing if
neither are requested. Also, it now supports a latency offset in seconds
with floating point precision. The two built-in visualizations currently
request zero larency. Increasing the latency asks for even older samples
while specifying a negative count requests samples from the "future"
relative to what the listener is hearing.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-26 05:39:24 -07:00
Christopher Snowhill 8af32e8d2e Replace Core Audio output with Core Media runtime
The output now uses AVSampleBufferAudioRenderer to play all formats, and
uses that to resample. It also supports Spatial Audio on macOS 12.0 or
newer. Note that there are some outstanding bugs with Spatial Audio
support. Namely that it appears to be limited to only 192 kHz at mono or
stereo, or 352800 Hz at surround configurations. This breaks DSD64
playback at stereo formats, as well as possibly other things. This is
entirely an Apple bug. I have reported it to Apple with reference code
FB10441301 for reference, in case anyone else wants to complain that it
isn't fixed.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-23 23:22:41 -07:00
Christopher Snowhill 5b6dacd29c Cog now requires macOS 10.13 as a minimum version
All optional fallback code for older versions has also been removed, and
everything now assumes 10.13.0 or newer. Some cases are still included
for point releases, such as 10.13.2.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-22 22:54:32 -07:00
Christopher Snowhill 071d23b1c6
[SceneKit Visualization] Refine blocklist again
* Remove exception variable setter

Remove SceneKit crash variable setting exception
handler from NSApplication delegate.

* Restrict SceneKit to 10.13, 10.14, and 11.0+

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-19 21:42:39 -07:00
Christopher Snowhill 2563125ec5 [SceneKit Visualizer] Refine blocklist
The blocklist wasn't actually blocking the requisite GPUs properly.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-19 20:03:47 -07:00
Christopher Snowhill b01924e10e [SceneKit Spectrum] Added device name to logging
Device name logging is essential in determining if crashes are on
specific device models that haven't been blocklisted.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-18 18:14:25 -07:00
Christopher Snowhill 711c18a3bd [SceneKit Spectrum] Add device block list
Currently blocking all Radeon cards up to and including Polaris cards.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-17 22:16:20 -07:00
Christopher Snowhill cbcbdf893d [Spectrum Visualizer] Add crash check for SceneKit
The SceneKit visualizer now has a crash check, which will trigger if an
exception is thrown by the app.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-17 22:15:14 -07:00
Christopher Snowhill 8db2e41049 [Event Handling] Add context to all observers
Add context field to all observers that support it, in case it's useful.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-15 16:47:43 -07:00
Christopher Snowhill 90b83f8f51 [Various] Clean up various warnings
Various warnings related to uninitialized variables, or setting values
to variables that would not be used later or would be overwritten by per
loop initializers.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-11 13:42:42 -07:00
Christopher Snowhill b821896560 [Visualizer] Constrain SceneKit visualizer events
Constrain observer events to the exact context requested, and remove
them with the same context specified.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-10 22:35:51 -07:00
Christopher Snowhill cdcbabd72f [Visualizer] Accidentally left in debug test code
This was changed to verify the legacy code still works.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-08 21:56:47 -07:00
Christopher Snowhill 1728debe94 [Visualizer] Bring back CoreGraphics visualizer
For legacy systems that do not support Metal. The Metal SceneKit view
does work on even 10.13.6, if a Metal GPU is present in the system.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-08 21:32:52 -07:00
Christopher Snowhill 6022526ad4 [Visualization] Improve hidden window detection
The NSView should detect if it's a visible control in a window

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-07 19:01:47 -07:00
Christopher Snowhill dc103ac546 [Visualizer] Disable processing when vis is hidden
When visualizer windows are created, but not actually visible, stop the
update timer, to save processing, especially if the vis is enabled in
one or the other main/mini windows.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-06 08:19:42 -07:00
Christopher Snowhill aabd9431f1 [Visualization] Gate registered observers
Gate registering observers behind a check variable in the object state,
which will be zero initialized by the Objective-C runtime, and will
prevent the class from erroneously unregistering observers without them
being registered in the first place. Apparently, services cannot be
unregistered if they were never registered first, or else an exception
will be thrown upon attempting to unregister them. This fixes a crash on
startup in the now several times running failure to work properly on
legacy Macs without Metal graphics, now that the new visualization
system has been implemented.

It's probably not worth bringing back the previous Core Graphics based
visualizer method anyway, as on those same legacy machines, it was
causing out of control CPU usage by WindowServer. At least on modern
Macs, any amount of 60fps UI updating will cause WindowServer to use
about 45% of a core, regardless of how many apps are drawing that much
at once.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-30 21:38:29 -07:00
Christopher Snowhill 8c2df13f3b [Visualization] Disable visualization if no Metal
If the system has no working Metal devices, disable the visualization.

The legacy visualization was also too slow for said systems to handle
reasonably anyway, so I guess it's safe to say that they shouldn't have
to handle any visualizers at all. At least have working audio playback,
of course, since that is the primary function of the application. Too
bad that the OpenGL renderers don't work on my scene, it would be nice
to have a fallback there. GL 4.1 crashes on an M1, and both GL 4.1 and
3.2 crash with SIGFPE division by zero error on Intel Macs without Metal
devices. Meh.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-30 00:15:49 -07:00
Christopher Snowhill 539a8c79eb [Visualization] Remove default Metal device option
Remove the default Metal device option, as it can return nil on systems
where it won't be expected to work.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-28 19:32:26 -07:00
Christopher Snowhill ec18d0b260 [Visualization] Fix crash with frequency mode
The frequency mode, apparently the default, doesn't like that the code
was setting the width of the spectrum data to 11 instead of the default
1000. This was causing it to overwrite freed memory when the spectrum
started processing audio.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-28 18:31:09 -07:00
Christopher Snowhill 6b381f3d08 [Visualization] Remove OpenGL fallback
The OpenGL fallback was causing division by zero errors on Intel Macs
running macOS High Sierra.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-28 18:23:15 -07:00
Christopher Snowhill 5e5b2e4071 [Visualization] Add micro bias to cylinder scale
Apparently, old macOS wants to divide something by the scale size, so
setting it to zero causes division by zero errors? Let's set it to a
really small number instead.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-27 04:33:07 -07:00
Christopher Snowhill 4b2cf22800 [Visualization] Use OpenGL on legacy systems
On legacy OSes, and legacy GPUs, it should use OpenGL and not Metal,
otherwise there could be horrible performance, or even crashes.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-23 17:21:13 -07:00
Christopher Snowhill 84eadd1f33 [Visualization] Use forced 3D mode in window
Windowed style should always use the perspective camera mode.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 17:45:51 -07:00
Christopher Snowhill 438634d6df [Visualization]: Change peaks to float on top
Change the peak sphere positions so they float on top of the bottom or
the bars, instead of clipping into them.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 17:25:21 -07:00
Christopher Snowhill f4712ad219 [Visualization]: Add Spectrum window
Add a dedicated spectrum visualization window, and add the necessary
hooks to start its event timer if playback is already running when it is
first opened.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 17:24:35 -07:00
Christopher Snowhill e2d7ebdec5 [Visualization] Enable anti-aliasing
Enable 8x multisampled anti-aliasing, to improve the appearance of the
spectrum on non-Retina/HiDPI displays. It can't really hurt on HiDPI,
either. Hopefully this won't cause it to use a whole load of GPU
resources, more than is reasonable.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 16:32:57 -07:00
Dzmitry Neviadomski a58b11dc90 [Visualizer] Adjust 2d projection camera angles. 2022-05-23 02:12:25 +03:00
Christopher Snowhill 4035ca861f Spectrum Visualizer: Add customization options
Add options to the Appearance preferences page to allow changing the
spectrum's projection between a 2D-like one and 3D perspective, and add
options to change the bar and peak dot colors.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 15:26:27 -07:00
Christopher Snowhill fce0e129a5 Spectrum Visualization: Replaced spectrum view
Introduced a brand new spectrum view based on SceneKit, with a scene
created by @kddlb and then altered by me to add the peak spheres. This
new scene should be lighter on display resources, even though it's fully
3D instead of a vector 2D scene done in Cocoa drawing primitives.

Co-authored-by: Kevin Lopez Brante <kevin@kddlb.cl>
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-05-22 00:03:52 -07:00
Christopher Snowhill 014f136b7e Visualization: Protect against out of bounds read
The analyzer was reading out of bounds, so guard against that.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-03-06 03:51:25 -08:00
Christopher Snowhill 1ac1fe29c7 Implement new spectrum mode, toggled by left click
The new spectrum mode is linear frequency. Both modes also now have a
lower range of 10Hz, where possible.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 23:24:58 -08:00
Christopher Snowhill 6d052bc1ac Visualization: Increase temporal resolution
By reducing the window size, we have a more responsive visualization.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-15 23:22:47 -08:00
Christopher Snowhill 52443066e7 Spectrum Visualizer: Fix frequency range, bands
Reduce the virtual resolution to match the actual resolution, and set
the analyzere frequency to Nyquist of the audio input, as it seems to
behave as if the entire range of the input FFT bands are up to the
specified frequency, rather than half of it. Otherwise, we lose half of
the frequency range provided by the input data.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-14 21:10:57 -08:00
Christopher Snowhill 4a0690b3ab Spectrum Visualizer: Change border dimensions
This should make the border consistently sized.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-14 17:15:38 -08:00
Christopher Snowhill 344ceb173d Visualization: Increased fft size, imported code
Boy, I just be outright stealing code now. But it looks nicer now.

Fixes #234

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-13 12:18:58 -08:00
Christopher Snowhill f2bebdefa7 Visualization: Clear peaks on stop
Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-13 01:42:02 -08:00
Christopher Snowhill 992b716193 Visualization: Greatly improve spectrum design
Improvement includes greatly reducing the CPU usage by not using an
NSImage based painting system.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-13 01:32:26 -08:00
Christopher Snowhill 417687600b Implement visualization support and a spectrum
Borrowing some DFT code from deadbeef, this implements a simple spectrum
visualization into the main toolbar of the app.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-02-12 23:04:03 -08:00