diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index c7e40cbf7..f51fedb64 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -16,13 +16,7 @@ #import #import -#ifdef __cplusplus -#import -using std::atomic_int; -using std::atomic_bool; -#else #import -#endif @class BufferChain; @class OutputNode; diff --git a/Audio/CogAudio.xcodeproj/project.pbxproj b/Audio/CogAudio.xcodeproj/project.pbxproj index 131c021ee..6942b1cca 100644 --- a/Audio/CogAudio.xcodeproj/project.pbxproj +++ b/Audio/CogAudio.xcodeproj/project.pbxproj @@ -92,14 +92,13 @@ 83725A9127AA16D50003F694 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 83725A7C27AA0D8E0003F694 /* AVFoundation.framework */; }; 8377C64C27B8C51500E8BC0F /* fft_accelerate.c in Sources */ = {isa = PBXBuildFile; fileRef = 8377C64B27B8C51500E8BC0F /* fft_accelerate.c */; }; 8377C64E27B8C54400E8BC0F /* fft.h in Headers */ = {isa = PBXBuildFile; fileRef = 8377C64D27B8C54400E8BC0F /* fft.h */; }; - 8377C65227B8CAD100E8BC0F /* VisualizationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 8377C65027B8CAD100E8BC0F /* VisualizationController.h */; }; - 8377C65327B8CAD100E8BC0F /* VisualizationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8377C65127B8CAD100E8BC0F /* VisualizationController.m */; }; 8384912718080FF100E7332D /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 8384912618080FF100E7332D /* Logging.h */; }; 839065F32853338700636FBB /* dsd2float.h in Headers */ = {isa = PBXBuildFile; fileRef = 839065F22853338700636FBB /* dsd2float.h */; }; 839366671815923C006DD712 /* CogPluginMulti.h in Headers */ = {isa = PBXBuildFile; fileRef = 839366651815923C006DD712 /* CogPluginMulti.h */; }; 839366681815923C006DD712 /* CogPluginMulti.m in Sources */ = {isa = PBXBuildFile; fileRef = 839366661815923C006DD712 /* CogPluginMulti.m */; }; 8399CF2C27B5D1D5008751F1 /* NSDictionary+Merge.h in Headers */ = {isa = PBXBuildFile; fileRef = 8399CF2A27B5D1D4008751F1 /* NSDictionary+Merge.h */; }; 8399CF2D27B5D1D5008751F1 /* NSDictionary+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = 8399CF2B27B5D1D4008751F1 /* NSDictionary+Merge.m */; }; + 839B83FA286D91ED00F529EE /* VisualizationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B83F9286D91ED00F529EE /* VisualizationController.swift */; }; 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; }; 8E8D3D2F0CBAEE6E00135C1B /* AudioContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E8D3D2D0CBAEE6E00135C1B /* AudioContainer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8E8D3D300CBAEE6E00135C1B /* AudioContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E8D3D2E0CBAEE6E00135C1B /* AudioContainer.m */; }; @@ -220,14 +219,13 @@ 83725A7C27AA0D8E0003F694 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 8377C64B27B8C51500E8BC0F /* fft_accelerate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fft_accelerate.c; sourceTree = ""; }; 8377C64D27B8C54400E8BC0F /* fft.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fft.h; sourceTree = ""; }; - 8377C65027B8CAD100E8BC0F /* VisualizationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VisualizationController.h; sourceTree = ""; }; - 8377C65127B8CAD100E8BC0F /* VisualizationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VisualizationController.m; sourceTree = ""; }; 8384912618080FF100E7332D /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = ../../Utils/Logging.h; sourceTree = ""; }; 839065F22853338700636FBB /* dsd2float.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dsd2float.h; sourceTree = ""; }; 839366651815923C006DD712 /* CogPluginMulti.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CogPluginMulti.h; sourceTree = ""; }; 839366661815923C006DD712 /* CogPluginMulti.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CogPluginMulti.m; sourceTree = ""; }; 8399CF2A27B5D1D4008751F1 /* NSDictionary+Merge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDictionary+Merge.h"; path = "../../Utils/NSDictionary+Merge.h"; sourceTree = ""; }; 8399CF2B27B5D1D4008751F1 /* NSDictionary+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDictionary+Merge.m"; path = "../../Utils/NSDictionary+Merge.m"; sourceTree = ""; }; + 839B83F9286D91ED00F529EE /* VisualizationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualizationController.swift; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* CogAudio.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CogAudio.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8E8D3D2D0CBAEE6E00135C1B /* AudioContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioContainer.h; sourceTree = ""; }; @@ -518,8 +516,7 @@ 8377C64F27B8CAAB00E8BC0F /* Visualization */ = { isa = PBXGroup; children = ( - 8377C65027B8CAD100E8BC0F /* VisualizationController.h */, - 8377C65127B8CAD100E8BC0F /* VisualizationController.m */, + 839B83F9286D91ED00F529EE /* VisualizationController.swift */, ); path = Visualization; sourceTree = ""; @@ -557,7 +554,6 @@ 831A4FE42865A7DC0049CFE4 /* pf_scalar_double.h in Headers */, 831A500D2865A7DC0049CFE4 /* CDSPHBDownsampler.h in Headers */, 831A500C2865A7DC0049CFE4 /* fft4g.h in Headers */, - 8377C65227B8CAD100E8BC0F /* VisualizationController.h in Headers */, 834FD4F027AF93680063BC83 /* ChunkList.h in Headers */, 17F94DD50B8D0F7000A34E87 /* PluginController.h in Headers */, 831A50122865A7DC0049CFE4 /* pffft.h in Headers */, @@ -624,6 +620,7 @@ LastUpgradeCheck = 1400; TargetAttributes = { 8DC2EF4F0486A6940098B216 = { + LastSwiftMigration = 1330; ProvisioningStyle = Manual; }; }; @@ -670,12 +667,12 @@ 831A50162865A8800049CFE4 /* r8bstate.cpp in Sources */, 17D21CA80B8BE4BA00D1EBDE /* Node.m in Sources */, 17D21CAA0B8BE4BA00D1EBDE /* OutputNode.m in Sources */, - 8377C65327B8CAD100E8BC0F /* VisualizationController.m in Sources */, 17D21CC60B8BE4BA00D1EBDE /* OutputAVFoundation.m in Sources */, 835C88B2279811A500E28EAE /* hdcd_decode2.c in Sources */, 835FAC5F27BCA14D00BA8562 /* BadSampleCleaner.m in Sources */, 834FD4ED27AF91220063BC83 /* AudioChunk.m in Sources */, 17D21CF40B8BE5EF00D1EBDE /* Semaphore.m in Sources */, + 839B83FA286D91ED00F529EE /* VisualizationController.swift in Sources */, 8347C7422796C58800FA8A7D /* NSFileHandle+CreateFile.m in Sources */, 17D21DC80B8BE79700D1EBDE /* CoreAudioUtils.m in Sources */, 8328995327CB511000D7F028 /* RedundantPlaylistDataStore.m in Sources */, @@ -704,15 +701,16 @@ 1DEB91AE08733DA50010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DEAD_CODE_STRIPPING = YES; + DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = CogAudio_Prefix.pch; @@ -724,32 +722,29 @@ INFOPLIST_FILE = Info.plist; INSTALL_PATH = "@executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/ThirdParty/r8brain-free-src/DLL/Win64", - "$(PROJECT_DIR)/ThirdParty/r8brain-free-src/DLL/Win32", - ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = org.cogx.cogaudio; PRODUCT_NAME = CogAudio; - SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; WARNING_LDFLAGS = ""; WRAPPER_EXTENSION = framework; - ZERO_LINK = YES; }; name = Debug; }; 1DEB91AF08733DA50010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; DEAD_CODE_STRIPPING = YES; + DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = CogAudio_Prefix.pch; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -759,16 +754,12 @@ INFOPLIST_FILE = Info.plist; INSTALL_PATH = "@executable_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/ThirdParty/r8brain-free-src/DLL/Win64", - "$(PROJECT_DIR)/ThirdParty/r8brain-free-src/DLL/Win32", - ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = org.cogx.cogaudio; PRODUCT_NAME = CogAudio; - SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; WARNING_LDFLAGS = ""; WRAPPER_EXTENSION = framework; }; diff --git a/Audio/Visualization/VisualizationController.swift b/Audio/Visualization/VisualizationController.swift new file mode 100644 index 000000000..5a1916007 --- /dev/null +++ b/Audio/Visualization/VisualizationController.swift @@ -0,0 +1,97 @@ +// +// VisualizationController.swift +// CogAudio Framework +// +// Created by Christopher Snowhill on 6/30/22. +// + +import Foundation + +@objc(VisualizationController) +class VisualizationController { + var serialQueue = DispatchQueue(label: "Visualization Queue") + var sampleRate = 44100.0 + var latency = 0.0 + var visAudio: [Float] = Array(repeating: 0.0, count: 44100 * 45) + var visAudioCursor = 0 + var visAudioSize = 0 + + private static var sharedController: VisualizationController = { + let visualizationController = VisualizationController() + return visualizationController + }() + + class func sharedVisualizationController() -> VisualizationController { + return sharedController + } + + func postLatency(_ latency: Double) { + self.latency = latency + } + + func postSampleRate(_ sampleRate: Double) { + serialQueue.sync { + if(self.sampleRate != sampleRate) { + self.sampleRate = sampleRate + visAudioSize = (Int)(sampleRate * 45.0) + visAudio = Array(repeating: 0.0, count: visAudioSize) + visAudioCursor = 0 + } + } + } + + func postVisPCM(_ inPCM: UnsafePointer?, amount: Int) { + serialQueue.sync { + let bufferPointer = UnsafeBufferPointer(start: inPCM, count: amount) + if let bptr = bufferPointer { + let dataArray = bptr.assumingMemoryBound(to: Float.self) + var j = self.visAudioCursor + var k = self.visAudioSize + for i in 0..= k { j = 0 } + } + self.visAudioCursor = j + } + } + } + + func readSampleRate() -> Double { + serialQueue.sync { + return self.sampleRate + } + } + + func copyVisPCM(_ outPCM: UnsafeMutablePointer?, visFFT: UnsafeMutablePointer?, latencyoffset: Double) { + let outPCMCopy = Array(repeating: 0.0, count: 4096) + + serialQueue.sync { + var latencySamples = (Int)(self.latency * self.sampleRate) + var j = self.visAudioCursor - latencySamples + var k = self.visAudioSize + if j < 0 { j += k } + for i in 0..4095 { + let x = self.visAudio[j] + outPCMCopy[i] = x + j++; if j >= k { j = 0 } + } + } + + let pcmPointer = UnsafeMutableBufferPointer(start: outPCM, count: 4096) + if let bptr = pcmPointer { + let dataArray = bptr.assumingMemoryBound(to: Float.self) + for i in 0..4095 { + let x = outPCMCopy[i] + dataArray[i] = x + } + } + + let fftPointer = UnsafeMutablePointer(start: visFFT, count: 2048) + if let bptr = fftPointer { + serialQueue.sync { + fft_calculate(outPCMCopy, bptr, 2048) + } + } + } +} diff --git a/SpectrumViewCG.h b/SpectrumViewCG.h index cff784cbc..722f39cfb 100644 --- a/SpectrumViewCG.h +++ b/SpectrumViewCG.h @@ -7,7 +7,7 @@ #import -#import "VisualizationController.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/Visualization/SpectrumViewSK.h b/Visualization/SpectrumViewSK.h index 34225c890..b2edcaa39 100644 --- a/Visualization/SpectrumViewSK.h +++ b/Visualization/SpectrumViewSK.h @@ -9,7 +9,7 @@ #import -#import "VisualizationController.h" +#import NS_ASSUME_NONNULL_BEGIN