Add in raw audio buffer loading support from PGE resource packs in the MiniAudio PGEX. Ready for merge. Release Build 11541.
This commit is contained in:
parent
9b69a4ebb3
commit
3682d9cf68
@ -39,7 +39,7 @@ All rights reserved.
|
|||||||
#define VERSION_MAJOR 1
|
#define VERSION_MAJOR 1
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 5
|
#define VERSION_PATCH 5
|
||||||
#define VERSION_BUILD 11523
|
#define VERSION_BUILD 11541
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -158,7 +158,15 @@ namespace olc
|
|||||||
// this is where the sounds are kept
|
// this is where the sounds are kept
|
||||||
std::vector<ma_sound*> vecSounds;
|
std::vector<ma_sound*> vecSounds;
|
||||||
std::vector<ma_sound*> vecOneOffSounds;
|
std::vector<ma_sound*> vecOneOffSounds;
|
||||||
std::vector<std::pair<size_t,ma_audio_buffer>>vecResourcePackBuffers;
|
struct ResourceData{
|
||||||
|
ma_engine*engine;
|
||||||
|
ResourceBuffer data;
|
||||||
|
std::string pathName;
|
||||||
|
~ResourceData(){
|
||||||
|
if(ma_resource_manager_unregister_data(ma_engine_get_resource_manager(engine),pathName.data())!=MA_SUCCESS)ERR(std::format("WARNING! Could not clear resources for {}!",pathName));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
std::unordered_map<size_t,ResourceData>vecResourceData;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,21 +332,11 @@ namespace olc
|
|||||||
if(!foundSound)vecSounds.emplace_back(sound);
|
if(!foundSound)vecSounds.emplace_back(sound);
|
||||||
|
|
||||||
if(soundType==BGM){
|
if(soundType==BGM){
|
||||||
ma_audio_buffer newBuffer{};
|
vecResourceData[id]={&engine,game->gamepack.GetFileBuffer(path),path};
|
||||||
ResourceBuffer rb{game->gamepack.GetFileBuffer(path)};
|
if(ma_resource_manager_register_encoded_data(ma_engine_get_resource_manager(&engine),path.data(),vecResourceData[id].data.vMemory.data(),vecResourceData[id].data.vMemory.size())!=MA_SUCCESS)ERR(std::format("WARNING! Could not load resources for {}!",path));
|
||||||
short*decodedOggFile;
|
|
||||||
int numSamples{stb_vorbis_decode_memory((const unsigned char*)(rb.vMemory.data()),rb.vMemory.size(),(int*)(&device.playback.channels),(int*)(&device.sampleRate),&decodedOggFile)};
|
|
||||||
if(numSamples==-1)ERR(std::format("Failed to decode Ogg Vorbis file! {}",path));
|
|
||||||
LOG(std::format("Samples: {}, Channels: {}, Sample Rate: {}",numSamples,device.playback.channels,device.sampleRate));
|
|
||||||
ma_audio_buffer_config config{ma_audio_buffer_config_init(device.playback.format,device.playback.channels,numSamples,decodedOggFile,nullptr)};
|
|
||||||
if(ma_audio_buffer_init(&config,&newBuffer)!=MA_SUCCESS)ERR(std::format("WARNING! Failed to load audio buffer~! {}",path));
|
|
||||||
if(ma_sound_init_from_data_source(&engine,&newBuffer,MA_SOUND_FLAG_DECODE|MA_SOUND_FLAG_ASYNC,nullptr,sound)!=MA_SUCCESS)ERR(std::format("Could not initialize sound! {}",path));
|
|
||||||
vecResourcePackBuffers.emplace_back(std::pair<size_t,ma_audio_buffer>{id,newBuffer});
|
|
||||||
}else{ //Sound effects
|
|
||||||
// load it from the file and decode it
|
|
||||||
if(ma_sound_init_from_file(&engine, path.c_str(), MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_ASYNC, NULL, NULL, sound) != MA_SUCCESS)
|
|
||||||
throw MiniAudioSoundException();
|
|
||||||
}
|
}
|
||||||
|
if(ma_sound_init_from_file(&engine, path.c_str(), MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_ASYNC, NULL, NULL, sound) != MA_SUCCESS)
|
||||||
|
throw MiniAudioSoundException();
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -348,7 +346,7 @@ namespace olc
|
|||||||
ma_sound_uninit(vecSounds.at(id));
|
ma_sound_uninit(vecSounds.at(id));
|
||||||
delete vecSounds.at(id);
|
delete vecSounds.at(id);
|
||||||
vecSounds.at(id) = nullptr;
|
vecSounds.at(id) = nullptr;
|
||||||
std::erase_if(vecResourcePackBuffers,[&id](const std::pair<size_t,ma_audio_buffer>&bufferData){return id==bufferData.first;});
|
if(vecResourceData.count(id))vecResourceData.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiniAudio::Play(const int id, const bool loop)
|
void MiniAudio::Play(const int id, const bool loop)
|
||||||
|
@ -713,6 +713,7 @@ namespace olc
|
|||||||
// O------------------------------------------------------------------------------O
|
// O------------------------------------------------------------------------------O
|
||||||
struct ResourceBuffer : public std::streambuf
|
struct ResourceBuffer : public std::streambuf
|
||||||
{
|
{
|
||||||
|
ResourceBuffer();
|
||||||
ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size);
|
ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size);
|
||||||
std::vector<char> vMemory;
|
std::vector<char> vMemory;
|
||||||
};
|
};
|
||||||
@ -1794,6 +1795,7 @@ namespace olc
|
|||||||
//=============================================================
|
//=============================================================
|
||||||
// Resource Packs - Allows you to store files in one large
|
// Resource Packs - Allows you to store files in one large
|
||||||
// scrambled file - Thanks MaGetzUb for debugging a null char in std::stringstream bug
|
// scrambled file - Thanks MaGetzUb for debugging a null char in std::stringstream bug
|
||||||
|
ResourceBuffer::ResourceBuffer(){}
|
||||||
ResourceBuffer::ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size)
|
ResourceBuffer::ResourceBuffer(std::ifstream& ifs, uint32_t offset, uint32_t size)
|
||||||
{
|
{
|
||||||
vMemory.resize(size);
|
vMemory.resize(size);
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user