audio/ogg_vorbis inspects Ogg Vorbis portably: audio/ogg's reader checks every page, then the identification, comment and setup headers are parsed and the setup header's mode table is read backwards from its framing bit, so each audio packet's block size and every granule position are checked. The exact frame count is the final granule position. Chained or multiplexed streams, timeline offsets, more than two channels and rates outside 8-192 kHz are Unsupported; truncation, CRC errors and granule mismatches are Malformed. Vorbis comments are copied and read by index or case-insensitive field name. audio/vorbis decodes through stb_vorbis 1.24 (nothings/stb 9600522d, public domain or MIT), compiled by native/ziran_vorbis.c into libziran_vorbis.a: open from memory or a file, float and s16 streaming, whole-file decode, exact seek and rewind. The read call keeps decoding past frames that return no samples, which stb_vorbis' own interleaved reader treats as the end. audio/vorbis_resample adds the best-sinc resampler. The CLI detects Vorbis next to Opus for inspect, decode, resample and transcode. Vorbis contracts decode five FFmpeg/libvorbis fixtures within 0.501 PCM16 steps of FFmpeg, check exact lengths, streaming, s16, seeks, comments, synthetic and malformed streams and 600 corrupted decodes, and pass under ASan and UBSan. The Windows and Android runs cover the Vorbis fixtures too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
"""Compare the Android device CLI results with the Linux CLI on the same inputs."""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import struct
|
|
import sys
|
|
import wave
|
|
|
|
host, abi, serial, mp3s = Path(sys.argv[1]), sys.argv[2], sys.argv[3], sys.argv[4:]
|
|
linux = host / 'linux'
|
|
# Float codec/sinc arithmetic may round differently across ISAs (NEON/SSE,
|
|
# fused multiply-add); PCM16 output must still agree within a few LSBs.
|
|
TOLERANCE = 4
|
|
|
|
def pcm(path):
|
|
with wave.open(str(path)) as audio:
|
|
params = (audio.getframerate(), audio.getnchannels(), audio.getnframes())
|
|
data = audio.readframes(audio.getnframes())
|
|
return params, struct.unpack('<%dh' % (len(data) // 2), data)
|
|
|
|
def inspect_lines(log):
|
|
return [line for line in log.read_text().splitlines() if line.strip()]
|
|
|
|
device_inspect = inspect_lines(host / 'device.log')
|
|
linux_inspect = inspect_lines(host / 'linux.log')
|
|
assert device_inspect == linux_inspect, (device_inspect, linux_inspect)
|
|
|
|
mp3_outputs = [Path(name).stem + '-decoded.wav' for name in mp3s]
|
|
for name in ('short.wav', 'voice-decoded.wav', 'chirp-decoded.wav', 'voice-16k.wav', 'chirp-44k.wav', 'vbr-48k.wav', 'vorbis-48k.wav', *mp3_outputs):
|
|
(device_params, device), (linux_params, reference) = pcm(host / name), pcm(linux / name)
|
|
assert device_params == linux_params, (name, device_params, linux_params)
|
|
worst = max((abs(a - b) for a, b in zip(device, reference)), default=0)
|
|
assert worst <= TOLERANCE, (name, worst)
|
|
print(f'android {abi} {name}: {device_params[2]} frames at {device_params[0]} Hz, max PCM16 difference {worst}')
|
|
|
|
# The device-encoded stream must decode on Linux with the source duration.
|
|
decoded = host / 'device-encoded-decoded.wav'
|
|
subprocess.run([str(Path('build/bin/audio').resolve()), 'decode', str(host / 'voice-encoded.opus'), str(decoded)], check=True)
|
|
(rate, channels, frames), _ = pcm(decoded)
|
|
(_, _, source_frames), _ = pcm(linux / 'voice.wav')
|
|
assert (rate, channels, frames) == (48000, 1, source_frames), (rate, channels, frames, source_frames)
|
|
print(f'android {abi} encode: {(host / "voice-encoded.opus").stat().st_size} bytes, decoded on Linux to {frames} frames')
|
|
print(f'android {abi} device {serial}: native Opus decode/encode, {len(mp3s)} MP3 and Vorbis decodes and best sinc resampling matched Linux')
|