// 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 stereo tone, decode it back, 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(OpusEncoder.framesPerPacket)) let pcmFormat = encoder.pcmFormat let frames = OpusEncoder.framesPerPacket var packets: [Data] = [] var phase: Float = 0 let step = 2 * Float.pi * 440 / 48_000 // 50 packets = 1 s of tone. for _ in 0..<50 { let buf = AVAudioPCMBuffer(pcmFormat: pcmFormat, frameCapacity: frames)! buf.frameLength = frames let p = buf.floatChannelData![0] // interleaved: one plane, L R L R … for f in 0..