wip audio #1
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
*.[Ww][Aa][Vv]
|
*.[Ww][Aa][Vv]
|
||||||
*.[Dd][Ff][Ff]
|
*.[Dd][Ff][Ff]
|
||||||
*.[Ii][Rr][Xx]
|
*.[Ii][Rr][Xx]
|
||||||
|
*.[Aa][Dd][Pp][Cc][Mm]
|
||||||
*.[Mm][Dd]2
|
*.[Mm][Dd]2
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|||||||
@@ -35,16 +35,18 @@ public:
|
|||||||
void play();
|
void play();
|
||||||
void stop();
|
void stop();
|
||||||
void loadSong(char *t_filename);
|
void loadSong(char *t_filename);
|
||||||
|
void test();
|
||||||
void unloadSong();
|
void unloadSong();
|
||||||
void setVolume(u8 t_volume);
|
void setVolume(u8 t_volume);
|
||||||
void addListener(AudioListener *t_listener);
|
void addListener(AudioListener *t_listener);
|
||||||
void startThread();
|
void startThread();
|
||||||
|
const u8 isPlaying() const { return shouldPlay; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void work();
|
void work();
|
||||||
static void audioThread();
|
static void audioThread();
|
||||||
u8 isInitialized, shouldPlay, songLoaded, isVolumeSet;
|
u8 isInitialized, shouldPlay, songLoaded, isVolumeSet, latestVolume, isADPCMLoaded, wasADPCMLoaded;
|
||||||
|
audsrv_adpcm_t adpcmSettings;
|
||||||
ee_thread_t audioThreadAttr;
|
ee_thread_t audioThreadAttr;
|
||||||
u8 audioThreadStack[STACK_SIZE] ALIGNED(16);
|
u8 audioThreadStack[STACK_SIZE] ALIGNED(16);
|
||||||
int audioThreadId;
|
int audioThreadId;
|
||||||
@@ -56,6 +58,9 @@ private:
|
|||||||
void loadModules();
|
void loadModules();
|
||||||
void initAUDSRV();
|
void initAUDSRV();
|
||||||
|
|
||||||
|
u8 *sample1;
|
||||||
|
u32 adpcmFileSize;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char chunk[2048];
|
char chunk[2048];
|
||||||
FILE *wav;
|
FILE *wav;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ Audio::Audio()
|
|||||||
songLoaded = 0;
|
songLoaded = 0;
|
||||||
isVolumeSet = 0;
|
isVolumeSet = 0;
|
||||||
shouldPlay = 0;
|
shouldPlay = 0;
|
||||||
|
isADPCMLoaded = false;
|
||||||
audioRef = this;
|
audioRef = this;
|
||||||
initSema();
|
initSema();
|
||||||
loadModules();
|
loadModules();
|
||||||
@@ -54,6 +55,7 @@ void Audio::init(u32 t_listenersAmount)
|
|||||||
listenersAmount = t_listenersAmount;
|
listenersAmount = t_listenersAmount;
|
||||||
listeners = new AudioListener *[t_listenersAmount];
|
listeners = new AudioListener *[t_listenersAmount];
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
|
latestVolume = 100;
|
||||||
PRINT_LOG("Audio module initialized!");
|
PRINT_LOG("Audio module initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,7 @@ void Audio::initAUDSRV()
|
|||||||
{
|
{
|
||||||
PRINT_LOG("Initialize AUDSRV started");
|
PRINT_LOG("Initialize AUDSRV started");
|
||||||
ret = audsrv_init();
|
ret = audsrv_init();
|
||||||
|
ret = audsrv_adpcm_init();
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
PRINT_ERR("Failed to initialize AUDSRV!");
|
PRINT_ERR("Failed to initialize AUDSRV!");
|
||||||
@@ -147,6 +150,7 @@ void Audio::loadSong(char *t_filename)
|
|||||||
void Audio::setVolume(u8 t_volume)
|
void Audio::setVolume(u8 t_volume)
|
||||||
{
|
{
|
||||||
audsrv_set_volume(t_volume);
|
audsrv_set_volume(t_volume);
|
||||||
|
latestVolume = t_volume;
|
||||||
isVolumeSet = true;
|
isVolumeSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,41 +171,23 @@ void Audio::startThread()
|
|||||||
PRINT_LOG("Audio thread started");
|
PRINT_LOG("Audio thread started");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Do not call this function.
|
|
||||||
* This is a audio thread, runned by AudioThread::start()
|
|
||||||
*/
|
|
||||||
void Audio::audioThread()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (audioRef->shouldPlay)
|
|
||||||
audioRef->work();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::play()
|
|
||||||
{
|
|
||||||
if (!isInitialized)
|
|
||||||
{
|
|
||||||
PRINT_ERR("Please initialize audio class first!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shouldPlay = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Audio::stop()
|
|
||||||
{
|
|
||||||
if (!isInitialized)
|
|
||||||
{
|
|
||||||
PRINT_ERR("Please initialize audio class first!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shouldPlay = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Play song and run it again on finish */
|
/** Play song and run it again on finish */
|
||||||
void Audio::work()
|
void Audio::work()
|
||||||
{
|
{
|
||||||
|
if (isADPCMLoaded)
|
||||||
|
{
|
||||||
|
if (audsrv_load_adpcm(&adpcmSettings, sample1, adpcmFileSize))
|
||||||
|
PRINT_ERR("audsrv_load_adpcm() failed!");
|
||||||
|
wasADPCMLoaded = true;
|
||||||
|
isADPCMLoaded = false;
|
||||||
|
}
|
||||||
|
if (wasADPCMLoaded)
|
||||||
|
{
|
||||||
|
if (audsrv_play_adpcm(&adpcmSettings))
|
||||||
|
PRINT_ERR("audsrv_play_adpcm() failed!");
|
||||||
|
}
|
||||||
|
if (!shouldPlay)
|
||||||
|
return;
|
||||||
if (!isTrackDone)
|
if (!isTrackDone)
|
||||||
{
|
{
|
||||||
ret = fread(chunk, 1, sizeof(chunk), wav);
|
ret = fread(chunk, 1, sizeof(chunk), wav);
|
||||||
@@ -231,15 +217,71 @@ void Audio::work()
|
|||||||
/** Unload audio module by closing file stream and stopping AUDSRV */
|
/** Unload audio module by closing file stream and stopping AUDSRV */
|
||||||
void Audio::unloadSong()
|
void Audio::unloadSong()
|
||||||
{
|
{
|
||||||
PRINT_LOG("Unloading audio module started");
|
PRINT_LOG("Song unloaded");
|
||||||
fclose(wav);
|
fclose(wav);
|
||||||
PRINT_LOG("Song file stream closed");
|
|
||||||
audsrv_quit();
|
|
||||||
PRINT_LOG("AUDSRV stopped");
|
|
||||||
PRINT_LOG("Audio module unloaded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Do not call this function.
|
void Audio::test()
|
||||||
|
{
|
||||||
|
// audsrv_adpcm_set_volume(100);
|
||||||
|
|
||||||
|
FILE *file = fopen("host:chiller.adpcm", "rb");
|
||||||
|
fseek(file, 0L, SEEK_END);
|
||||||
|
adpcmFileSize = ftell(file);
|
||||||
|
sample1 = new u8[adpcmFileSize];
|
||||||
|
rewind(file);
|
||||||
|
fread(sample1, sizeof(u8), adpcmFileSize, file);
|
||||||
|
fclose(file);
|
||||||
|
adpcmSettings.size = 0;
|
||||||
|
adpcmSettings.buffer = 0;
|
||||||
|
adpcmSettings.loop = 0;
|
||||||
|
adpcmSettings.pitch = 0;
|
||||||
|
adpcmSettings.channels = 0;
|
||||||
|
isADPCMLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::play()
|
||||||
|
{
|
||||||
|
if (!isInitialized)
|
||||||
|
{
|
||||||
|
PRINT_ERR("Please initialize audio class first!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!shouldPlay)
|
||||||
|
{
|
||||||
|
shouldPlay = 1;
|
||||||
|
audsrv_set_volume(latestVolume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Audio::stop()
|
||||||
|
{
|
||||||
|
if (!isInitialized)
|
||||||
|
{
|
||||||
|
PRINT_ERR("Please initialize audio class first!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (shouldPlay)
|
||||||
|
{
|
||||||
|
shouldPlay = 0;
|
||||||
|
audsrv_set_volume(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not call this function.
|
||||||
|
* This is a audio thread, runned by AudioThread::start()
|
||||||
|
*/
|
||||||
|
void Audio::audioThread()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
audioRef->work();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not call this function.
|
||||||
* This is a static callback function
|
* This is a static callback function
|
||||||
* for AUDSRV fillbuffer (semaphore)
|
* for AUDSRV fillbuffer (semaphore)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,10 +32,9 @@ Ari::~Ari() {}
|
|||||||
|
|
||||||
void Ari::onInit()
|
void Ari::onInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes);
|
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes);
|
||||||
engine->audio.init(0);
|
engine->audio.init(0);
|
||||||
engine->audio.setVolume(40);
|
engine->audio.setVolume(30);
|
||||||
engine->audio.loadSong("MOV-CIRC.WAV");
|
engine->audio.loadSong("MOV-CIRC.WAV");
|
||||||
engine->audio.play();
|
engine->audio.play();
|
||||||
|
|
||||||
@@ -88,7 +87,15 @@ void Ari::initBulb()
|
|||||||
void Ari::onUpdate()
|
void Ari::onUpdate()
|
||||||
{
|
{
|
||||||
if (engine->pad.isCrossClicked)
|
if (engine->pad.isCrossClicked)
|
||||||
|
{
|
||||||
|
// engine->audio.stop();
|
||||||
|
engine->audio.test();
|
||||||
|
// engine->audio.unloadSong();
|
||||||
|
// engine->audio.loadSong("nob-else.wav");
|
||||||
|
// engine->audio.play();
|
||||||
|
|
||||||
printf("FPS:%f\n", engine->fps);
|
printf("FPS:%f\n", engine->fps);
|
||||||
|
}
|
||||||
camera.update(engine->pad, player.mesh);
|
camera.update(engine->pad, player.mesh);
|
||||||
engine->renderer->draw(skybox);
|
engine->renderer->draw(skybox);
|
||||||
engine->renderer->draw(island);
|
engine->renderer->draw(island);
|
||||||
|
|||||||
Reference in New Issue
Block a user