diff options
Diffstat (limited to 'smelt/sdl')
-rw-r--r-- | smelt/sdl/sfx_sdl.cpp | 35 | ||||
-rw-r--r-- | smelt/sdl/smelt_internal.hpp | 2 |
2 files changed, 33 insertions, 4 deletions
diff --git a/smelt/sdl/sfx_sdl.cpp b/smelt/sdl/sfx_sdl.cpp index b61a8a0..c49162a 100644 --- a/smelt/sdl/sfx_sdl.cpp +++ b/smelt/sdl/sfx_sdl.cpp @@ -13,6 +13,7 @@ static const char* SFX_SDL_SRCFN="smelt/sdl/sfx_sdl.cpp"; struct oggdata{const BYTE *data;DWORD size,pos;}; static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq); +static void* readRiffWv(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq); SMSFX SMELT_IMPL::smSFXLoad(const char *path) { FILE *pFile;DWORD size,rsize; char *buff; @@ -33,15 +34,20 @@ SMSFX SMELT_IMPL::smSFXLoadFromMemory(const char *ptr,DWORD size) if(pOpenALDevice&&!mute) { bool isOgg=size>4&&ptr[0]=='O'&&ptr[1]=='g'&&ptr[2]=='g'&&ptr[3]=='S'; - if(!isOgg)return 0; void *decompdata=NULL,*decomp=NULL; ALsizei decompsize=0,freq=0; ALenum fmt=AL_FORMAT_STEREO16; - decompdata=readVorbis((const BYTE*)ptr,size,&decompsize,&fmt,&freq); + decompdata=readRiffWv((const BYTE*)ptr,size,&decompsize,&fmt,&freq); + if(!decompdata) + { + if(!isOgg)return 0; + else decompdata=readVorbis((const BYTE*)ptr,size,&decompsize,&fmt,&freq); + } + if(!decompdata)return 0; decomp=decompdata; ALuint buff=0;alGenBuffers(1,&buff); alBufferData(buff,fmt,decomp,decompsize,freq); - free(decompdata);return (SMSFX)buff; + free(decompdata);return(SMSFX)buff; } return 0; } @@ -270,6 +276,29 @@ static void* readVorbis(const BYTE *data,const DWORD size, ALsizei *decomp_size, } return NULL; } +static void* readRiffWv(const BYTE *data,const DWORD size, ALsizei *decomp_size,ALenum *fmt,ALsizei *freq) +{ + if(data[0x0]!='R'||data[0x1]!='I'||data[0x2]!='F'||data[0x3]!='F')return NULL; + if(data[0x8]!='W'||data[0x9]!='A'||data[0xA]!='V'||data[0xB]!='E')return NULL; + if(data[0xC]!='f'||data[0xD]!='m'||data[0xE]!='t'||data[0xF]!=' ')return NULL; + if(data[0x16]==2) + { + if(data[0x22]==16)*fmt=AL_FORMAT_STEREO16; + else if(data[0x22]==8)*fmt=AL_FORMAT_STEREO8; + else return NULL; + } + else if(data[0x16]==1) + { + if(data[0x22]==16)*fmt=AL_FORMAT_MONO16; + else if(data[0x22]==8)*fmt=AL_FORMAT_MONO8; + else return NULL; + }else return NULL; + *decomp_size=(ALsizei)(data[0x28]|(data[0x29]<<8L)|(data[0x2A]<<16L)|(data[0x2B]<<24L)); + *freq=(ALsizei)(data[0x18]|(data[0x19]<<8L)|(data[0x1A]<<16L)|(data[0x1B]<<24L)); + ALubyte *ret=(ALubyte*)malloc(*decomp_size); + memcpy(ret,data+44,*decomp_size); + return ret; +} ALuint SMELT_IMPL::getSource() { for(int i=0;i<scnt;++i) diff --git a/smelt/sdl/smelt_internal.hpp b/smelt/sdl/smelt_internal.hpp index 2688fdd..a434079 100644 --- a/smelt/sdl/smelt_internal.hpp +++ b/smelt/sdl/smelt_internal.hpp @@ -12,6 +12,7 @@ #define SMELT_INTERNAL_H #include "../../include/smelt.hpp" +#include "smelt_config.hpp" #include <cstdio> #include <cstring> #include <cstdlib> @@ -25,7 +26,6 @@ #include <AL/alext.h> #include <ogg/ogg.h> #include <vorbis/vorbisfile.h> -#include <smelt_config.hpp> #ifdef WIN32 #include <windows.h> #include <intrin.h> |