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