-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f95c05
commit 5c625ff
Showing
10 changed files
with
615 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_library(linguine-aaudio | ||
src/AAudioAudioManager.cpp | ||
) | ||
|
||
target_include_directories(linguine-aaudio PUBLIC include) | ||
target_include_directories(linguine-aaudio PRIVATE src) | ||
|
||
target_link_libraries(linguine-aaudio PRIVATE linguine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#pragma once | ||
|
||
#include <audio/AudioManager.h> | ||
|
||
#include <array> | ||
#include <queue> | ||
|
||
#include <aaudio/AAudio.h> | ||
|
||
#include "AAudioFileLoader.h" | ||
|
||
namespace linguine::audio { | ||
|
||
class AAudioAudioManager : public AudioManager { | ||
public: | ||
struct EffectStreamState { | ||
std::vector<std::byte>* buffer; | ||
int32_t nextFrame; | ||
bool isPlaying; | ||
}; | ||
|
||
struct SongStreamState { | ||
std::vector<std::byte>* buffer; | ||
int32_t delayFrames; | ||
int32_t nextFrame; | ||
std::optional<int32_t> loopPoint; | ||
bool isPlaying; | ||
}; | ||
|
||
explicit AAudioAudioManager(std::unique_ptr<AAudioFileLoader> fileLoader); | ||
|
||
~AAudioAudioManager() override; | ||
|
||
void poll() override {} | ||
|
||
void setMusicEnabled(bool enabled) override; | ||
|
||
void setSoundEffectsEnabled(bool enabled) override; | ||
|
||
void play(EffectType effectType) override; | ||
|
||
void play(SongType songType, Mode mode) override; | ||
|
||
[[nodiscard]] std::optional<SongType> getCurrentSongType() const override; | ||
|
||
void stopSongs() override; | ||
|
||
void pause() override; | ||
|
||
void resume() override; | ||
|
||
EffectStreamState& getEffectStreamState(AAudioStream* stream) { | ||
return _effectStreamStates.at(stream); | ||
} | ||
|
||
SongStreamState& getSongStreamState(AAudioStream* stream) { | ||
return _songStreamStates.at(stream); | ||
} | ||
|
||
private: | ||
std::unique_ptr<AAudioFileLoader> _fileLoader; | ||
|
||
bool _isMusicEnabled = true; | ||
bool _isSoundEffectsEnabled = true; | ||
|
||
std::array<AAudioStream*, 8> _effectStreams{}; | ||
std::array<AAudioStream*, 2> _songStreams{}; | ||
|
||
std::queue<AAudioStream*> _effectLruPool{}; | ||
int _currentSongStream = 0; | ||
std::optional<SongType> _currentSongType{}; | ||
|
||
std::unordered_map<EffectType, std::vector<std::byte>> _effectBuffers; | ||
std::unordered_map<SongType, std::vector<std::byte>> _songBuffers; | ||
|
||
std::unordered_map<AAudioStream*, EffectStreamState> _effectStreamStates; | ||
std::unordered_map<AAudioStream*, SongStreamState> _songStreamStates; | ||
|
||
void loadBuffer(EffectType effectType); | ||
|
||
void loadBuffer(SongType songType); | ||
|
||
AAudioStream* getNextSongStream(); | ||
}; | ||
|
||
} // namespace linguine::audio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <audio/EffectType.h> | ||
#include <audio/SongType.h> | ||
|
||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace linguine::audio { | ||
|
||
class AAudioFileLoader { | ||
public: | ||
virtual ~AAudioFileLoader() = default; | ||
|
||
[[nodiscard]] int32_t getSongLoopPoint(SongType songType) const { | ||
return _songLoopPoints.at(songType); | ||
} | ||
|
||
[[nodiscard]] virtual std::vector<std::byte> getAudioDataForEffect(EffectType effectType) const = 0; | ||
|
||
[[nodiscard]] virtual std::vector<std::byte> getAudioDataForSong(SongType songType) const = 0; | ||
|
||
private: | ||
const std::unordered_map<SongType, int32_t> _songLoopPoints = { | ||
{ SongType::Title, 1058400 }, | ||
{ SongType::Theme, 2646000 }, | ||
{ SongType::GameOver, 529200 } | ||
}; | ||
}; | ||
|
||
} // namespace linguine::audio |
Oops, something went wrong.