Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Soundtrack Struct Reference

#include <Soundtrack.hxx>

+ Collaboration diagram for Soundtrack:

Public Member Functions

 Soundtrack (SoundtrackID, ChannelID, DecodedAudioData *, RepeatCount, bool, bool, bool, bool)
 
 ~Soundtrack ()
 

Public Attributes

SoundtrackID ID
 
ChannelID Channel
 The ChannelID. More...
 
RepeatCount Loop
 The number of times this track should be repeated. More...
 
bool isMusic: 1
 true if the Soundtrack is Music, false if it's a Sound More...
 
bool isPlaying: 1
 true if the Soundtrack is currently playing More...
 
bool isTriggerable: 1
 true if the Soundtrack can be played by AudioTrigger More...
 
bool isPlayable: 1
 true if the Soundtrack can be played by SoundtrackID More...
 
ALuint source [2]
 The OpenAL sources of the sound track. More...
 
ALuint buffer
 The OpenAL buffer of the sound track. More...
 
ALuint effect_slot
 The OpenAL effect slot of the sound track. More...
 
DecodedAudioData dAudioDataBuffer
 The audio data of the Soundtrack. More...
 

Detailed Description

Definition at line 32 of file Soundtrack.hxx.

Constructor & Destructor Documentation

◆ Soundtrack()

Soundtrack::Soundtrack ( SoundtrackID  id,
ChannelID  channelID,
DecodedAudioData dAudioData,
RepeatCount  repeat,
bool  isMusic,
bool  isPlaying,
bool  isPlayable,
bool  isTriggerable 
)

Definition at line 6 of file Soundtrack.cxx.

10 {
11 
12  /* initialize buffer */
13  alGenBuffers(1, &buffer);
14  ALenum errorCode = alGetError();
15  if (errorCode != AL_NO_ERROR)
16  throw AudioError(TRACE_INFO "Could not create buffers: Error " + std::to_string(errorCode));
17 
18  /* set buffer data */
19  ALenum format = Settings::instance().audio3DStatus ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
20 
21  /* parameters: buffer, format, data, sample length in bytes, frequency(sample rate) */
22  alBufferData(buffer, format, dAudioData->char_data_vec.data(), dAudioData->nBytes, dAudioData->data_sample_rate);
23 
24  errorCode = alGetError();
25  if (errorCode != AL_NO_ERROR)
26  throw AudioError(TRACE_INFO "Failed to load audio data into buffer: Error " + std::to_string(errorCode));
27 
28  /* initialize sources */
29  alGenSources(2, source);
30  alSourcei(source[0], AL_SOURCE_RELATIVE, AL_FALSE); // sfx channel/source
31  alSourcei(source[1], AL_SOURCE_RELATIVE, AL_FALSE); // music channel/source
32  errorCode = alGetError();
33  if (errorCode != AL_NO_ERROR)
34  throw AudioError(TRACE_INFO "Failed to setup sound source: Error " + std::to_string(errorCode));
35 
36  /* attach buffer to source */
37  alSourcei(source[isMusic], AL_BUFFER, buffer);
38 }
+ Here is the call graph for this function:

◆ ~Soundtrack()

Soundtrack::~Soundtrack ( )

Definition at line 40 of file Soundtrack.cxx.

41 {
42  if (alIsSource(source[0]))
43  alDeleteSources(2, source);
44  if (alIsBuffer(buffer))
45  alDeleteBuffers(1, &buffer);
46 }

Member Data Documentation

◆ buffer

ALuint Soundtrack::buffer

The OpenAL buffer of the sound track.

An object that tells the OpenAL system what the sound made is. Must be connected to a source to tell the system where the sound is made.

Definition at line 80 of file Soundtrack.hxx.

◆ Channel

ChannelID Soundtrack::Channel

The ChannelID.

Definition at line 39 of file Soundtrack.hxx.

◆ dAudioDataBuffer

DecodedAudioData Soundtrack::dAudioDataBuffer

The audio data of the Soundtrack.

Definition at line 92 of file Soundtrack.hxx.

◆ effect_slot

ALuint Soundtrack::effect_slot

The OpenAL effect slot of the sound track.

An object that tells the OpenAL system what effect to apply to the sound. Must be connected to a source to tell the system where the sound is made.

Definition at line 87 of file Soundtrack.hxx.

◆ ID

SoundtrackID Soundtrack::ID

Definition at line 34 of file Soundtrack.hxx.

◆ isMusic

bool Soundtrack::isMusic

true if the Soundtrack is Music, false if it's a Sound

Definition at line 51 of file Soundtrack.hxx.

◆ isPlayable

bool Soundtrack::isPlayable

true if the Soundtrack can be played by SoundtrackID

Definition at line 66 of file Soundtrack.hxx.

◆ isPlaying

bool Soundtrack::isPlaying

true if the Soundtrack is currently playing

Definition at line 56 of file Soundtrack.hxx.

◆ isTriggerable

bool Soundtrack::isTriggerable

true if the Soundtrack can be played by AudioTrigger

Definition at line 61 of file Soundtrack.hxx.

◆ Loop

RepeatCount Soundtrack::Loop

The number of times this track should be repeated.

Must be between [0, 255]. A value of 0 will only play once while a value of 255 will play forever

Definition at line 46 of file Soundtrack.hxx.

◆ source

ALuint Soundtrack::source[2]

The OpenAL sources of the sound track.

An object that tells the OpenAL system where the sound making object is located in 3D space and what buffer(sound) it makes. source[0] is for sound effects and source[1] is for music.

Definition at line 73 of file Soundtrack.hxx.


The documentation for this struct was generated from the following files:
TRACE_INFO
#define TRACE_INFO
Definition: Exception.hxx:12
Soundtrack::source
ALuint source[2]
The OpenAL sources of the sound track.
Definition: Soundtrack.hxx:73
DecodedAudioData::data_sample_rate
int data_sample_rate
Definition: Soundtrack.hxx:29
Soundtrack::isPlayable
bool isPlayable
true if the Soundtrack can be played by SoundtrackID
Definition: Soundtrack.hxx:66
DecodedAudioData::char_data_vec
std::vector< char > char_data_vec
pcm audio data
Definition: Soundtrack.hxx:27
SettingsData::audio3DStatus
bool audio3DStatus
whether to play 3D sound or not
Definition: Settings.hxx:103
Soundtrack::ID
SoundtrackID ID
Definition: Soundtrack.hxx:34
Soundtrack::isMusic
bool isMusic
true if the Soundtrack is Music, false if it's a Sound
Definition: Soundtrack.hxx:51
Soundtrack::Loop
RepeatCount Loop
The number of times this track should be repeated.
Definition: Soundtrack.hxx:46
Soundtrack::buffer
ALuint buffer
The OpenAL buffer of the sound track.
Definition: Soundtrack.hxx:80
DecodedAudioData::nBytes
long nBytes
number of bytes in decoded audio data
Definition: Soundtrack.hxx:28
Singleton< Settings >::instance
static Settings & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
Soundtrack::Channel
ChannelID Channel
The ChannelID.
Definition: Soundtrack.hxx:39
Soundtrack::isTriggerable
bool isTriggerable
true if the Soundtrack can be played by AudioTrigger
Definition: Soundtrack.hxx:61
Soundtrack::isPlaying
bool isPlaying
true if the Soundtrack is currently playing
Definition: Soundtrack.hxx:56
AudioError
An audio-related error occured.
Definition: Exception.hxx:52