OpenTTD Source: src/sound.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
sound.cpp File Reference

Handling of playing sounds. More...

`#include "stdafx.h"`
`#include "landscape.h"`
`#include "sound_type.h"`
`#include "soundloader_func.h"`
`#include "mixer.h"`
`#include "newgrf_sound.h"`
`#include "random_access_file_type.h"`
`#include "window_func.h"`
`#include "window_gui.h"`
`#include "vehicle_base.h"`
`#include "base_media_func.h"`
`#include "base_media_sounds.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
static void | OpenBankFile (const std::string &filename)
static bool | SetBankSource (MixerChannel *mc, SoundEntry *sound, SoundID sound_id)
void | InitializeSound ()
static void | StartSound (SoundID sound_id, float pan, uint volume)
void | SndCopyToPool ()
void | ChangeSoundSet (int index)
| Change the configured sound set and reset sounds.
static void | SndPlayScreenCoordFx (SoundID sound, int left, int right, int top, int bottom)
| Decide 'where' (between left and right speaker) to play the sound effect.
void | SndPlayTileFx (SoundID sound, TileIndex tile)
void | SndPlayVehicleFx (SoundID sound, const Vehicle *v)
void | SndPlayFx (SoundID sound)
void | SndClickBeep ()
| Play a beep sound for a click event if enabled in settings.
void | SndConfirmBeep ()
| Play a beep sound for a confirm event if enabled in settings.

## Variables
static std::array< SoundEntry, ORIGINAL_SAMPLE_COUNT > | _original_sounds
static const uint8_t | _vol_factor_by_zoom [] = {255, 255, 255, 190, 134, 87}
static const uint8_t | _sound_base_vol []
static const uint8_t | _sound_idx []
static const std::string_view | _sound_file_names [] = { "samples" }
| Names corresponding to the sound set's files.

## Detailed Description

Handling of playing sounds.

Definition in file sound.cpp.

## Function Documentation

## ◆ ChangeSoundSet()

void ChangeSoundSet | ( | int | index | ) |

Change the configured sound set and reset sounds.

Parameters

  index | Index of sound set to switch to.

Definition at line 167 of file sound.cpp.

References BaseMedia< SoundsSet >::GetIndexOfUsedSet(), BaseMedia< SoundsSet >::GetSet(), SoundEntry::grf_container_ver, BaseSounds::ini_set, InvalidateWindowData(), MxCloseAllChannels(), ORIGINAL_SAMPLE_COUNT, BaseMedia< SoundsSet >::SetSet(), WC_GAME_OPTIONS, and WN_GAME_OPTIONS_GAME_OPTIONS.

Referenced by GameOptionsWindow::OnDropdownSelect().

## ◆ InitializeSound()

void InitializeSound | ( |  | ) |

Definition at line 90 of file sound.cpp.

## ◆ OpenBankFile()

static void OpenBankFile | ( | const std::string & | filename | ) |
| static

The sound file for the original sounds, i.e. those not defined/overridden by a NewGRF. Needs to be kept alive during the game as _original_sounds[n].file refers to this.

Definition at line 27 of file sound.cpp.

References BASESET_DIR, ClrBit(), Debug, GB(), HasBit(), and ORIGINAL_SAMPLE_COUNT.

## ◆ SetBankSource()

static bool SetBankSource | ( | MixerChannel * | mc,
|  | SoundEntry * | sound,
|  | SoundID | sound_id
| ) |  |
| static

Definition at line 69 of file sound.cpp.

## ◆ SndClickBeep()

void SndClickBeep | ( |  | ) |

Play a beep sound for a click event if enabled in settings.

Definition at line 253 of file sound.cpp.

References _settings_client, SoundSettings::click_beep, SND_15_BEEP, and ClientSettings::sound.

Referenced by BuildRailClick_Remove(), Window::HandleButtonClick(), HandlePlacePushButton(), BuildAirportWindow::OnClick(), DepotWindow::OnClick(), BuildDocksStationWindow::OnClick(), BuildDocksDepotWindow::OnClick(), GenerateLandscapeWindow::OnClick(), GraphLegendWindow::OnClick(), BaseGraphWindow::OnClick(), BaseCargoGraphWindow::OnClick(), IndustryCargoesWindow::OnClick(), BuildObjectWindow::OnClick(), PickerWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildSignalWindow::OnClick(), BuildRailDepotWindow::OnClick(), BuildRoadToolbarWindow::OnClick(), BuildRoadDepotWindow::OnClick(), BuildRoadStationWindow::OnClick(), GameOptionsWindow::OnClick(), SmallMapWindow::OnClick(), TownAuthorityWindow::OnClick(), BuildHouseWindow::OnClick(), TransparenciesWindow::OnClick(), ScenarioEditorToolbarWindow::OnDropdownSelect(), ShowDropDownList(), and ToolbarFastForwardClick().

## ◆ SndConfirmBeep()

void SndConfirmBeep | ( |  | ) |

Play a beep sound for a confirm event if enabled in settings.

Definition at line 261 of file sound.cpp.

References _settings_client, SoundSettings::confirm, SND_15_BEEP, and ClientSettings::sound.

Referenced by BuildTreesWindow::OnClick(), and BuildTreesWindow::UpdateMode().

## ◆ SndCopyToPool()

void SndCopyToPool | ( |  | ) |

Definition at line 153 of file sound.cpp.

## ◆ SndPlayFx()

void SndPlayFx | ( | SoundID | sound | ) |

Definition at line 245 of file sound.cpp.

## ◆ SndPlayScreenCoordFx()

static void SndPlayScreenCoordFx | ( | SoundID | sound,
|  | int | left,
|  | int | right,
|  | int | top,
|  | int | bottom
| ) |  |
| static

Decide 'where' (between left and right speaker) to play the sound effect.

Note: Callers must determine if sound effects are enabled. This plays a sound regardless of the setting.

Parameters

  sound | Sound effect to play
  left | Left edge of virtual coordinates where the sound is produced
  right | Right edge of virtual coordinates where the sound is produced
  top | Top edge of virtual coordinates where the sound is produced
  bottom | Bottom edge of virtual coordinates where the sound is produced

Definition at line 202 of file sound.cpp.

References to_underlying(), Viewport::virtual_left, Viewport::virtual_top, Viewport::virtual_width, and Viewport::zoom.

## ◆ SndPlayTileFx()

void SndPlayTileFx | ( | SoundID | sound,
|  | TileIndex | tile
| ) |  |

Definition at line 225 of file sound.cpp.

## ◆ SndPlayVehicleFx()

void SndPlayVehicleFx | ( | SoundID | sound,
|  | const Vehicle * | v
| ) |  |

Definition at line 237 of file sound.cpp.

## ◆ StartSound()

static void StartSound | ( | SoundID | sound_id,
|  | float | pan,
|  | uint | volume
| ) |  |
| static

Definition at line 98 of file sound.cpp.

## Variable Documentation

## ◆ _original_sounds

std::array<SoundEntry, ORIGINAL_SAMPLE_COUNT> _original_sounds
| static

Definition at line 25 of file sound.cpp.

## ◆ _sound_base_vol

const uint8_t _sound_base_vol[]
| static

Initial value:
= {
128, 90, 128, 128, 128, 128, 128, 128,
128, 90, 90, 128, 128, 128, 128, 128,
128, 128, 128, 80, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 90, 90, 90, 128, 90, 128,
128, 90, 128, 128, 128, 90, 128, 128,
128, 128, 128, 128, 90, 128, 128, 128,
128, 90, 128, 128, 128, 128, 128, 128,
128, 128, 90, 90, 90, 128, 128, 128,
90,
}

Definition at line 127 of file sound.cpp.

## ◆ _sound_file_names

const std::string_view _sound_file_names[] = { "samples" }
| static

Names corresponding to the sound set's files.

Definition at line 267 of file sound.cpp.

## ◆ _sound_idx

const uint8_t _sound_idx[]
| static

Initial value:
= {
2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 0,
1, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71,
72,
}

Definition at line 140 of file sound.cpp.

## ◆ _vol_factor_by_zoom

const uint8_t _vol_factor_by_zoom[] = {255, 255, 255, 190, 134, 87}
| static

Definition at line 124 of file sound.cpp.