[go: up one dir, main page]

Menu

[2d94f2]: / world / Sounds.hpp  Maximize  Restore  History

Download this file

119 lines (100 with data), 3.5 kB

  1
  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
 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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Sound management
//
// Copyright (C) 2003-2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _SOUNDS_H_
#define _SOUNDS_H_
#include "../media/Sample.hpp"
#include "../media/XML_Parser.hpp"
#include <memory>
#include <string>
namespace Vamos_World
{
class Souds_Reader;
class Sounds
{
friend class Sounds_Reader;
public:
Sounds(double volume);
// Set the overall volume level 0.0-1.0.
void set_volume(double volume);
// Read the sound definition file.
void read(std::string data_dir = "", std::string sounds_file = "");
using V3 = Vamos_Geometry::Three_Vector;
// The other sounds are adjusted by these functions.
void play_tire_squeal_sound(double slide, const V3& position);
void play_kerb_sound(double speed, const V3& position);
void play_grass_sound(double speed, const V3& position);
void play_gravel_sound(double speed, const V3& position);
void play_scrape_sound(double speed, const V3& position);
void play_wind_sound(double speed, const V3& position);
void play_hard_crash_sound(double speed, const V3& position);
void play_soft_crash_sound(double speed, const V3& position);
// Pause all sounds.
void pause();
private:
enum Sound_Type
{
TIRE_SQUEAL,
KERB,
GRASS,
GRAVEL,
SCRAPE,
WIND,
SOFT_CRASH,
HARD_CRASH,
NONE
};
void add_sample(std::string file, Sound_Type type, double volume, double pitch);
std::string m_data_dir;
std::string m_sounds_file;
using Sample_Ptr = std::unique_ptr<Vamos_Media::Sample>;
// The sound for tires slipping on a hard surface.
Sample_Ptr mp_tire_squeal_sound;
// The sound for driving on kerbs.
Sample_Ptr mp_kerb_sound;
// The sound for driving or sliding on grass.
Sample_Ptr mp_grass_sound;
// The sound for driving or sliding on gravel.
Sample_Ptr mp_gravel_sound;
// The sound for hard surfaces sliding.
Sample_Ptr mp_scrape_sound;
// Wind noise.
Sample_Ptr mp_wind_sound;
// The sound for a crash into a soft surface.
Sample_Ptr mp_soft_crash_sound;
// The sound for a crash into a hard surface.
Sample_Ptr mp_hard_crash_sound;
};
class Sounds_Reader : public Vamos_Media::XML_Parser
{
public:
Sounds_Reader(std::string file_name, Sounds* sounds);
// XML_Parser overrides
virtual void on_end_tag(const Vamos_Media::XML_Tag& tag) override;
virtual void on_data(std::string data_string) override;
Sounds* mp_sounds;
std::string m_file;
double m_pitch;
double m_volume;
int m_rate;
// The number of seconds of sound buffered for playing. Delay in responding to a
// change in a sound may be as long as this.
double m_buffer_duration;
};
} // namespace Vamos_World
#endif // not _SOUNDS_H_