mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-21 07:59:58 -04:00
Keep only the game's select and back sounds in the launcher, and make none of its own.
The cursor's sound played at every move of the pointer and cut the other two short, as one sound plays at a time: it is gone, and moving the cursor is silent. A choice, a changed switch, Play and the end of a build play the game's decide sound; going back and a failure play its cancel sound. The chimes the launcher made from sine tones are removed too, so every sound it plays is decoded from the player's own game into data/cache/sounds and it is silent until the game has been read. No sound file is in the repository, the release or the setup. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -47,13 +47,13 @@ Customize Launcher (on the home screen) makes the look the player's own:
|
|||||||
- Animations (on by default): the cursor glides from row to row, a new screen slides into place, sparks drift up
|
- Animations (on by default): the cursor glides from row to row, a new screen slides into place, sparks drift up
|
||||||
over the backdrop and Navi bobs in the title band with a pulsing halo (`App.animate`). They move by the time that
|
over the backdrop and Navi bobs in the title band with a pulsing halo (`App.animate`). They move by the time that
|
||||||
passed, stand still while the window is hidden or minimised, and Off stops them all.
|
passed, stand still while the window is hidden or minimised, and Off stops them all.
|
||||||
- Sounds (off by default; Low, Medium or High): the game's own interface sounds, the cursor, decide and cancel
|
- Sounds (off by default; Low, Medium or High): two of the game's own interface sounds, the decide and cancel sounds
|
||||||
sounds of its menus, when the cursor moves or a choice changes, a row is chosen and the player goes back. The
|
of its menus, when a row is chosen or a choice changes and when the player goes back. The launcher decodes them
|
||||||
launcher decodes them from the player's built game or dump into `data/cache/sounds` (`gamefiles.extract_sounds`:
|
from the player's built game or dump into `data/cache/sounds` (`gamefiles.extract_sounds`:
|
||||||
`Sound/Resource/Stream/SE_Sys_Cursor00.bwav`, `SE_Sys_Do00.bwav` and `SE_Sys_Cancel00.bwav`, the files
|
`Sound/Resource/Stream/SE_Sys_Do00.bwav` and `SE_Sys_Cancel00.bwav`, the files `runtime/menu_sound.c` plays in the
|
||||||
`runtime/menu_sound.c` plays in the in-game menu), so no sound ships; until they are decoded, chimes made from sine
|
in-game menu). No sound is in the repository, the release or the setup, and the launcher makes none of its own:
|
||||||
tones in `launcher/ui/sound.py` stand in. They are played from memory (PlaySound on Windows; `pw-play`, `paplay`
|
it is silent until the player's game has been read. Moving the cursor makes no sound. They are played from memory
|
||||||
or `aplay` elsewhere).
|
(PlaySound on Windows; `pw-play`, `paplay` or `aplay` elsewhere).
|
||||||
|
|
||||||
The choices are `theme`, `background`, `background_dim`, `animations` and `sounds` in `data/launcher.json`.
|
The choices are `theme`, `background`, `background_dim`, `animations` and `sounds` in `data/launcher.json`.
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Draft notes for the release after 0.6.1. The version number is not decided yet.
|
|||||||
it takes effect at the next start.
|
it takes effect at the next start.
|
||||||
- Customize Launcher (on the launcher's home screen): six colour schemes, a background picture of your own with
|
- Customize Launcher (on the launcher's home screen): six colour schemes, a background picture of your own with
|
||||||
adjustable dimming, animations (a gliding cursor, sliding screens, drifting sparks) and sound effects: the game's
|
adjustable dimming, animations (a gliding cursor, sliding screens, drifting sparks) and sound effects: the game's
|
||||||
own cursor, select and back sounds, read from your game. The sounds are off until you turn them on.
|
own select and back sounds, read from your game. The sounds are off until you turn them on.
|
||||||
- Three more settings take effect without a restart: HDR between off and the tone mapper (only the game's native
|
- Three more settings take effect without a restart: HDR between off and the tone mapper (only the game's native
|
||||||
HDR still waits for one), the camera's stick sensitivity, and the speakers (stereo or 5.1).
|
HDR still waits for one), the camera's stick sensitivity, and the speakers (stereo or 5.1).
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ FONTS = { # role -> RomFS path; the window sets all its text in Cetra Display
|
|||||||
'title': 'Font2/Scalable/CetraDisplayPro-Medium.Nin_Ounce_NVN2.bfotf.zs',
|
'title': 'Font2/Scalable/CetraDisplayPro-Medium.Nin_Ounce_NVN2.bfotf.zs',
|
||||||
}
|
}
|
||||||
SOUNDS = { # the window's sound effect (launcher/ui/sound.py) -> the game's interface sound
|
SOUNDS = { # the window's sound effect (launcher/ui/sound.py) -> the game's interface sound
|
||||||
'move': 'Sound/Resource/Stream/SE_Sys_Cursor00.bwav',
|
|
||||||
'select': 'Sound/Resource/Stream/SE_Sys_Do00.bwav',
|
'select': 'Sound/Resource/Stream/SE_Sys_Do00.bwav',
|
||||||
'back': 'Sound/Resource/Stream/SE_Sys_Cancel00.bwav',
|
'back': 'Sound/Resource/Stream/SE_Sys_Cancel00.bwav',
|
||||||
}
|
}
|
||||||
@@ -398,8 +397,8 @@ def cached_sounds(layout):
|
|||||||
|
|
||||||
|
|
||||||
def extract_sounds(layout, game_dir='', dump=''):
|
def extract_sounds(layout, game_dir='', dump=''):
|
||||||
"""Decode the game's cursor, select and back sounds into data/cache/sounds as WAV files; {effect: path} of the
|
"""Decode the game's select and back sounds into data/cache/sounds as WAV files; {effect: path} of the ones
|
||||||
ones found."""
|
found."""
|
||||||
romfs = open_romfs(layout, game_dir, dump)
|
romfs = open_romfs(layout, game_dir, dump)
|
||||||
if romfs is None:
|
if romfs is None:
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Mouse, keyboard (arrows, Enter or Space, Esc, F5) and an XInput gamepad (d-pad o
|
|||||||
The look is the player's (Customize Launcher): art.set_theme fills the palette every picture is drawn from, a picture
|
The look is the player's (Customize Launcher): art.set_theme fills the palette every picture is drawn from, a picture
|
||||||
of the player's own can replace the backdrop (picture.py), and unless Animations is off the cursor glides between
|
of the player's own can replace the backdrop (picture.py), and unless Animations is off the cursor glides between
|
||||||
rows, a new screen slides in, sparks drift over the backdrop and Navi bobs in the title band (animate). sound.py
|
rows, a new screen slides in, sparks drift over the backdrop and Navi bobs in the title band (animate). sound.py
|
||||||
plays a short chime for a move, a change, a choice and the end of a job.
|
plays the game's own decide and cancel sounds, read from the player's game, for a choice and for going back.
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import math
|
import math
|
||||||
@@ -482,10 +482,7 @@ class App:
|
|||||||
if not idx:
|
if not idx:
|
||||||
return
|
return
|
||||||
pos = idx.index(self.focus) if self.focus in idx else 0
|
pos = idx.index(self.focus) if self.focus in idx else 0
|
||||||
was = self.focus
|
|
||||||
self.focus = idx[max(0, min(len(idx) - 1, pos + d))]
|
self.focus = idx[max(0, min(len(idx) - 1, pos + d))]
|
||||||
if self.focus != was:
|
|
||||||
self.sounds.play('move')
|
|
||||||
self.render()
|
self.render()
|
||||||
|
|
||||||
def focused(self):
|
def focused(self):
|
||||||
@@ -503,7 +500,8 @@ class App:
|
|||||||
r.pick = max(0, min(len(r.actions) - 1, getattr(r, 'pick', 0) + d))
|
r.pick = max(0, min(len(r.actions) - 1, getattr(r, 'pick', 0) + d))
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
self.sounds.play('move' if r.kind == 'pair' else 'toggle')
|
if r.kind != 'pair': # a switch or a choice changed
|
||||||
|
self.sounds.play('select')
|
||||||
self.render()
|
self.render()
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
@@ -511,10 +509,10 @@ class App:
|
|||||||
if not r or not r.enabled:
|
if not r or not r.enabled:
|
||||||
return
|
return
|
||||||
if r.kind == 'toggle':
|
if r.kind == 'toggle':
|
||||||
self.sounds.play('toggle')
|
self.sounds.play('select')
|
||||||
r.on(not r.get())
|
r.on(not r.get())
|
||||||
elif r.kind == 'enum':
|
elif r.kind == 'enum':
|
||||||
self.sounds.play('toggle')
|
self.sounds.play('select')
|
||||||
r.right()
|
r.right()
|
||||||
elif r.kind == 'pair':
|
elif r.kind == 'pair':
|
||||||
self.sounds.play('select')
|
self.sounds.play('select')
|
||||||
@@ -572,7 +570,6 @@ class App:
|
|||||||
r = self.rows[i]
|
r = self.rows[i]
|
||||||
if r.kind == 'pair':
|
if r.kind == 'pair':
|
||||||
r.pick = 0 if e.x < (r.rect[0] + r.rect[2]) / 2 else 1
|
r.pick = 0 if e.x < (r.rect[0] + r.rect[2]) / 2 else 1
|
||||||
self.sounds.play('move')
|
|
||||||
self.render()
|
self.render()
|
||||||
elif i is not None and self.rows[i].kind == 'pair':
|
elif i is not None and self.rows[i].kind == 'pair':
|
||||||
r = self.rows[i]
|
r = self.rows[i]
|
||||||
@@ -608,12 +605,12 @@ class App:
|
|||||||
return
|
return
|
||||||
if r.kind == 'toggle' and r.value_rect:
|
if r.kind == 'toggle' and r.value_rect:
|
||||||
x0, _, x1, _ = r.value_rect
|
x0, _, x1, _ = r.value_rect
|
||||||
self.sounds.play('toggle')
|
self.sounds.play('select')
|
||||||
r.on(e.x < (x0 + x1) / 2)
|
r.on(e.x < (x0 + x1) / 2)
|
||||||
self.render()
|
self.render()
|
||||||
elif r.kind == 'enum' and r.value_rect:
|
elif r.kind == 'enum' and r.value_rect:
|
||||||
x0, _, x1, _ = r.value_rect
|
x0, _, x1, _ = r.value_rect
|
||||||
self.sounds.play('toggle')
|
self.sounds.play('select')
|
||||||
(r.left if e.x < x0 + (x1 - x0) / 3 else r.right)()
|
(r.left if e.x < x0 + (x1 - x0) / 3 else r.right)()
|
||||||
self.render()
|
self.render()
|
||||||
elif r.kind == 'pair':
|
elif r.kind == 'pair':
|
||||||
@@ -925,7 +922,7 @@ class App:
|
|||||||
self.settings['sounds'] = keys[max(0, min(len(keys) - 1, at + d))]
|
self.settings['sounds'] = keys[max(0, min(len(keys) - 1, at + d))]
|
||||||
self.settings.save()
|
self.settings.save()
|
||||||
self.sounds.set_level(self.settings['sounds'])
|
self.sounds.set_level(self.settings['sounds'])
|
||||||
self.sounds.play('toggle') # the new loudness, heard at once
|
self.sounds.play('select') # the new loudness, heard at once
|
||||||
|
|
||||||
bg_desc = ('Use a picture of your own as the background.',)
|
bg_desc = ('Use a picture of your own as the background.',)
|
||||||
if self.look_message:
|
if self.look_message:
|
||||||
@@ -951,7 +948,7 @@ class App:
|
|||||||
desc=('A gliding cursor, sliding screens and drifting sparks.',)),
|
desc=('A gliding cursor, sliding screens and drifting sparks.',)),
|
||||||
Row('enum', 'Sounds', get=lambda: dict(SOUND_LEVELS).get(self.settings.get('sounds'), 'Off'),
|
Row('enum', 'Sounds', get=lambda: dict(SOUND_LEVELS).get(self.settings.get('sounds'), 'Off'),
|
||||||
left=lambda: sounds(-1), right=lambda: sounds(1),
|
left=lambda: sounds(-1), right=lambda: sounds(1),
|
||||||
desc=('The game\'s cursor, select and back sounds. Off by default.',)),
|
desc=('The game\'s select and back sounds. Off by default.',)),
|
||||||
Row('divider'),
|
Row('divider'),
|
||||||
Row('action', 'Back', on=lambda: self.show('home', self.home_row('Customize Launcher')), height=40,
|
Row('action', 'Back', on=lambda: self.show('home', self.home_row('Customize Launcher')), height=40,
|
||||||
desc=('Back to the main menu.',)),
|
desc=('Back to the main menu.',)),
|
||||||
@@ -973,7 +970,7 @@ class App:
|
|||||||
self.ctx.log(f'background: {path}: {e!r}')
|
self.ctx.log(f'background: {path}: {e!r}')
|
||||||
self.look_message = str(e) if isinstance(e, picture.PictureError) else \
|
self.look_message = str(e) if isinstance(e, picture.PictureError) else \
|
||||||
f'{Path(path).name} could not be used as the background: {e}'
|
f'{Path(path).name} could not be used as the background: {e}'
|
||||||
self.sounds.play('error')
|
self.sounds.play('back')
|
||||||
self.show('customize', self.focus)
|
self.show('customize', self.focus)
|
||||||
return
|
return
|
||||||
self.look_message = ''
|
self.look_message = ''
|
||||||
@@ -1224,7 +1221,7 @@ class App:
|
|||||||
self.render()
|
self.render()
|
||||||
return
|
return
|
||||||
self.ctx.log(f'play: {exe}')
|
self.ctx.log(f'play: {exe}')
|
||||||
self.sounds.play('start')
|
self.sounds.play('select')
|
||||||
if self.settings.get('hide_while_playing'):
|
if self.settings.get('hide_while_playing'):
|
||||||
self.root.withdraw()
|
self.root.withdraw()
|
||||||
self.root.after(1000, self.watch_game)
|
self.root.after(1000, self.watch_game)
|
||||||
@@ -1502,7 +1499,7 @@ class App:
|
|||||||
winsys.keep_awake(False)
|
winsys.keep_awake(False)
|
||||||
self.ctx.log(f'job {j.kind}: {j.result} {j.error}')
|
self.ctx.log(f'job {j.kind}: {j.result} {j.error}')
|
||||||
if j.result in ('ok', 'failed'):
|
if j.result in ('ok', 'failed'):
|
||||||
self.sounds.play('done' if j.result == 'ok' else 'error')
|
self.sounds.play('select' if j.result == 'ok' else 'back')
|
||||||
if j.result == 'ok':
|
if j.result == 'ok':
|
||||||
if j.after == 'restart':
|
if j.after == 'restart':
|
||||||
if winsys.restart(self.layout, ['--continue-update', versions.display(self.layout.version)]):
|
if winsys.restart(self.layout, ['--continue-update', versions.display(self.layout.version)]):
|
||||||
|
|||||||
@@ -1,77 +1,31 @@
|
|||||||
"""The launcher's sound effects: the game's own interface sounds, the ones its menus make for the cursor, a choice
|
"""The launcher's sound effects: two of the game's own interface sounds, the ones its menus make for a choice and for
|
||||||
and going back, read from the player's game (launcher/gamefiles.py extract_sounds decodes them into
|
going back, read from the player's game (launcher/gamefiles.py extract_sounds decodes them into data/cache/sounds, as
|
||||||
data/cache/sounds, as runtime/menu_sound.c plays them in the in-game menu). No sound file ships: until the player's
|
runtime/menu_sound.c plays them in the in-game menu). No sound ships with the launcher and none is made here: until
|
||||||
game has been read, and for a sound it does not hold, short chimes made here from sine tones stand in.
|
the player's game has been read, and for a sound it does not hold, the launcher is silent.
|
||||||
|
|
||||||
They are off until the player picks a loudness in Customize Launcher (the Sounds row). An effect is a 16-bit WAV in
|
They are off until the player picks a loudness in Customize Launcher (the Sounds row). An effect is the game's sound
|
||||||
memory: the game's sound scaled to the loudness (the cursor's a little under the others, as in the game's menu), or a
|
as a 16-bit WAV in memory, scaled to the loudness. Windows plays it with PlaySound from that memory; elsewhere the WAV
|
||||||
few plucked notes (a tone with two overtones, a quick attack and an exponential decay). Windows plays it with
|
goes to a file in the cache folder and the first of pw-play, paplay and aplay found plays it. One effect sounds at a
|
||||||
PlaySound from that memory; elsewhere the WAV goes to a file in the cache folder and the first of pw-play, paplay
|
time: a new one cuts the last. Moving the cursor makes no sound, as it would cut a choice's sound short every time
|
||||||
and aplay found plays it. One effect sounds at a time: a new one cuts the last, so the cursor's sound is left out
|
the pointer lands on a row of the next screen.
|
||||||
for a quarter of a second after a choice, which the pointer landing on a row of the next screen would otherwise cut.
|
|
||||||
|
|
||||||
move the cursor went to another row the game's cursor sound
|
select a row was chosen, a switch or a choice changed, Play, the end of a build the game's decide sound
|
||||||
toggle a switch or a choice changed the cursor sound
|
back back to the screen before, something could not be done the game's cancel sound
|
||||||
select a row was chosen (another screen) the game's decide sound
|
|
||||||
back back to the screen before the game's cancel sound
|
|
||||||
start Play the decide sound
|
|
||||||
done an install, update or rebuild finished the decide sound
|
|
||||||
error something could not be done the cancel sound
|
|
||||||
"""
|
"""
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
RATE = 44100
|
|
||||||
LEVELS = {'off': 0.0, 'low': 0.18, 'medium': 0.4, 'high': 0.75} # the Sounds choice: the loudest sample's share of full scale
|
LEVELS = {'off': 0.0, 'low': 0.18, 'medium': 0.4, 'high': 0.75} # the Sounds choice: the loudest sample's share of full scale
|
||||||
# Which of the game's sounds (gamefiles.SOUNDS) each effect plays, and how loud beside the others.
|
EFFECTS = ('select', 'back') # the names play takes: the game's sounds of gamefiles.SOUNDS
|
||||||
GAME_SOUND = {'move': ('move', 0.6), 'toggle': ('move', 0.6), 'select': ('select', 1.0), 'start': ('select', 1.0),
|
|
||||||
'done': ('select', 1.0), 'back': ('back', 1.0), 'error': ('back', 1.0)}
|
|
||||||
QUIET_AFTER = 0.25 # seconds after a choice in which the cursor's sound is left out
|
|
||||||
|
|
||||||
# Notes as (start in seconds, frequency in Hz, length in seconds, loudness 0..1).
|
|
||||||
C5, D5, E5, G5, A5, C6, D6, E6, G6, C7 = 523.25, 587.33, 659.25, 783.99, 880.0, 1046.5, 1174.66, 1318.51, 1567.98, 2093.0
|
|
||||||
EFFECTS = {
|
|
||||||
'move': [(0, E6, 0.07, 0.55)],
|
|
||||||
'toggle': [(0, G5, 0.10, 0.8), (0.035, D6, 0.10, 0.5)],
|
|
||||||
'select': [(0, C6, 0.12, 0.8), (0.07, G6, 0.20, 0.8)],
|
|
||||||
'back': [(0, G5, 0.12, 0.8), (0.07, C5, 0.20, 0.7)],
|
|
||||||
'start': [(0, C6, 0.14, 0.7), (0.08, E6, 0.14, 0.7), (0.16, G6, 0.14, 0.7), (0.24, C7, 0.45, 0.8)],
|
|
||||||
'done': [(0, G5, 0.16, 0.8), (0.12, C6, 0.16, 0.8), (0.24, E6, 0.16, 0.8), (0.36, G6, 0.5, 0.9)],
|
|
||||||
'error': [(0, 220.0, 0.16, 0.9), (0.14, 174.61, 0.3, 0.9)],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def pluck(freq, length, loudness):
|
def wav_bytes(samples, level, rate, channels):
|
||||||
"""One note: the tone and two quieter overtones, in within 4 ms and dying away over its length."""
|
"""A 16-bit WAV of samples (-1..1, interleaved when there are two channels) at level (0..1 of full scale)."""
|
||||||
n = int(RATE * length)
|
|
||||||
t = np.arange(n, dtype=np.float32) / RATE
|
|
||||||
wave = np.sin(2 * np.pi * freq * t) + 0.35 * np.sin(2 * np.pi * 2 * freq * t) + 0.12 * np.sin(2 * np.pi * 3 * freq * t)
|
|
||||||
env = np.minimum(t / 0.004, 1) * np.exp(-t * 5.5 / length)
|
|
||||||
tail = np.minimum((length - t) / 0.01, 1) # the last 10 ms go to nothing, so the end does not click
|
|
||||||
return wave * env * tail * loudness
|
|
||||||
|
|
||||||
|
|
||||||
def synth(name):
|
|
||||||
"""The effect's samples in -1..1, its loudest at 1."""
|
|
||||||
notes = EFFECTS[name]
|
|
||||||
total = int(RATE * max(start + length for start, _f, length, _l in notes)) + 1
|
|
||||||
out = np.zeros(total, dtype=np.float32)
|
|
||||||
for start, freq, length, loudness in notes:
|
|
||||||
note = pluck(freq, length, loudness)
|
|
||||||
at = int(RATE * start)
|
|
||||||
out[at:at + len(note)] += note
|
|
||||||
peak = float(np.abs(out).max())
|
|
||||||
return out / peak if peak > 0 else out
|
|
||||||
|
|
||||||
|
|
||||||
def wav_bytes(samples, level, rate=RATE, channels=1):
|
|
||||||
"""A 16-bit WAV of samples (-1..1; frames by channels when there are two) at level (0..1 of full scale)."""
|
|
||||||
pcm = (np.clip(samples * level, -1, 1) * 32767).astype('<i2').tobytes()
|
pcm = (np.clip(samples * level, -1, 1) * 32767).astype('<i2').tobytes()
|
||||||
return (b'RIFF' + struct.pack('<I', 36 + len(pcm)) + b'WAVEfmt '
|
return (b'RIFF' + struct.pack('<I', 36 + len(pcm)) + b'WAVEfmt '
|
||||||
+ struct.pack('<IHHIIHH', 16, 1, channels, rate, rate * 2 * channels, 2 * channels, 16)
|
+ struct.pack('<IHHIIHH', 16, 1, channels, rate, rate * 2 * channels, 2 * channels, 16)
|
||||||
@@ -101,7 +55,6 @@ class Sounds:
|
|||||||
self.log = log or (lambda line: None)
|
self.log = log or (lambda line: None)
|
||||||
self.level = None # set_level below: 'off' unless the player chose a loudness
|
self.level = None # set_level below: 'off' unless the player chose a loudness
|
||||||
self.game = {} # the game's sounds decoded from the player's files: name -> (rate, channels, samples)
|
self.game = {} # the game's sounds decoded from the player's files: name -> (rate, channels, samples)
|
||||||
self.last_choice = 0.0 # when a sound other than the cursor's last started
|
|
||||||
self.wavs = {} # name -> WAV bytes at the current level (Windows plays from this memory: it must stay)
|
self.wavs = {} # name -> WAV bytes at the current level (Windows plays from this memory: it must stay)
|
||||||
self.files = {} # name -> the WAV file elsewhere
|
self.files = {} # name -> the WAV file elsewhere
|
||||||
self.player = None # elsewhere: the program that plays a WAV file
|
self.player = None # elsewhere: the program that plays a WAV file
|
||||||
@@ -122,7 +75,7 @@ class Sounds:
|
|||||||
def load_game(self):
|
def load_game(self):
|
||||||
"""Takes up the game's sounds decoded into <cache>/sounds (again after gamefiles.extract_sounds wrote them)."""
|
"""Takes up the game's sounds decoded into <cache>/sounds (again after gamefiles.extract_sounds wrote them)."""
|
||||||
game = {}
|
game = {}
|
||||||
for name in {g for g, _gain in GAME_SOUND.values()}:
|
for name in EFFECTS:
|
||||||
try:
|
try:
|
||||||
got = read_wav((self.cache / 'sounds' / f'{name}.wav').read_bytes())
|
got = read_wav((self.cache / 'sounds' / f'{name}.wav').read_bytes())
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -144,12 +97,8 @@ class Sounds:
|
|||||||
|
|
||||||
def wav(self, name):
|
def wav(self, name):
|
||||||
if name not in self.wavs:
|
if name not in self.wavs:
|
||||||
source, gain = GAME_SOUND[name]
|
rate, channels, samples = self.game[name]
|
||||||
if source in self.game:
|
self.wavs[name] = wav_bytes(samples, LEVELS[self.level], rate, channels)
|
||||||
rate, channels, samples = self.game[source]
|
|
||||||
self.wavs[name] = wav_bytes(samples, LEVELS[self.level] * gain, rate, channels)
|
|
||||||
else:
|
|
||||||
self.wavs[name] = wav_bytes(synth(name), LEVELS[self.level])
|
|
||||||
return self.wavs[name]
|
return self.wavs[name]
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@@ -161,14 +110,8 @@ class Sounds:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def play(self, name):
|
def play(self, name):
|
||||||
if LEVELS.get(self.level, 0) <= 0 or self.failed or name not in EFFECTS:
|
if LEVELS.get(self.level, 0) <= 0 or self.failed or name not in self.game:
|
||||||
return
|
return
|
||||||
now = time.monotonic()
|
|
||||||
if GAME_SOUND[name][0] == 'move':
|
|
||||||
if now - self.last_choice < QUIET_AFTER:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
self.last_choice = now
|
|
||||||
try:
|
try:
|
||||||
if self.winmm:
|
if self.winmm:
|
||||||
# SND_ASYNC | SND_NODEFAULT | SND_MEMORY: PlaySound reads the bytes while it plays, and self.wavs
|
# SND_ASYNC | SND_NODEFAULT | SND_MEMORY: PlaySound reads the bytes while it plays, and self.wavs
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Run: python tests/launcher_test.py (Python 3.14 for the zstd tests; the window
|
|||||||
step with the system's C compiler, and its windres call under folders with spaces (a script in windres's place)
|
step with the system's C compiler, and its windres call under folders with spaces (a script in windres's place)
|
||||||
- jobs: an install driven by a fake make_game.py, with and without the prompts row
|
- jobs: an install driven by a fake make_game.py, with and without the prompts row
|
||||||
- the look: the colour schemes, the background picture's fitting and kept copy, the sound effects (off by default,
|
- the look: the colour schemes, the background picture's fitting and kept copy, the sound effects (off by default,
|
||||||
the game's own interface sounds decoded from a made-up .bwav)
|
only the game's own select and back sounds, decoded from a made-up .bwav)
|
||||||
- the window: --selftest draws every screen (skipped without a display)
|
- the window: --selftest draws every screen (skipped without a display)
|
||||||
"""
|
"""
|
||||||
import contextlib
|
import contextlib
|
||||||
@@ -2514,42 +2514,6 @@ class LookTest(Tmp):
|
|||||||
with self.assertRaises(self.picture.PictureError):
|
with self.assertRaises(self.picture.PictureError):
|
||||||
self.picture.read_ppm(b'P5\n1 1\n255\n\0')
|
self.picture.read_ppm(b'P5\n1 1\n255\n\0')
|
||||||
|
|
||||||
def test_the_effects_are_short_wavs(self):
|
|
||||||
sound = self.sound
|
|
||||||
for name in sound.EFFECTS:
|
|
||||||
samples = sound.synth(name)
|
|
||||||
self.assertAlmostEqual(float(abs(samples).max()), 1.0, places=5, msg=name)
|
|
||||||
self.assertLess(len(samples) / sound.RATE, 1.0, name)
|
|
||||||
self.assertLess(abs(float(samples[-1])), 0.01, name) # it ends at nothing: no click
|
|
||||||
wav = sound.wav_bytes(samples, 0.4)
|
|
||||||
self.assertEqual(wav[:4] + wav[8:16], b'RIFFWAVEfmt ')
|
|
||||||
self.assertEqual(struct.unpack_from('<I', wav, 4)[0], len(wav) - 8)
|
|
||||||
self.assertEqual(struct.unpack_from('<HHIIHH', wav, 20), (1, 1, sound.RATE, sound.RATE * 2, 2, 16))
|
|
||||||
peak = max(abs(v) for v in struct.unpack_from(f'<{len(samples)}h', wav, 44))
|
|
||||||
self.assertAlmostEqual(peak / 32767, 0.4, delta=0.01)
|
|
||||||
|
|
||||||
def test_sounds_are_off_until_the_player_turns_them_on(self):
|
|
||||||
sound = self.sound
|
|
||||||
self.assertEqual(settings.DEFAULTS['sounds'], 'off')
|
|
||||||
with mock.patch.object(sound.os, 'name', 'posix'), mock.patch.object(sound.shutil, 'which',
|
|
||||||
return_value='/usr/bin/aplay'), \
|
|
||||||
mock.patch.object(sound.subprocess, 'Popen') as popen:
|
|
||||||
s = sound.Sounds(self.tmp) # no level given, as a new launcher.json has it
|
|
||||||
s.play('move')
|
|
||||||
popen.assert_not_called()
|
|
||||||
s.set_level('nonsense') # a level launcher.json cannot hold: off
|
|
||||||
s.play('move')
|
|
||||||
popen.assert_not_called()
|
|
||||||
s.set_level('low')
|
|
||||||
s.play('move')
|
|
||||||
s.play('no such effect')
|
|
||||||
popen.assert_called_once()
|
|
||||||
path = Path(popen.call_args[0][0][1])
|
|
||||||
self.assertEqual(path.read_bytes()[:4], b'RIFF')
|
|
||||||
s.set_level('off')
|
|
||||||
s.play('move')
|
|
||||||
popen.assert_called_once()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bwav(channels, rate=48000):
|
def bwav(channels, rate=48000):
|
||||||
"""A .bwav of channels given as (codec, pan, samples, data): the header, 0x4c bytes a channel, the data."""
|
"""A .bwav of channels given as (codec, pan, samples, data): the header, 0x4c bytes a channel, the data."""
|
||||||
@@ -2565,6 +2529,18 @@ class LookTest(Tmp):
|
|||||||
out += data
|
out += data
|
||||||
return bytes(out)
|
return bytes(out)
|
||||||
|
|
||||||
|
def game_sounds(self, names=('Do', 'Cancel')):
|
||||||
|
"""A dump folder whose RomFS holds the given interface sounds; decoded into this layout's cache."""
|
||||||
|
dump = self.tmp / 'dump'
|
||||||
|
(dump / 'exefs').mkdir(parents=True, exist_ok=True)
|
||||||
|
(dump / 'exefs' / 'main').write_bytes(b'')
|
||||||
|
stream = dump / 'romfs' / 'Sound' / 'Resource' / 'Stream'
|
||||||
|
stream.mkdir(parents=True, exist_ok=True)
|
||||||
|
loud = struct.pack('<4h', 0, 16000, -16000, 8000)
|
||||||
|
for name in names:
|
||||||
|
(stream / f'SE_Sys_{name}00.bwav').write_bytes(self.bwav([(0, 0, 4, loud), (0, 1, 4, loud)]))
|
||||||
|
return gamefiles.extract_sounds(self.layout, '', str(dump))
|
||||||
|
|
||||||
def test_the_games_interface_sounds(self):
|
def test_the_games_interface_sounds(self):
|
||||||
sound = self.sound
|
sound = self.sound
|
||||||
# one PCM16 channel in the middle: both sides, at 0.707
|
# one PCM16 channel in the middle: both sides, at 0.707
|
||||||
@@ -2577,42 +2553,53 @@ class LookTest(Tmp):
|
|||||||
self.assertEqual(gamefiles.bwav_to_pcm(both), (48000, [(256, 256), (-256, -256), (1792, 0)]))
|
self.assertEqual(gamefiles.bwav_to_pcm(both), (48000, [(256, 256), (-256, -256), (1792, 0)]))
|
||||||
for bad in (b'', b'RIFF' + bytes(60), mono[:0x30], self.bwav([(7, 2, 3, bytes(6))]), mono[:-2]):
|
for bad in (b'', b'RIFF' + bytes(60), mono[:0x30], self.bwav([(7, 2, 3, bytes(6))]), mono[:-2]):
|
||||||
self.assertIsNone(gamefiles.bwav_to_pcm(bad))
|
self.assertIsNone(gamefiles.bwav_to_pcm(bad))
|
||||||
# from a dump folder into data/cache/sounds, and from there into the effects
|
# from a dump folder into data/cache/sounds, and from there into the effects: the decide sound only here
|
||||||
dump = self.tmp / 'dump'
|
got = self.game_sounds(('Do',))
|
||||||
(dump / 'exefs').mkdir(parents=True)
|
(self.tmp / 'dump' / 'romfs' / 'Sound' / 'Resource' / 'Stream' / 'SE_Sys_Cancel00.bwav').write_bytes(b'no sound')
|
||||||
(dump / 'exefs' / 'main').write_bytes(b'')
|
self.assertEqual(set(got), {'select'})
|
||||||
stream = dump / 'romfs' / 'Sound' / 'Resource' / 'Stream'
|
|
||||||
stream.mkdir(parents=True)
|
|
||||||
loud = struct.pack('<4h', 0, 16000, -16000, 8000)
|
|
||||||
(stream / 'SE_Sys_Cursor00.bwav').write_bytes(self.bwav([(0, 0, 4, loud), (0, 1, 4, loud)]))
|
|
||||||
(stream / 'SE_Sys_Do00.bwav').write_bytes(b'not a sound')
|
|
||||||
got = gamefiles.extract_sounds(self.layout, '', str(dump))
|
|
||||||
self.assertEqual(set(got), {'move'})
|
|
||||||
self.assertEqual(gamefiles.cached_sounds(self.layout), got)
|
self.assertEqual(gamefiles.cached_sounds(self.layout), got)
|
||||||
with mock.patch.object(sound.os, 'name', 'posix'), mock.patch.object(sound.shutil, 'which', return_value=None):
|
with mock.patch.object(sound.os, 'name', 'posix'), mock.patch.object(sound.shutil, 'which', return_value=None):
|
||||||
s = sound.Sounds(self.layout.cache, 'high')
|
s = sound.Sounds(self.layout.cache, 'high')
|
||||||
self.assertEqual(set(s.game), {'move'})
|
self.assertEqual(set(s.game), {'select'})
|
||||||
wav = s.wav('toggle') # the cursor's sound: the game's, stereo at its rate
|
wav = s.wav('select') # the game's sound: stereo at its rate, at the level
|
||||||
|
self.assertEqual(wav[:4] + wav[8:16], b'RIFFWAVEfmt ')
|
||||||
|
self.assertEqual(struct.unpack_from('<I', wav, 4)[0], len(wav) - 8)
|
||||||
self.assertEqual(struct.unpack_from('<HHI', wav, 20), (1, 2, 48000))
|
self.assertEqual(struct.unpack_from('<HHI', wav, 20), (1, 2, 48000))
|
||||||
peak = max(abs(v) for v in struct.unpack_from('<8h', wav, 44))
|
peak = max(abs(v) for v in struct.unpack_from('<8h', wav, 44))
|
||||||
self.assertAlmostEqual(peak / 32767, sound.LEVELS['high'] * 0.6, delta=0.01)
|
self.assertAlmostEqual(peak / 32767, sound.LEVELS['high'], delta=0.01)
|
||||||
self.assertEqual(struct.unpack_from('<HHI', s.wav('select'), 20), (1, 1, sound.RATE)) # no decide sound: the chime
|
|
||||||
self.assertFalse(sound.Sounds(self.tmp / 'empty', 'high').game)
|
self.assertFalse(sound.Sounds(self.tmp / 'empty', 'high').game)
|
||||||
|
|
||||||
def test_the_cursor_is_quiet_right_after_a_choice(self):
|
def test_only_the_games_sounds_play_and_only_once_turned_on(self):
|
||||||
sound = self.sound
|
sound = self.sound
|
||||||
|
self.assertEqual(settings.DEFAULTS['sounds'], 'off')
|
||||||
|
self.assertEqual(set(gamefiles.SOUNDS), set(sound.EFFECTS))
|
||||||
|
empty = self.tmp / 'empty'
|
||||||
|
self.game_sounds()
|
||||||
with mock.patch.object(sound.os, 'name', 'posix'), mock.patch.object(sound.shutil, 'which',
|
with mock.patch.object(sound.os, 'name', 'posix'), mock.patch.object(sound.shutil, 'which',
|
||||||
return_value='/usr/bin/aplay'), \
|
return_value='/usr/bin/aplay'), \
|
||||||
mock.patch.object(sound.subprocess, 'Popen') as popen, \
|
mock.patch.object(sound.subprocess, 'Popen') as popen:
|
||||||
mock.patch.object(sound.time, 'monotonic') as clock:
|
quiet = sound.Sounds(empty, 'high') # before the game has been read: nothing to play
|
||||||
clock.return_value = 100.0
|
quiet.play('select')
|
||||||
s = sound.Sounds(self.tmp, 'low')
|
quiet.play('back')
|
||||||
s.play('select')
|
popen.assert_not_called()
|
||||||
clock.return_value = 100.1
|
quiet.cache = self.layout.cache
|
||||||
s.play('move') # the pointer landing on the next screen's row
|
self.assertTrue(quiet.load_game()) # the game's sounds, once decoded
|
||||||
|
quiet.play('select')
|
||||||
self.assertEqual(popen.call_count, 1)
|
self.assertEqual(popen.call_count, 1)
|
||||||
clock.return_value = 100.4
|
s = sound.Sounds(self.layout.cache) # no level given, as a new launcher.json has it
|
||||||
s.play('move')
|
s.play('select')
|
||||||
|
s.set_level('nonsense') # a level launcher.json cannot hold: off
|
||||||
|
s.play('select')
|
||||||
|
self.assertEqual(popen.call_count, 1)
|
||||||
|
s.set_level('low')
|
||||||
|
s.play('back')
|
||||||
|
s.play('move') # the cursor has no sound
|
||||||
|
s.play('no such effect')
|
||||||
|
self.assertEqual(popen.call_count, 2)
|
||||||
|
with open(popen.call_args[0][0][1], 'rb') as f:
|
||||||
|
self.assertEqual(f.read(4), b'RIFF')
|
||||||
|
s.set_level('off')
|
||||||
|
s.play('select')
|
||||||
self.assertEqual(popen.call_count, 2)
|
self.assertEqual(popen.call_count, 2)
|
||||||
|
|
||||||
def test_the_look_settings_survive_and_fall_back(self):
|
def test_the_look_settings_survive_and_fall_back(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user