Skip to content

Commit

Permalink
Implement infrastructure for audio backends integration.
Browse files Browse the repository at this point in the history
Main features of this infrastructure are:
- backends compiled into the ui are selected at compile time via a
  HAVE_XXX_BACKEND macro / Makefile variable. This allow frontend
  maintainer to select which audio backend is adapted for their
  platform and avoid potential unwanted dependencies.
- audio backend selection at runtime is done using the --audio
  parameter. This allow the user to choose which audio backend (among
  those available) to use.
- it is possible to list available audio backends on the command line
  (--audio list).
  • Loading branch information
bsmiles32 committed Mar 7, 2015
1 parent 398b96c commit b1e1fa8
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 3 deletions.
8 changes: 7 additions & 1 deletion projects/VisualStudio2013/mupen64plus-ui-console.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ copy ..\..\..\mupen64plus-win32-deps\zlib-1.2.3\bin\*.dll "$(OutDir)"
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\backends\audio\dummy_audio_backend.c" />
<ClCompile Include="..\..\src\backends\audio\sdl_audio_backend.c" />
<ClCompile Include="..\..\src\backend_factory.c" />
<ClCompile Include="..\..\src\cheat.c" />
<ClCompile Include="..\..\src\compare_core.c" />
<ClCompile Include="..\..\src\core_interface.c" />
Expand All @@ -127,6 +130,9 @@ copy ..\..\..\mupen64plus-win32-deps\zlib-1.2.3\bin\*.dll "$(OutDir)"
<ClCompile Include="..\..\src\plugin.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\backends\audio\dummy_audio_backend.h" />
<ClInclude Include="..\..\src\backends\audio\sdl_audio_backend.h" />
<ClInclude Include="..\..\src\backend_factory.h" />
<ClInclude Include="..\..\src\cheat.h" />
<ClInclude Include="..\..\src\compare_core.h" />
<ClInclude Include="..\..\src\core_interface.h" />
Expand All @@ -140,4 +146,4 @@ copy ..\..\..\mupen64plus-win32-deps\zlib-1.2.3\bin\*.dll "$(OutDir)"
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
14 changes: 12 additions & 2 deletions projects/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,19 @@ endif

# list of source files to compile
SOURCE = \
$(SRCDIR)/backend_factory.c \
$(SRCDIR)/cheat.c \
$(SRCDIR)/compare_core.c \
$(SRCDIR)/core_interface.c \
$(SRCDIR)/main.c \
$(SRCDIR)/plugin.c
$(SRCDIR)/plugin.c \
$(SRCDIR)/backends/audio/dummy_audio_backend.c

# optional audio backends
ifeq ($(HAVE_SDL_AUDIO_BACKEND),1)
CFLAGS += '-DHAVE_SDL_AUDIO_BACKEND'
SOURCE += $(SRCDIR)/backends/audio/sdl_audio_backend.c
endif

ifeq ($(OS), MINGW)
SOURCE += \
Expand Down Expand Up @@ -265,7 +273,9 @@ targets:
@echo " OPTFLAGS=flags == compiler optimization (default: -O3 -flto)"
@echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)"
@echo " PIE=(1|0) == Force enable/disable of position independent executables"
@echo " POSTFIX=name == String added to the name of the the build (default: '')"
@echo " POSTFIX=name == String added to the name of the the build (default: '')"
@echo " Optional backends:"
@echo " HAVE_SDL_AUDIO_BACKEND=(1|0) == enable|disable SDL audio backend compilation (default:0)"
@echo " Install Options:"
@echo " PREFIX=path == install/uninstall prefix (default: /usr/local/)"
@echo " BINDIR=path == path to install mupen64plus binary (default: PREFIX/bin/)"
Expand Down
59 changes: 59 additions & 0 deletions src/backend_factory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - audio_backend_factory.c *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "backend_factory.h"

#include "backends/audio/dummy_audio_backend.h"

