aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/audio/SDL
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/audio/SDL')
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.cpp46
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.h23
2 files changed, 26 insertions, 43 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()
diff --git a/src/libjin/audio/SDL/je_sdl_source.h b/src/libjin/audio/SDL/je_sdl_source.h
index 07333ae..8a3309e 100644
--- a/src/libjin/audio/SDL/je_sdl_source.h
+++ b/src/libjin/audio/SDL/je_sdl_source.h
@@ -28,21 +28,19 @@ namespace JinEngine
{
public:
///
- /// Create source from raw source data file.
+ /// Source constructor.
+ ///
+ SDLSource();
+
+ ///
///
- /// @param file Audio source file.
- /// @return Return source if create successful, otherwise return null.
///
- static SDLSource* createSource(const char* file);
+ SDLSource(const char* file);
///
- /// Create source from raw source data.
- ///
- /// @param mem Source data.
- /// @param size Source data size.
- /// @return Return source if create successful, otherwise return null.
///
- static SDLSource* createSource(void* mem, size_t size);
+ ///
+ SDLSource(void* mem, size_t size);
///
/// Source destructor.
@@ -134,11 +132,6 @@ namespace JinEngine
protected:
///
- /// Source constructor.
- ///
- SDLSource();
-
- ///
/// Decode wav file.
///
/// @param mem Wav file data.