Merge remote-tracking branch 'desktop/parity-audio' into t3/achieve-full-parity
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Shared runner for the audio differential harnesses.
|
||||
|
||||
Each harness writes an input file, runs a Java oracle against the pinned
|
||||
client (the real SoundManager / SoundEngine / MusicManager / ambient handlers;
|
||||
OpenAL runs on OpenAL Soft's "No Output" device so channel parameters can be
|
||||
read back from real AL sources) and a Rust example replaying the same inputs
|
||||
through Horizon's audio code, then requires byte-identical output.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
from . import lab, test_rust_parity as base, test_model_baking_parity as baking
|
||||
except ImportError:
|
||||
import lab, test_rust_parity as base, test_model_baking_parity as baking
|
||||
|
||||
RESOURCES = lab.LOCAL / 'horizon-client/26.3'
|
||||
COMMON_SOURCES = [
|
||||
lab.ROOT / 'tools/audio_harness.py',
|
||||
lab.ROOT / 'tools/test_rust_parity.py',
|
||||
lab.ROOT / 'tools/lab.py',
|
||||
lab.ROOT / 'Cargo.toml',
|
||||
lab.ROOT / 'Cargo.lock',
|
||||
lab.ROOT / 'crates/horizon-client/Cargo.toml',
|
||||
lab.ROOT / 'crates/horizon-client/src/sound_events.rs',
|
||||
lab.ROOT / 'crates/horizon-client/src/sound_engine.rs',
|
||||
]
|
||||
|
||||
|
||||
def require_sounds():
|
||||
if not (RESOURCES / 'assets/minecraft/sounds.json').is_file():
|
||||
raise SystemExit('Sound assets missing: run tools/fetch_sounds.py first')
|
||||
|
||||
|
||||
def run_harness(name, oracle, example, inputs_text, extra_sources=(), java_args=(), rust_args=(), scope='', timeout=1800):
|
||||
"""Run oracle and example on inputs; returns the number of matched lines."""
|
||||
require_sounds()
|
||||
lock, jars, _ = base.verify_artifacts()
|
||||
libraries = baking.client_libraries()
|
||||
build = lab.LOCAL / f'rust-{name}'
|
||||
build.mkdir(parents=True, exist_ok=True)
|
||||
report = build / 'report.json'
|
||||
report.unlink(missing_ok=True)
|
||||
oracle_path = lab.ROOT / f'mods/horizon/src/test/java/dev/horizonlab/parity/{oracle}.java'
|
||||
example_path = lab.ROOT / f'crates/horizon-client/examples/{example}.rs'
|
||||
sources = [*COMMON_SOURCES, oracle_path, example_path, *[Path(s) for s in extra_sources]]
|
||||
tested = base.source_hashes(sources)
|
||||
inputs = build / 'inputs.txt'
|
||||
inputs.write_text(inputs_text)
|
||||
input_hash = lab.digest(inputs, 'sha256')
|
||||
|
||||
def run(command, log, env=None):
|
||||
with (build / (log + ".log")).open("w") as out:
|
||||
try:
|
||||
subprocess.run(list(map(str, command)), cwd=lab.ROOT, check=True, timeout=timeout, stdout=out, stderr=subprocess.STDOUT, env=env)
|
||||
except subprocess.CalledProcessError:
|
||||
raise SystemExit(f"{log} failed: see {build / (log + '.log')}") from None
|
||||
|
||||
classes = build / 'classes'
|
||||
classes.mkdir(exist_ok=True)
|
||||
dependencies = os.pathsep.join(map(str, [jars['client'], *libraries]))
|
||||
run(['javac', '--release', lock['minecraft']['java_major'], '-proc:none', '-sourcepath', lab.ROOT / 'mods/horizon/src/test/java',
|
||||
'-cp', dependencies, '-d', classes, oracle_path], 'compile-java')
|
||||
run(['cargo', 'build', '--locked', '-p', 'horizon-client', '--example', example], 'compile-rust')
|
||||
metadata = json.loads(subprocess.check_output(['cargo', 'metadata', '--locked', '--no-deps', '--format-version', '1'], cwd=lab.ROOT))
|
||||
binary = Path(metadata['target_directory']) / 'debug/examples' / (example + ('.exe' if os.name == 'nt' else ''))
|
||||
run([binary, *rust_args, inputs, build / 'rust.txt'], 'rust')
|
||||
env = dict(os.environ, ALSOFT_DRIVERS='null')
|
||||
run(['java', '-Xmx1G', '-cp', str(classes) + os.pathsep + dependencies, f'dev.horizonlab.parity.{oracle}', *java_args, inputs, build / 'client.txt'],
|
||||
'client', env=env)
|
||||
matched = base.compare(build / 'client.txt', build / 'rust.txt')
|
||||
base.ensure_sources_unchanged(sources, tested)
|
||||
if input_hash != lab.digest(inputs, 'sha256'):
|
||||
raise AssertionError('Input fixtures changed')
|
||||
lab.write_json(report, dict(
|
||||
schema=1, minecraft=lock['minecraft']['version'], manifest_sha1=lock['minecraft']['manifest_sha1'], platform=platform.platform(),
|
||||
rustc=subprocess.check_output(['rustc', '--version'], text=True).strip(),
|
||||
java=subprocess.check_output(['java', '--version'], text=True).splitlines()[0],
|
||||
sources_sha256=tested, input_sha256=input_hash, client_jar_sha256=lab.digest(jars['client'], 'sha256'),
|
||||
sounds_json_sha256=lab.digest(RESOURCES / 'assets/minecraft/sounds.json', 'sha256'),
|
||||
matched_output_lines=matched, output_sha256=lab.digest(build / 'rust.txt', 'sha256'), scope=scope))
|
||||
return matched, report
|
||||
|
||||
|
||||
def bits(value):
|
||||
import struct
|
||||
return struct.pack('>f', value).hex()
|
||||
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the local player's ambient sounds with the vanilla 26.3 client.
|
||||
|
||||
The oracle runs the real `LocalPlayer.updateIsUnderwater` (enter/exit sounds
|
||||
seeded from the level random, the `UnderLiquidAmbientSoundInstance`),
|
||||
`UnderwaterAmbientSoundHandler`, `BubbleColumnAmbientSoundHandler` and
|
||||
`BiomeAmbientSoundsHandler` over the real
|
||||
`SoundEngine` (see VanillaSoundRig), then `SoundManager.tick`, once per client
|
||||
tick. The `AMBIENT_SOUNDS` value (loops, moods and additions from the biomes
|
||||
and dimensions of the data pack plus faster custom moods), the player's
|
||||
position, eye height, eyes in water, spectator and removed flags and the
|
||||
level's brightness are script inputs. Every step prints the level random's
|
||||
next long (so every draw is compared), moodiness, the underwater state and
|
||||
delay, the handler's loop instances (fade, direction, stopped, active), each
|
||||
playing instance and the subtitle notifications. Horizon's `Ambience` and
|
||||
`SoundEngine` replay the scripts.
|
||||
"""
|
||||
import json
|
||||
import random
|
||||
import struct
|
||||
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
|
||||
def dbits(v):
|
||||
return struct.pack('>d', v).hex()
|
||||
|
||||
|
||||
def settings():
|
||||
"""Every AMBIENT_SOUNDS value in the data pack."""
|
||||
data = h.RESOURCES / 'data/minecraft'
|
||||
values = []
|
||||
for path in sorted(list((data / 'worldgen/biome').glob('*.json')) + list((data / 'dimension_type').glob('*.json'))):
|
||||
v = json.loads(path.read_text()).get('attributes', {}).get('minecraft:audio/ambient_sounds')
|
||||
if v is None:
|
||||
continue
|
||||
additions = v.get('additions', [])
|
||||
if isinstance(additions, dict):
|
||||
additions = [additions]
|
||||
mood = v.get('mood')
|
||||
values.append(dict(loop=v.get('loop'), mood=None if mood is None else (mood['sound'], mood['tick_delay'], mood['block_search_extent'], mood['offset']),
|
||||
additions=[(a['sound'], a['tick_chance']) for a in additions]))
|
||||
return values
|
||||
|
||||
|
||||
class Script:
|
||||
def __init__(self):
|
||||
self.lines = []
|
||||
|
||||
def add(self, *parts):
|
||||
self.lines.append(' '.join(map(str, parts)))
|
||||
|
||||
def sounds(self, value):
|
||||
mood = '-' if value['mood'] is None else '{},{},{},{}'.format(value['mood'][0], value['mood'][1], value['mood'][2], dbits(value['mood'][3]))
|
||||
self.add('sounds', value['loop'] or '-', mood, *[f'{s},{dbits(c)}' for s, c in value['additions']])
|
||||
|
||||
def player(self, at=(0.5, 64.0, 0.5), eye=1.62, water=0, spectator=0, removed=0, mode=0, height=1.8, columns=()):
|
||||
self.add('player', *map(dbits, at), h.bits(eye), water, spectator, removed, mode, h.bits(height),
|
||||
*[f'{x},{y},{z},{d}' for x, y, z, d in columns])
|
||||
|
||||
def tick(self, n=1):
|
||||
for _ in range(n):
|
||||
self.add('tick')
|
||||
|
||||
|
||||
def scripted(s, values):
|
||||
by_loop = [v for v in values if v['loop']]
|
||||
cave = next(v for v in values if v['mood'] and v['mood'][0] == 'minecraft:ambient.cave' and not v['loop'])
|
||||
s.add('start', 1)
|
||||
s.sounds(cave)
|
||||
s.player(mode=1)
|
||||
s.tick(6100)
|
||||
s.player((100.25, -20.0, -7.75), mode=2)
|
||||
s.tick(400)
|
||||
s.player((3.5, 12.0, 3.5), mode=3)
|
||||
s.tick(400)
|
||||
# Biome loops cross-fading, back and forth.
|
||||
s.add('start', 2)
|
||||
for v in by_loop:
|
||||
s.sounds(v)
|
||||
s.tick(30)
|
||||
s.sounds(by_loop[0])
|
||||
s.tick(20)
|
||||
s.sounds(by_loop[1])
|
||||
s.tick(5)
|
||||
s.sounds(by_loop[0])
|
||||
s.tick(60)
|
||||
s.sounds(dict(loop=None, mood=None, additions=[]))
|
||||
s.tick(60)
|
||||
# Water: enter, the loop's fade, sub-sounds, exit, re-entering mid-fade, spectators.
|
||||
s.add('start', 3)
|
||||
s.sounds(cave)
|
||||
s.player(water=1, mode=0)
|
||||
s.tick(300)
|
||||
s.player(water=0)
|
||||
s.tick(10)
|
||||
s.player(water=1)
|
||||
s.tick(3)
|
||||
s.player(water=0)
|
||||
s.tick(2)
|
||||
s.player(water=1)
|
||||
s.tick(60)
|
||||
s.player(water=1, spectator=1)
|
||||
s.tick(5)
|
||||
s.player(water=0, spectator=1)
|
||||
s.tick(5)
|
||||
s.player(water=1, removed=1)
|
||||
s.tick(5)
|
||||
s.player(water=0)
|
||||
s.tick(25)
|
||||
# Silent ambient category: loops never start and linger.
|
||||
s.add('start', 4)
|
||||
s.add('volume', 8, h.bits(0.0))
|
||||
s.sounds(by_loop[0])
|
||||
s.tick(50)
|
||||
s.add('volume', 8, h.bits(1.0))
|
||||
s.sounds(by_loop[1])
|
||||
s.tick(50)
|
||||
s.sounds(by_loop[0])
|
||||
s.tick(50)
|
||||
# Bubble columns: entering, staying, the first tick, spectators, small boxes.
|
||||
s.add('start', 5)
|
||||
column = [(0, 64, 0, 1), (0, 65, 0, 1)]
|
||||
s.player((0.5, 64.0, 0.5), water=1, columns=column)
|
||||
s.tick(3)
|
||||
s.player((3.5, 64.0, 0.5), water=1, columns=column)
|
||||
s.tick(2)
|
||||
s.player((0.5, 64.0, 0.5), water=1, columns=column)
|
||||
s.tick(2)
|
||||
s.player((0.5, 64.0, 0.5), water=1, columns=[(0, 64, 0, 0), (1, 64, 0, 1)])
|
||||
s.tick(2)
|
||||
s.player((3.5, 64.0, 0.5))
|
||||
s.tick(2)
|
||||
s.player((0.9, 64.5, 0.5), water=1, height=0.6, columns=[(1, 64, 0, 0), (0, 64, 0, 1)])
|
||||
s.tick(2)
|
||||
s.player((3.5, 64.0, 0.5))
|
||||
s.tick(1)
|
||||
s.player((0.5, 63.7, 0.5), spectator=1, columns=column)
|
||||
s.tick(2)
|
||||
|
||||
|
||||
def fuzz(s, rng, values, steps):
|
||||
s.add('start', rng.getrandbits(63))
|
||||
for _ in range(steps):
|
||||
op = rng.random()
|
||||
if op < 0.05:
|
||||
v = rng.choice(values + [dict(loop=None, mood=None, additions=[])])
|
||||
if rng.random() < 0.5 and v['mood']:
|
||||
v = dict(v, mood=(v['mood'][0], rng.choice([20, 60, 150]), rng.choice([1, 4, 8, 16]), rng.choice([0.0, 2.0, 5.5])))
|
||||
s.sounds(v)
|
||||
elif op < 0.12:
|
||||
at = (rng.uniform(-3e4, 3e4) if rng.random() < 0.2 else rng.uniform(-200, 200), rng.uniform(-64, 320), rng.uniform(-200, 200))
|
||||
columns = []
|
||||
if rng.random() < 0.3:
|
||||
bx, by, bz = int(at[0] // 1), int(at[1] // 1), int(at[2] // 1)
|
||||
columns = [(bx + rng.randrange(-1, 2), by + rng.randrange(-1, 3), bz + rng.randrange(-1, 2), rng.randrange(2)) for _ in range(rng.randrange(1, 4))]
|
||||
s.player(at, rng.choice([1.62, 1.27, 0.4, 0.2]), int(rng.random() < 0.4), int(rng.random() < 0.05), int(rng.random() < 0.03), rng.randrange(4),
|
||||
rng.choice([1.8, 1.5, 0.6]), columns)
|
||||
elif op < 0.13:
|
||||
s.add('volume', rng.choice([0, 8]), h.bits(rng.choice([0.0, 1.0, 0.5])))
|
||||
else:
|
||||
s.tick(rng.randrange(1, 40))
|
||||
|
||||
|
||||
def fixtures():
|
||||
values = settings()
|
||||
s = Script()
|
||||
scripted(s, values)
|
||||
rng = random.Random(0x414d4249)
|
||||
for _ in range(40):
|
||||
fuzz(s, rng, values, 150)
|
||||
return s.lines
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'ambient', 'VanillaAmbientOracle', 'ambient_fixture', ''.join(l + '\n' for l in lines),
|
||||
extra_sources=[h.lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSoundRig.java',
|
||||
h.lab.ROOT / 'crates/horizon-client/src/ambience.rs',
|
||||
h.lab.ROOT / 'crates/horizon-client/examples/audio_common/mod.rs'],
|
||||
java_args=[h.RESOURCES], rust_args=[h.RESOURCES],
|
||||
scope='Real LocalPlayer.updateIsUnderwater, UnderwaterAmbientSoundHandler and BiomeAmbientSoundsHandler (loop cross-fades, additions, '
|
||||
'cave mood sampling, moodiness and the mood sound position) with UnderLiquidAmbientSoundInstance/UnderLiquidSubSound/LoopSoundInstance '
|
||||
'ticking in the real SoundEngine: every level random draw, handler state, playing instance and notification per tick. The '
|
||||
'AMBIENT_SOUNDS value, eyes-in-water state and brightness are inputs. BubbleColumnAmbientSoundHandler runs on a scripted block world.')
|
||||
print(f'{matched:,} ambient lines match the pinned client ({len(lines):,} steps): {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the audio environment attributes with the vanilla 26.3 data pack.
|
||||
|
||||
The oracle evaluates vanilla's `EnvironmentAttributeSystem` (dimension layer,
|
||||
biome positional layer, dimension timelines, weather layers) for every
|
||||
dimension type and biome and prints `BACKGROUND_MUSIC` (all three tracks and
|
||||
`BackgroundMusic.select` for each creative/underwater combination),
|
||||
`MUSIC_VOLUME` and `AMBIENT_SOUNDS` (loop, mood, additions), plus the
|
||||
`Musics` constants. Horizon's `MusicTables` and `AmbientTables` answer the same.
|
||||
"""
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
|
||||
def fixtures():
|
||||
data = h.RESOURCES / 'data/minecraft'
|
||||
biomes = sorted('minecraft:' + p.stem for p in (data / 'worldgen/biome').glob('*.json'))
|
||||
dimensions = sorted('minecraft:' + p.stem for p in (data / 'dimension_type').glob('*.json'))
|
||||
return [f'{d} {b} {t}' for d in dimensions for b in biomes for t in (0, 13000)]
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'audio-attributes', 'VanillaAudioAttributesOracle', 'audio_attributes_fixture', ''.join(l + '\n' for l in lines),
|
||||
extra_sources=[h.lab.ROOT / 'crates/horizon-client/src/music.rs', h.lab.ROOT / 'crates/horizon-client/src/ambience.rs'],
|
||||
rust_args=[h.RESOURCES],
|
||||
scope='Vanilla EnvironmentAttributeSystem values of audio/background_music (with BackgroundMusic.select), audio/music_volume and '
|
||||
'audio/ambient_sounds for every dimension type x biome at two times of day, and the Musics constants.')
|
||||
print(f'{matched:,} audio attribute lines match the pinned data ({len(lines):,} cases): {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the music manager with the vanilla 26.3 client.
|
||||
|
||||
The oracle runs the real `MusicManager` over the real `SoundEngine` (OpenAL
|
||||
Soft "No Output" device, see VanillaSoundRig). The situation
|
||||
(`getSituationalMusic`, `getMusicVolume`), the loading screen, pauses, the
|
||||
end of a track, `stopPlaying`, `setMinutesBetweenSongs`, the music category
|
||||
volume and `showNowPlayingToastIfNeeded` are script inputs; every step prints
|
||||
the current track, `nextSongDelay`, `currentGain`, `toastShown`, the toast
|
||||
calls, the MUSIC category gain and the music channel's AL source. Horizon's
|
||||
`MusicManager` and `SoundEngine` replay the scripts. Tracks use events whose
|
||||
variants share one volume, since `forMusic` resolves with an unseeded random.
|
||||
"""
|
||||
import random
|
||||
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
TRACKS = ['minecraft:music.credits', 'minecraft:music.dragon', 'minecraft:music.end', 'minecraft:music.under_water',
|
||||
'minecraft:music.overworld.swamp', 'minecraft:music_disc.cat', 'minecraft:music_disc.13']
|
||||
ODD = ['minecraft:music.nether.warped_forest', 'minecraft:not.a.track']
|
||||
|
||||
|
||||
class Script:
|
||||
def __init__(self):
|
||||
self.lines = []
|
||||
|
||||
def add(self, *parts):
|
||||
self.lines.append(' '.join(map(str, parts)))
|
||||
|
||||
def situation(self, sound=None, lo=0, hi=0, replace=0, volume=1.0):
|
||||
self.add('situation', '-' if sound is None else f'{sound},{lo},{hi},{replace}', h.bits(volume))
|
||||
|
||||
def tick(self, n=1, loading=0, paused=0):
|
||||
for _ in range(n):
|
||||
self.add('tick', loading, paused)
|
||||
|
||||
|
||||
def scripted(s):
|
||||
end, dragon, water, credits, cat = TRACKS[2], TRACKS[1], TRACKS[3], TRACKS[0], TRACKS[5]
|
||||
s.add('start', 1, 'DEFAULT')
|
||||
# Menu-like music: 20..600 ticks, replacing.
|
||||
s.situation(end, 20, 600, 1)
|
||||
s.tick(3, loading=1)
|
||||
s.tick(120)
|
||||
s.add('finish')
|
||||
s.tick(650)
|
||||
# Game music does not replace, and the next delay comes from its range.
|
||||
s.situation(water, 12000, 24000, 0)
|
||||
s.tick(5)
|
||||
s.add('finish')
|
||||
s.tick(30)
|
||||
s.add('freq', 'FREQUENT')
|
||||
s.tick(3)
|
||||
s.add('freq', 'CONSTANT')
|
||||
s.tick(110)
|
||||
s.add('freq', 'DEFAULT')
|
||||
s.tick(2)
|
||||
# A replacing track stops the current one over the following ticks.
|
||||
s.situation(dragon, 0, 0, 1)
|
||||
s.tick(30)
|
||||
s.situation(credits, 0, 0, 1)
|
||||
s.tick(30)
|
||||
s.situation(None)
|
||||
s.tick(5)
|
||||
s.add('finish')
|
||||
s.tick(5)
|
||||
s.situation(end, 6000, 24000, 1)
|
||||
s.tick(130)
|
||||
# Music volume fades: down to silence, then up from a partial volume.
|
||||
s.situation(end, 6000, 24000, 1, volume=0.0)
|
||||
s.tick(320)
|
||||
s.situation(cat, 0, 0, 1, volume=0.25)
|
||||
s.tick(5)
|
||||
s.situation(cat, 0, 0, 1, volume=1.0)
|
||||
s.tick(400)
|
||||
s.situation(cat, 0, 0, 1, volume=0.6)
|
||||
s.tick(80)
|
||||
# Silent starts and the toast, stops, pauses.
|
||||
s.add('volume', 1, h.bits(0.0))
|
||||
s.add('stop')
|
||||
s.situation(dragon, 0, 0, 1)
|
||||
s.tick(105)
|
||||
s.add('toast')
|
||||
s.add('volume', 1, h.bits(0.5))
|
||||
s.add('toast')
|
||||
s.tick(2)
|
||||
s.add('stopmusic', f'{end},0,0,1')
|
||||
s.add('stopmusic', f'{dragon},0,0,1')
|
||||
s.tick(105, paused=1)
|
||||
s.add('finish')
|
||||
s.tick(3, paused=1)
|
||||
s.tick(5)
|
||||
s.add('stopall')
|
||||
s.tick(5)
|
||||
# Events that cannot play.
|
||||
for event in ODD:
|
||||
s.add('start', 7, 'DEFAULT')
|
||||
s.situation(event, 0, 40, 1)
|
||||
s.tick(150)
|
||||
# Real Musics delays over a long session.
|
||||
s.add('start', 99, 'DEFAULT')
|
||||
s.situation(water, 12000, 24000, 0)
|
||||
s.tick(130)
|
||||
s.add('finish')
|
||||
s.tick(24100)
|
||||
|
||||
|
||||
def fuzz(s, rng, steps):
|
||||
s.add('start', rng.getrandbits(63), rng.choice(['DEFAULT', 'FREQUENT', 'CONSTANT']))
|
||||
for _ in range(steps):
|
||||
op = rng.random()
|
||||
if op < 0.08:
|
||||
sound = rng.choice(TRACKS + ODD[:1]) if rng.random() < 0.9 else None
|
||||
lo = rng.choice([0, 20, 100, 300])
|
||||
s.situation(sound, lo, lo + rng.choice([0, 50, 280, 600]), int(rng.random() < 0.5),
|
||||
rng.choice([1.0, 1.0, 1.0, 0.0, 0.5, rng.random()]))
|
||||
elif op < 0.13:
|
||||
s.add('finish')
|
||||
elif op < 0.15:
|
||||
s.add('stop')
|
||||
elif op < 0.16:
|
||||
s.add('stopmusic', f'{rng.choice(TRACKS)},0,0,1')
|
||||
elif op < 0.17:
|
||||
s.add('freq', rng.choice(['DEFAULT', 'FREQUENT', 'CONSTANT']))
|
||||
elif op < 0.18:
|
||||
s.add('toast')
|
||||
elif op < 0.20:
|
||||
s.add('volume', rng.choice([0, 1]), h.bits(rng.choice([0.0, 1.0, 0.5])))
|
||||
elif op < 0.21:
|
||||
s.add('stopall')
|
||||
elif op < 0.25:
|
||||
s.tick(rng.randrange(1, 30), loading=1)
|
||||
elif op < 0.28:
|
||||
s.tick(rng.randrange(1, 30), paused=1)
|
||||
else:
|
||||
s.tick(rng.randrange(1, 60))
|
||||
|
||||
|
||||
def fixtures():
|
||||
s = Script()
|
||||
scripted(s)
|
||||
rng = random.Random(0x4d55534943)
|
||||
for _ in range(60):
|
||||
fuzz(s, rng, 120)
|
||||
return s.lines
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'music', 'VanillaMusicOracle', 'music_fixture', ''.join(l + '\n' for l in lines),
|
||||
extra_sources=[h.lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSoundRig.java',
|
||||
h.lab.ROOT / 'crates/horizon-client/src/music.rs',
|
||||
h.lab.ROOT / 'crates/horizon-client/examples/audio_common/mod.rs'],
|
||||
java_args=[h.RESOURCES], rust_args=[h.RESOURCES],
|
||||
scope='Real MusicManager.tick/startPlaying/stopPlaying/fadePlaying/setMinutesBetweenSongs/showNowPlayingToastIfNeeded with a seeded '
|
||||
'random over the real SoundEngine: track starts and replacements, nextSongDelay draws, the three music frequencies, the loading '
|
||||
'screen hold, fades and the MUSIC category gain, silent starts, toasts, pauses, track ends and unplayable events. The situation '
|
||||
'(getSituationalMusic/getMusicVolume) is an input here; see test_audio_attributes_parity.py for the attribute values.')
|
||||
print(f'{matched:,} music lines match the pinned client ({len(lines):,} steps): {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the situational music choice with the vanilla 26.3 client.
|
||||
|
||||
The oracle calls the real `Minecraft.getSituationalMusic` and
|
||||
`getMusicVolume` with the open screen (none or the credits), the boss
|
||||
overlay's bars (none, darkening, music), the player (absent, or in a dimension
|
||||
with creative abilities and an underwater state) and a real camera
|
||||
`EnvironmentAttributeProbe` over the dimension and biome attribute layers of
|
||||
the vanilla data pack. Horizon's `Situation` with `MusicTables` answers the
|
||||
same, for every dimension type x biome and every combination of the rest.
|
||||
"""
|
||||
import itertools
|
||||
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
|
||||
def fixtures():
|
||||
data = h.RESOURCES / 'data/minecraft'
|
||||
biomes = sorted('minecraft:' + p.stem for p in (data / 'worldgen/biome').glob('*.json'))
|
||||
dimensions = ['minecraft:overworld', 'minecraft:the_nether', 'minecraft:the_end']
|
||||
lines = []
|
||||
for screen, boss in itertools.product(['none', 'win'], ['none', 'dark', 'music', 'dark+music']):
|
||||
lines.append(f'{screen} 0 minecraft:overworld minecraft:plains {boss} 0 0 0')
|
||||
for d, b in itertools.product(dimensions, biomes):
|
||||
for screen, boss, instabuild, mayfly, water in itertools.product(['none', 'win'], ['none', 'dark', 'music'], '01', '01', '01'):
|
||||
lines.append(f'{screen} 1 {d} {b} {boss} {instabuild} {mayfly} {water}')
|
||||
return lines
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'situational-music', 'VanillaSituationalMusicOracle', 'situational_music_fixture', ''.join(l + '\n' for l in lines),
|
||||
extra_sources=[h.lab.ROOT / 'crates/horizon-client/src/music.rs'], rust_args=[h.RESOURCES],
|
||||
scope='Real Minecraft.getSituationalMusic/getMusicVolume: screen music (credits), menu without a player, End boss music from '
|
||||
'the boss overlay, BACKGROUND_MUSIC and MUSIC_VOLUME through a real camera EnvironmentAttributeProbe, creative abilities '
|
||||
'(instabuild && mayfly) and underwater selection, for every dimension x biome.')
|
||||
print(f'{matched:,} situational music lines match the pinned client: {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,247 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare the sound engine's bookkeeping with the vanilla 26.3 client.
|
||||
|
||||
The oracle runs the real `SoundManager`/`SoundEngine` on OpenAL Soft's "No
|
||||
Output" device (see VanillaSoundRig) and replays scripts of plays (simple,
|
||||
biome loop, underwater loop and sub-sound instances), stops (by instance, by
|
||||
sound and/or source, all), category gains, source volume options and
|
||||
refreshes, channel ends, delayed and queued sounds, pauses and client ticks.
|
||||
After every step it prints each instance's `isActive` and the AL source the
|
||||
engine configured (state, gain, pitch, position, relative, looping, distance
|
||||
model, max distance, rolloff, reference distance), the subtitle notifications
|
||||
and the channel pool counts. Horizon's `SoundEngine` replays the scripts
|
||||
against a backend that records the same AL source fields.
|
||||
"""
|
||||
import json
|
||||
import random
|
||||
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
|
||||
def dbits(v):
|
||||
import struct
|
||||
return struct.pack('>d', v).hex()
|
||||
|
||||
|
||||
class Script:
|
||||
def __init__(self, events, streams):
|
||||
self.lines = []
|
||||
self.events, self.streams = events, streams
|
||||
|
||||
def add(self, *parts):
|
||||
self.lines.append(' '.join(map(str, parts)))
|
||||
|
||||
def play(self, name, event, source=4, volume=1.0, pitch=1.0, at=(0.0, 0.0, 0.0), looping=0, delay=0, linear=True, relative=0, seed=0, kind='simple'):
|
||||
self.add('play', name, kind, event, source, h.bits(volume), h.bits(pitch), *map(dbits, at), looping, delay,
|
||||
'linear' if linear else 'none', relative, seed)
|
||||
|
||||
def tick(self, n=1, paused=0):
|
||||
for _ in range(n):
|
||||
self.add('tick', paused)
|
||||
|
||||
def reset(self):
|
||||
self.add('stopmatch', '-', '-')
|
||||
for source in range(11):
|
||||
self.add('volume', source, h.bits(1.0))
|
||||
self.tick()
|
||||
|
||||
|
||||
def scripted(s):
|
||||
stone, cave, click = 'minecraft:block.stone.break', 'minecraft:ambient.cave', 'minecraft:ui.button.click'
|
||||
music, loop, uloop = 'minecraft:music.game', 'minecraft:ambient.crimson_forest.loop', 'minecraft:ambient.underwater.loop'
|
||||
# Positional and relative sounds, lifetimes and channel ends.
|
||||
s.play('a', stone, 4, 1.0, 0.8, (10.5, 64.0, -3.25), seed=5)
|
||||
s.play('b', click, 10, 0.25, 1.0, linear=False, relative=1, seed=6)
|
||||
s.play('c', cave, 8, 4.0, 1.0, (100.0, 20.0, 100.0), seed=7)
|
||||
s.play('d', stone, 4, 1.5, 3.0, (0.5, 0.5, 0.5), seed=8)
|
||||
s.play('e', stone, 4, 0.5, 0.1, (1.0, 2.0, 3.0), seed=9)
|
||||
s.tick(3)
|
||||
s.add('finish', 'a')
|
||||
s.tick(25)
|
||||
s.add('finish', 'b')
|
||||
s.add('stop', 'c')
|
||||
s.tick(2)
|
||||
s.reset()
|
||||
# Volumes: options, category gains, refreshes, silent starts.
|
||||
s.add('volume', 4, h.bits(0.5))
|
||||
s.add('volume', 0, h.bits(0.75))
|
||||
s.play('a', stone, 4, 1.0, 1.0, (1.0, 1.0, 1.0), seed=1)
|
||||
s.add('volume', 4, h.bits(0.0))
|
||||
s.play('b', stone, 4, 1.0, 1.0, (1.0, 1.0, 1.0), seed=2)
|
||||
s.add('volume', 1, h.bits(0.0))
|
||||
s.play('m', music, 1, 1.0, 1.0, linear=False, relative=1, seed=3)
|
||||
s.add('refresh', 4)
|
||||
s.add('volume', 4, h.bits(0.3))
|
||||
s.add('refresh', 0)
|
||||
s.add('gain', 1, h.bits(0.5))
|
||||
s.add('gain', 1, h.bits(1.5))
|
||||
s.add('gain', 4, h.bits(-0.2))
|
||||
s.add('volume', 1, h.bits(1.0))
|
||||
s.add('refresh', 1)
|
||||
s.tick(2)
|
||||
s.add('volume', 0, h.bits(2.0))
|
||||
s.add('refresh', 0)
|
||||
s.reset()
|
||||
# Biome loops: fades, crossfade, stopping, removal.
|
||||
s.play('l1', loop, kind='loop', seed=11)
|
||||
s.add('fade', 'l1', 'in')
|
||||
s.tick(45)
|
||||
s.play('l2', 'minecraft:ambient.warped_forest.loop', kind='loop', seed=12)
|
||||
s.add('fade', 'l1', 'out')
|
||||
s.add('fade', 'l2', 'in')
|
||||
s.tick(50)
|
||||
s.add('fade', 'l2', 'out')
|
||||
s.tick(10)
|
||||
s.add('fade', 'l2', 'in')
|
||||
s.tick(60)
|
||||
s.add('volume', 8, h.bits(0.0))
|
||||
s.play('l3', loop, kind='loop', seed=13)
|
||||
s.tick(3)
|
||||
s.reset()
|
||||
# Underwater loop and sub-sounds.
|
||||
s.add('player', 1, 0)
|
||||
s.play('u', uloop, kind='uloop', seed=21)
|
||||
s.play('v', 'minecraft:ambient.underwater.loop.additions.rare', kind='usub', seed=22)
|
||||
s.tick(50)
|
||||
s.add('player', 0, 0)
|
||||
s.tick(5)
|
||||
s.add('player', 1, 0)
|
||||
s.tick(5)
|
||||
s.add('player', 0, 0)
|
||||
s.tick(30)
|
||||
s.add('player', 1, 1)
|
||||
s.play('u2', uloop, kind='uloop', seed=23)
|
||||
s.tick(3)
|
||||
s.add('player', 0, 0)
|
||||
s.reset()
|
||||
# Queued tickables, delayed and manually looped sounds.
|
||||
s.play('q', loop, kind='loop', seed=31)
|
||||
s.add('stop', 'q')
|
||||
s.tick(25)
|
||||
s.add('queue', 'q')
|
||||
s.add('fade', 'q', 'in')
|
||||
s.tick(3)
|
||||
s.play('w', stone, 4, 1.0, 1.0, (2.0, 2.0, 2.0), seed=32)
|
||||
s.add('delayed', 'w', 5)
|
||||
s.tick(7)
|
||||
s.play('r', stone, 4, 1.0, 1.0, (3.0, 3.0, 3.0), looping=1, delay=4, seed=33)
|
||||
s.tick(22)
|
||||
s.add('finish', 'r')
|
||||
s.tick(8)
|
||||
s.add('finish', 'r')
|
||||
s.tick(6)
|
||||
s.play('n', stone, 4, 1.0, 1.0, (3.0, 3.0, 3.0), looping=1, seed=34)
|
||||
s.tick(2)
|
||||
s.reset()
|
||||
# Stopping by source and sound, pauses.
|
||||
s.play('a', stone, 4, seed=41)
|
||||
s.play('b', stone, 5, seed=42)
|
||||
s.play('c', cave, 8, seed=43)
|
||||
s.play('m', music, 1, linear=False, relative=1, seed=44)
|
||||
s.play('u', click, 10, linear=False, relative=1, seed=45)
|
||||
s.add('pause')
|
||||
s.tick(1, paused=1)
|
||||
s.add('stop', 'm')
|
||||
s.tick(1, paused=1)
|
||||
s.add('resume')
|
||||
s.add('stopmatch', stone, '-')
|
||||
s.tick(25)
|
||||
s.add('stopmatch', '-', 8)
|
||||
s.add('stopmatch', click, 4)
|
||||
s.add('stopmatch', click, 10)
|
||||
s.tick(2)
|
||||
s.reset()
|
||||
# Unknown, empty and intentionally empty events; replaying an instance.
|
||||
for i, event in enumerate(['minecraft:not.a.sound', 'minecraft:intentionally_empty', 'minecraft:empty', 'minecraft:entity.generic.eat']):
|
||||
s.play(f'x{i}', event, 6, seed=50 + i)
|
||||
s.add('replay', 'x3')
|
||||
s.tick(25)
|
||||
s.reset()
|
||||
# Channel pools.
|
||||
for i in range(252):
|
||||
s.play('p', stone, 4, 1.0, 1.0, (float(i), 0.0, 0.0), seed=i)
|
||||
for i in range(10):
|
||||
s.play('s', music, 1, linear=False, relative=1, seed=i)
|
||||
s.tick(2)
|
||||
s.add('stopmatch', '-', '-')
|
||||
s.tick(1)
|
||||
|
||||
|
||||
def fuzz(s, rng, steps):
|
||||
names = ['f0', 'f1', 'f2', 'f3', 'f4', 'f5']
|
||||
live = set()
|
||||
for _ in range(steps):
|
||||
op = rng.random()
|
||||
name = rng.choice(names)
|
||||
if op < 0.25:
|
||||
kind = rng.choice(['simple', 'simple', 'simple', 'loop', 'uloop', 'usub'])
|
||||
event = rng.choice(s.streams if kind != 'simple' and rng.random() < 0.5 else s.events)
|
||||
at = tuple(rng.choice([0.0, rng.uniform(-200, 200)]) for _ in range(3))
|
||||
s.play(name, event, rng.randrange(11), rng.choice([1.0, 0.5, 2.0, 0.0, 4.0, rng.uniform(0, 3)]), rng.choice([1.0, 0.5, 2.5, rng.uniform(0.2, 3)]),
|
||||
at, int(rng.random() < 0.2), rng.choice([0, 0, 0, 3]), rng.random() < 0.7, int(rng.random() < 0.3), rng.getrandbits(63), kind)
|
||||
live.add(name)
|
||||
elif not live:
|
||||
s.tick()
|
||||
elif op < 0.32:
|
||||
s.add('finish', rng.choice(sorted(live)))
|
||||
elif op < 0.36:
|
||||
s.add('stop', rng.choice(sorted(live)))
|
||||
elif op < 0.40:
|
||||
s.add('fade', rng.choice(sorted(live)), rng.choice(['in', 'out']))
|
||||
elif op < 0.42:
|
||||
s.add('stopmatch', rng.choice(['-', rng.choice(s.events)]), rng.choice(['-', rng.randrange(11)]))
|
||||
elif op < 0.45:
|
||||
s.add('volume', rng.randrange(11), h.bits(rng.choice([0.0, 1.0, 0.5, rng.random()])))
|
||||
elif op < 0.48:
|
||||
s.add('refresh', rng.randrange(11))
|
||||
elif op < 0.51:
|
||||
s.add('gain', rng.randrange(11), h.bits(rng.choice([0.0, 1.0, 0.3, 1.2])))
|
||||
elif op < 0.53:
|
||||
s.add('player', int(rng.random() < 0.6), int(rng.random() < 0.05))
|
||||
elif op < 0.55:
|
||||
s.add('replay', rng.choice(sorted(live)))
|
||||
elif op < 0.56:
|
||||
s.add('pause')
|
||||
s.tick(rng.randrange(1, 4), paused=1)
|
||||
s.add('resume')
|
||||
elif op < 0.57:
|
||||
s.add('forget', name)
|
||||
live.discard(name)
|
||||
else:
|
||||
s.tick(rng.randrange(1, 6))
|
||||
|
||||
|
||||
def fixtures():
|
||||
sounds = json.loads((h.RESOURCES / 'assets/minecraft/sounds.json').read_text())
|
||||
names = sorted(sounds)
|
||||
streams = sorted('minecraft:' + n for n in names if any(isinstance(e, dict) and e.get('stream') for e in sounds[n].get('sounds', [])))
|
||||
rng = random.Random(0x454e47494e45)
|
||||
events = sorted(set(['minecraft:' + rng.choice(names) for _ in range(60)] + ['minecraft:ambient.cave', 'minecraft:block.stone.break']))
|
||||
s = Script(events, streams)
|
||||
scripted(s)
|
||||
for _ in range(40):
|
||||
s.reset()
|
||||
fuzz(s, rng, 150)
|
||||
return s.lines
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'sound-engine', 'VanillaSoundEngineOracle', 'sound_engine_fixture', ''.join(l + '\n' for l in lines),
|
||||
extra_sources=[h.lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSoundRig.java'],
|
||||
java_args=[h.RESOURCES], rust_args=[h.RESOURCES],
|
||||
scope='Real SoundEngine (OpenAL Soft null device, inline executor, silent static buffers, never-ready streams): play results, '
|
||||
'AL source parameters set by play/tickInGameSound/refreshCategoryVolume (gain from calculateVolume, clamped pitch, linear '
|
||||
'attenuation distance, looping, position, relative), isActive, the 20-tick minimum lifetime, channel ends, stop by instance/sound/source/all, '
|
||||
'pauseAllExcept/resume, tickMusicWhenPaused, queued tickables, playDelayed and manual looping, LoopSoundInstance, '
|
||||
'UnderLiquidAmbientSoundInstance and UnderLiquidSubSound ticks, subtitle notifications and ranges, and the 247/8 channel pools. '
|
||||
'Not compared: decoded sample output, OpenAL panning/HRTF and distance gain inside the mixer, asset loading timing.')
|
||||
print(f'{matched:,} sound engine lines match the pinned client ({len(lines):,} steps): {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare sound event resolution with the vanilla 26.3 client.
|
||||
|
||||
The oracle builds the real `SoundManager` registry from the client asset root
|
||||
(`SoundManager.prepare` + `Preparations.apply`: sounds.json, `replace`,
|
||||
subtitles, file validation against the listed .ogg resources, event references
|
||||
weighing as much as their event) and resolves seeded `SimpleSoundInstance`s:
|
||||
`getOrResolve`, `getVolume`, `getPitch`, `Sound.getAttenuationDistance`, the
|
||||
stream/preload/type fields and the instance random's next draw. Horizon's
|
||||
`SoundRegistry` + `SoundEngine::resolve` replay the same inputs.
|
||||
"""
|
||||
import json
|
||||
import random
|
||||
|
||||
try:
|
||||
from . import audio_harness as h
|
||||
except ImportError:
|
||||
import audio_harness as h
|
||||
|
||||
|
||||
def fixtures():
|
||||
sounds = json.loads((h.RESOURCES / 'assets/minecraft/sounds.json').read_text())
|
||||
rng = random.Random(0x534f554e44)
|
||||
volumes = [1.0, 0.5, 0.25, 2.0, 4.0, 0.0, 1e-3, 16.0]
|
||||
pitches = [1.0, 0.5, 2.0, 0.8, 1.2, 3.0, 0.1]
|
||||
lines = []
|
||||
for name in sorted(sounds):
|
||||
event = 'minecraft:' + name
|
||||
count = len(sounds[name].get('sounds', []))
|
||||
seeds = [0, 1, -1, 42] + [rng.getrandbits(64) - (1 << 63) for _ in range(max(4, 2 * count))]
|
||||
for seed in seeds:
|
||||
lines.append(f'{event} {seed} {h.bits(rng.choice(volumes))} {h.bits(rng.choice(pitches))}')
|
||||
for event in ['minecraft:intentionally_empty', 'minecraft:empty', 'minecraft:not.a.sound', 'horizon:missing', 'block.stone.break', 'music.game']:
|
||||
for seed in [0, 7, -99]:
|
||||
lines.append(f'{event} {seed} {h.bits(1.0)} {h.bits(1.0)}')
|
||||
return lines
|
||||
|
||||
|
||||
def main():
|
||||
lines = fixtures()
|
||||
matched, report = h.run_harness(
|
||||
'sound-events', 'VanillaSoundEventOracle', 'sound_event_fixture', ''.join(l + '\n' for l in lines),
|
||||
java_args=[h.RESOURCES], rust_args=[h.RESOURCES],
|
||||
scope='Real SoundManager.prepare/Preparations.apply over the client asset root and SimpleSoundInstance.getOrResolve/getVolume/getPitch '
|
||||
'for every sounds.json event with seeded randoms (weighted choice, nested event references, MultipliedFloats volume/pitch, '
|
||||
'stream/preload/attenuation fields, EMPTY and INTENTIONALLY_EMPTY sentinels, draw counts) and the full registered event list.')
|
||||
print(f'{matched:,} sound event lines match the pinned client ({len(lines):,} resolutions): {report}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user