#ifdef HAVE_SDL_AUDIO_BACKEND
#include "backends/audio/sdl_audio_backend.h"
#endif

#include <string.h>


const struct backend_factory* const audio_backend_factories[] =
{
&dummy_audio_backend_factory,
#ifdef HAVE_SDL_AUDIO_BACKEND
&sdl_audio_backend_factory,
#endif
NULL /* end of array sentinel */
};

const struct backend_factory* get_backend_factory(const struct backend_factory* const* factories, const char* name)
{
if (factories != NULL && name != NULL)
{
while((*factories) != NULL)
{
if (strcmp(name, (*factories)->name) == 0)
{
return *factories;
}

++factories;
}
}

return NULL;
}

38 changes: 38 additions & 0 deletions src/backend_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - backend_factory.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_BACKEND_FACTORY_H
#define M64P_BACKEND_FACTORY_H

#include "m64p_types.h"

struct backend_factory
{
const char* name;
m64p_error (*init)(struct m64p_audio_backend* backend);
void (*release)(struct m64p_audio_backend* backend);
};

const struct backend_factory*
get_backend_factory(const struct backend_factory* const* factories, const char* name);

extern const struct backend_factory* const audio_backend_factories[];
#endif
45 changes: 45 additions & 0 deletions src/backends/audio/dummy_audio_backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - dummy_audio_backend.c *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "dummy_audio_backend.h"

#include "m64p_types.h"

#include <string.h>

/* dummy audio backend factory implementation */
static m64p_error init(struct m64p_audio_backend* backend)
{
/* set to NULL all members to trigger dummy audio backend behavior in the core */
memset(backend, 0, sizeof(*backend));
return M64ERR_SUCCESS;
}

static void release(struct m64p_audio_backend* backend)
{
}


const struct backend_factory dummy_audio_backend_factory =
{
"dummy", init, release
};

29 changes: 29 additions & 0 deletions src/backends/audio/dummy_audio_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - dummy_audio_backend.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_DUMMY_AUDIO_BACKEND_H
#define M64P_DUMMY_AUDIO_BACKEND_H

#include "backend_factory.h"

const struct backend_factory dummy_audio_backend_factory;

#endif
58 changes: 58 additions & 0 deletions src/backends/audio/sdl_audio_backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - sdl_audio_backend.c *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "sdl_audio_backend.h"

#include "m64p_types.h"
#include "main.h"

static void set_audio_format(void* user_data, unsigned int frequency, unsigned int bits)
{
/* TODO implement set audio format */
DebugMessage(M64MSG_WARNING, "SDL audio backend set format: %dHz %d bits", frequency, bits);

}

static void push_audio_samples(void* user_data, const void* buffer, size_t size)
{
/* TODO implement push audio samples */
DebugMessage(M64MSG_WARNING, "SDL audio backend push samples: @%p 0x%x bytes", buffer, size);
}

static m64p_error init(struct m64p_audio_backend* backend)
{
/* TODO open SDL audio subsystem */

/* fill backend structure */
backend->user_data = NULL;
backend->set_audio_format = set_audio_format;
backend->push_audio_samples = push_audio_samples;

return M64ERR_SUCCESS;
}

static void release(struct m64p_audio_backend* backend)
{
/* TODO close SDL audio subsystem */
}

/* SDL audio backend descriptor */
const struct backend_factory sdl_audio_backend_factory = { "sdl", init, release };
29 changes: 29 additions & 0 deletions src/backends/audio/sdl_audio_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - sdl_audio_backend.h *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2015 Bobby Smiles *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_AUDIO_BACKENDS_SDL_AUDIO_BACKEND_H
#define M64P_AUDIO_BACKENDS_SDL_AUDIO_BACKEND_H

#include "backend_factory.h"

const struct backend_factory sdl_audio_backend_factory;

#endif
Loading

0 comments on commit b1e1fa8

Please sign in to comment.