1.0.0 release
This commit is contained in:
+44
@@ -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 multi-channel audio Generator that returns N rows from _computeSamples. Calls super.init(channels: N) to allocate N pre-allocated result rows; overrides outputChannelCount to expose the fixed channel count. Modeled on Pan2's two-channel shape. Pass directly to output(bus:source:) — Out writes channel k to bus+k.</string>
|
||||
<key>Summary</key>
|
||||
<string>Lyrebird Multi-Channel Generator (N-row output)</string>
|
||||
<key>SortOrder</key>
|
||||
<string>21</string>
|
||||
<key>AllowedTypes</key>
|
||||
<array>
|
||||
<string>public.swift-source</string>
|
||||
</array>
|
||||
<key>DefaultCompletionName</key>
|
||||
<string>MyMultiChannel</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>Generator name:</string>
|
||||
<key>Description</key>
|
||||
<string>Name of the multi-channel Generator class (also used as the file name).</string>
|
||||
<key>Type</key>
|
||||
<string>text</string>
|
||||
<key>Default</key>
|
||||
<string>MyMultiChannel</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
//___FILEHEADER___
|
||||
|
||||
import Foundation
|
||||
@_spi(LyrebirdExtensions) import LyrebirdSynth
|
||||
|
||||
// MARK: - ___FILEBASENAMEASIDENTIFIER___
|
||||
|
||||
/// One-line description of ___FILEBASENAMEASIDENTIFIER___.
|
||||
///
|
||||
/// Returns N output channels per render block. The channel count is fixed at
|
||||
/// init time via `super.init(channels: N)` — `GeneratorBase` pre-allocates the
|
||||
/// `_result` buffer with N rows. `outputChannelCount` returns the same N so
|
||||
/// downstream operators (`+`, `-`, `*`, `/`) treat this as multi-channel rather
|
||||
/// than mono.
|
||||
///
|
||||
/// Channel count must be derivable from a `let` at init — never runtime-mutable.
|
||||
/// To support a user-chosen channel count, accept it as an `Int` init parameter
|
||||
/// (see Pan4 etc).
|
||||
///
|
||||
/// ## Usage
|
||||
/// ```swift
|
||||
/// override func build() {
|
||||
/// let src = OscSin.Audio(freq: 440.0)
|
||||
/// // Out writes channel k to bus+k:
|
||||
/// output(bus: 0, source: ___FILEBASENAMEASIDENTIFIER___(input: src))
|
||||
/// }
|
||||
/// ```
|
||||
public final class ___FILEBASENAMEASIDENTIFIER___: GeneratorBase, AudioGenerator {
|
||||
|
||||
// MARK: - Channel count (fixed at init)
|
||||
|
||||
/// Output channel count. Hard-coded here as a starting value — replace with an
|
||||
/// init parameter if your generator needs user-chosen channel counts.
|
||||
private static let outChannels: Int = 2
|
||||
|
||||
public override var outputChannelCount: Int { Self.outChannels }
|
||||
|
||||
// MARK: - Inputs
|
||||
|
||||
private let _input: any ValidGeneratorInput
|
||||
private let _mulAdd: MulAddSpec
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// - Parameters:
|
||||
/// - input: Source signal. Mono input fans out across all channels by
|
||||
/// default; multi-row input maps element-wise (mismatched channel counts
|
||||
/// should `precondition`-trap at init).
|
||||
/// - mul: Output multiplier. Defaults to `1.0`. Channel-aware: scalar
|
||||
/// broadcasts, equal-N multi-row applies element-wise.
|
||||
/// - add: Output offset. Defaults to `0.0`. Same channel-aware policy.
|
||||
public init(
|
||||
input: any ValidGeneratorInput,
|
||||
mul: any ValidGeneratorInput = 1.0,
|
||||
add: any ValidGeneratorInput = 0.0
|
||||
) {
|
||||
_input = input
|
||||
_mulAdd = MulAddSpec(mul: mul, add: add)
|
||||
super.init(channels: Self.outChannels)
|
||||
}
|
||||
|
||||
public func _computeSamples(
|
||||
graph: SynthGraph,
|
||||
count: Int
|
||||
) -> [[Double]] {
|
||||
_checkCount(count)
|
||||
|
||||
let inputSamples = _input.calculatedSamples(graph: graph, count: count)
|
||||
guard let ins = inputSamples.first else { return _result }
|
||||
|
||||
// TODO: replace this body with whatever per-channel processing you want.
|
||||
// The starter logic copies the first input row into every output row —
|
||||
// i.e. fans a mono source out to N identical channels. Real generators
|
||||
// typically produce different content per channel (panning, decoder
|
||||
// matrices, multi-bus routing, etc.).
|
||||
for ch: Int in 0..<Self.outChannels {
|
||||
for i: Int in 0..<count {
|
||||
_result[ch][i] = ins[i]
|
||||
}
|
||||
}
|
||||
|
||||
_mulAdd.applyIfNeeded(to: &_result, graph: graph, count: count)
|
||||
return _result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user