Rearrangements; Audio support
This commit is contained in:
5
src/sound/CMakeLists.txt
Normal file
5
src/sound/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
project(sound)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
add_library(sound STATIC sound.cpp)
|
||||
target_link_libraries(sound PRIVATE miniaudio PUBLIC OgreMain)
|
||||
target_include_directories(sound PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
47
src/sound/sound.cpp
Normal file
47
src/sound/sound.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <miniaudio.h>
|
||||
#include <Ogre.h>
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include "sound.h"
|
||||
namespace Sound
|
||||
{
|
||||
static ma_decoder decoder;
|
||||
static ma_device_config deviceConfig;
|
||||
static ma_device device;
|
||||
static ma_engine engine;
|
||||
std::vector<ma_sound> psound_data;
|
||||
std::map<Ogre::String, int> psounds;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int i;
|
||||
ma_result result;
|
||||
result = ma_engine_init(NULL, &engine);
|
||||
OgreAssert(result == MA_SUCCESS, "MiniAudio init failed");
|
||||
Ogre::FileInfoListPtr sounds =
|
||||
Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
|
||||
"Audio", "*.wav");
|
||||
psound_data.resize(sounds->size());
|
||||
for (i = 0; i < sounds->size(); i++) {
|
||||
Ogre::FileInfo fi = sounds->at(i);
|
||||
Ogre::String path =
|
||||
fi.archive->getName() + "/" + fi.path + fi.filename;
|
||||
std::cout << "sound: " << path << "\n";
|
||||
std::cout << "sound: " << fi.basename << "\n";
|
||||
ma_sound_init_from_file(&engine, path.c_str(), 0, NULL, NULL,
|
||||
&psound_data[i]);
|
||||
psounds[fi.basename] = i;
|
||||
}
|
||||
}
|
||||
void ding()
|
||||
{
|
||||
ma_sound &sound = psound_data[psounds["load.wav"]];
|
||||
if (ma_sound_is_playing(&sound) && ma_sound_at_end(&sound)) {
|
||||
ma_sound_stop(&sound);
|
||||
ma_sound_seek_to_pcm_frame(&sound, 0);
|
||||
} else if (ma_sound_is_playing(&sound))
|
||||
return;
|
||||
ma_sound_start(&sound);
|
||||
}
|
||||
}
|
||||
/* nothing */
|
||||
8
src/sound/sound.h
Normal file
8
src/sound/sound.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SOUND_H_
|
||||
#define SOUND_H_
|
||||
namespace Sound
|
||||
{
|
||||
void setup();
|
||||
void ding();
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user