Adapters

EngineAdapter

class EngineAdapter(bus: EventBus, ev: EVSoundEngine)[source]

Bases: object

Adapter responsible for synchronizing vehicle dynamics with the EV sound engine.

This class subscribes to simulation data from the EventBus (speed and throttle) and translates these values into auditory parameters for the EVSoundEngine. It ensures that engine sounds react dynamically to the driver’s input and vehicle state.

ev

The engine responsible for generating electric vehicle sounds.

Type:

EVSoundEngine

speed

The current velocity of the vehicle in km/h.

Type:

float

throttle

The current throttle input, ranging from 0.0 to 1.0.

Type:

float

__init__(bus: EventBus, ev: EVSoundEngine)[source]

Initializes the EngineAdapter and subscribes to relevant data keys.

Parameters:
  • bus (EventBus) – The system bus used for data subscription.

  • ev (EVSoundEngine) – The sound engine instance to be controlled.

on_speed(speed)[source]

Callback triggered when a new speed value is published to the EventBus.

Parameters:

speed (float) – The updated speed value from the simulation.

on_throttle(throttle)[source]

Callback triggered when a new throttle value is published to the EventBus.

Parameters:

throttle (float) – The updated throttle input from the simulation.

calculate_torque(throttle)[source]

Calculates a simplified torque value used for sound modulation.

Parameters:

throttle (float) – Current throttle position.

Returns:

Returns 1 if throttle is active, 0 otherwise.

Return type:

int

update()[source]

Updates the engine and sound states for the current frame.

Ensures the sound engine is running and pushes the latest speed and torque parameters to the FMOD system.

EnvironmentAdapter

class EnvironmentAdapter(event_bus: EventBus, bank: EnvironmentBank)[source]

Bases: object

Adapter responsible for mapping environmental simulation data to FMOD sound events.

This class monitors environmental factors like rain and wind intensity from the EventBus. It translates these raw simulation values into discrete levels (defined by RainIntensity and WindIntensity) and updates the corresponding FMOD Studio parameters to modulate the ambient audio.

bank

The sound bank containing environmental audio events.

Type:

EnvironmentBank

rain_event

The FMOD event instance controlling rain audio.

Type:

EventInstance

wind_event

The FMOD event instance controlling wind audio.

Type:

EventInstance

__init__(event_bus: EventBus, bank: EnvironmentBank)[source]

Initializes the EnvironmentAdapter and subscribes to relevant data keys.

Parameters:
  • event_bus (EventBus) – The system bus for subscribing to intensity data.

  • bank (EnvironmentBank) – The bank instance providing access to FMOD events.

on_rain(intensity: float)[source]

Callback triggered by rain intensity updates from the simulation.

Maps the float intensity to a discrete FMOD parameter ‘regenstaerke’.

Parameters:

intensity (float) – The raw rain intensity value from the simulation.

on_wind(intensity: float)[source]

Callback triggered by wind intensity updates from the simulation.

Maps the float intensity to a discrete FMOD parameter ‘Windstaerke’.

Parameters:

intensity (float) – The raw wind intensity value from the simulation.

RainIntensity

class RainIntensity(*values)[source]

Bases: RangeLevel

Enum-style class defining rain intensity ranges for FMOD parameter mapping.

This class categorizes raw rain intensity percentages (0-100) into four discrete levels. Each level is defined by a tuple representing the inclusive lower bound, the exclusive upper bound, and the corresponding FMOD parameter value used by the EnvironmentAdapter.

NONE = (0, 10, 0)

Range (0, 10) mapped to FMOD value 0.

Type:

NONE (tuple)

LOW = (10, 44, 1)

Range (10, 44) mapped to FMOD value 1.

Type:

LOW (tuple)

MEDIUM = (44, 77, 2)

Range (44, 77) mapped to FMOD value 2.

Type:

MEDIUM (tuple)

HIGH = (77, 100, 3)

Range (77, 100) mapped to FMOD value 3.

Type:

HIGH (tuple)

TriggerAdapter

class TriggerAdapter(event_bus: EventBus, rev_beep: ReverseBeep, bank: TriggerBank)[source]

Bases: object

Adapter for managing discrete sound triggers based on simulation events.

This class handles one-shot audio events such as gear shifts, crashes, speed warnings, and the vehicle horn. It implements internal debouncing logic and state tracking (e.g., counters and flags) to ensure sounds are triggered correctly and only once per event, preventing double-triggering from the EventBus.

reverse_beep

Engine for the rhythmic reverse warning sound.

Type:

ReverseBeep

bank

FMOD bank containing one-shot sound events.

Type:

TriggerBank

honk_counter

Counter used to debounce horn events, ensuring the sound only plays once per key press.

Type:

int

GEAR_REVERSE = -1

Value CARLA Simulator returnes when reverse gear is selected

Type:

GEAR_REVERSE (int) = -1

SPEED_LIMIT = 100

Sets Value for speed warning if vehicle exceeds this limit

Type:

SPEED_LIMIT (int) = 100

HANDBRAKE_SPEED = 40

Minimum speed for the handbrake sound to play

Type:

HANDBRAKE_SPEED (int) = 40

__init__(event_bus: EventBus, rev_beep: ReverseBeep, bank: TriggerBank)[source]

Initializes the TriggerAdapter and subscribes to relevant data keys.

Parameters:
  • event_bus (EventBus) – The system bus used for data subscription.

  • rev_beep (ReverseBeep) – The sound engine instance for reverse beeps.

  • bank (TriggerBank) – The bank containing one-shot audio instances.

on_reverse(current_gear)[source]

Evaluates gear changes to trigger the reverse beep engine.

Parameters:

current_gear (int) – The current gear value from the simulation.

on_tick()[source]

Updates the internal sound engine and FMOD system.

on_speed(speed=0)[source]

Triggers an overspeed warning sound if the speed limit is exceeded.

The trigger is reset only once the warning sound has finished playing.

Parameters:

speed (float) – Current vehicle speed.

on_crash(crash)[source]

Triggers the crash sound effect upon impact.

Parameters:

crash – unused. Necesarry due to the event bus design

on_honk(honk)[source]

Triggers the vehicle horn with debouncing logic.

Uses an internal counter to filter out redundant triggers from continuous key-press updates.

Parameters:

honk – unused. Necesarry due to the event bus design

on_handBrake(handBrake)[source]

Triggers the handbrake sound effect if the vehicle is moving.

Parameters:

handBrake – unused. Necesarry due to the event bus design

WindIntensity

class WindIntensity(*values)[source]

Bases: RangeLevel

Enum-style class defining wind intensity ranges for FMOD parameter mapping.

This class categorizes raw wind intensity percentages (0-100) into three discrete levels. Each level is defined by a tuple containing the inclusive lower bound, the exclusive upper bound, and the corresponding FMOD parameter value used by the EnvironmentAdapter to control ‘Windstaerke’.

NONE = (0, 10, 0)

Range (0, 10) mapped to FMOD value 0.

Type:

NONE (tuple)

LOW = (10, 55, 1)

Range (10, 55) mapped to FMOD value 1.

Type:

LOW (tuple)

HIGH = (55, 100, 2)

Range (55, 100) mapped to FMOD value 2.

Type:

HIGH (tuple)