added music
This commit is contained in:
1 parent
a1dda3fd50
commit
b5bcd3a812
9 files changed
+306
-92
No files matched your search
+23
-31
@@ -1,53 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include "cmakeaudioplayer/include/AudioPlayer.hpp"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
class AudioPlayerAsync {
|
||||
public:
|
||||
AudioPlayerAsync();
|
||||
~AudioPlayerAsync();
|
||||
|
||||
void resetAsync();
|
||||
bool init();
|
||||
void shutdown();
|
||||
|
||||
void playSoundAsync(std::string soundName);
|
||||
void playSoundAsync(const std::string& filePath, int loops = 0, int channel = -1);
|
||||
void playMusicAsync(const std::string& filePath, int loops = -1);
|
||||
void stopMusicAsync();
|
||||
void pauseMusicAsync();
|
||||
void resumeMusicAsync();
|
||||
void setMusicVolume(int volume); // 0..128
|
||||
void setSoundVolume(int volume); // 0..128
|
||||
|
||||
void playMusicAsync(std::string musicName);
|
||||
|
||||
void stopAsync();
|
||||
|
||||
void exit()
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
|
||||
std::thread worker;
|
||||
void exit() { stop = true; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<AudioPlayer> audioPlayer;
|
||||
//std::mutex audioPlayerMutex;
|
||||
|
||||
std::mutex soundNameMutex;
|
||||
std::mutex musicNameMutex;
|
||||
|
||||
std::string latestSoundName;
|
||||
std::string latestMusicName;
|
||||
void workerThread();
|
||||
|
||||
std::thread worker;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
std::queue<std::function<void()>> taskQueue;
|
||||
bool stop = false;
|
||||
|
||||
void workerThread();
|
||||
std::unordered_map<std::string, Mix_Chunk*> soundCache;
|
||||
std::mutex soundCacheMutex;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
bool initialized = false;
|
||||
};
|
||||
Reference in new issue
Block a user