Uniform naming for Overcharge toolset enums
This commit is contained in:
@@ -16,8 +16,8 @@ typedef Containers::Pointer<class Sound> SoundContainer;
|
|||||||
typedef Containers::Pointer<class Listener> ListenerContainer;
|
typedef Containers::Pointer<class Listener> ListenerContainer;
|
||||||
class Sound {
|
class Sound {
|
||||||
public:
|
public:
|
||||||
enum class SoundState { Idle, Playing, Paused, Finished };
|
enum class State { Idle, Playing, Paused, Finished };
|
||||||
enum class SoundType { FromFile, StreamedRawPCM, RawPCM };
|
enum class Type { FromFile, StreamedRawPCM, RawPCM };
|
||||||
// No copying
|
// No copying
|
||||||
Sound(const Sound &) = delete;
|
Sound(const Sound &) = delete;
|
||||||
Sound &operator=(const Sound &) = delete;
|
Sound &operator=(const Sound &) = delete;
|
||||||
@@ -31,8 +31,8 @@ public:
|
|||||||
void Pause();
|
void Pause();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
const SoundState GetState();
|
const State GetState();
|
||||||
const SoundType GetSoundType();
|
const Type GetSoundType();
|
||||||
const size_t GetPlayedSampleCount();
|
const size_t GetPlayedSampleCount();
|
||||||
|
|
||||||
const float GetPlaybackTime();
|
const float GetPlaybackTime();
|
||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Sound(class Engine *engine, std::function<void(Sound *)> setupFunction,
|
Sound(class Engine *engine, std::function<void(Sound *)> setupFunction,
|
||||||
SoundType type, std::string additionalErrorMessage = "");
|
Type type, std::string additionalErrorMessage = "");
|
||||||
static void onSoundFinish(void *customData, ma_sound *);
|
static void onSoundFinish(void *customData, ma_sound *);
|
||||||
|
|
||||||
class Engine *baseEngine;
|
class Engine *baseEngine;
|
||||||
@@ -56,8 +56,8 @@ private:
|
|||||||
ma_sound_config maConfig;
|
ma_sound_config maConfig;
|
||||||
ma_pcm_rb maRingBuffer;
|
ma_pcm_rb maRingBuffer;
|
||||||
ma_audio_buffer maAudioBuffer;
|
ma_audio_buffer maAudioBuffer;
|
||||||
SoundState state = SoundState::Idle;
|
State state = State::Idle;
|
||||||
SoundType type;
|
Type type;
|
||||||
|
|
||||||
friend class Engine;
|
friend class Engine;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ SoundContainer Engine::CreateSound(int bufferLengthInSeconds) {
|
|||||||
ThrowOnRuntimeError("Failed to create a new ring buffer!", result);
|
ThrowOnRuntimeError("Failed to create a new ring buffer!", result);
|
||||||
sound->maConfig.pDataSource = &sound->maRingBuffer;
|
sound->maConfig.pDataSource = &sound->maRingBuffer;
|
||||||
},
|
},
|
||||||
Sound::SoundType::StreamedRawPCM,
|
Sound::Type::StreamedRawPCM,
|
||||||
"Failed to create the sound from ring buffer: "));
|
"Failed to create the sound from ring buffer: "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +52,7 @@ SoundContainer Engine::CreateSound(uint8_t *data, int length) {
|
|||||||
ThrowOnRuntimeError("Failed to create a new audio buffer!", result);
|
ThrowOnRuntimeError("Failed to create a new audio buffer!", result);
|
||||||
sound->maConfig.pDataSource = &sound->maAudioBuffer;
|
sound->maConfig.pDataSource = &sound->maAudioBuffer;
|
||||||
},
|
},
|
||||||
Sound::SoundType::RawPCM,
|
Sound::Type::RawPCM, "Failed to create the sound from the PCM data: "));
|
||||||
"Failed to create the sound from the PCM data: "));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundContainer Engine::CreateSound(const std::string filepath,
|
SoundContainer Engine::CreateSound(const std::string filepath,
|
||||||
@@ -64,7 +63,7 @@ SoundContainer Engine::CreateSound(const std::string filepath,
|
|||||||
sound->maConfig.pFilePath = filepath.c_str();
|
sound->maConfig.pFilePath = filepath.c_str();
|
||||||
sound->maConfig.flags = (streamFile ? MA_SOUND_FLAG_STREAM : 0);
|
sound->maConfig.flags = (streamFile ? MA_SOUND_FLAG_STREAM : 0);
|
||||||
},
|
},
|
||||||
Sound::SoundType::FromFile,
|
Sound::Type::FromFile,
|
||||||
"Failed to create the sound from the file: " + filepath));
|
"Failed to create the sound from the file: " + filepath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
using namespace ChargeAudio;
|
using namespace ChargeAudio;
|
||||||
Sound::Sound(Engine *engine, std::function<void(Sound *)> setupFunction,
|
Sound::Sound(Engine *engine, std::function<void(Sound *)> setupFunction,
|
||||||
SoundType soundType, std::string additionalErrorMessage)
|
Type soundType, std::string additionalErrorMessage)
|
||||||
: baseEngine(engine) {
|
: baseEngine(engine) {
|
||||||
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
||||||
maConfig.endCallback = Sound::onSoundFinish;
|
maConfig.endCallback = Sound::onSoundFinish;
|
||||||
@@ -24,10 +24,10 @@ Sound::Sound(Engine *engine, std::function<void(Sound *)> setupFunction,
|
|||||||
|
|
||||||
Sound::~Sound() {
|
Sound::~Sound() {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Sound::SoundType::RawPCM:
|
case Sound::Type::RawPCM:
|
||||||
ma_audio_buffer_uninit_and_free(&maAudioBuffer);
|
ma_audio_buffer_uninit_and_free(&maAudioBuffer);
|
||||||
break;
|
break;
|
||||||
case Sound::SoundType::StreamedRawPCM:
|
case Sound::Type::StreamedRawPCM:
|
||||||
ma_pcm_rb_uninit(&maRingBuffer);
|
ma_pcm_rb_uninit(&maRingBuffer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -36,13 +36,13 @@ Sound::~Sound() {
|
|||||||
ma_sound_uninit(&maSound);
|
ma_sound_uninit(&maSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sound::SoundState Sound::GetState() { return state; }
|
const Sound::State Sound::GetState() { return state; }
|
||||||
const Sound::SoundType Sound::GetSoundType() { return type; }
|
const Sound::Type Sound::GetSoundType() { return type; }
|
||||||
|
|
||||||
const float Sound::GetDuration() {
|
const float Sound::GetDuration() {
|
||||||
WarnIfTrue("You are using StreamedRawPCM sound! GetDuration() will not work "
|
WarnIfTrue("You are using StreamedRawPCM sound! GetDuration() will not work "
|
||||||
"since the PCM data is in a fixed ring buffer.",
|
"since the PCM data is in a fixed ring buffer.",
|
||||||
type == Sound::SoundType::StreamedRawPCM);
|
type == Sound::Type::StreamedRawPCM);
|
||||||
float time;
|
float time;
|
||||||
ma_sound_get_length_in_seconds(&this->maSound, &time);
|
ma_sound_get_length_in_seconds(&this->maSound, &time);
|
||||||
return time;
|
return time;
|
||||||
@@ -53,7 +53,7 @@ const float Sound::GetPlaybackTime() {
|
|||||||
"You are using StreamedRawPCM sound! GetPlaybackTime() will not work "
|
"You are using StreamedRawPCM sound! GetPlaybackTime() will not work "
|
||||||
"since the PCM data is in a fixed ring buffer. However you can do "
|
"since the PCM data is in a fixed ring buffer. However you can do "
|
||||||
"GetPlayedSampleCount()/SAMPLE_RATE to get time elapsed.",
|
"GetPlayedSampleCount()/SAMPLE_RATE to get time elapsed.",
|
||||||
type == Sound::SoundType::StreamedRawPCM);
|
type == Sound::Type::StreamedRawPCM);
|
||||||
float time;
|
float time;
|
||||||
ma_sound_get_cursor_in_seconds(&this->maSound, &time);
|
ma_sound_get_cursor_in_seconds(&this->maSound, &time);
|
||||||
return time;
|
return time;
|
||||||
@@ -65,7 +65,7 @@ bool Sound::SetPlaybackTime(float time) {
|
|||||||
"You cannot set playback time on a StreamedRawPCM as it uses a ring "
|
"You cannot set playback time on a StreamedRawPCM as it uses a ring "
|
||||||
"buffer. If you wanted to skip forward or backward. Empty the buffer and "
|
"buffer. If you wanted to skip forward or backward. Empty the buffer and "
|
||||||
"then write what you want.",
|
"then write what you want.",
|
||||||
type == Sound::SoundType::StreamedRawPCM);
|
type == Sound::Type::StreamedRawPCM);
|
||||||
|
|
||||||
// Better to just catch it from the start
|
// Better to just catch it from the start
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
@@ -83,19 +83,19 @@ bool Sound::SetPlaybackTime(float time) {
|
|||||||
// Controls
|
// Controls
|
||||||
void Sound::Play() {
|
void Sound::Play() {
|
||||||
ThrowOnRuntimeError("Failed to start the sound.", ma_sound_start(&maSound));
|
ThrowOnRuntimeError("Failed to start the sound.", ma_sound_start(&maSound));
|
||||||
state = Sound::SoundState::Playing;
|
state = Sound::State::Playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::Pause() {
|
void Sound::Pause() {
|
||||||
ThrowOnRuntimeError("Failed to pause the sound.", ma_sound_stop(&maSound));
|
ThrowOnRuntimeError("Failed to pause the sound.", ma_sound_stop(&maSound));
|
||||||
state = Sound::SoundState::Paused;
|
state = Sound::State::Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::Reset() {
|
void Sound::Reset() {
|
||||||
ThrowOnRuntimeError(
|
ThrowOnRuntimeError(
|
||||||
"You cannot reset on Streamed RawPCM sounds! Since the buffer is a "
|
"You cannot reset on Streamed RawPCM sounds! Since the buffer is a "
|
||||||
"ring buffer there isn't a \"start\" to return to.",
|
"ring buffer there isn't a \"start\" to return to.",
|
||||||
type == SoundType::StreamedRawPCM);
|
type == Type::StreamedRawPCM);
|
||||||
ma_sound_seek_to_pcm_frame(&maSound, 0);
|
ma_sound_seek_to_pcm_frame(&maSound, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,5 +141,5 @@ void Sound::WriteToRingBuffer(uint8_t *data, uint32_t length) {
|
|||||||
// STATICs
|
// STATICs
|
||||||
void Sound::onSoundFinish(void *customData, ma_sound *) {
|
void Sound::onSoundFinish(void *customData, ma_sound *) {
|
||||||
auto sound = static_cast<Sound *>(customData);
|
auto sound = static_cast<Sound *>(customData);
|
||||||
sound->state = SoundState::Finished;
|
sound->state = State::Finished;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user