Audio: Replace SFML solution by using OpenAL directly
This is a major change in the Audio module that comes with many changes throughout the codebase and dependency list. The main gist is that we're finally nuking the last pieces of SFML from the project. sfml-audio brought with itself unneeded and big dependencies (libsndfile, libvorbisenc) while at the same time limiting the amount of audio formats mkxp can support (eg. we now get mp3 for free, and wma/midi can be implemented by extending SDL_sound directly). The increased control gained by interfacing with OpenAL directly will also allow for easy integration of a dedicated audio stretcher (librubberband), as well as enable us to implement looped ogg vorbis (via the 'LOOPSTART'/'LOOPLENGTH' tags), as required by RGSS2, in the future. The FileSystem class has had its SFML parts removed. Aditionally, audio file extensions to be supplemented are now automatically detected based on how SDL_sound was built (ie. if no mp3 support was built, mkxp won't try to look for *.mp3 files). The final used extension can be optionally returned by 'openRead' calls so SDL_sound and SDL2_image can immediately choose the right decoder. The OpenAL context is created and destroyed in main.cpp along side the GL context.
This commit is contained in:
parent
47db7165a6
commit
64f35071ab
6 changed files with 1655 additions and 634 deletions
src
55
src/main.cpp
55
src/main.cpp
|
@ -20,10 +20,12 @@
|
|||
*/
|
||||
|
||||
#include "glew.h"
|
||||
#include <alc.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_image.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include <SDL_sound.h>
|
||||
|
||||
#include "sharedstate.h"
|
||||
#include "eventthread.h"
|
||||
|
@ -77,7 +79,7 @@ int rgssThreadFun(void *userdata)
|
|||
{
|
||||
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
|
||||
SDL_Window *win = threadData->window;
|
||||
SDL_GLContext ctx;
|
||||
SDL_GLContext glCtx;
|
||||
|
||||
/* Setup GL context */
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
@ -85,9 +87,9 @@ int rgssThreadFun(void *userdata)
|
|||
if (threadData->config.debugMode)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||
|
||||
ctx = SDL_GL_CreateContext(win);
|
||||
glCtx = SDL_GL_CreateContext(win);
|
||||
|
||||
if (!ctx)
|
||||
if (!glCtx)
|
||||
{
|
||||
rgssThreadError(threadData, QByteArray("Error creating context: ") + SDL_GetError());
|
||||
return 0;
|
||||
|
@ -96,7 +98,7 @@ int rgssThreadFun(void *userdata)
|
|||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
rgssThreadError(threadData, "Error initializing glew");
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -110,7 +112,7 @@ int rgssThreadFun(void *userdata)
|
|||
if (!GLEW_VERSION_2_0)
|
||||
{
|
||||
rgssThreadError(threadData, "At least OpenGL 2.0 is required");
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -121,7 +123,7 @@ int rgssThreadFun(void *userdata)
|
|||
{
|
||||
rgssThreadError(threadData, QByteArray("Required GL extension \"")
|
||||
+ reqExt[i] + "\" not present");
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +132,28 @@ int rgssThreadFun(void *userdata)
|
|||
|
||||
DebugLogger dLogger;
|
||||
|
||||
/* Setup AL context */
|
||||
ALCdevice *alcDev = alcOpenDevice(0);
|
||||
|
||||
if (!alcDev)
|
||||
{
|
||||
rgssThreadError(threadData, "Error opening OpenAL device");
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ALCcontext *alcCtx = alcCreateContext(alcDev, 0);
|
||||
|
||||
if (!alcCtx)
|
||||
{
|
||||
rgssThreadError(threadData, "Error creating OpenAL context");
|
||||
alcCloseDevice(alcDev);
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
alcMakeContextCurrent(alcCtx);
|
||||
|
||||
SharedState::initInstance(threadData);
|
||||
|
||||
/* Start script execution */
|
||||
|
@ -140,7 +164,10 @@ int rgssThreadFun(void *userdata)
|
|||
|
||||
SharedState::finiInstance();
|
||||
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
alcDestroyContext(alcCtx);
|
||||
alcCloseDevice(alcDev);
|
||||
|
||||
SDL_GL_DeleteContext(glCtx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -155,6 +182,7 @@ int main(int, char *argv[])
|
|||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
|
||||
{
|
||||
qDebug() << "Error initializing SDL:" << SDL_GetError();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -163,6 +191,7 @@ int main(int, char *argv[])
|
|||
{
|
||||
qDebug() << "Error initializing SDL_image:" << SDL_GetError();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -171,6 +200,17 @@ int main(int, char *argv[])
|
|||
qDebug() << "Error initializing SDL_ttf:" << SDL_GetError();
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Sound_Init() == 0)
|
||||
{
|
||||
qDebug() << "Error initializing SDL_sound:" << Sound_GetError();
|
||||
TTF_Quit();
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -241,6 +281,7 @@ int main(int, char *argv[])
|
|||
|
||||
SDL_DestroyWindow(win);
|
||||
|
||||
Sound_Quit();
|
||||
TTF_Quit();
|
||||
IMG_Quit();
|
||||
SDL_Quit();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue