mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-01 22:23:41 +08:00
Mustang and Supra
This commit is contained in:
@@ -23519,6 +23519,10 @@ msgstr ""
|
||||
msgid "Mustang GT"
|
||||
msgstr ""
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr ""
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr ""
|
||||
|
||||
@@ -23538,6 +23538,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -23538,6 +23538,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -23538,6 +23538,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -23534,6 +23534,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -23534,6 +23534,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -23534,6 +23534,10 @@ msgstr "Hellcat"
|
||||
msgid "Mustang GT"
|
||||
msgstr "Mustang GT"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "Supra Turbo"
|
||||
msgstr "Supra Turbo"
|
||||
|
||||
#: openpilot/starpilot/engine_sound/profiles.py
|
||||
msgid "LFA"
|
||||
msgstr "LFA"
|
||||
|
||||
@@ -8,13 +8,15 @@ commit 85f7c3b959a908ed5232ede4f1a4ac7eafe6b630), recorded with tools/esrec:
|
||||
f1_car assets/engines/atg-video-2/12_ferrari_412_t2.mr
|
||||
ferrari_f136 assets/engines/atg-video-2/08_ferrari_f136_v8.mr
|
||||
lfa assets/engines/atg-video-2/10_lfa_v10.mr
|
||||
supra_turbo assets/engines/atg-video-2/03_2jz.mr
|
||||
|
||||
From recordings of real cars supplied for this project, built with tools/bank_from_recording.py and equalised with
|
||||
tools/lower_bank.py --pitch 1.0 --off-mix 0 --off-mid 0:
|
||||
|
||||
hellcat hellcat.wav: --cylinders 8 --anchor 14 700 --idle 10.5-17.5 --on 25-94 --off 94-119
|
||||
mustang_gt mustanggt3.wav: --cylinders 8 --anchor 5 893 --anchor 48 835 --idle 42.5-54.5 --on 22-41 56-84
|
||||
--off 22-41 56-84
|
||||
mustang_gt Mustanggt4.wav: --cylinders 8 --half-orders --anchor 89 1900 --on 28-124 --off 28-124, above 1150 rpm;
|
||||
idle loops (833 rpm) from mustanggt3.wav: --cylinders 8 --anchor 5 893 --anchor 48 835 --idle 42.5-54.5
|
||||
--on 22-41 56-84 --off 22-41 56-84; the two were re-levelled together on the bank's rpm curve
|
||||
|
||||
engine-sim is distributed under the following license:
|
||||
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
{
|
||||
"version": 1,
|
||||
"source": "recording mustanggt3.wav",
|
||||
"source": "recordings mustanggt4.wav, idle from mustanggt3.wav",
|
||||
"layers": {
|
||||
"off": [
|
||||
{
|
||||
"rpm": 750,
|
||||
"file": "off_750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 833,
|
||||
"file": "off_833.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1000,
|
||||
"file": "off_1000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1250,
|
||||
"file": "off_1250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1500,
|
||||
"file": "off_1500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1750,
|
||||
"file": "off_1750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2000,
|
||||
"file": "off_2000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2250,
|
||||
"file": "off_2250.wav"
|
||||
@@ -46,32 +42,60 @@
|
||||
{
|
||||
"rpm": 3500,
|
||||
"file": "off_3500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 3750,
|
||||
"file": "off_3750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4000,
|
||||
"file": "off_4000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4250,
|
||||
"file": "off_4250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4500,
|
||||
"file": "off_4500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4750,
|
||||
"file": "off_4750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5000,
|
||||
"file": "off_5000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5250,
|
||||
"file": "off_5250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5500,
|
||||
"file": "off_5500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5750,
|
||||
"file": "off_5750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 6000,
|
||||
"file": "off_6000.wav"
|
||||
}
|
||||
],
|
||||
"on": [
|
||||
{
|
||||
"rpm": 750,
|
||||
"file": "on_750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 833,
|
||||
"file": "on_833.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1000,
|
||||
"file": "on_1000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1250,
|
||||
"file": "on_1250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1500,
|
||||
"file": "on_1500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2000,
|
||||
"file": "on_2000.wav"
|
||||
"rpm": 1750,
|
||||
"file": "on_1750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2250,
|
||||
@@ -90,12 +114,44 @@
|
||||
"file": "on_3000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 3250,
|
||||
"file": "on_3250.wav"
|
||||
"rpm": 3750,
|
||||
"file": "on_3750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 3500,
|
||||
"file": "on_3500.wav"
|
||||
"rpm": 4000,
|
||||
"file": "on_4000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4250,
|
||||
"file": "on_4250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4500,
|
||||
"file": "on_4500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4750,
|
||||
"file": "on_4750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5000,
|
||||
"file": "on_5000.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5250,
|
||||
"file": "on_5250.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5500,
|
||||
"file": "on_5500.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5750,
|
||||
"file": "on_5750.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 6000,
|
||||
"file": "on_6000.wav"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"version": 1,
|
||||
"source": "engine-sim engines/atg-video-2/03_2jz.mr",
|
||||
"layers": {
|
||||
"on": [
|
||||
{
|
||||
"rpm": 1200,
|
||||
"file": "on_1200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1950,
|
||||
"file": "on_1950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2700,
|
||||
"file": "on_2700.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 3450,
|
||||
"file": "on_3450.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4200,
|
||||
"file": "on_4200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4950,
|
||||
"file": "on_4950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5700,
|
||||
"file": "on_5700.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 6450,
|
||||
"file": "on_6450.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 7200,
|
||||
"file": "on_7200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 7950,
|
||||
"file": "on_7950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 8700,
|
||||
"file": "on_8700.wav"
|
||||
}
|
||||
],
|
||||
"off": [
|
||||
{
|
||||
"rpm": 1200,
|
||||
"file": "off_1200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 1950,
|
||||
"file": "off_1950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 2700,
|
||||
"file": "off_2700.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 3450,
|
||||
"file": "off_3450.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4200,
|
||||
"file": "off_4200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 4950,
|
||||
"file": "off_4950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 5700,
|
||||
"file": "off_5700.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 6450,
|
||||
"file": "off_6450.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 7200,
|
||||
"file": "off_7200.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 7950,
|
||||
"file": "off_7950.wav"
|
||||
},
|
||||
{
|
||||
"rpm": 8700,
|
||||
"file": "off_8700.wav"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
"""Sound layers mixed over a profile's engine voice."""
|
||||
from __future__ import annotations
|
||||
|
||||
from openpilot.starpilot.engine_sound.pops import Pops
|
||||
from openpilot.starpilot.engine_sound.profiles import Profile
|
||||
from openpilot.starpilot.engine_sound.turbo import Turbo
|
||||
|
||||
|
||||
def layers(profile: Profile, sample_rate: int) -> list:
|
||||
out: list = []
|
||||
if profile.pops:
|
||||
out.append(Pops(profile.pops, profile.idle_rpm, profile.redline_rpm, sample_rate))
|
||||
if profile.turbo:
|
||||
out.append(Turbo(profile.turbo, profile.idle_rpm, profile.redline_rpm, sample_rate))
|
||||
return out
|
||||
@@ -13,7 +13,7 @@ from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openpilot.starpilot.engine_sound.pops import Pops
|
||||
from openpilot.starpilot.engine_sound import effects
|
||||
from openpilot.starpilot.engine_sound.profiles import Profile
|
||||
from openpilot.starpilot.engine_sound.synth import SAMPLE_RATE
|
||||
|
||||
@@ -87,7 +87,7 @@ class LoopSynth:
|
||||
self.rpm = profile.idle_rpm
|
||||
self.load = 0.0
|
||||
self.gain = 0.0
|
||||
self.pops = Pops(profile.pops, profile.idle_rpm, profile.redline_rpm, sample_rate) if profile.pops else None
|
||||
self.effects = effects.layers(profile, sample_rate)
|
||||
|
||||
def _layer(self, layer: str, rpm: np.ndarray) -> np.ndarray:
|
||||
points, loops = self.bank[layer]
|
||||
@@ -126,6 +126,6 @@ class LoopSynth:
|
||||
out = on * np.sqrt(load_ramp) + off * np.sqrt(1 - load_ramp)
|
||||
self.rpm, self.load, self.gain = rpm, load, target_gain
|
||||
out = out * gain
|
||||
if self.pops is not None:
|
||||
out = out + self.pops.render(rpm, load, frames, volume)
|
||||
for layer in self.effects:
|
||||
out = out + layer.render(rpm, load, frames, volume)
|
||||
return np.tanh(out).astype(np.float32)
|
||||
|
||||
@@ -38,6 +38,7 @@ class Profile:
|
||||
tremolo: tuple[float, float] = (0.0, 0.0) # rate in Hz, depth
|
||||
gain: tuple[float, float] = (0.35, 1.0) # loudness at no load and full load
|
||||
pops: float = 0.0 # overrun pops and crackle, 0 none to 1 heavy
|
||||
turbo: float = 0.0 # turbo whistle and blow-off valve, 0 none to 1 loud
|
||||
|
||||
|
||||
def _engine_partials(firing: int, count: int, rough: float, bright: float) -> tuple[tuple[int, float, float], ...]:
|
||||
@@ -56,11 +57,12 @@ RACE_GEARS = (520.0, 340.0, 250.0, 198.0, 165.0, 142.0)
|
||||
RACE_REDLINE = 8600.0
|
||||
|
||||
|
||||
def _recorded(name: str, label: str, *, cylinders: int, idle: float, redline: float, loops: str = '', pops: float = 0.0) -> Profile:
|
||||
def _recorded(name: str, label: str, *, cylinders: int, idle: float, redline: float, loops: str = '', pops: float = 0.0,
|
||||
turbo: float = 0.0) -> Profile:
|
||||
"""A bundled loop bank (of the same name unless given), geared like the race car but scaled to its own rev range."""
|
||||
scale = redline / RACE_REDLINE
|
||||
return Profile(
|
||||
name=name, label=label, loops=loops or name, pops=pops,
|
||||
name=name, label=label, loops=loops or name, pops=pops, turbo=turbo,
|
||||
idle_rpm=idle, redline_rpm=redline,
|
||||
gears=tuple(ratio * scale for ratio in RACE_GEARS),
|
||||
upshift_rpm=(0.38 * redline, 0.96 * redline), downshift_rpm=(0.2 * redline, 0.6 * redline),
|
||||
@@ -75,10 +77,11 @@ PROFILES: dict[str, Profile] = {profile.name: profile for profile in (
|
||||
_recorded('bmw_m52', 'BMW M52', cylinders=6, idle=700.0, redline=7000.0),
|
||||
_recorded('f1_car', 'F1 Car', cylinders=12, idle=2000.0, redline=17000.0),
|
||||
_recorded('ferrari_f136', 'Ferrari F136', cylinders=8, idle=1000.0, redline=9000.0),
|
||||
# Banks from real recordings that end at 3000 and 3500 rpm; above about 1.5 times that the loops sound sped up.
|
||||
# Banks from real recordings that end at 3000 and 6000 rpm; above about 1.5 times that the loops sound sped up.
|
||||
_recorded('hellcat', 'Hellcat', cylinders=8, idle=700.0, redline=4500.0),
|
||||
_recorded('lfa', 'LFA', cylinders=10, idle=1000.0, redline=9000.0),
|
||||
_recorded('mustang_gt', 'Mustang GT', cylinders=8, idle=835.0, redline=5250.0),
|
||||
_recorded('mustang_gt', 'Mustang GT', cylinders=8, idle=835.0, redline=7000.0),
|
||||
_recorded('supra_turbo', 'Supra Turbo', cylinders=6, idle=800.0, redline=6000.0, turbo=1.0),
|
||||
)}
|
||||
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ class Synth:
|
||||
self.frequency = profile.idle_rpm * profile.pitch
|
||||
self.load = 0.0
|
||||
self.gain = 0.0
|
||||
from openpilot.starpilot.engine_sound.pops import Pops
|
||||
self.pops = Pops(profile.pops, profile.idle_rpm, profile.redline_rpm, sample_rate) if profile.pops else None
|
||||
from openpilot.starpilot.engine_sound import effects
|
||||
self.effects = effects.layers(profile, sample_rate)
|
||||
|
||||
def _lookup(self, table: np.ndarray, phase: np.ndarray) -> np.ndarray:
|
||||
position = (phase % 1.0) * TABLE_SIZE
|
||||
@@ -84,8 +84,8 @@ class Synth:
|
||||
self.phase = float(phase[-1] % 1.0)
|
||||
self.frequency, self.load, self.gain = float(frequency[-1]), load, target_gain
|
||||
out = 0.8 * out * gain
|
||||
if self.pops is not None:
|
||||
out = out + self.pops.render(rpm, load, frames, volume)
|
||||
for layer in self.effects:
|
||||
out = out + layer.render(rpm, load, frames, volume)
|
||||
return np.tanh(out).astype(np.float32)
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ def test_quiet_at_zero_volume_and_profiles_without_pops_are_unchanged(tmp_path):
|
||||
assert not np.concatenate([pops.render(6000.0, load, FRAMES, 0.0) for load in [1.0] * 50 + [0.0] * 100]).any()
|
||||
bank = load_bank(make_bank(tmp_path))
|
||||
plain = LoopSynth(PROFILES['bmw_m52'], bank)
|
||||
assert plain.pops is None
|
||||
assert plain.effects == []
|
||||
popping = LoopSynth(replace(PROFILES['bmw_m52'], pops=1.0), bank)
|
||||
steps = [(5000.0, 1.0)] * 50 + [(5000.0 - 20 * i, 0.0) for i in range(150)]
|
||||
quiet = np.concatenate([plain.render(rpm, load, FRAMES, 1.0) for rpm, load in steps])
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
from dataclasses import replace
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openpilot.starpilot.engine_sound.loops import LoopSynth, load_bank
|
||||
from openpilot.starpilot.engine_sound.profiles import PROFILES
|
||||
from openpilot.starpilot.engine_sound.tests.test_loops import make_bank
|
||||
from openpilot.starpilot.engine_sound.turbo import BOV_FROM, Turbo
|
||||
|
||||
FRAMES = 480
|
||||
|
||||
|
||||
def run(turbo, steps, volume=1.0):
|
||||
return np.concatenate([turbo.render(rpm, load, FRAMES, volume) for rpm, load in steps])
|
||||
|
||||
|
||||
def test_boost_lags_the_throttle_and_needs_revs():
|
||||
turbo = Turbo(1.0, 800.0, 6000.0)
|
||||
run(turbo, [(4000.0, 1.0)] * 10)
|
||||
early = turbo.boost
|
||||
run(turbo, [(4000.0, 1.0)] * 150)
|
||||
assert early < 0.25 < 0.8 < turbo.boost
|
||||
low = Turbo(1.0, 800.0, 6000.0)
|
||||
run(low, [(850.0, 1.0)] * 200)
|
||||
assert low.boost == 0.0
|
||||
|
||||
|
||||
def test_lifting_on_boost_fires_the_valve_and_vents_it():
|
||||
turbo = Turbo(1.0, 800.0, 6000.0)
|
||||
run(turbo, [(4000.0, 1.0)] * 200)
|
||||
on_boost = np.abs(run(turbo, [(4000.0, 1.0)] * 20)).max()
|
||||
release = run(turbo, [(3800.0, 0.0)] * 90)
|
||||
assert np.abs(release).max() > 4 * on_boost
|
||||
assert turbo.boost < 0.1
|
||||
assert np.abs(release[-FRAMES * 10:]).max() < 0.5 * np.abs(release[FRAMES * 10:FRAMES * 20]).max()
|
||||
|
||||
|
||||
def test_a_rev_limiter_cut_does_not_open_the_valve():
|
||||
turbo = Turbo(1.0, 800.0, 6000.0)
|
||||
on_boost = np.abs(run(turbo, [(5800.0, 1.0)] * 200)).max()
|
||||
bouncing = run(turbo, ([(5800.0, 0.0)] * 7 + [(5800.0, 1.0)] * 5) * 10)
|
||||
assert not turbo.venting and np.abs(bouncing).max() < 1.5 * on_boost
|
||||
|
||||
|
||||
def test_no_valve_without_boost_or_without_a_lift():
|
||||
quick = Turbo(1.0, 800.0, 6000.0)
|
||||
run(quick, [(4000.0, 1.0)] * 5)
|
||||
assert quick.boost < BOV_FROM
|
||||
assert np.abs(run(quick, [(3800.0, 0.0)] * 40)).max() < 0.05
|
||||
cruise = Turbo(1.0, 800.0, 6000.0)
|
||||
steady = run(cruise, [(3000.0, 0.6)] * 300)
|
||||
assert np.abs(steady).max() < 0.2
|
||||
|
||||
|
||||
def test_quiet_at_zero_volume_and_engines_without_a_turbo_are_unchanged(tmp_path):
|
||||
assert not run(Turbo(1.0, 800.0, 6000.0), [(4000.0, 1.0)] * 200 + [(3800.0, 0.0)] * 50, volume=0.0).any()
|
||||
bank = load_bank(make_bank(tmp_path))
|
||||
plain = LoopSynth(PROFILES['bmw_m52'], bank)
|
||||
assert plain.effects == []
|
||||
turbo = LoopSynth(replace(PROFILES['bmw_m52'], turbo=1.0), bank)
|
||||
steps = [(4000.0, 1.0)] * 200 + [(3800.0, 0.0)] * 50
|
||||
out = np.concatenate([turbo.render(rpm, load, FRAMES, 1.0) for rpm, load in steps])
|
||||
assert np.abs(out).max() <= 1.0
|
||||
|
||||
|
||||
def test_the_supra_has_a_turbo():
|
||||
assert PROFILES['supra_turbo'].turbo > 0 and PROFILES['supra_turbo'].pops == 0
|
||||
@@ -114,7 +114,9 @@ def stretch(times: np.ndarray, rpm: np.ndarray, mask: np.ndarray, target: float)
|
||||
def steady(audio: np.ndarray, times: np.ndarray, rpm: np.ndarray, span: tuple[float, float], target: float) -> np.ndarray | None:
|
||||
"""The span replayed against the engine's own cycle so it runs at exactly the target rpm, as a seamless loop."""
|
||||
sample_times = np.arange(int(span[0] * SAMPLE_RATE), int(span[1] * SAMPLE_RATE)) / SAMPLE_RATE
|
||||
cycles = np.cumsum(np.interp(sample_times, times, rpm)) / 120.0 / SAMPLE_RATE
|
||||
if len(sample_times) < 2:
|
||||
return None
|
||||
cycles =np.cumsum(np.interp(sample_times, times, rpm)) / 120.0 / SAMPLE_RATE
|
||||
per_sample = target / 120.0 / SAMPLE_RATE
|
||||
out_cycles = np.arange(cycles[0], cycles[-1], per_sample)
|
||||
source = np.interp(out_cycles, cycles, sample_times) * SAMPLE_RATE
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
"""Turbocharger: a spool whistle that follows boost, and a blow-off valve release when the throttle closes on boost.
|
||||
|
||||
Boost builds with load once the engine is spinning fast enough, with lag. Lifting while boosted fires the blow-off valve,
|
||||
which vents the boost. The valve sounds are built once at start, so firing one only mixes a sample.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
|
||||
from openpilot.starpilot.engine_sound.synth import SAMPLE_RATE
|
||||
|
||||
SPOOL_SHARE = (0.15, 0.4) # share of redline where boost starts and where it can be full
|
||||
SPOOL_SECONDS = 0.8 # lag while boost builds
|
||||
BLEED_SECONDS = 0.35 # boost falling on a part lift that does not open the valve
|
||||
VENT_SECONDS = 0.08 # boost falling through the open valve
|
||||
LOAD_CURVE = 0.5 # an EV pulls on little pedal, so modest load still makes boost
|
||||
LIFT_FROM = 0.3 # load the throttle must come down from
|
||||
CLOSED = 0.1 # at or below this load the throttle counts as closed
|
||||
CLOSED_SECONDS = 0.1 # longer than a rev-limiter cut, which must not open the valve
|
||||
BOV_FROM = 0.3 # boost needed for the valve to open
|
||||
BOV_LEVEL = 1.0
|
||||
BOV_SECONDS = (0.3, 0.7) # release length from just enough boost to full boost
|
||||
WHISTLE_HZ = (1400.0, 3200.0) # whistle pitch from no boost to full boost
|
||||
WHISTLE_LEVEL = 0.07
|
||||
WHOOSH_LEVEL = 0.06
|
||||
VARIANTS = 6
|
||||
|
||||
|
||||
def _release(rng: np.random.Generator, seconds: float, sample_rate: int) -> np.ndarray:
|
||||
"""Hiss whose band slides down as the pressure drops, with a sharp opening and a long tail."""
|
||||
frame, hop = 1024, 256
|
||||
length = int(seconds * sample_rate) + frame
|
||||
noise = rng.standard_normal(length)
|
||||
window = np.hanning(frame)
|
||||
freq = np.fft.rfftfreq(frame, 1 / sample_rate)
|
||||
start_hz, end_hz = rng.uniform(2200, 3000), rng.uniform(700, 1000)
|
||||
out = np.zeros(length)
|
||||
norm = np.zeros(length)
|
||||
for at in range(0, length - frame, hop):
|
||||
share = at / (length - frame)
|
||||
centre = start_hz * (end_hz / start_hz) ** share
|
||||
gain = np.exp(-0.5 * (np.log2(np.maximum(freq, 1.0) / centre) / 0.7) ** 2)
|
||||
out[at:at + frame] += np.fft.irfft(np.fft.rfft(noise[at:at + frame] * window) * gain, frame) * window
|
||||
norm[at:at + frame] += window ** 2
|
||||
out = out[:length - frame] / np.maximum(norm[:length - frame], 1e-3)
|
||||
t = np.arange(len(out)) / sample_rate
|
||||
envelope = np.minimum(t / 0.004, 1.0) * (0.75 * np.exp(-t / (0.22 * seconds)) + 0.25 * np.exp(-t / (0.6 * seconds)))
|
||||
envelope[-256:] *= np.linspace(1.0, 0.0, 256)
|
||||
out = out * envelope
|
||||
return (out / np.max(np.abs(out))).astype(np.float32)
|
||||
|
||||
|
||||
def _whoosh(sample_rate: int, seconds: float = 2.0, seed: int = 9) -> np.ndarray:
|
||||
noise = np.random.default_rng(seed).standard_normal(int(seconds * sample_rate))
|
||||
freq = np.fft.rfftfreq(len(noise), 1 / sample_rate)
|
||||
shaped = np.fft.irfft(np.fft.rfft(noise) * np.exp(-0.5 * (np.log2(np.maximum(freq, 1.0) / 1300.0) / 0.8) ** 2), len(noise))
|
||||
return (shaped / np.max(np.abs(shaped))).astype(np.float32)
|
||||
|
||||
|
||||
class Turbo:
|
||||
def __init__(self, intensity: float, idle_rpm: float, redline_rpm: float, sample_rate: int = SAMPLE_RATE, seed: int = 7):
|
||||
self.intensity = intensity
|
||||
self.spool = (SPOOL_SHARE[0] * redline_rpm, SPOOL_SHARE[1] * redline_rpm)
|
||||
self.sample_rate = sample_rate
|
||||
rng = np.random.default_rng(seed)
|
||||
self.releases = [_release(rng, BOV_SECONDS[1], sample_rate) for _ in range(VARIANTS)]
|
||||
self.longest = max(len(release) for release in self.releases)
|
||||
self.noise = _whoosh(sample_rate)
|
||||
self.noise_at = 0
|
||||
self.rng = rng
|
||||
self.tail = np.zeros(0, dtype=np.float32)
|
||||
self.boost = 0.0
|
||||
self.load = 0.0
|
||||
self.armed = False
|
||||
self.closed = 0.0
|
||||
self.venting = False
|
||||
self.phase = 0.0
|
||||
self.whistle_hz = WHISTLE_HZ[0]
|
||||
|
||||
def _target(self, rpm: float, load: float) -> float:
|
||||
spool = min(max((rpm - self.spool[0]) / (self.spool[1] - self.spool[0]), 0.0), 1.0)
|
||||
return spool * max(load, 0.0) ** LOAD_CURVE
|
||||
|
||||
def render(self, rpm: float, load: float, frames: int, volume: float) -> np.ndarray:
|
||||
dt = frames / self.sample_rate
|
||||
self.armed = self.armed or load > LIFT_FROM
|
||||
self.closed = self.closed + dt if load <= CLOSED else 0.0
|
||||
release = None
|
||||
if self.closed >= CLOSED_SECONDS - 1e-9 and self.armed:
|
||||
self.armed = False
|
||||
if self.boost >= BOV_FROM:
|
||||
release = self.boost
|
||||
self.venting = True
|
||||
if load > CLOSED:
|
||||
self.venting = False
|
||||
target = self._target(rpm, load)
|
||||
seconds = SPOOL_SECONDS if target > self.boost else VENT_SECONDS if self.venting else BLEED_SECONDS
|
||||
start = self.boost
|
||||
self.boost = target + (self.boost - target) * np.exp(-dt / seconds)
|
||||
self.load = load
|
||||
|
||||
out = np.zeros(frames + self.longest, dtype=np.float32)
|
||||
out[:len(self.tail)] += self.tail
|
||||
level = self.intensity * volume
|
||||
if level > 0.0:
|
||||
ramp = (start + (self.boost - start) * np.arange(1, frames + 1) / frames).astype(np.float32)
|
||||
hz = WHISTLE_HZ[0] + (WHISTLE_HZ[1] - WHISTLE_HZ[0]) * ramp
|
||||
phase = self.phase + np.cumsum(hz) / self.sample_rate
|
||||
self.phase = float(phase[-1] % 1.0)
|
||||
index = (self.noise_at + np.arange(frames)) % len(self.noise)
|
||||
self.noise_at = int((self.noise_at + frames) % len(self.noise))
|
||||
out[:frames] += level * (WHISTLE_LEVEL * ramp ** 1.5 * np.sin(2 * np.pi * phase).astype(np.float32) +
|
||||
WHOOSH_LEVEL * ramp * self.noise[index])
|
||||
if release is not None:
|
||||
sample = self.releases[self.rng.integers(VARIANTS)]
|
||||
share = min((release - BOV_FROM) / (1.0 - BOV_FROM), 1.0)
|
||||
size = int((BOV_SECONDS[0] + (BOV_SECONDS[1] - BOV_SECONDS[0]) * share) / BOV_SECONDS[1] * len(sample))
|
||||
fade = np.ones(size, dtype=np.float32)
|
||||
fade[-min(size, 2048):] = np.linspace(1.0, 0.0, min(size, 2048))
|
||||
out[:size] += level * BOV_LEVEL * (0.6 + 0.4 * share) * sample[:size] * fade
|
||||
self.tail = out[frames:frames + self.longest].copy()
|
||||
if not self.tail.any():
|
||||
self.tail = self.tail[:0]
|
||||
return out[:frames]
|
||||
@@ -272,7 +272,7 @@ assert.equal(previewVolume.vm.soundError, "Keep the comma offroad")
|
||||
assert.equal(previewVolume.vm.previewLabel, "Test alert")
|
||||
|
||||
{
|
||||
const engine = control({ label: "Engine Type", value: "LFA", choices: ["BMW M3", "BMW M52","F1 Car","Ferrari F136", "Hellcat", "LFA", "Mustang GT"],
|
||||
const engine = control({ label: "Engine Type", value: "LFA", choices: ["BMW M3", "BMW M52","F1 Car","Ferrari F136", "Hellcat", "LFA", "Mustang GT", "Supra Turbo"],
|
||||
available: true, action: true, previewSound: "EngineSoundProfile" })
|
||||
assert.equal(settingControl(engine.vm.row), "select")
|
||||
assert.equal(engine.vm.previewLabel, "Rev engine")
|
||||
|
||||
@@ -122,7 +122,7 @@ class SoundsSettingsTests(unittest.TestCase):
|
||||
self.params.put("EngineSoundProfile", "race_car", block=True)
|
||||
row = self.row("EngineSoundProfile")
|
||||
self.assertEqual((row.value, row.repair_value), ("LFA", ""))
|
||||
self.assertEqual([r.value for r in self.owner.engine_type_snapshot().rows], ["", "", "", "", "", "Active", ""])
|
||||
self.assertEqual([r.value for r in self.owner.engine_type_snapshot().rows], ["", "", "", "", "", "Active", "", ""])
|
||||
self.assertTrue(self.owner.apply(FeatureSettingsRequest("EngineSoundProfile", row.source, "BMW M52")))
|
||||
self.assertEqual(self.params.get("EngineSoundProfile"), "bmw_m52")
|
||||
|
||||
@@ -160,14 +160,15 @@ class SoundsSettingsTests(unittest.TestCase):
|
||||
self.assertEqual([(row.label, row.value, row.actions) for row in picker.rows],
|
||||
[("BMW M3", "", (("Use", True),)), ("BMW M52", "", (("Use", True),)), ("F1 Car", "", (("Use", True),)),
|
||||
("Ferrari F136", "", (("Use", True),)), ("Hellcat", "", (("Use", True),)),
|
||||
("LFA", "Active", (("Active", True),)), ("Mustang GT", "", (("Use", True),))])
|
||||
("LFA", "Active", (("Active", True),)), ("Mustang GT", "", (("Use", True),)),
|
||||
("Supra Turbo", "", (("Use", True),))])
|
||||
stale = picker.rows[1]
|
||||
request = owner.engine_choice_request(stale)
|
||||
assert request is not None
|
||||
self.assertTrue(owner.apply(request))
|
||||
self.assertEqual((self.params.get("EngineSoundProfile"), revs), ("bmw_m52", [1]))
|
||||
picker = owner.engine_type_snapshot()
|
||||
self.assertEqual([row.value for row in picker.rows], ["", "Active", "", "", "", "", ""])
|
||||
self.assertEqual([row.value for row in picker.rows], ["", "Active", "", "", "", "", "", ""])
|
||||
replay = owner.engine_choice_request(picker.rows[1])
|
||||
assert replay is not None
|
||||
self.assertTrue(owner.apply(replay))
|
||||
|
||||
@@ -32242,6 +32242,12 @@
|
||||
"openpilot/starpilot/engine_sound/profiles.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": "Supra Turbo",
|
||||
"refs": [
|
||||
"openpilot/starpilot/engine_sound/profiles.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": "LFA",
|
||||
"refs": [
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "f5c1698cb8c081875e8697d72c082622dbe44baa84a547a7fb859d27c5d63a26", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "a0671ebc1645e866a355eee18144b221167310b970d4271d839001606e67400b", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user