Skip to content

Commit

Permalink
Merge branch 'master' into openmpt_looping
Browse files Browse the repository at this point in the history
  • Loading branch information
jarikomppa authored Nov 15, 2021
2 parents b3e8e3f + 00fadcc commit f94b503
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 42 deletions.
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ Samson Close https://github.com/qwertysam
Bruce A Henderson https://github.com/woollybah
Philip Bennefall https://github.com/blastbay/
HumanGamer https://github.com/HumanGamer/
Ales Mlakar https://github.com/jazzbre
lexander Yashin https://github.com/yashin-alexander
Nils Duval https://github.com/nlsdvl
JackRedstonia jackredstonia64@gmail.com
David Bullock https://github.com/dwbullock
3 changes: 3 additions & 0 deletions contrib/Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ print_option_status (SOLOUD_BACKEND_NULL "NULL backend")
option (SOLOUD_BACKEND_SDL2 "Set to ON for building SDL2 backend" ON)
print_option_status (SOLOUD_BACKEND_SDL2 "SDL2 backend")

option (SOLOUD_BACKEND_ALSA "Set to ON for building ALSA backend" OFF)
print_option_status (SOLOUD_BACKEND_ALSA "ALSA backend")

option (SOLOUD_BACKEND_COREAUDIO "Set to ON for building CoreAudio backend" OFF)
print_option_status (SOLOUD_BACKEND_COREAUDIO "CoreAudio backend")

Expand Down
4 changes: 2 additions & 2 deletions contrib/cmake/FindSDL2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ SET(SDL2_SEARCH_PATHS
${SDL2_PATH}
)

FIND_PATH(SDL2_INCLUDE_DIR SDL2/SDL.h
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
HINTS
$ENV{SDL2DIR}
PATH_SUFFIXES include
PATH_SUFFIXES include include/SDL2
PATHS ${SDL2_SEARCH_PATHS}
)

Expand Down
16 changes: 16 additions & 0 deletions contrib/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ if (SOLOUD_BACKEND_SDL2)

endif()

if (SOLOUD_BACKEND_ALSA)
add_definitions (-DWITH_ALSA)

set (BACKENDS_SOURCES
${BACKENDS_SOURCES}
${BACKENDS_PATH}/alsa/soloud_alsa.cpp
)

find_library (ALSA_LIBRARY asound)
set (LINK_LIBRARIES
${LINK_LIBRARIES}
${ALSA_LIBRARY}
)
endif()


if (SOLOUD_BACKEND_COREAUDIO)
if (NOT APPLE)
message (FATAL_ERROR "CoreAudio backend can be enabled only on Apple!")
Expand Down
2 changes: 1 addition & 1 deletion demos/common/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -6359,7 +6359,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
first_frame = 1;
} else {
// second frame - how do we dispoase of the previous one?
// second frame - how do we dispose of the previous one?
dispose = (g->eflags & 0x1C) >> 2;
pcount = g->w * g->h;

Expand Down
8 changes: 8 additions & 0 deletions include/soloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace SoLoud
typedef void (*mutexCallFunction)(void *aMutexPtr);
typedef void (*soloudCallFunction)(Soloud *aSoloud);
typedef unsigned int result;
typedef result (*soloudResultFunction)(Soloud *aSoloud);
typedef unsigned int handle;
typedef double time;
};
Expand Down Expand Up @@ -165,6 +166,10 @@ namespace SoLoud
// Called by SoLoud to shut down the back-end. If NULL, not called. Should be set by back-end.
soloudCallFunction mBackendCleanupFunc;

// Some backends like CoreAudio on iOS must be paused/resumed in some cases. On incoming call as instance.
soloudResultFunction mBackendPauseFunc;
soloudResultFunction mBackendResumeFunc;

// CTor
Soloud();
// DTor
Expand Down Expand Up @@ -224,6 +229,9 @@ namespace SoLoud
// Initialize SoLoud. Must be called before SoLoud can be used.
result init(unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aBackend = Soloud::AUTO, unsigned int aSamplerate = Soloud::AUTO, unsigned int aBufferSize = Soloud::AUTO, unsigned int aChannels = 2);

result pause();
result resume();

// Deinitialize SoLoud. Must be called before shutting down.
void deinit();

Expand Down
1 change: 1 addition & 0 deletions include/soloud_wavstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace SoLoud
public:
WavStreamInstance(WavStream *aParent);
virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize);
virtual result seek(double aSeconds, float* mScratch, unsigned int mScratchSize);
virtual result rewind();
virtual bool hasEnded();
virtual ~WavStreamInstance();
Expand Down
175 changes: 175 additions & 0 deletions scripts/gen_beef.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#!/usr/bin/env python3
""" SoLoud Beef (bf) wrapper generator """

