v1.6.0 release: soundfile format expansion (WAV int depths + RF64 >4GB, AIFF/CAF, AAC/ALAC compressed, 4GB guard, unified AudioFileFormat)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 17:45:34 -07:00
parent 62b2f5dbec
commit 8eb64f883f
33 changed files with 2650 additions and 352 deletions
@@ -0,0 +1,105 @@
// RenderOptionsAccessoryTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
#if os(macOS)
import Testing
import AppKit
import LyrebirdSynth
@testable import LyrebirdLiveCompileUI
// Serialized: these tests mutate a shared `UserDefaults` key (the persisted
// last-format), so they must not interleave.
@Suite("RenderOptionsAccessory", .serialized)
@MainActor
struct RenderOptionsAccessoryTests {
// Popup order (see RenderOptionsAccessory.options).
private let wavFloat32Index: Int = 0
private let wavInt24Index: Int = 2
private let rf64Float32Index: Int = 5
private func makeAccessory() -> (RenderOptionsAccessory, NSSavePanel) {
let panel: NSSavePanel = NSSavePanel()
let accessory: RenderOptionsAccessory = RenderOptionsAccessory(
baseName: "render", initialDuration: 5.0, savePanel: panel
)
return (accessory, panel)
}
// MARK: - Duration parsing
@Test("parseDuration accepts positive finite numbers and rejects the rest")
func durationParsing() {
#expect(RenderOptionsAccessory.parseDuration("5.0") == 5.0)
#expect(RenderOptionsAccessory.parseDuration(" 2.5 ") == 2.5)
#expect(RenderOptionsAccessory.parseDuration("0") == nil)
#expect(RenderOptionsAccessory.parseDuration("-1") == nil)
#expect(RenderOptionsAccessory.parseDuration("") == nil)
#expect(RenderOptionsAccessory.parseDuration("abc") == nil)
#expect(RenderOptionsAccessory.parseDuration("nan") == nil)
#expect(RenderOptionsAccessory.parseDuration("inf") == nil)
}
// MARK: - Format read-out
@Test("Selecting a format updates selectedFormat")
func selectedFormatReflectsPopup() {
RenderOptionsAccessory.clearPersistedFormatForTesting()
defer { RenderOptionsAccessory.clearPersistedFormatForTesting() }
let (accessory, _): (RenderOptionsAccessory, NSSavePanel) = makeAccessory()
accessory.selectFormatForTesting(at: wavFloat32Index)
#expect(accessory.selectedFormat == .wavFloat32)
accessory.selectFormatForTesting(at: wavInt24Index)
#expect(accessory.selectedFormat == .wavInt24)
accessory.selectFormatForTesting(at: rf64Float32Index)
#expect(accessory.selectedFormat == .rf64Float32)
}
// MARK: - Panel filename sync
@Test("Changing format preserves a user-typed filename stem")
func formatChangePreservesUserStem() {
RenderOptionsAccessory.clearPersistedFormatForTesting()
defer { RenderOptionsAccessory.clearPersistedFormatForTesting() }
let (accessory, panel): (RenderOptionsAccessory, NSSavePanel) = makeAccessory()
// User renames the target, then switches format.
panel.nameFieldStringValue = "mySound.caf"
accessory.selectFormatForTesting(at: wavFloat32Index)
#expect(panel.nameFieldStringValue == "mySound.wav")
// Switching again keeps the stem, swaps only the extension.
accessory.selectFormatForTesting(at: rf64Float32Index)
#expect(panel.nameFieldStringValue == "mySound.wav") // RF64 keeps .wav
}
@Test("Empty filename falls back to the base name")
func emptyStemFallsBackToBaseName() {
RenderOptionsAccessory.clearPersistedFormatForTesting()
defer { RenderOptionsAccessory.clearPersistedFormatForTesting() }
let (accessory, panel): (RenderOptionsAccessory, NSSavePanel) = makeAccessory()
panel.nameFieldStringValue = ""
accessory.selectFormatForTesting(at: wavInt24Index)
#expect(panel.nameFieldStringValue == "render.wav")
}
// MARK: - Persistence
@Test("Last-selected format persists to a fresh accessory")
func formatSelectionPersists() {
RenderOptionsAccessory.clearPersistedFormatForTesting()
defer { RenderOptionsAccessory.clearPersistedFormatForTesting() }
let (first, _): (RenderOptionsAccessory, NSSavePanel) = makeAccessory()
first.selectFormatForTesting(at: rf64Float32Index) // persists "rf64F32"
// A brand-new accessory should open on the remembered format.
let (second, _): (RenderOptionsAccessory, NSSavePanel) = makeAccessory()
#expect(second.selectedFormat == .rf64Float32)
}
}
#endif
@@ -93,6 +93,33 @@ struct ScratchModelRenderTests {
#expect(!ok)
#expect(!FileManager.default.fileExists(atPath: url.path))
}
/// The `format:` argument reaches the NRT driver: rendering to a WAV Int24 target
/// and an RF64 target produces files with the requested on-disk encoding.
@Test(arguments: [
(AudioFileFormat.wavInt24, "wav", UInt32(24), false),
(AudioFileFormat.rf64Float32, "wav", UInt32(32), true),
])
func rendersHonourFormat(format: AudioFileFormat, ext: String, bits: UInt32, isFloat: Bool) async throws {
let model: LyrebirdScratchModel = makeModel(text: "context.play { OscSin.Audio(freq: 440) * 0.1 }")
let url: URL = FileManager.default.temporaryDirectory
.appendingPathComponent("LBRenderTest-\(UUID().uuidString)").appendingPathExtension(ext)
defer { try? FileManager.default.removeItem(at: url) }
let ok: Bool = await model.renderToFile(url: url, format: format, duration: 0.1)
#expect(ok)
#expect(FileManager.default.fileExists(atPath: url.path))
var fileRef: ExtAudioFileRef?
#expect(ExtAudioFileOpenURL(url as CFURL, &fileRef) == noErr)
let ref: ExtAudioFileRef = try #require(fileRef)
defer { ExtAudioFileDispose(ref) }
var asbd: AudioStreamBasicDescription = AudioStreamBasicDescription()
var size: UInt32 = UInt32(MemoryLayout<AudioStreamBasicDescription>.size)
#expect(ExtAudioFileGetProperty(ref, kExtAudioFileProperty_FileDataFormat, &size, &asbd) == noErr)
#expect(asbd.mBitsPerChannel == bits)
#expect((asbd.mFormatFlags & kAudioFormatFlagIsFloat != 0) == isFloat)
}
}
#endif