// The Opus codec through CoreAudio (kAudioFormatOpus): a real encode → decode round // trip. This is the load-bearing assumption of the whole audio feature (no bundled // libopus) — if AVAudioConverter can't handle raw Opus packets, fail HERE, not in the // app. import AVFoundation import XCTest @testable import PunktfunkKit final class OpusCodecTests: XCTestCase { /// Encode a 440 Hz mono tone (the uplink's shape), decode it back through the /// STEREO-configured decoder (the host-plane shape — Opus upmixes mono packets), and /// require the result to be recognizably the same signal (Opus is lossy — check /// correlation, not bytes). func testEncodeDecodeRoundTripPreservesTone() throws { let encoder = try OpusEncoder() let decoder = try OpusDecoder(framesPerPacket: UInt32(encoder.framesPerPacket)) let pcmFormat = encoder.pcmFormat let frames = encoder.framesPerPacket var packets: [Data] = [] var phase: Float = 0 let step = 2 * Float.pi * 440 / 48_000 // 1 s of tone, whatever packet duration the encoder chose (10 ms → 100 chunks). let chunks = Int(48_000 / frames) for _ in 0..