Last active
May 11, 2026 05:42
-
-
Save jaekong/8d921d92e36010cdabdde3ecb0aa6936 to your computer and use it in GitHub Desktop.
Swift + RNBO C++ Export
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
| var object = RNBO.CoreObject(nil) | |
| object.prepareToProcess(44100, 128) | |
| let input = [ | |
| [128 of Double](repeating: 440) | |
| ] | |
| var output = [ | |
| [128 of Double](repeating: 0) | |
| ] | |
| object.process(input: input, output: &output) | |
| print(output) | |
| // InlineArray to Array (InlineArray does not conform to CustomStringConvertible) | |
| let outputArray = [Double](capacity: 128) { span in | |
| for i in output[0].indices { | |
| span.append(output[0][i]) | |
| } | |
| } | |
| print(outputArray) |
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
| // swift-tools-version: 6.3 | |
| // The swift-tools-version declares the minimum version of Swift required to build this package. | |
| import PackageDescription | |
| let package = Package( | |
| name: "SwiftRNBO", | |
| platforms: [.macOS(.v26)], | |
| targets: [ | |
| .target( | |
| name: "CxxRNBO", | |
| sources: [ | |
| "rnbo_source.cpp", | |
| "rnbo/RNBO.cpp" | |
| ], | |
| publicHeadersPath: "rnbo/common", | |
| cxxSettings: [ | |
| .headerSearchPath("rnbo"), | |
| .headerSearchPath("rnbo/common") | |
| ] | |
| ), | |
| .executableTarget( | |
| name: "SwiftRNBO", | |
| dependencies: [ | |
| .target(name: "CxxRNBO") | |
| ], | |
| swiftSettings: [ | |
| .interoperabilityMode(.Cxx) | |
| ] | |
| ), | |
| ], | |
| swiftLanguageModes: [.v6] | |
| ) |
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
| // Sources/<rnbo_export_dir>/rnbo/common/RNBO.h | |
| #include "../RNBO.h" |
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
| import CxxRNBO | |
| extension RNBO.CoreObject { | |
| mutating func process<let sampleCount: Int>( | |
| input: some Collection<InlineArray<sampleCount, RNBO.SampleValue>>, | |
| output: inout some Collection<InlineArray<sampleCount, RNBO.SampleValue>> | |
| ) { | |
| input.withContiguousStorageIfAvailable { buffer in | |
| withUnsafePointer(to: buffer.baseAddress) { inputPointer in | |
| output.withContiguousStorageIfAvailable { buffer in | |
| withUnsafePointer(to: buffer) { outputPointer in | |
| self.process(.init(OpaquePointer(inputPointer)), RNBO.Index(input.count), .init(OpaquePointer(outputPointer)), RNBO.Index(output.count), RNBO.Index(sampleCount)) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment