// HRIRFileTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing import Foundation @testable @_spi(LyrebirdExtensions) import LyrebirdSynth // MARK: - Test Data helpers /// Appends a `UInt32` in little-endian byte order. private func appendLE32(_ v: UInt32, to data: inout Data) { var le: UInt32 = v.littleEndian withUnsafeBytes(of: &le) { data.append(contentsOf: $0) } } /// Appends a `Double` (as its bit pattern) in little-endian byte order. private func appendLEDouble(_ v: Double, to data: inout Data) { var le: UInt64 = v.bitPattern.littleEndian withUnsafeBytes(of: &le) { data.append(contentsOf: $0) } } /// Appends an `Int16` in little-endian byte order. private func appendLE16(_ v: Int16, to data: inout Data) { var le: Int16 = v.littleEndian withUnsafeBytes(of: &le) { data.append(contentsOf: $0) } } /// Builds a minimal valid `.lbhr` blob with the given header values and /// writes it to a temporary URL. Returns both the URL and the `Data`. /// Caller is responsible for cleanup via `FileManager.default.removeItem(at:)`. private func makeMinimalLBHR( magic: [UInt8] = [0x4C, 0x42, 0x48, 0x52], // "LBHR" version: UInt32 = 1, sampleRate: UInt32 = 44_100, irLength: UInt32 = 4, positionCount: UInt32 = 1 ) throws -> (url: URL, data: Data) { let tmpURL: URL = FileManager.default.temporaryDirectory .appendingPathComponent("test-\(UUID().uuidString).lbhr") var bytes: Data = Data() bytes.append(contentsOf: magic) appendLE32(version, to: &bytes) appendLE32(sampleRate, to: &bytes) appendLE32(irLength, to: &bytes) appendLE32(positionCount, to: &bytes) appendLE32(0, to: &bytes) // reserved // Position table entries: one per positionCount. for i: Int in 0..