-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vorbis decoding of ogg via miniaudio working, specifies all licenses
- Loading branch information
1 parent
981de77
commit 228af52
Showing
438 changed files
with
114,032 additions
and
103 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
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,154 @@ | ||
#ifndef SSOUND_H | ||
#define SSOUND_H | ||
|
||
#define MA_NO_VORBIS | ||
#define MINIAUDIO_IMPLEMENTATION | ||
#include <miniaudio/miniaudio.h> | ||
#include <System/Sound/vorbis.h> | ||
|
||
#include <log.h> | ||
#include <sstream> | ||
|
||
#include <Object/entityComponentSystem.h> | ||
|
||
namespace Hop::Object | ||
{ | ||
class EntityComponentSystem; | ||
} | ||
|
||
namespace Hop::System::Sound | ||
{ | ||
|
||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); | ||
|
||
std::string maErrorToString(ma_result code); | ||
|
||
enum class DECODER {MA, VORBIS, NONE}; | ||
|
||
class sSound : public System | ||
{ | ||
|
||
public: | ||
|
||
sSound() | ||
: loopingFile("") | ||
{ | ||
ma_result result = ma_engine_init(NULL, &engine); | ||
} | ||
|
||
~sSound() | ||
{ | ||
ma_engine_uninit(&engine); | ||
ma_device_uninit(&device); | ||
ma_decoder_uninit(&decoder); | ||
} | ||
|
||
ma_result decode(std::string file) | ||
{ | ||
ma_result result = ma_decoder_init_file(file.c_str(), NULL, &decoder); | ||
|
||
if (result != MA_SUCCESS) | ||
{ | ||
vorbisConfig = ma_decoder_config_init_default(); | ||
vorbisConfig.pCustomBackendUserData = NULL; | ||
vorbisConfig.ppCustomBackendVTables = pCustomBackendVTables; | ||
vorbisConfig.customBackendCount = sizeof(pCustomBackendVTables) / sizeof(pCustomBackendVTables[0]); | ||
|
||
result = ma_decoder_init_file(file.c_str(), &vorbisConfig, &vorbisDecoder); | ||
|
||
if (result == MA_SUCCESS) | ||
{ | ||
decoderInUse = DECODER::VORBIS; | ||
} | ||
} | ||
else | ||
{ | ||
decoderInUse = DECODER::MA; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void setLoopSound(std::string filename) | ||
{ | ||
if (loopingFile == "") | ||
{ | ||
loopingFile = filename; | ||
|
||
ma_result result = decode(filename); | ||
|
||
if (result != MA_SUCCESS) | ||
{ | ||
Hop::Logging::Log log; | ||
std::stringstream ss; | ||
ss << "Could not decode audio file: " << filename << ", got error: " << maErrorToString(result); | ||
Hop::Logging::ERROR(ss.str()) >> log; | ||
} | ||
|
||
if (decoderInUse == DECODER::MA) | ||
{ | ||
ma_data_source_set_looping(&decoder, MA_TRUE); | ||
|
||
config = ma_device_config_init(ma_device_type_playback); | ||
|
||
config.playback.format = decoder.outputFormat; | ||
config.playback.channels = decoder.outputChannels; | ||
config.sampleRate = decoder.outputSampleRate; | ||
config.dataCallback = data_callback; | ||
config.pUserData = &decoder; | ||
} | ||
else | ||
{ | ||
ma_data_source_set_looping(&vorbisDecoder, MA_TRUE); | ||
|
||
config = ma_device_config_init(ma_device_type_playback); | ||
|
||
config.playback.format = vorbisDecoder.outputFormat; | ||
config.playback.channels = vorbisDecoder.outputChannels; | ||
config.sampleRate = vorbisDecoder.outputSampleRate; | ||
config.dataCallback = data_callback; | ||
config.pUserData = &vorbisDecoder; | ||
} | ||
|
||
ma_device_init(NULL, &config, &device); | ||
|
||
ma_device_start(&device); | ||
looping = true; | ||
} | ||
} | ||
|
||
void stopLoopSound() | ||
{ | ||
if (looping) | ||
{ | ||
ma_device_stop(&device); | ||
} | ||
} | ||
|
||
private: | ||
|
||
ma_engine engine; | ||
|
||
ma_decoder decoder; | ||
|
||
ma_decoder vorbisDecoder; | ||
ma_decoder_config vorbisConfig; | ||
|
||
ma_device device; | ||
ma_device_config config; | ||
|
||
std::string loopingFile; | ||
bool looping = false; | ||
|
||
DECODER decoderInUse = DECODER::NONE; | ||
|
||
ma_decoding_backend_vtable* pCustomBackendVTables[1] = | ||
{ | ||
&g_ma_decoding_backend_vtable_libvorbis | ||
}; | ||
|
||
|
||
}; | ||
|
||
} | ||
#endif /* SSOUND_H */ |
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,91 @@ | ||
#ifndef VORBIS_H | ||
#define VORBIS_H | ||
|
||
#include <miniaudio/miniaudio.h> | ||
|
||
/* | ||
Miniaudio's libvorbis example | ||
https://miniaud.io/docs/examples/custom_decoder.html | ||
*/ | ||
|
||
namespace Hop::System::Sound | ||
{ | ||
static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) | ||
{ | ||
ma_result result; | ||
ma_libvorbis* pVorbis; | ||
|
||
(void)pUserData; | ||
|
||
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); | ||
if (pVorbis == NULL) { | ||
return MA_OUT_OF_MEMORY; | ||
} | ||
|
||
result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); | ||
if (result != MA_SUCCESS) { | ||
ma_free(pVorbis, pAllocationCallbacks); | ||
return result; | ||
} | ||
|
||
*ppBackend = pVorbis; | ||
|
||
return MA_SUCCESS; | ||
} | ||
|
||
static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) | ||
{ | ||
ma_result result; | ||
ma_libvorbis* pVorbis; | ||
|
||
(void)pUserData; | ||
|
||
pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); | ||
if (pVorbis == NULL) { | ||
return MA_OUT_OF_MEMORY; | ||
} | ||
|
||
result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); | ||
if (result != MA_SUCCESS) { | ||
ma_free(pVorbis, pAllocationCallbacks); | ||
return result; | ||
} | ||
|
||
*ppBackend = pVorbis; | ||
|
||
return MA_SUCCESS; | ||
} | ||
|
||
static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) | ||
{ | ||
ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend; | ||
|
||
(void)pUserData; | ||
|
||
ma_libvorbis_uninit(pVorbis, pAllocationCallbacks); | ||
ma_free(pVorbis, pAllocationCallbacks); | ||
} | ||
|
||
static ma_result ma_decoding_backend_get_channel_map__libvorbis(void* pUserData, ma_data_source* pBackend, ma_channel* pChannelMap, size_t channelMapCap) | ||
{ | ||
ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend; | ||
|
||
(void)pUserData; | ||
|
||
return ma_libvorbis_get_data_format(pVorbis, NULL, NULL, NULL, pChannelMap, channelMapCap); | ||
} | ||
|
||
static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libvorbis = | ||
{ | ||
ma_decoding_backend_init__libvorbis, | ||
ma_decoding_backend_init_file__libvorbis, | ||
NULL, /* onInitFileW() */ | ||
NULL, /* onInitMemory() */ | ||
ma_decoding_backend_uninit__libvorbis | ||
}; | ||
|
||
} | ||
|
||
#endif /* VORBIS_H */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.