diff options
author | chai <chaifix@163.com> | 2018-05-28 23:05:57 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-05-28 23:05:57 +0800 |
commit | 733cffe5d3cf6c421940b38d41456c89029a975d (patch) | |
tree | 2d910e91da928a4c564fce87e71ea39be3cf606f | |
parent | 90a2ec2b18d7d3a36fa3106c4d063b1048d8d98e (diff) |
更新音频模块
-rw-r--r-- | bin/jin.exe | bin | 1533440 -> 1533440 bytes | |||
-rw-r--r-- | src/libjin/audio/sdl/source.cpp | 22 |
2 files changed, 13 insertions, 9 deletions
diff --git a/bin/jin.exe b/bin/jin.exe Binary files differindex 1ae3818..c4b35b2 100644 --- a/bin/jin.exe +++ b/bin/jin.exe diff --git a/src/libjin/audio/sdl/source.cpp b/src/libjin/audio/sdl/source.cpp index bfe090b..69c0670 100644 --- a/src/libjin/audio/sdl/source.cpp +++ b/src/libjin/audio/sdl/source.cpp @@ -57,7 +57,13 @@ namespace audio SDLSource* SDLSource::createSource(SourceType format, const char* file) { - std::ifstream fs(file, std::ios::binary); + std::ifstream fs; + fs.open(file, std::ios::binary); + if (!fs.is_open()) + { + fs.close(); + return nullptr; + } fs.seekg(0,std::ios::end); int size = fs.tellg(); fs.seekg(0, std::ios::beg); @@ -74,20 +80,16 @@ namespace audio if (mem == nullptr) return nullptr; SDLSource* source = new SDLSource(); - memset(&source->status, 0, sizeof(status)); - memset(&source->raw, 0, sizeof(raw)); +#define read(FMT) case FMT : source->load##FMT(mem, size); break try { switch (format) { - case WAV: - source->loadWAV(mem, size); - break; - case OGG: - source->loadOGG(mem, size); - break; + read(OGG); + read(WAV); } } +#undef read catch (SourceException& exp) { delete source; @@ -98,6 +100,8 @@ namespace audio SDLSource::SDLSource() { + memset(&status, 0, sizeof(status)); + memset(&raw, 0, sizeof(raw)); } SDLSource::~SDLSource() |