Remove SDL_sound dependency

This commit is contained in:
Varun Patil 2020-05-06 17:24:03 +05:30
parent bf1602e49f
commit fa912b616b
8 changed files with 58 additions and 10 deletions

View File

@ -380,7 +380,6 @@ endif()
link_directories(
../libsigc++-2.10.3/sigc++/.libs
../SDL_sound/.libs
../pixman-0.40.0/pixman/.libs
../physfs-3.0.2
../ruby
@ -388,6 +387,7 @@ link_directories(
../mruby/build/x86_64-pc-linux-gnu/lib
libs
#../SDL_sound/.libs
${SDL2_LIBRARY_DIRS}
)
@ -406,11 +406,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE
src
windows
../libsigc++-2.10.3
../SDL_sound
../pixman-0.40.0/pixman
../physfs-3.0.2/src
../mruby/include
#..
#../SDL_sound
${SDL2_INCLUDE_DIRS}
#${VORBISFILE_INCLUDE_DIRS}
@ -421,11 +422,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE
target_link_libraries(${PROJECT_NAME}
#ruby-static.a
sigc-2.0.a physfs.a SDL_sound.a pixman-1.a
sigc-2.0.a physfs.a pixman-1.a
#sigc-2.0.x86.a physfs.x86.a SDL_sound.x86.a pixman-1.x86.a
mruby.a
#SDL_sound.a
#ruby-static.x86.a
#crypt
#dl

View File

@ -40,6 +40,11 @@ struct ALDataSource
* to provided AL buffer */
virtual Status fillBuffer(AL::Buffer::ID alBuffer) = 0;
/* Read everything into the provided buffer */
virtual int fillBufferFull(AL::Buffer::ID alBuffer) {
return 0;
};
virtual int sampleRate() = 0;
/* If the source doesn't support seeking, it will
@ -53,10 +58,12 @@ struct ALDataSource
virtual bool setPitch(float value) = 0;
};
#ifndef __EMSCRIPTEN__
ALDataSource *createSDLSource(SDL_RWops &ops,
const char *extension,
uint32_t maxBufSize,
bool looped);
#endif
ALDataSource *createVorbisSource(SDL_RWops &ops,
bool looped);

View File

@ -244,7 +244,9 @@ struct ALStreamOpenHandler : FileSystem::OpenHandler
}
}
#ifndef __EMSCRIPTEN__
source = createSDLSource(*srcOps, ext, STREAM_BUF_SIZE, looped);
#endif
}
catch (const Exception &e)
{

View File

@ -31,8 +31,6 @@
#include <physfs.h>
#include <SDL_sound.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

View File

@ -24,7 +24,10 @@
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#ifndef __EMSCRIPTEN__
#include <SDL_sound.h>
#endif
#include <unistd.h>
#include <string.h>
@ -272,6 +275,7 @@ int main(int argc, char *argv[])
return 0;
}
#ifndef __EMSCRIPTEN__
if (Sound_Init() == 0)
{
showInitError(std::string("Error initializing SDL_sound: ") + Sound_GetError());
@ -281,6 +285,7 @@ int main(int argc, char *argv[])
return 0;
}
#endif
SDL_Window *win;
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS;
@ -385,7 +390,10 @@ int main(int argc, char *argv[])
alcCloseDevice(alcDev);
SDL_DestroyWindow(win);
#ifndef __EMSCRIPTEN__
Sound_Quit();
#endif
TTF_Quit();
IMG_Quit();
SDL_Quit();

View File

@ -22,6 +22,8 @@
#include "aldatasource.h"
#include "exception.h"
#ifndef __EMSCRIPTEN__
#include <SDL_sound.h>
struct SDLSoundSource : ALDataSource
@ -129,3 +131,5 @@ ALDataSource *createSDLSource(SDL_RWops &ops,
{
return new SDLSoundSource(ops, extension, maxBufSize, looped);
}
#endif

View File

@ -28,10 +28,11 @@
#include "util.h"
#include "debugwriter.h"
#ifndef __EMSCRIPTEN__
#include <SDL_sound.h>
#ifdef __EMSCRIPTEN__
#else
#include "emscripten.hpp"
#include "aldatasource.h"
#endif
#define SE_CACHE_MEM (10*1024*1024) // 10 MB
@ -198,6 +199,11 @@ struct SoundOpenHandler : FileSystem::OpenHandler
bool tryRead(SDL_RWops &ops, const char *ext, const char *fullPath)
{
#ifdef __EMSCRIPTEN__
ALDataSource *source = createVorbisSource(ops, false);
buffer = new SoundBuffer;
buffer->bytes = source->fillBufferFull(buffer->alBuffer);
#else
Sound_Sample *sample = Sound_NewSample(&ops, ext, 0, STREAM_BUF_SIZE);
if (!sample)
@ -221,7 +227,7 @@ struct SoundOpenHandler : FileSystem::OpenHandler
buffer->bytes, sample->actual.rate);
Sound_FreeSample(sample);
#endif
return true;
}
};
@ -253,8 +259,13 @@ SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename)
if (!buffer)
{
char buf[512];
#ifdef __EMSCRIPTEN__
snprintf(buf, sizeof(buf), "Unable to decode with vorbisfile: %s",
filename.c_str());
#else
snprintf(buf, sizeof(buf), "Unable to decode sound: %s: %s",
filename.c_str(), Sound_GetError());
#endif
Debug() << buf;
return 0;

View File

@ -78,6 +78,9 @@ struct VorbisSource : ALDataSource
std::vector<int16_t> sampleBuf;
int bufUsed = 0;
bool readFull = false;
VorbisSource(SDL_RWops &ops,
bool looped)
: src(ops),
@ -178,7 +181,7 @@ struct VorbisSource : ALDataSource
{
void *bufPtr = sampleBuf.data();
int availBuf = sampleBuf.size();
int bufUsed = 0;
bufUsed = 0;
int canRead = availBuf;
@ -259,6 +262,12 @@ struct VorbisSource : ALDataSource
}
canRead -= res;
/* Double size if we want to read everything */
if (readFull && !(canRead > 16)) {
canRead += sampleBuf.size();
sampleBuf.resize(sampleBuf.size() * 2);
}
}
if (retStatus != ALDataSource::Error)
@ -268,6 +277,13 @@ struct VorbisSource : ALDataSource
return retStatus;
}
int fillBufferFull(AL::Buffer::ID alBuffer) {
readFull = true;
fillBuffer(alBuffer);
readFull = false;
return bufUsed*sizeof(int16_t);
}
uint32_t loopStartFrames()
{
if (loop.valid)