import soloud_codegen

fo = open("../glue/soloud.bf", "w")


C_TO_BF_TYPES = {
"string":"String",
"int":"int32",
"void":"void",
"const char *":"char8 *",
"char *":"char8 *",
"unsigned int":"uint32",
"float":"float",
"double":"double",
"float *":"float *",
"File *":"void *",
"unsigned char *":"uint8 *",
"const unsigned char *":"uint8 *",
"unsigned char":"uint8",
"short *":"uint16 *"
}

for soloud_type in soloud_codegen.soloud_type:
C_TO_BF_TYPES[soloud_type + " *"] = "SoloudObject"


def has_ex_variant(funcname):
""" Checks if this function has an "Ex" variant """
if funcname[-2::] == "Ex":
# Already an Ex..
return False
for func in soloud_codegen.soloud_func:
if func[1] == (funcname + "Ex"):
return True
return False

fo.write("""
// SoLoud wrapper for Beef (bf)
// This file is autogenerated; any changes will be overwritten
using System;
namespace SoLoud
{
public class SoloudObject
{
public void* objhandle;
}
""")

fo.write("\n")
#################################################################

def fix_default_param(defparam, classname):
""" 'fixes' default parameters from C to what python expectes """
if defparam == "false":
return "0"
if defparam == "true":
return "1"
if (classname + '::') == defparam[0:len(classname)+2:]:
return defparam[len(classname)+2::]
if 'Soloud::' in defparam:
return "Soloud." + defparam[len("Soloud")+2::]
return defparam

def external_pointer_fix(param):
if param == "SoloudObject":
return "void *"
if param == "string":
return "char8 *"
return param

for x in soloud_codegen.soloud_type:
first = True
for y in soloud_codegen.soloud_func:
if (x + "_") == y[1][0:len(x)+1:]:
if first:
fo.write('\n')
fo.write('public class %s : SoloudObject\n{\n'%(x))
for z in soloud_codegen.soloud_enum:
if z[0:len(x)+1] == x.upper()+'_':
s = str(soloud_codegen.soloud_enum[z])
fo.write('\tpublic const int %s = %s;\n'%(z[len(x)+1::], s))
fo.write('\n\t[LinkName(\"%s_create\")]\n\tprivate static extern void* create();\n'%(x))
fo.write('\tpublic this()\n\t{\n')
fo.write('\t\tobjhandle = create();\n')
fo.write('\t}\n')

fo.write('\n\t[LinkName(\"%s_destroy\")]\n\tprivate static extern void* destroy(void* aObjHandle);\n'%(x))
fo.write('\tpublic ~this()\n\t{\n')
fo.write('\t\tdestroy(objhandle);\n')
fo.write('\t}\n')

first = False
funcname = y[1][len(x)+1::]
# If the function has the name "Ex", remove the subfix
if funcname[-2::] == "Ex":
funcname = funcname[:len(funcname)-2]
# Skip generating functions that have an Ex variant
if funcname == "create" or funcname == "destroy" or has_ex_variant(y[1]):
pass # omit create/destroy, handled by __exit__ / close
else:
charptr = False
floatptr = False
ret = C_TO_BF_TYPES[y[0]]
if y[0] == 'const char *':
charptr = True
ret = 'char8 *'
if y[0] == 'const unsigned char *':
charptr = True
ret = 'uint8 *'
if y[0] == 'float *':
floatptr = True
ret = 'float *'
fo.write('\n\t[CLink]\n\tprivate static extern %s %s(void* aObjHandle'%(ret, y[1]))
for z in y[2]:
if len(z) > 1:
if z[1] == 'a'+x:
pass # skip the 'self' pointer
else:
fo.write(', ')
fo.write(external_pointer_fix(C_TO_BF_TYPES[z[0]]) + ' ' + z[1])
fo.write(');\n')

fo.write('\tpublic %s %s('%(C_TO_BF_TYPES[y[0]], funcname))
firstparm = True
for z in y[2]:
if len(z) > 1:
if z[1] == 'a'+x:
pass # skip the 'self' pointer
else:
if firstparm:
firstparm = False
else:
fo.write(', ')
fo.write(C_TO_BF_TYPES[z[0]] + ' ' + z[1])
if len(z) > 2:
fo.write(' = ' + fix_default_param(z[2], x))
fo.write(')\n\t{\n')
fo.write('\t\t')
if y[0] == 'void':
pass
elif charptr:
fo.write('return ')
elif floatptr:
fo.write('return ')
else:
fo.write('return ')
fo.write(y[1] + '(objhandle')
for z in y[2]:
if len(z) > 1:
if z[1] == 'a'+x:
pass # skip the 'self' pointer
else:
fo.write(', ')
fudged_type = C_TO_BF_TYPES[z[0]]
if fudged_type == 'SoloudObject':
fo.write(z[1] + '.objhandle')
else:
fo.write(z[1])
fo.write(');\n')
fo.write('\t}\n')
if not first:
fo.write('}\n')

