diff options
Diffstat (limited to 'src/libjin/audio/SDL/je_sdl_source.cpp')
-rw-r--r-- | src/libjin/audio/SDL/je_sdl_source.cpp | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/src/libjin/audio/SDL/je_sdl_source.cpp b/src/libjin/audio/SDL/je_sdl_source.cpp index d417bf7..90f8daa 100644 --- a/src/libjin/audio/SDL/je_sdl_source.cpp +++ b/src/libjin/audio/SDL/je_sdl_source.cpp @@ -24,7 +24,6 @@ namespace JinEngine namespace SDL { - #define BITS 8 typedef struct SDLSourceCommand @@ -74,14 +73,22 @@ namespace JinEngine //std::vector<SDLSource*> Manager::sources; Manager* Manager::manager = nullptr; - SDLSource* SDLSource::createSource(const char* file) + SDLSource::SDLSource() + { + memset(&status, 0, sizeof(status)); + memset(&raw, 0, sizeof(raw)); + status.volume = 1; + } + + SDLSource::SDLSource(const char* file) + : SDLSource() { std::ifstream fs; fs.open(file, std::ios::binary); if (!fs.is_open()) { fs.close(); - return nullptr; + return; } fs.seekg(0, std::ios::end); int size = fs.tellg(); @@ -90,38 +97,21 @@ namespace JinEngine memset(buffer, 0, size); fs.read(buffer, size); fs.close(); - SDLSource* source = createSource(buffer, size); + SDLSource(buffer, size); free(buffer); - return source; } - SDLSource* SDLSource::createSource(void* mem, size_t size) + SDLSource::SDLSource(void* mem, size_t size) + : SDLSource() { if (mem == nullptr) - return nullptr; - SDLSource* source = new SDLSource(); - try + return; + SourceType format = getType(mem, size); + switch (format) { - SourceType format = getType(mem, size); - switch (format) - { - case OGG: source->decode_ogg(mem, size); break; - case WAV: source->decode_wav(mem, size); break; - } + case OGG: decode_ogg(mem, size); break; + case WAV: decode_wav(mem, size); break; } - catch (SourceException& exp) - { - delete source; - return nullptr; - }; - return source; - } - - SDLSource::SDLSource() - { - memset(&status, 0, sizeof(status)); - memset(&raw, 0, sizeof(raw)); - status.volume = 1; } SDLSource::~SDLSource() |