aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/audio/SDL/je_sdl_source.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-12-06 13:12:29 +0800
committerchai <chaifix@163.com>2018-12-06 13:12:29 +0800
commitb3712ebdf148bd8d2d31e70734a4b7923f6038f8 (patch)
treec813d158030ee33b76d7ec23fa2deaa1eb0a4e36 /src/libjin/audio/SDL/je_sdl_source.cpp
parent17d86218e25a6c889c24822da8d7b59967babd89 (diff)
*remove create function
Diffstat (limited to 'src/libjin/audio/SDL/je_sdl_source.cpp')
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.cpp46
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()