fo.write('}\n')

print("soloud.bf generated")

fo.close()
55 changes: 39 additions & 16 deletions scripts/gen_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
""" SoLoud Python wrapper generator """

import soloud_codegen

fo = open("../glue/soloud.py", "w")

#
Expand Down Expand Up @@ -62,22 +61,44 @@ def has_ex_variant(funcname):
return True
return False

fo.write("# SoLoud wrapper for Python\n")
fo.write("# This file is autogenerated; any changes will be overwritten\n")

fo.write("\n")
fo.write('import ctypes\n')
fo.write('import sys\n')
fo.write('\n')
fo.write('try:\n')
fo.write('\tsoloud_dll = ctypes.CDLL("soloud_x86")\n')
fo.write('except:\n')
fo.write('\ttry:\n')
fo.write('\t\tsoloud_dll = ctypes.CDLL("soloud_x64")\n')
fo.write('\texcept:\n')
fo.write('\t\tprint("SoLoud dynamic link library (soloud_x86.dll / soloud_x64.dll on Windows, .so on Linux / OSX) not found. Terminating.")\n')
fo.write('\t\tsys.exit()')
fo.write("\n")
bootstrap = '''\
# SoLoud wrapper for Python
# This file is autogenerated; any changes will be overwritten
# See: http://sol.gfxile.net/soloud/codegen.html
import ctypes
import sys
import os
soloud_dll = None
try:
for filename in ['soloud_x86','soloud_x64','libsoloud_x64.so']:
try:
soloud_dll = ctypes.CDLL("%s/%s" %(os.path.dirname(os.path.abspath(__file__)), filename))
break
except FileNotFoundError:
# on windows, we get an explicit FileNotFoundError
continue
except OSError as e:
# but on linux, we don't
if 'No such file or directory' in str(e):
continue
else:
raise e
if soloud_dll == None:
raise Exception("SoLoud dynamic library not found in %s " % (os.path.dirname(os.path.abspath(__file__))))
except BaseException as e:
print("Error while loading Soloud dynamic library on %s %sbit" % (sys.platform, sys.maxsize.bit_length()+1))
print(e)
sys.exit()
'''


fo.write(bootstrap)

# Since there's no reason to use the "raw" data anymore,
# skip generating the enum dictionary
Expand Down Expand Up @@ -138,6 +159,8 @@ def fix_default_param(defparam, classname):
defparam = 'True'
if (classname + '::') == defparam[0:len(classname)+2:]:
return defparam[len(classname)+2::]
elif defparam.startswith('Soloud::'):
return 'Soloud.%s'%(defparam[8:])
if defparam[len(defparam)-1] == "f":
return defparam[0:len(defparam)-1]
return defparam
Expand Down
3 changes: 1 addition & 2 deletions src/audiosource/ay/sndbuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include "sndbuffer.h"
#include "sndrender.h"

#include <stdlib.h>
#include <memory.h>

SNDBUFFER::SNDBUFFER(unsigned aSize) {
Expand Down
1 change: 1 addition & 0 deletions src/audiosource/wav/soloud_wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace SoLoud
mChannels = info.channels;
}
mData = new float[samples * mChannels];
memset(mData, 0, samples * mChannels * sizeof(float));
mSampleCount = samples;
samples = 0;
while(1)
Expand Down
19 changes: 19 additions & 0 deletions src/audiosource/wav/soloud_wavstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ namespace SoLoud
return aSamplesToRead;
}

result WavStreamInstance::seek(double aSeconds, float* mScratch, unsigned int mScratchSize)
{
if (mCodec.mOgg)
{
int pos = (int)floor(mBaseSamplerate * aSeconds);
stb_vorbis_seek(mCodec.mOgg, pos);
// Since the position that we just sought to might not be *exactly*
// the position we asked for, we're re-calculating the position just
// for the sake of correctness.
mOffset = stb_vorbis_get_sample_offset(mCodec.mOgg);
double newPosition = float(mOffset / mBaseSamplerate);
mStreamPosition = newPosition;
return 0;
}
else {
return AudioSourceInstance::seek(aSeconds, mScratch, mScratchSize);
}
}

result WavStreamInstance::rewind()
{
switch (mParent->mFiletype)
Expand Down
Loading

0 comments on commit f94b503

Please sign in to comment.