Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC / WIP] Preview of new audio backend API integration for frontends #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion projects/VisualStudio2013/mupen64plus-ui-console.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,34 @@ copy ..\..\..\mupen64plus-win32-deps\zlib-1.2.3\bin\*.dll "$(OutDir)"
<ClCompile Include="..\..\src\compare_core.c" />
<ClCompile Include="..\..\src\core_interface.c" />
<ClCompile Include="..\..\src\main.c" />
<ClCompile Include="..\..\src\object_factory.c" />
<ClCompile Include="..\..\src\osal_dynamiclib_win32.c" />
<ClCompile Include="..\..\src\osal_files_win32.c" />
<ClCompile Include="..\..\src\plugin.c" />
<ClCompile Include="..\..\src\audio_backends\circular_buffer.c" />
<ClCompile Include="..\..\src\audio_backends\dummy_audio_backend.c" />
<ClCompile Include="..\..\src\audio_backends\sdl_audio_backend.c" />
<ClCompile Include="..\..\src\resamplers\resampler.c" />
<ClCompile Include="..\..\src\resamplers\trivial_resampler.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\cheat.h" />
<ClInclude Include="..\..\src\compare_core.h" />
<ClInclude Include="..\..\src\core_interface.h" />
<ClInclude Include="..\..\src\main.h" />
<ClInclude Include="..\..\src\object_factory.h" />
<ClInclude Include="..\..\src\osal_dynamiclib.h" />
<ClInclude Include="..\..\src\osal_files.h" />
<ClInclude Include="..\..\src\osal_preproc.h" />
<ClInclude Include="..\..\src\plugin.h" />
<ClInclude Include="..\..\src\version.h" />
<ClInclude Include="..\..\src\audio_backends\circular_buffer.h" />
<ClInclude Include="..\..\src\audio_backends\dummy_audio_backend.h" />
<ClInclude Include="..\..\src\audio_backends\sdl_audio_backend.h" />
<ClInclude Include="..\..\src\resamplers\resampler.h" />
<ClInclude Include="..\..\src\resamplers\trivial_resampler.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
17 changes: 15 additions & 2 deletions projects/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,18 @@ SOURCE = \
$(SRCDIR)/compare_core.c \
$(SRCDIR)/core_interface.c \
$(SRCDIR)/main.c \
$(SRCDIR)/plugin.c
$(SRCDIR)/object_factory.c \
$(SRCDIR)/plugin.c \
$(SRCDIR)/audio_backends/circular_buffer.c \
$(SRCDIR)/audio_backends/dummy_audio_backend.c \
$(SRCDIR)/resamplers/resampler.c \
$(SRCDIR)/resamplers/trivial_resampler.c

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

ifeq ($(OS), MINGW)
SOURCE += \
Expand Down Expand Up @@ -265,7 +276,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 modules:"
@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
83 changes: 83 additions & 0 deletions src/audio_backends/circular_buffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - circular_buffer.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 "circular_buffer.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>


int init_cbuff(struct circular_buffer* cbuff, size_t capacity)
{
void* data = malloc(capacity);

if (data == NULL)
{
return -1;
}

cbuff->data = data;
cbuff->size = capacity;
cbuff->head = 0;

return 0;
}

void release_cbuff(struct circular_buffer* cbuff)
{
free(cbuff->data);
memset(cbuff, 0, sizeof(*cbuff));
}


void* cbuff_head(const struct circular_buffer* cbuff, size_t* available)
{
assert(cbuff->head <= cbuff->size);

*available = cbuff->size - cbuff->head;
return (void*)((char*)cbuff->data + cbuff->head);
}


void* cbuff_tail(const struct circular_buffer* cbuff, size_t* available)
{
*available = cbuff->head;
return cbuff->data;
}


void produce_cbuff_data(struct circular_buffer* cbuff, size_t amount)
{
assert(cbuff->head + amount <= cbuff->size);

cbuff->head += amount;
}


void consume_cbuff_data(struct circular_buffer* cbuff, size_t amount)
{
assert(cbuff->head >= amount);

memmove(cbuff->data, cbuff->data + amount, cbuff->head - amount);
cbuff->head -= amount;
}

46 changes: 46 additions & 0 deletions src/audio_backends/circular_buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-ui-console - circular_buffer.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_CIRCULAR_BUFFER_H
#define M64P_CIRCULAR_BUFFER_H

#include <stddef.h>

struct circular_buffer
{
void* data;
size_t size;
size_t head;
};

int init_cbuff(struct circular_buffer* cbuff, size_t capacity);

void release_cbuff(struct circular_buffer* cbuff);

void* cbuff_head(const struct circular_buffer* cbuff, size_t* available);

void* cbuff_tail(const struct circular_buffer* cbuff, size_t* available);

void produce_cbuff_data(struct circular_buffer* cbuff, size_t amount);

void consume_cbuff_data(struct circular_buffer* cbuff, size_t amount);

#endif
45 changes: 45 additions & 0 deletions src/audio_backends/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(void* object)
{
struct m64p_audio_backend* backend = (struct m64p_audio_backend*)object;

/* 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(void* object)
{
}


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

29 changes: 29 additions & 0 deletions src/audio_backends/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 "object_factory.h"

const struct object_factory dummy_audio_backend_factory;

#endif
Loading