Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6875da2cb | |||
| 5e6534a615 |
@@ -144,6 +144,17 @@
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
C8D00000000000000000013 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C8D00000000000000000041 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
C8D00000000000000000042 /* Bundle Lyrebird swiftmodules */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
@@ -162,17 +173,6 @@
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
C8D00000000000000000013 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C8D00000000000000000041 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
C8D00000000000000000011 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
@@ -189,14 +189,14 @@
|
||||
C8D00000000000000000016 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
AUTOMATION_APPLE_EVENTS = NO;
|
||||
CODE_SIGN_ENTITLEMENTS = LyrebirdScratch/LyrebirdScratch.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@@ -206,12 +206,14 @@
|
||||
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
|
||||
ENABLE_RESOURCE_ACCESS_PHOTO_LIBRARY = NO;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
INFOPLIST_FILE = LyrebirdScratch/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 1.6.2;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.LyrebirdScratch;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
@@ -229,14 +231,14 @@
|
||||
C8D00000000000000000017 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||
AUTOMATION_APPLE_EVENTS = NO;
|
||||
CODE_SIGN_ENTITLEMENTS = LyrebirdScratch/LyrebirdScratch.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 2;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
ENABLE_RESOURCE_ACCESS_AUDIO_INPUT = YES;
|
||||
@@ -245,12 +247,14 @@
|
||||
ENABLE_RESOURCE_ACCESS_CONTACTS = NO;
|
||||
ENABLE_RESOURCE_ACCESS_LOCATION = NO;
|
||||
ENABLE_RESOURCE_ACCESS_PHOTO_LIBRARY = NO;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = NO;
|
||||
INFOPLIST_FILE = LyrebirdScratch/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 1.6.2;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.LyrebirdScratch;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.6.1</string>
|
||||
<string>1.6.3</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>3</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
+53
@@ -7,6 +7,59 @@ functionality in a backward-compatible way.
|
||||
|
||||
---
|
||||
|
||||
## 1.6.4 — `LookAheadLimiter` release time decoupled from look-ahead
|
||||
|
||||
A patch release. One backward-compatible library addition.
|
||||
|
||||
`LookAheadLimiter` gains a `releaseTime` parameter, independent of
|
||||
`lookAheadTime`:
|
||||
|
||||
```swift
|
||||
LookAheadLimiter(in:maxAmplitude:lookAheadTime:releaseTime:sampleRate:)
|
||||
```
|
||||
|
||||
Previously the gain-release one-pole coefficient was derived from
|
||||
`lookAheadTime` (default 5 ms), so the release was fast enough to modulate the
|
||||
gain within a single cycle of a low-frequency signal — audible as distortion on
|
||||
sustained bass when the limiter was driven hard. `releaseTime` (default
|
||||
`0.050`) is now a separate control, read per block from a `ValidGeneratorInput`
|
||||
so it can be driven by a live parameter / knob. The look-ahead window size and
|
||||
the no-overshoot ceiling guarantee are unchanged.
|
||||
|
||||
The new parameter has a default, so existing call sites are source-compatible.
|
||||
|
||||
---
|
||||
|
||||
## 1.6.3 — Notarization-ready `macos-ui-xcode` template
|
||||
|
||||
A patch release. Project-scaffolding fixes; no library API changes.
|
||||
|
||||
The `macos-ui-xcode` template (`lyrebird new MyApp --template macos-ui-xcode`)
|
||||
now scaffolds a distributable, notarization-ready macOS performance app out of
|
||||
the box:
|
||||
|
||||
- **Entitlements shipped and wired** — `<name>.entitlements` grants
|
||||
`com.apple.security.device.audio-input` (wired via `CODE_SIGN_ENTITLEMENTS`
|
||||
in both build configs), plus `NSMicrophoneUsageDescription` in `Info.plist`.
|
||||
Under the Hardened Runtime (already enabled) the OS hard-kills the process the
|
||||
moment the AUHAL input bus opens without these. They are harmless for
|
||||
output-only synths — no permission prompt fires until input is actually used.
|
||||
The app is deliberately **unsandboxed**: a live-performance app needs
|
||||
unrestricted audio-device / file / MIDI / OSC access the App Sandbox gates.
|
||||
|
||||
- **Compiles under Swift 6** — fixed a latent actor-isolation error that kept
|
||||
the generated project from building: `NoteController` (calls the engine's
|
||||
`@MainActor add(_:)`) and `AppDelegate` (constructs the main-actor controller
|
||||
and synth) are now `@MainActor`. Xcode app templates are excluded from the
|
||||
`swift build` CI matrix, so this had never been compile-checked; it is now
|
||||
verified end-to-end with `xcodebuild`.
|
||||
|
||||
A normal Lyrebird app needs no module-bundling: Lyrebird is statically linked
|
||||
from SPM source. (The swiftmodule / `LyrebirdC` bundling in `LyrebirdScratch`,
|
||||
added in 1.6.2, is unique to its runtime `swiftc` scratchpad.)
|
||||
|
||||
---
|
||||
|
||||
## 1.6.2 — Live Scratch: distributable / notarized app
|
||||
|
||||
A patch release. Live Scratch packaging only; no library API changes.
|
||||
|
||||
@@ -11,7 +11,11 @@ import Darwin
|
||||
/// the output never exceeds ±`maxAmplitude` regardless of transients.
|
||||
///
|
||||
/// The gain attack is instantaneous within the look-ahead window. Gain release uses
|
||||
/// a one-pole smoother with a time constant equal to `lookAheadTime`.
|
||||
/// a one-pole smoother whose time constant is `releaseTime`, decoupled from
|
||||
/// `lookAheadTime`. A too-fast release modulates the gain within a single cycle of a
|
||||
/// low-frequency signal, which distorts sustained bass; keeping release slow (tens of
|
||||
/// ms) while the look-ahead window stays short (a few ms) catches transients without
|
||||
/// that distortion.
|
||||
///
|
||||
/// ## Latency
|
||||
/// Output is delayed by exactly `lookAheadSamples = Int(lookAheadTime × sampleRate)`.
|
||||
@@ -42,18 +46,22 @@ import Darwin
|
||||
/// - maxAmplitude: Peak ceiling (absolute value). Output `|y|` never exceeds
|
||||
/// this value once the look-ahead window has filled. Default `1.0`.
|
||||
/// - lookAheadTime: Look-ahead and output delay in seconds. Fixed at init —
|
||||
/// determines ring buffer size and release time constant.
|
||||
/// Range `[0, ∞)`; values above ~50 ms waste memory.
|
||||
/// Default `0.005` (5 ms).
|
||||
/// determines ring buffer size. Range `[0, ∞)`; values above
|
||||
/// ~50 ms waste memory. Default `0.005` (5 ms).
|
||||
/// - releaseTime: Gain-release time constant in seconds. Clamped to ≥ 0. Read per block,
|
||||
/// so it may be driven by a live parameter. Independent of `lookAheadTime`.
|
||||
/// Keep it well above the period of the lowest frequency you expect
|
||||
/// (tens of ms) to avoid low-frequency distortion. Default `0.050`.
|
||||
/// - sampleRate: Engine sample rate in Hz. **Must match `SynthesisEngine.sampleRate`.**
|
||||
/// Required — no default. Ring buffer sizes and release coefficient
|
||||
/// are computed at init from this value and cannot be updated at runtime.
|
||||
/// Required — no default. Ring buffer sizes are computed at init from
|
||||
/// this value and cannot be updated at runtime.
|
||||
public final class LookAheadLimiter: GeneratorBase, AudioGenerator {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
private let _input: any ValidGeneratorInput
|
||||
private let _maxAmpInput: any ValidGeneratorInput
|
||||
private let _releaseTimeInput: any ValidGeneratorInput
|
||||
private let _lookAheadSamples: Int
|
||||
|
||||
// MARK: - Pre-allocated delay ring
|
||||
@@ -80,8 +88,6 @@ public final class LookAheadLimiter: GeneratorBase, AudioGenerator {
|
||||
|
||||
private var _writePos: Int = 0
|
||||
private var _gain: Double = 1.0
|
||||
private let _releaseCoeff: Double
|
||||
private let _attackComp: Double
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -90,30 +96,30 @@ public final class LookAheadLimiter: GeneratorBase, AudioGenerator {
|
||||
/// - maxAmplitude: Peak ceiling (absolute value). Output `|y|` never exceeds
|
||||
/// this value once the look-ahead window has filled. Default `1.0`.
|
||||
/// - lookAheadTime: Look-ahead and output delay in seconds. Fixed at init —
|
||||
/// determines ring buffer size and release time constant.
|
||||
/// Range `[0, ∞)`. Default `0.005` (5 ms).
|
||||
/// determines ring buffer size. Range `[0, ∞)`. Default `0.005` (5 ms).
|
||||
/// - releaseTime: Gain-release time constant in seconds. Clamped to ≥ 0. Read per block, so it may be
|
||||
/// driven by a live parameter. Independent of `lookAheadTime`. Default `0.050`.
|
||||
/// - sampleRate: Engine sample rate in Hz. **Must match `SynthesisEngine.sampleRate`.**
|
||||
/// Required — no default. Ring buffer sizes and the release coefficient
|
||||
/// are computed at init from this value and cannot be updated at runtime.
|
||||
/// Required — no default. Ring buffer sizes are computed at init from this
|
||||
/// value and cannot be updated at runtime.
|
||||
public init(
|
||||
in input: any ValidGeneratorInput,
|
||||
maxAmplitude: any ValidGeneratorInput = 1.0,
|
||||
lookAheadTime: Double = 0.005,
|
||||
releaseTime: any ValidGeneratorInput = 0.050,
|
||||
sampleRate: Double
|
||||
) {
|
||||
precondition(lookAheadTime >= 0, "LookAheadLimiter: lookAheadTime must be ≥ 0")
|
||||
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||
let resolvedMaxAmp: any ValidGeneratorInput = maxAmplitude._resolvedInput()
|
||||
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||
let resolvedMaxAmp: any ValidGeneratorInput = maxAmplitude._resolvedInput()
|
||||
let resolvedRelease: any ValidGeneratorInput = releaseTime._resolvedInput()
|
||||
_input = resolvedInput
|
||||
_maxAmpInput = resolvedMaxAmp
|
||||
_releaseTimeInput = resolvedRelease
|
||||
_lookAheadSamples = Int(lookAheadTime * sampleRate)
|
||||
let bufferSize: Int = _lookAheadSamples + lyrebirdDefaultResultBufferSize + 1
|
||||
_ringSize = bufferSize
|
||||
_delayRing = [Double](repeating: 0.0, count: bufferSize)
|
||||
_releaseCoeff = lookAheadTime > 0
|
||||
? exp(-1.0 / (sampleRate * lookAheadTime))
|
||||
: 0.0
|
||||
_attackComp = 1.0 - _releaseCoeff
|
||||
// Deque capacity = max-live (_lookAheadSamples + 1) + 1 slot of slack
|
||||
// so push-before-front-pop on a wraparound step does not collide.
|
||||
_dequeCapacity = max(2, _lookAheadSamples + 2)
|
||||
@@ -136,9 +142,14 @@ public final class LookAheadLimiter: GeneratorBase, AudioGenerator {
|
||||
let maxAmp: Double = max(0.0, Double(_maxAmpInput.floatValue(graph: graph)))
|
||||
let inputSamples: [[Double]] = _input.calculatedSamples(graph: graph, count: count)
|
||||
|
||||
// Release coefficient recomputed per block from the (possibly live) releaseTime.
|
||||
// Decoupled from lookAheadTime — a slow release avoids modulating the waveform.
|
||||
let sr: Double = graph.engine.sampleRate
|
||||
let releaseT: Double = max(0.0, Double(_releaseTimeInput.floatValue(graph: graph)))
|
||||
let releaseCoeff: Double = releaseT > 0 ? exp(-1.0 / (sr * releaseT)) : 0.0
|
||||
let attackComp: Double = 1.0 - releaseCoeff
|
||||
|
||||
let ringSize: Int = _ringSize
|
||||
let releaseCoeff: Double = _releaseCoeff
|
||||
let attackComp: Double = _attackComp
|
||||
|
||||
guard let ins: [Double] = inputSamples.first else {
|
||||
// Pathological branch: upstream returned a 0-row matrix. Advance ring +
|
||||
|
||||
@@ -41,6 +41,7 @@ extension ProjectScaffolder {
|
||||
/* Begin PBXFileReference section */
|
||||
\t\t\(pbxAppProductRef) /* \(name).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = \(name).app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
\t\t\(pbxInfoPlistRef) /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
\t\t\(pbxAppEntitlementsRef) /* \(name).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = \(name).entitlements; sourceTree = "<group>"; };
|
||||
\t\t\(pbxMainSwiftRef) /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
\t\t\(pbxAppDelegateRef) /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
\t\t\(pbxSynthRef) /* \(name)Synth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = \(name)Synth.swift; sourceTree = "<group>"; };
|
||||
@@ -85,6 +86,7 @@ extension ProjectScaffolder {
|
||||
\t\t\t\t\(pbxNoteControllerRef) /* NoteController.swift */,
|
||||
\t\t\t\t\(pbxViewRef) /* \(name)View.swift */,
|
||||
\t\t\t\t\(pbxInfoPlistRef) /* Info.plist */,
|
||||
\t\t\t\t\(pbxAppEntitlementsRef) /* \(name).entitlements */,
|
||||
\t\t\t);
|
||||
\t\t\tpath = \(name);
|
||||
\t\t\tsourceTree = "<group>";
|
||||
@@ -177,6 +179,7 @@ extension ProjectScaffolder {
|
||||
\t\t\(pbxAppDebugConfig) /* Debug */ = {
|
||||
\t\t\tisa = XCBuildConfiguration;
|
||||
\t\t\tbuildSettings = {
|
||||
\t\t\t\tCODE_SIGN_ENTITLEMENTS = \(name)/\(name).entitlements;
|
||||
\t\t\t\tCODE_SIGN_STYLE = Automatic;
|
||||
\t\t\t\tCOMBINE_HIDPI_IMAGES = YES;
|
||||
\t\t\t\tDEAD_CODE_STRIPPING = YES;
|
||||
@@ -197,6 +200,7 @@ extension ProjectScaffolder {
|
||||
\t\t\(pbxAppReleaseConfig) /* Release */ = {
|
||||
\t\t\tisa = XCBuildConfiguration;
|
||||
\t\t\tbuildSettings = {
|
||||
\t\t\t\tCODE_SIGN_ENTITLEMENTS = \(name)/\(name).entitlements;
|
||||
\t\t\t\tCODE_SIGN_STYLE = Automatic;
|
||||
\t\t\t\tCOMBINE_HIDPI_IMAGES = YES;
|
||||
\t\t\t\tDEAD_CODE_STRIPPING = YES;
|
||||
|
||||
@@ -122,6 +122,8 @@ extension ProjectScaffolder {
|
||||
let files: [(String, String)] = [
|
||||
((appGroupDir as NSString).appendingPathComponent("Info.plist"),
|
||||
macOSAppInfoPlist(name: name)),
|
||||
((appGroupDir as NSString).appendingPathComponent("\(name).entitlements"),
|
||||
macOSAppEntitlements()),
|
||||
((appGroupDir as NSString).appendingPathComponent("main.swift"),
|
||||
macOSAppMainSwift(name: name)),
|
||||
((appGroupDir as NSString).appendingPathComponent("AppDelegate.swift"),
|
||||
@@ -146,6 +148,35 @@ extension ProjectScaffolder {
|
||||
appInfoPlist(name: name, platform: .macOS)
|
||||
}
|
||||
|
||||
/// Entitlements for the standalone macOS performance app.
|
||||
///
|
||||
/// Not sandboxed — a live-performance app needs unrestricted access to
|
||||
/// audio devices, files (buffer load/render), MIDI, and OSC networking,
|
||||
/// which the App Sandbox would gate. The one entitlement granted is
|
||||
/// microphone / line-in: under the Hardened Runtime (enabled in the
|
||||
/// pbxproj, and required for notarization) the OS hard-kills the process
|
||||
/// the moment the AUHAL input bus opens unless this is present. It only
|
||||
/// prompts the user when input is actually opened
|
||||
/// (`numInputChannels > 0`), so it is harmless for output-only synths.
|
||||
///
|
||||
/// If a project needs to load dynamic libraries signed by a different
|
||||
/// team (e.g. a bundled `.dylib`), add
|
||||
/// `com.apple.security.cs.disable-library-validation`. If it must ship on
|
||||
/// the Mac App Store, add `com.apple.security.app-sandbox` and the
|
||||
/// specific resource entitlements the piece uses instead.
|
||||
static func macOSAppEntitlements() -> String {
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.device.audio-input</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
"""
|
||||
}
|
||||
|
||||
static func macOSAppMainSwift(name: String) -> String {
|
||||
"""
|
||||
// \(name) — entry point
|
||||
@@ -178,6 +209,9 @@ extension ProjectScaffolder {
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// `@MainActor`: constructs the main-actor `NoteController` and synth,
|
||||
/// and `NSApplicationDelegate` callbacks already run on the main actor.
|
||||
@MainActor
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
let engine: SynthesisEngine
|
||||
let controller: NoteController
|
||||
@@ -246,6 +280,11 @@ extension ProjectScaffolder {
|
||||
|
||||
/// Owns engine + synth + scope; mediates start/stop from the UI so the
|
||||
/// engine isn't kicked until user is ready (avoids first-block dropouts).
|
||||
///
|
||||
/// `@MainActor`: this drives SwiftUI and calls the engine's
|
||||
/// main-actor-isolated `add(_:)`, so the whole controller lives on the
|
||||
/// main actor.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class NoteController {
|
||||
|
||||
@@ -385,9 +424,15 @@ extension ProjectScaffolder {
|
||||
case .macOS:
|
||||
minOSKey = "LSMinimumSystemVersion"
|
||||
minOSValue = "$(MACOSX_DEPLOYMENT_TARGET)"
|
||||
// The mic usage string is required whenever the app opens the
|
||||
// AUHAL input bus: macOS crashes a Hardened-Runtime process on
|
||||
// audio-input access if this key is absent. Harmless for
|
||||
// output-only synths (no prompt fires until input opens).
|
||||
extras = """
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>\(name) uses audio input for live signal processing.</string>
|
||||
"""
|
||||
case .iOS:
|
||||
minOSKey = "MinimumOSVersion"
|
||||
|
||||
@@ -3332,6 +3332,7 @@ extension DSLBuiltinRegistry {
|
||||
DSLParameter(label: "in", hasDefault: false),
|
||||
DSLParameter(label: "maxAmplitude", hasDefault: true),
|
||||
DSLParameter(label: "lookAheadTime", hasDefault: true),
|
||||
DSLParameter(label: "releaseTime", hasDefault: true),
|
||||
DSLParameter(label: "sampleRate", hasDefault: false),
|
||||
],
|
||||
make: { args in
|
||||
@@ -3339,6 +3340,7 @@ extension DSLBuiltinRegistry {
|
||||
in: try DSLArgument.input(args["in"], "LookAheadLimiter", "in"),
|
||||
maxAmplitude: try DSLArgument.input(args["maxAmplitude"] ?? .signal(1.0), "LookAheadLimiter", "maxAmplitude"),
|
||||
lookAheadTime: try DSLArgument.double(args["lookAheadTime"] ?? .signal(0.005), "LookAheadLimiter", "lookAheadTime"),
|
||||
releaseTime: try DSLArgument.input(args["releaseTime"] ?? .signal(0.050), "LookAheadLimiter", "releaseTime"),
|
||||
sampleRate: try DSLArgument.double(args["sampleRate"], "LookAheadLimiter", "sampleRate")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -280,6 +280,7 @@ struct ProjectScaffolderTests {
|
||||
"MyMac/NoteController.swift",
|
||||
"MyMac/MyMacView.swift",
|
||||
"MyMac/Info.plist",
|
||||
"MyMac/MyMac.entitlements",
|
||||
]
|
||||
for rel: String in expected {
|
||||
let path: String = (root as NSString).appendingPathComponent(rel)
|
||||
@@ -299,6 +300,15 @@ struct ProjectScaffolderTests {
|
||||
#expect(src.contains("engine.remove(synth)"))
|
||||
}
|
||||
|
||||
@Test func macOSAppControllerAndDelegateAreMainActor() {
|
||||
// Both call the engine's @MainActor `add(_:)` / a main-actor synth
|
||||
// init; without @MainActor the template fails to compile under Swift 6.
|
||||
let controller: String = ProjectScaffolder.macOSAppNoteControllerSwift(name: "Foo")
|
||||
#expect(controller.contains("@MainActor"))
|
||||
let delegate: String = ProjectScaffolder.macOSAppDelegateSwift(name: "Foo")
|
||||
#expect(delegate.contains("@MainActor"))
|
||||
}
|
||||
|
||||
@Test func macOSAppViewHasStartStopButtons() {
|
||||
let src: String = ProjectScaffolder.macOSAppViewSwift(name: "Foo")
|
||||
#expect(src.contains("Start Engine"))
|
||||
@@ -576,6 +586,29 @@ struct ProjectScaffolderTests {
|
||||
#expect(pbx.contains("/local/Lyrebird"))
|
||||
}
|
||||
|
||||
@Test func macOSAppPBXProjWiresEntitlementsAndHardenedRuntime() {
|
||||
let pbx: String = ProjectScaffolder.macOSAppPBXProj(name: "Perf")
|
||||
// Hardened Runtime + entitlements are both required for a notarized,
|
||||
// distributable performance app that opens the AUHAL input bus.
|
||||
#expect(pbx.contains("ENABLE_HARDENED_RUNTIME = YES"))
|
||||
#expect(pbx.contains("CODE_SIGN_ENTITLEMENTS = Perf/Perf.entitlements;"))
|
||||
#expect(pbx.contains("Perf.entitlements */ = {isa = PBXFileReference"))
|
||||
}
|
||||
|
||||
@Test func macOSAppEntitlementsGrantAudioInputAndAreNotSandboxed() {
|
||||
let ent: String = ProjectScaffolder.macOSAppEntitlements()
|
||||
#expect(ent.contains("com.apple.security.device.audio-input"))
|
||||
// A live-performance app must not be sandboxed — it needs free file /
|
||||
// device / MIDI / OSC access the sandbox would gate.
|
||||
#expect(!ent.contains("com.apple.security.app-sandbox"))
|
||||
}
|
||||
|
||||
@Test func macOSAppInfoPlistHasMicrophoneUsageDescription() {
|
||||
let plist: String = ProjectScaffolder.macOSAppInfoPlist(name: "Perf")
|
||||
// Absent, a Hardened-Runtime process crashes on audio-input access.
|
||||
#expect(plist.contains("NSMicrophoneUsageDescription"))
|
||||
}
|
||||
|
||||
@Test func iOSAppPBXProjReferencesIPhoneOS() {
|
||||
let pbx: String = ProjectScaffolder.iOSAppPBXProj(name: "Foo")
|
||||
#expect(pbx.contains("SDKROOT = iphoneos"))
|
||||
|
||||
@@ -480,6 +480,34 @@ struct LookAheadLimiterTests {
|
||||
let tailMax: Double = tail.map { abs($0) }.max() ?? 0
|
||||
#expect(tailMax < maxAmp * 10.0) // generous bound; really we want "small"
|
||||
}
|
||||
|
||||
/// `releaseTime` is decoupled from `lookAheadTime`: with the look-ahead window held
|
||||
/// fixed, two different release times must produce different gain-recovery behaviour
|
||||
/// (hence different output) on a low-frequency signal that crosses the ceiling on its
|
||||
/// peaks and dips below between them — while both still respect the ceiling.
|
||||
@Test func releaseTimeIndependentOfLookAhead() {
|
||||
let maxAmp: Double = 0.3
|
||||
func run(_ releaseTime: Double) -> [Double] {
|
||||
let sine: OscSin.Audio = OscSin.Audio(freq: 60.0, mul: 1.0)
|
||||
let lim: LookAheadLimiter = LookAheadLimiter(
|
||||
in: sine, maxAmplitude: maxAmp,
|
||||
lookAheadTime: 0.005, releaseTime: releaseTime, sampleRate: sr)
|
||||
return collectBlocks(lim, engine: engine, blocks: 100)
|
||||
}
|
||||
let fast: [Double] = run(0.005)
|
||||
let slow: [Double] = run(0.200)
|
||||
// Ceiling holds for both release settings.
|
||||
#expect(fast.allSatisfy { abs($0) <= maxAmp + 0.001 })
|
||||
#expect(slow.allSatisfy { abs($0) <= maxAmp + 0.001 })
|
||||
// Different release → different waveform.
|
||||
let tailFast: [Double] = Array(fast.suffix(engine.blockSize * 50))
|
||||
let tailSlow: [Double] = Array(slow.suffix(engine.blockSize * 50))
|
||||
let ssd: Double = zip(tailFast, tailSlow).reduce(0.0) { acc, pair in
|
||||
let diff: Double = pair.0 - pair.1
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "releaseTime had no effect on limiter output")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Compressor Tests
|
||||
|
||||
@@ -105,7 +105,7 @@ File: `Sources/Lyrebird/Generators/Dynamics/LookAheadLimiter.swift`
|
||||
Delays the output by `lookAheadTime` seconds and uses the look-ahead window to detect peaks before they arrive, guaranteeing the output never exceeds `±maxAmplitude`. No overshoot.
|
||||
|
||||
```swift
|
||||
LookAheadLimiter(in:maxAmplitude:lookAheadTime:sampleRate:)
|
||||
LookAheadLimiter(in:maxAmplitude:lookAheadTime:releaseTime:sampleRate:)
|
||||
```
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
@@ -113,6 +113,7 @@ LookAheadLimiter(in:maxAmplitude:lookAheadTime:sampleRate:)
|
||||
| `in` | `ValidGeneratorInput` | — | Signal to limit |
|
||||
| `maxAmplitude` | `ValidGeneratorInput` | `1.0` | Peak ceiling (absolute value) |
|
||||
| `lookAheadTime` | `Double` | `0.005` | Delay in seconds. Set at init. |
|
||||
| `releaseTime` | `ValidGeneratorInput` | `0.050` | Gain-release time constant (seconds), read per block; decoupled from `lookAheadTime`. Clamped to ≥ 0. Keep it above the period of the lowest expected frequency to avoid low-frequency distortion. |
|
||||
| `sampleRate` | `Double` | `44100.0` | Used to size ring buffers at init. |
|
||||
|
||||
**Output:** single channel, delayed by `lookAheadSamples = Int(lookAheadTime × sampleRate)`.
|
||||
@@ -122,7 +123,7 @@ LookAheadLimiter(in:maxAmplitude:lookAheadTime:sampleRate:)
|
||||
2. Scan the look-ahead window (`lookAheadSamples`) for peak.
|
||||
3. Required gain = `min(1, maxAmplitude / peak)`.
|
||||
4. Attack is **instantaneous** (gain can always be reduced within the window).
|
||||
5. Release smoothed: `releaseCoeff = exp(−1 / (sr × lookAheadTime))`.
|
||||
5. Release smoothed: `releaseCoeff = exp(−1 / (sr × releaseTime))`, recomputed per block (so `releaseTime` may track a live parameter) rather than fixed at init.
|
||||
6. Output = delayed sample × current gain.
|
||||
|
||||
**Pre-allocated buffers:**
|
||||
@@ -134,7 +135,8 @@ LookAheadLimiter(in:maxAmplitude:lookAheadTime:sampleRate:)
|
||||
|
||||
**Usage:**
|
||||
```swift
|
||||
let mastered = LookAheadLimiter(in: mix, maxAmplitude: 0.99, lookAheadTime: 0.005)
|
||||
let mastered = LookAheadLimiter(in: mix, maxAmplitude: 0.99, lookAheadTime: 0.005,
|
||||
releaseTime: 0.050, sampleRate: engine.sampleRate)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -49,7 +49,7 @@ Xcode-project templates (ship a real `.xcodeproj` for deliverables SwiftPM can't
|
||||
|
||||
| Template | Command | Description |
|
||||
|---|---|---|
|
||||
| `macos-ui-xcode` | `lyrebird new MyApp --template macos-ui-xcode` | macOS `.app` (AppKit + SwiftUI), `@UIParam` synth, hardened runtime |
|
||||
| `macos-ui-xcode` | `lyrebird new MyApp --template macos-ui-xcode` | macOS `.app` (AppKit + SwiftUI), `@UIParam` synth. Notarization-ready: hardened runtime + `.entitlements` (audio-input) + mic usage string, unsandboxed for performance |
|
||||
| `ios-ui` | `lyrebird new MyApp --template ios-ui` | iOS `.app` (SwiftUI + `iOSAudioDriver`), `AVAudioSession` activation, iPhone + iPad device family |
|
||||
| `auv3` | `lyrebird new MyPlugin --template auv3` | AUv3 host `.app` + `aumu` `.appex` subclassing `LyrebirdAudioUnit`. Entitlements for both. Subtype + manufacturer pre-filled (manufacturer = `LYRB` placeholder — rewrite for distribution) |
|
||||
|
||||
@@ -62,7 +62,7 @@ Each Xcode-project template lays out:
|
||||
│ └── xcshareddata/xcschemes/<name>.xcscheme
|
||||
├── <name>.xcworkspace/
|
||||
│ └── contents.xcworkspacedata (references <name>.xcodeproj)
|
||||
├── <name>/ (app target sources + Info.plist [+ entitlements for auv3])
|
||||
├── <name>/ (app target sources + Info.plist [+ .entitlements for macos-ui-xcode / auv3])
|
||||
│ └── ...
|
||||
└── <name>Extension/ (auv3 only — extension target + Info.plist + .entitlements)
|
||||
└── ...
|
||||
@@ -70,20 +70,26 @@ Each Xcode-project template lays out:
|
||||
|
||||
Lyrebird is pulled in via a remote SPM dependency on `https://realizedsound.mooo.com/josh/Lyrebird` (configurable via `ProjectScaffolder.lyrebirdPackageURL`). The scaffolded project lives anywhere on disk and does not need a local checkout.
|
||||
|
||||
### Microphone input — not pre-wired in any template
|
||||
### Distribution & microphone input
|
||||
|
||||
No template adds `NSMicrophoneUsageDescription` to the generated `Info.plist`, no template adds the hardened-runtime / sandbox audio-input capability, and the `ios-ui` template's `AVAudioSession` category is `.playback` (output only). Most pieces don't read live input, so the templates default to "no mic capability" rather than triggering a permission prompt on every first run.
|
||||
The `macos-ui-xcode` template is **notarization-ready and distributable for performance out of the box**. It ships:
|
||||
- **Hardened Runtime** enabled (required for Developer-ID notarization), and
|
||||
- `<name>.entitlements` granting `com.apple.security.device.audio-input`, plus `NSMicrophoneUsageDescription` in `Info.plist`.
|
||||
|
||||
If a piece needs live input (e.g. tapping the engine input bus into `ScopeCapture` or routing `In.Audio(bus: numOutputChannels)` through the graph), the project owner must add these themselves:
|
||||
The app is deliberately **not sandboxed** — a live-performance app needs unrestricted audio-device / file / MIDI / OSC access that the App Sandbox would gate. Nothing else is required to move the signed `.app` to another machine and run it: Lyrebird is statically linked (compiled from the SPM source), so there is no external module to bundle. (The bundled-swiftmodule dance in `LyrebirdScratch` is unique to its *runtime* `swiftc` scratchpad and does not apply to a normal Lyrebird app.)
|
||||
|
||||
**Engine init** — set `numInputChannels > 0` and pass a non-nil `inputDeviceID` (macOS) when constructing `SynthesisEngine` / starting the driver.
|
||||
The audio-input entitlement + usage string are **harmless for output-only synths**: no permission prompt fires until the AUHAL input bus actually opens (`numInputChannels > 0`). They exist so a piece that *does* take live input works without the OS hard-killing the Hardened-Runtime process on first input access.
|
||||
|
||||
**macOS** (`macos-ui-xcode`, `ui-demo` opened in Xcode, any AppKit/SwiftUI app):
|
||||
- Add `NSMicrophoneUsageDescription` (string explaining the use) to the target's `Info.plist`. Required since macOS 10.14 — without it the OS silently denies input access and `CoreAudioDriver` reads zeros.
|
||||
- If the app is sandboxed: add `com.apple.security.device.audio-input` to the `.entitlements` file. The `macos-ui-xcode` template ships unsandboxed; the `auv3` host app is sandboxed and will need the entitlement before the host can read mic in addition to hosting the plugin.
|
||||
If a piece needs live input (e.g. tapping the engine input bus into `ScopeCapture` or routing `In.Audio(bus: numOutputChannels)` through the graph):
|
||||
|
||||
**Engine init** — set `numInputChannels > 0` and pass a non-nil `inputDeviceID` (macOS) when constructing `SynthesisEngine` / starting the driver. On `macos-ui-xcode` the mic entitlement + usage string are already present, so the first `start()` after that triggers the permission prompt directly.
|
||||
|
||||
**Other knobs:**
|
||||
- **Mac App Store** target: add `com.apple.security.app-sandbox` to `<name>.entitlements` plus the specific resource entitlements the piece uses. (Sandboxing is off by default precisely because most performance work is Developer-ID / direct-distribution, not App Store.)
|
||||
- **Loading a differently-signed dynamic library** (a bundled `.dylib`): add `com.apple.security.cs.disable-library-validation`.
|
||||
|
||||
**iOS** (`ios-ui`):
|
||||
- Add `NSMicrophoneUsageDescription` to the app `Info.plist`.
|
||||
- Add `NSMicrophoneUsageDescription` to the app `Info.plist` (not pre-wired — the iOS template is output-only by default).
|
||||
- Change the `AVAudioSession` category in the generated `AppDelegate` / `App` activation block from `.playback` to `.playAndRecord` (typically `mode: .default` or `.measurement`, options `[.defaultToSpeaker, .allowBluetooth]` depending on routing needs). `.playback` is output-only and will return zero-filled input buffers regardless of the engine's `numInputChannels`.
|
||||
|
||||
The first `start()` call after these are in place triggers the system permission prompt. Until the user grants, input frames remain zero — a scope tap on input buses will draw a flat line.
|
||||
|
||||
Reference in New Issue
Block a user