1.0.0 release

This commit is contained in:
2026-06-01 18:27:40 -07:00
parent b1ab0f102c
commit 1f20fcab20
1151 changed files with 230703 additions and 14 deletions
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTD/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Platforms</key>
<array>
<string>com.apple.platform.macosx</string>
<string>com.apple.platform.iphoneos</string>
</array>
<key>Description</key>
<string>A sample-playback Synthesizer that loads a LyrebirdBuffer from an audio file URL and plays it via PlayBuffer.Audio. Honours the file's native sample rate via nativeRateScale, supports loop / rate-modulation via @LiveParam. Loading runs at init (non-RT) and traps on file errors — convert to throwing init for production code.</string>
<key>Summary</key>
<string>Lyrebird Buffer Reader (file → PlayBuffer Synthesizer)</string>
<key>SortOrder</key>
<string>33</string>
<key>AllowedTypes</key>
<array>
<string>public.swift-source</string>
</array>
<key>DefaultCompletionName</key>
<string>MySamplePlayer</string>
<key>MainTemplateFile</key>
<string>___FILEBASENAME___.swift</string>
<key>Options</key>
<array>
<dict>
<key>Identifier</key>
<string>productName</string>
<key>Required</key>
<true/>
<key>Name</key>
<string>Synthesizer name:</string>
<key>Description</key>
<string>Name of the sample-player Synthesizer (also used as the file name).</string>
<key>Type</key>
<string>text</string>
<key>Default</key>
<string>MySamplePlayer</string>
</dict>
</array>
</dict>
</plist>
@@ -0,0 +1,87 @@
//___FILEHEADER___
import Foundation
import LyrebirdSynth
// MARK: - ___FILEBASENAMEASIDENTIFIER___
/// Sample-playback Synthesizer that loads an audio file at init and plays it
/// through `PlayBuffer.Audio`. Output channel count matches the loaded buffer.
///
/// `LyrebirdBuffer.loadAllChannels(url:)` reads every channel into a single
/// multichannel buffer and records the file's sample rate on it; passing
/// `buffer.nativeRateScale(engineSampleRate:)` to `PlayBuffer.Audio` rate:
/// ensures the file plays back at the correct pitch / speed when the engine
/// runs at a different sample rate than the file.
///
/// ## Usage
/// ```swift
/// let player = try ___FILEBASENAMEASIDENTIFIER___(
/// fileURL: URL(fileURLWithPath: "/path/to/sample.wav"),
/// loop: true,
/// engineSampleRate: engine.sampleRate
/// )
/// try engine.add(player)
///
/// // Modulate playback rate at runtime:
/// player.rate = 0.5 // half speed / one octave down
/// ```
public final class ___FILEBASENAMEASIDENTIFIER___: SynthesizerBase {
// MARK: - Parameters
/// Playback rate multiplier. `1.0` = native pitch, `2.0` = +1 octave,
/// `0.5` = −1 octave. Negative values reverse playback if the underlying
/// PlayBuffer is configured to honour them.
@LiveParam public var rate: Double = 1.0
/// Output amplitude (linear gain).
@LiveParam public var amplitude: Double = 1.0
// MARK: - State
private let buffer: LyrebirdBuffer
private let loop: Bool
private let engineSampleRate: Double
// MARK: - Init
/// - Parameters:
/// - fileURL: Path to a WAV / AIFF / CAF audio file. Loaded synchronously
/// on a non-RT thread; do not call from the audio callback.
/// - loop: When `true`, playback restarts from frame 0 after the end.
/// When `false`, the generator emits silence after the final frame
/// (or frees the node if `doneAction == .freeNode`).
/// - engineSampleRate: The engine's sample rate. Passed at init so the
/// `build()` closure (which has no engine reference) can compute the
/// native-sample-rate compensation. Get from `engine.sampleRate`.
public init(
fileURL: URL,
loop: Bool = false,
engineSampleRate: Double
) throws {
self.buffer = try LyrebirdBuffer.loadAllChannels(url: fileURL)
self.loop = loop
self.engineSampleRate = engineSampleRate
super.init()
}
// MARK: - Build
public override func build() {
// Compose rate: user-controlled `rate` multiplier × the buffer's
// native-sample-rate compensation. nativeRateScale falls back to 1.0
// when the buffer carries no recorded rate.
let nativeScale = buffer.nativeRateScale(engineSampleRate: engineSampleRate)
let combinedRate = $rate * nativeScale
let player = PlayBuffer.Audio(
buffer: buffer,
loop: loop,
doneAction: loop ? .nothing : .freeNode,
rate: combinedRate
)
output(bus: 0, source: player * $amplitude)
}
}