mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
make fields lowercase for structs in Audio.c
This commit is contained in:
parent
8e57167ba3
commit
75c2e21c69
@ -21,20 +21,23 @@
|
|||||||
# As such, you may want to uninstall libcurl package, manually compile curl's source code for both 32 and 64 bit,
|
# As such, you may want to uninstall libcurl package, manually compile curl's source code for both 32 and 64 bit,
|
||||||
# then add the .so files to /usr/lib/i386-linux-gnu and /usr/lib/x86_64-linux-gnu/
|
# then add the .so files to /usr/lib/i386-linux-gnu and /usr/lib/x86_64-linux-gnu/
|
||||||
|
|
||||||
# change these as needed
|
# paths, change these as needed
|
||||||
SOURCE_DIR=~/client
|
SOURCE_DIR=~/client
|
||||||
EMSCRIPTEN_PATH=/usr/bin/emscripten/emcc
|
WEB_CC=~/emscripten/emsdk/emscripten/tag-1.38.30/emcc
|
||||||
CLANG32_PATH=/usr/bin/clang/osx32
|
MAC32_CC=/usr/bin/clang/osx32
|
||||||
CLANG64_PATH=/usr/bin/clang/osx64
|
MAC64_CC=/usr/bin/clang/osx64
|
||||||
|
WIN32_CC=i686-w64-mingw32-gcc
|
||||||
|
WIN64_CC=x86_64-w64-mingw32-gccnostartfiles -Wl,-emain_real -DCC_NOMAIN"
|
||||||
|
LINUX_FLAGS="-fvisibility=hidden
|
||||||
|
|
||||||
# to simplify stuff
|
# to simplify stuff
|
||||||
ALL_FLAGS="-O1 -s -fno-stack-protector -fno-math-errno -w"
|
ALL_FLAGS="-O1 -s -fno-stack-protector -fno-math-errno -w"
|
||||||
WIN32_FLAGS="-mwindows -nostartfiles -Wl,-e_main_real -DCC_NOMAIN"
|
WIN32_FLAGS="-mwindows -nostartfiles -Wl,-e_main_real -DCC_NOMAIN"
|
||||||
WIN64_FLAGS="-mwindows -nostartfiles -Wl,-emain_real -DCC_NOMAIN"
|
WIN64_FLAGS="-mwindows - -rdynamic -DCC_BUILD_X11ICON"
|
||||||
LINUX_FLAGS="-fvisibility=hidden -rdynamic -DCC_BUILD_X11ICON"
|
|
||||||
|
|
||||||
# I cloned https://github.com/raspberrypi/tools to get prebuilt cross compilers
|
# I cloned https://github.com/raspberrypi/tools to get prebuilt cross compilers
|
||||||
# Then I copied across various files/folders from /usr/include and /usr/lib as needed
|
# Then I copied across various files/folders from /usr/include and /usr/lib as needed
|
||||||
RPI_PATH=~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc-4.8.3
|
RPI_CC=~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc-4.8.3
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
build_win32() {
|
build_win32() {
|
||||||
@ -42,8 +45,8 @@ build_win32() {
|
|||||||
cp $SOURCE_DIR/misc/CCicon_32.res $SOURCE_DIR/src/CCicon_32.res
|
cp $SOURCE_DIR/misc/CCicon_32.res $SOURCE_DIR/src/CCicon_32.res
|
||||||
rm cc-w32-d3d.exe cc-w32-ogl.exe
|
rm cc-w32-d3d.exe cc-w32-ogl.exe
|
||||||
|
|
||||||
i686-w64-mingw32-gcc *.c $ALL_FLAGS $WIN32_FLAGS -o cc-w32-d3d.exe CCicon_32.res -DCC_COMMIT_SHA=\"$LATEST\" -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
|
$WIN32_CC *.c $ALL_FLAGS $WIN32_FLAGS -o cc-w32-d3d.exe CCicon_32.res -DCC_COMMIT_SHA=\"$LATEST\" -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
|
||||||
i686-w64-mingw32-gcc *.c $ALL_FLAGS $WIN32_FLAGS -o cc-w32-ogl.exe CCicon_32.res -DCC_COMMIT_SHA=\"$LATEST\" -DCC_BUILD_MANUAL -DCC_BUILD_WIN -DCC_BUILD_GL -DCC_BUILD_WINGUI -DCC_BUILD_WGL -DCC_BUILD_WINMM -DCC_BUILD_WININET -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -lopengl32
|
$WIN32_CC *.c $ALL_FLAGS $WIN32_FLAGS -o cc-w32-ogl.exe CCicon_32.res -DCC_COMMIT_SHA=\"$LATEST\" -DCC_BUILD_MANUAL -DCC_BUILD_WIN -DCC_BUILD_GL -DCC_BUILD_WINGUI -DCC_BUILD_WGL -DCC_BUILD_WINMM -DCC_BUILD_WININET -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -lopengl32
|
||||||
}
|
}
|
||||||
|
|
||||||
build_win64() {
|
build_win64() {
|
||||||
@ -51,8 +54,8 @@ build_win64() {
|
|||||||
cp $SOURCE_DIR/misc/CCicon_64.res $SOURCE_DIR/src/CCicon_64.res
|
cp $SOURCE_DIR/misc/CCicon_64.res $SOURCE_DIR/src/CCicon_64.res
|
||||||
rm cc-w64-d3d.exe cc-w64-ogl.exe
|
rm cc-w64-d3d.exe cc-w64-ogl.exe
|
||||||
|
|
||||||
x86_64-w64-mingw32-gcc *.c $ALL_FLAGS $WIN64_FLAGS -o cc-w64-d3d.exe CCicon_64.res -DCC_COMMIT_SHA=\"$LATEST\" -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
|
$WIN64_CC *.c $ALL_FLAGS $WIN64_FLAGS -o cc-w64-d3d.exe CCicon_64.res -DCC_COMMIT_SHA=\"$LATEST\" -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -ld3d9
|
||||||
x86_64-w64-mingw32-gcc *.c $ALL_FLAGS $WIN64_FLAGS -o cc-w64-ogl.exe CCicon_64.res -DCC_COMMIT_SHA=\"$LATEST\" -DCC_BUILD_MANUAL -DCC_BUILD_WIN -DCC_BUILD_GL -DCC_BUILD_WINGUI -DCC_BUILD_WGL -DCC_BUILD_WINMM -DCC_BUILD_WININET -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -lopengl32
|
$WIN64_CC *.c $ALL_FLAGS $WIN64_FLAGS -o cc-w64-ogl.exe CCicon_64.res -DCC_COMMIT_SHA=\"$LATEST\" -DCC_BUILD_MANUAL -DCC_BUILD_WIN -DCC_BUILD_GL -DCC_BUILD_WINGUI -DCC_BUILD_WGL -DCC_BUILD_WINMM -DCC_BUILD_WININET -lws2_32 -lwininet -lwinmm -limagehlp -lcrypt32 -lopengl32
|
||||||
}
|
}
|
||||||
|
|
||||||
build_nix32() {
|
build_nix32() {
|
||||||
@ -72,19 +75,19 @@ build_nix64() {
|
|||||||
build_osx32() {
|
build_osx32() {
|
||||||
echo "Building mac32.."
|
echo "Building mac32.."
|
||||||
rm cc-osx32
|
rm cc-osx32
|
||||||
$CLANG32_PATH *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx32 -framework Carbon -framework AGL -framework OpenAL -framework OpenGL -lcurl
|
$MAC32_CC *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx32 -framework Carbon -framework AGL -framework OpenAL -framework OpenGL -lcurl
|
||||||
}
|
}
|
||||||
|
|
||||||
build_osx64() {
|
build_osx64() {
|
||||||
echo "Building mac64.."
|
echo "Building mac64.."
|
||||||
rm cc-osx64
|
rm cc-osx64
|
||||||
$CLANG64_PATH *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx64 -framework Cocoa -framework OpenAL -framework OpenGL -lcurl -lobjc
|
$MAC64_CC *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx64 -framework Cocoa -framework OpenAL -framework OpenGL -lcurl -lobjc
|
||||||
}
|
}
|
||||||
|
|
||||||
build_web() {
|
build_web() {
|
||||||
echo "Building web.."
|
echo "Building web.."
|
||||||
rm cc.js
|
rm cc.js
|
||||||
$EMSCRIPTEN_PATH *.c -O1 -o cc.js -s FETCH=1 -s WASM=0 -s LEGACY_VM_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip -w
|
$WEB_CC *.c -O1 -o cc.js -s FETCH=1 -s WASM=0 -s LEGACY_VM_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip -w
|
||||||
# so game loads textures from classicube.net/static/default.zip
|
# so game loads textures from classicube.net/static/default.zip
|
||||||
sed -i 's#cc.data#/static/default.zip#g' cc.js
|
sed -i 's#cc.data#/static/default.zip#g' cc.js
|
||||||
# fix texture pack overlay always showing 'Download size: Determining..."
|
# fix texture pack overlay always showing 'Download size: Determining..."
|
||||||
@ -98,7 +101,7 @@ build_rpi() {
|
|||||||
echo "Building rpi.."
|
echo "Building rpi.."
|
||||||
cp $SOURCE_DIR/misc/CCicon_rpi $SOURCE_DIR/src/CCicon_rpi.o
|
cp $SOURCE_DIR/misc/CCicon_rpi $SOURCE_DIR/src/CCicon_rpi.o
|
||||||
rm cc-rpi
|
rm cc-rpi
|
||||||
$RPI_PATH *.c $ALL_FLAGS $LINUX_FLAGS CCicon_rpi.o -DCC_COMMIT_SHA=\"$LATEST\" -o cc-rpi -DCC_BUILD_RPI -I ~/rpi/include -L ~/rpi/lib -lGLESv2 -lEGL -lX11 -lcurl -lopenal -lm -lpthread -ldl -lrt -Wl,-rpath-link ~/rpi/lib
|
$RPI_CC *.c $ALL_FLAGS $LINUX_FLAGS CCicon_rpi.o -DCC_COMMIT_SHA=\"$LATEST\" -o cc-rpi -DCC_BUILD_RPI -I ~/rpi/include -L ~/rpi/lib -lGLESv2 -lEGL -lX11 -lcurl -lopenal -lm -lpthread -ldl -lrt -Wl,-rpath-link ~/rpi/lib
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
@ -116,4 +119,7 @@ build_nix64
|
|||||||
build_osx32
|
build_osx32
|
||||||
build_osx64
|
build_osx64
|
||||||
build_web
|
build_web
|
||||||
build_rpi
|
build_rpi
|
||||||
|
|
||||||
|
cd ~
|
||||||
|
python notify.py
|
228
src/Audio.c
228
src/Audio.c
@ -82,12 +82,12 @@ static void Volume_Mix16(cc_int16* samples, int count, int volume) {
|
|||||||
static cc_result Audio_AllCompleted(AudioHandle handle, cc_bool* finished);
|
static cc_result Audio_AllCompleted(AudioHandle handle, cc_bool* finished);
|
||||||
#if defined CC_BUILD_WINMM
|
#if defined CC_BUILD_WINMM
|
||||||
struct AudioContext {
|
struct AudioContext {
|
||||||
HWAVEOUT Handle;
|
HWAVEOUT handle;
|
||||||
WAVEHDR Headers[AUDIO_MAX_BUFFERS];
|
WAVEHDR headers[AUDIO_MAX_BUFFERS];
|
||||||
struct AudioFormat Format;
|
struct AudioFormat format;
|
||||||
int Count;
|
int count;
|
||||||
};
|
};
|
||||||
static struct AudioContext Audio_Contexts[20];
|
static struct AudioContext audioContexts[20];
|
||||||
static void Audio_SysInit(void) { }
|
static void Audio_SysInit(void) { }
|
||||||
static void Audio_SysFree(void) { }
|
static void Audio_SysFree(void) { }
|
||||||
|
|
||||||
@ -95,16 +95,16 @@ void Audio_Open(AudioHandle* handle, int buffers) {
|
|||||||
struct AudioContext* ctx;
|
struct AudioContext* ctx;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
for (i = 0; i < Array_Elems(Audio_Contexts); i++) {
|
for (i = 0; i < Array_Elems(audioContexts); i++) {
|
||||||
ctx = &Audio_Contexts[i];
|
ctx = &audioContexts[i];
|
||||||
if (ctx->Count) continue;
|
if (ctx->count) continue;
|
||||||
|
|
||||||
for (j = 0; j < buffers; j++) {
|
for (j = 0; j < buffers; j++) {
|
||||||
ctx->Headers[j].dwFlags = WHDR_DONE;
|
ctx->headers[j].dwFlags = WHDR_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = i;
|
*handle = i;
|
||||||
ctx->Count = buffers;
|
ctx->count = buffers;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger_Abort("No free audio contexts");
|
Logger_Abort("No free audio contexts");
|
||||||
@ -114,24 +114,24 @@ cc_result Audio_Close(AudioHandle handle) {
|
|||||||
struct AudioFormat fmt = { 0 };
|
struct AudioFormat fmt = { 0 };
|
||||||
struct AudioContext* ctx;
|
struct AudioContext* ctx;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
ctx = &Audio_Contexts[handle];
|
ctx = &audioContexts[handle];
|
||||||
|
|
||||||
ctx->Count = 0;
|
ctx->count = 0;
|
||||||
ctx->Format = fmt;
|
ctx->format = fmt;
|
||||||
if (!ctx->Handle) return 0;
|
if (!ctx->handle) return 0;
|
||||||
|
|
||||||
res = waveOutClose(ctx->Handle);
|
res = waveOutClose(ctx->handle);
|
||||||
ctx->Handle = NULL;
|
ctx->handle = NULL;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
cc_result Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
struct AudioFormat* cur = &ctx->Format;
|
struct AudioFormat* cur = &ctx->format;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
|
|
||||||
if (AudioFormat_Eq(cur, format)) return 0;
|
if (AudioFormat_Eq(cur, format)) return 0;
|
||||||
if (ctx->Handle && (res = waveOutClose(ctx->Handle))) return res;
|
if (ctx->handle && (res = waveOutClose(ctx->handle))) return res;
|
||||||
|
|
||||||
int sampleSize = format->Channels * 2; /* 16 bits per sample / 8 */
|
int sampleSize = format->Channels * 2; /* 16 bits per sample / 8 */
|
||||||
WAVEFORMATEX fmt;
|
WAVEFORMATEX fmt;
|
||||||
@ -143,13 +143,13 @@ cc_result Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
|||||||
fmt.wBitsPerSample = 16;
|
fmt.wBitsPerSample = 16;
|
||||||
fmt.cbSize = 0;
|
fmt.cbSize = 0;
|
||||||
|
|
||||||
ctx->Format = *format;
|
ctx->format = *format;
|
||||||
return waveOutOpen(&ctx->Handle, WAVE_MAPPER, &fmt, 0, 0, CALLBACK_NULL);
|
return waveOutOpen(&ctx->handle, WAVE_MAPPER, &fmt, 0, 0, CALLBACK_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_BufferData(AudioHandle handle, int idx, void* data, cc_uint32 dataSize) {
|
cc_result Audio_BufferData(AudioHandle handle, int idx, void* data, cc_uint32 dataSize) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
WAVEHDR* hdr = &ctx->Headers[idx];
|
WAVEHDR* hdr = &ctx->headers[idx];
|
||||||
cc_result res;
|
cc_result res;
|
||||||
|
|
||||||
Mem_Set(hdr, 0, sizeof(WAVEHDR));
|
Mem_Set(hdr, 0, sizeof(WAVEHDR));
|
||||||
@ -157,29 +157,29 @@ cc_result Audio_BufferData(AudioHandle handle, int idx, void* data, cc_uint32 da
|
|||||||
hdr->dwBufferLength = dataSize;
|
hdr->dwBufferLength = dataSize;
|
||||||
hdr->dwLoops = 1;
|
hdr->dwLoops = 1;
|
||||||
|
|
||||||
if ((res = waveOutPrepareHeader(ctx->Handle, hdr, sizeof(WAVEHDR)))) return res;
|
if ((res = waveOutPrepareHeader(ctx->handle, hdr, sizeof(WAVEHDR)))) return res;
|
||||||
if ((res = waveOutWrite(ctx->Handle, hdr, sizeof(WAVEHDR)))) return res;
|
if ((res = waveOutWrite(ctx->handle, hdr, sizeof(WAVEHDR)))) return res;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_Play(AudioHandle handle) { return 0; }
|
cc_result Audio_Play(AudioHandle handle) { return 0; }
|
||||||
|
|
||||||
cc_result Audio_Stop(AudioHandle handle) {
|
cc_result Audio_Stop(AudioHandle handle) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
if (!ctx->Handle) return 0;
|
if (!ctx->handle) return 0;
|
||||||
return waveOutReset(ctx->Handle);
|
return waveOutReset(ctx->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_IsCompleted(AudioHandle handle, int idx, cc_bool* completed) {
|
cc_result Audio_IsCompleted(AudioHandle handle, int idx, cc_bool* completed) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
WAVEHDR* hdr = &ctx->Headers[idx];
|
WAVEHDR* hdr = &ctx->headers[idx];
|
||||||
|
|
||||||
*completed = false;
|
*completed = false;
|
||||||
if (!(hdr->dwFlags & WHDR_DONE)) return 0;
|
if (!(hdr->dwFlags & WHDR_DONE)) return 0;
|
||||||
cc_result res = 0;
|
cc_result res = 0;
|
||||||
|
|
||||||
if (hdr->dwFlags & WHDR_PREPARED) {
|
if (hdr->dwFlags & WHDR_PREPARED) {
|
||||||
res = waveOutUnprepareHeader(ctx->Handle, hdr, sizeof(WAVEHDR));
|
res = waveOutUnprepareHeader(ctx->handle, hdr, sizeof(WAVEHDR));
|
||||||
}
|
}
|
||||||
*completed = true; return res;
|
*completed = true; return res;
|
||||||
}
|
}
|
||||||
@ -187,14 +187,14 @@ cc_result Audio_IsCompleted(AudioHandle handle, int idx, cc_bool* completed) {
|
|||||||
cc_result Audio_IsFinished(AudioHandle handle, cc_bool* finished) { return Audio_AllCompleted(handle, finished); }
|
cc_result Audio_IsFinished(AudioHandle handle, cc_bool* finished) { return Audio_AllCompleted(handle, finished); }
|
||||||
#elif defined CC_BUILD_OPENAL
|
#elif defined CC_BUILD_OPENAL
|
||||||
struct AudioContext {
|
struct AudioContext {
|
||||||
ALuint Source;
|
ALuint source;
|
||||||
ALuint Buffers[AUDIO_MAX_BUFFERS];
|
ALuint buffers[AUDIO_MAX_BUFFERS];
|
||||||
cc_bool Completed[AUDIO_MAX_BUFFERS];
|
cc_bool completed[AUDIO_MAX_BUFFERS];
|
||||||
struct AudioFormat Format;
|
struct AudioFormat format;
|
||||||
int Count;
|
int count;
|
||||||
ALenum DataFormat;
|
ALenum dataFormat;
|
||||||
};
|
};
|
||||||
static struct AudioContext Audio_Contexts[20];
|
static struct AudioContext audioContexts[20];
|
||||||
|
|
||||||
static pthread_mutex_t audio_lock;
|
static pthread_mutex_t audio_lock;
|
||||||
static ALCdevice* audio_device;
|
static ALCdevice* audio_device;
|
||||||
@ -242,13 +242,13 @@ static void Audio_DestroyContext(void) {
|
|||||||
|
|
||||||
static ALenum Audio_FreeSource(struct AudioContext* ctx) {
|
static ALenum Audio_FreeSource(struct AudioContext* ctx) {
|
||||||
ALenum err;
|
ALenum err;
|
||||||
if (ctx->Source == -1) return 0;
|
if (ctx->source == -1) return 0;
|
||||||
|
|
||||||
alDeleteSources(1, &ctx->Source);
|
alDeleteSources(1, &ctx->source);
|
||||||
ctx->Source = -1;
|
ctx->source = -1;
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
|
|
||||||
alDeleteBuffers(ctx->Count, ctx->Buffers);
|
alDeleteBuffers(ctx->count, ctx->buffers);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -266,17 +266,17 @@ void Audio_Open(AudioHandle* handle, int buffers) {
|
|||||||
|
|
||||||
alDistanceModel(AL_NONE);
|
alDistanceModel(AL_NONE);
|
||||||
|
|
||||||
for (i = 0; i < Array_Elems(Audio_Contexts); i++) {
|
for (i = 0; i < Array_Elems(audioContexts); i++) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[i];
|
struct AudioContext* ctx = &audioContexts[i];
|
||||||
if (ctx->Count) continue;
|
if (ctx->count) continue;
|
||||||
|
|
||||||
for (j = 0; j < buffers; j++) {
|
for (j = 0; j < buffers; j++) {
|
||||||
ctx->Completed[j] = true;
|
ctx->completed[j] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = i;
|
*handle = i;
|
||||||
ctx->Count = buffers;
|
ctx->count = buffers;
|
||||||
ctx->Source = -1;
|
ctx->source = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger_Abort("No free audio contexts");
|
Logger_Abort("No free audio contexts");
|
||||||
@ -286,11 +286,11 @@ cc_result Audio_Close(AudioHandle handle) {
|
|||||||
struct AudioFormat fmt = { 0 };
|
struct AudioFormat fmt = { 0 };
|
||||||
struct AudioContext* ctx;
|
struct AudioContext* ctx;
|
||||||
ALenum err;
|
ALenum err;
|
||||||
ctx = &Audio_Contexts[handle];
|
ctx = &audioContexts[handle];
|
||||||
|
|
||||||
if (!ctx->Count) return 0;
|
if (!ctx->count) return 0;
|
||||||
ctx->Count = 0;
|
ctx->count = 0;
|
||||||
ctx->Format = fmt;
|
ctx->format = fmt;
|
||||||
|
|
||||||
err = Audio_FreeSource(ctx);
|
err = Audio_FreeSource(ctx);
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
@ -311,89 +311,89 @@ static ALenum GetALFormat(int channels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
cc_result Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
struct AudioFormat* cur = &ctx->Format;
|
struct AudioFormat* cur = &ctx->format;
|
||||||
ALenum err;
|
ALenum err;
|
||||||
|
|
||||||
if (AudioFormat_Eq(cur, format)) return 0;
|
if (AudioFormat_Eq(cur, format)) return 0;
|
||||||
ctx->DataFormat = GetALFormat(format->Channels);
|
ctx->dataFormat = GetALFormat(format->Channels);
|
||||||
ctx->Format = *format;
|
ctx->format = *format;
|
||||||
|
|
||||||
if ((err = Audio_FreeSource(ctx))) return err;
|
if ((err = Audio_FreeSource(ctx))) return err;
|
||||||
alGenSources(1, &ctx->Source);
|
alGenSources(1, &ctx->source);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
|
|
||||||
alGenBuffers(ctx->Count, ctx->Buffers);
|
alGenBuffers(ctx->count, ctx->buffers);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_BufferData(AudioHandle handle, int idx, void* data, cc_uint32 dataSize) {
|
cc_result Audio_BufferData(AudioHandle handle, int idx, void* data, cc_uint32 dataSize) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
ALuint buffer = ctx->Buffers[idx];
|
ALuint buffer = ctx->buffers[idx];
|
||||||
ALenum err;
|
ALenum err;
|
||||||
ctx->Completed[idx] = false;
|
ctx->completed[idx] = false;
|
||||||
|
|
||||||
alBufferData(buffer, ctx->DataFormat, data, dataSize, ctx->Format.SampleRate);
|
alBufferData(buffer, ctx->dataFormat, data, dataSize, ctx->format.SampleRate);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
alSourceQueueBuffers(ctx->Source, 1, &buffer);
|
alSourceQueueBuffers(ctx->source, 1, &buffer);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_Play(AudioHandle handle) {
|
cc_result Audio_Play(AudioHandle handle) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
alSourcePlay(ctx->Source);
|
alSourcePlay(ctx->source);
|
||||||
return alGetError();
|
return alGetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_Stop(AudioHandle handle) {
|
cc_result Audio_Stop(AudioHandle handle) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
alSourceStop(ctx->Source);
|
alSourceStop(ctx->source);
|
||||||
return alGetError();
|
return alGetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_IsCompleted(AudioHandle handle, int idx, cc_bool* completed) {
|
cc_result Audio_IsCompleted(AudioHandle handle, int idx, cc_bool* completed) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
ALint i, processed = 0;
|
ALint i, processed = 0;
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
ALenum err;
|
ALenum err;
|
||||||
|
|
||||||
alGetSourcei(ctx->Source, AL_BUFFERS_PROCESSED, &processed);
|
alGetSourcei(ctx->source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
|
|
||||||
if (processed > 0) {
|
if (processed > 0) {
|
||||||
alSourceUnqueueBuffers(ctx->Source, 1, &buffer);
|
alSourceUnqueueBuffers(ctx->source, 1, &buffer);
|
||||||
if ((err = alGetError())) return err;
|
if ((err = alGetError())) return err;
|
||||||
|
|
||||||
for (i = 0; i < ctx->Count; i++) {
|
for (i = 0; i < ctx->count; i++) {
|
||||||
if (ctx->Buffers[i] == buffer) ctx->Completed[i] = true;
|
if (ctx->buffers[i] == buffer) ctx->completed[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*completed = ctx->Completed[idx]; return 0;
|
*completed = ctx->completed[idx]; return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_IsFinished(AudioHandle handle, cc_bool* finished) {
|
cc_result Audio_IsFinished(AudioHandle handle, cc_bool* finished) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
ALint state = 0;
|
ALint state = 0;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
|
|
||||||
if (ctx->Source == -1) { *finished = true; return 0; }
|
if (ctx->source == -1) { *finished = true; return 0; }
|
||||||
res = Audio_AllCompleted(handle, finished);
|
res = Audio_AllCompleted(handle, finished);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
alGetSourcei(ctx->Source, AL_SOURCE_STATE, &state);
|
alGetSourcei(ctx->source, AL_SOURCE_STATE, &state);
|
||||||
*finished = state != AL_PLAYING; return 0;
|
*finished = state != AL_PLAYING; return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static cc_result Audio_AllCompleted(AudioHandle handle, cc_bool* finished) {
|
static cc_result Audio_AllCompleted(AudioHandle handle, cc_bool* finished) {
|
||||||
struct AudioContext* ctx = &Audio_Contexts[handle];
|
struct AudioContext* ctx = &audioContexts[handle];
|
||||||
cc_result res;
|
cc_result res;
|
||||||
int i;
|
int i;
|
||||||
*finished = false;
|
*finished = false;
|
||||||
|
|
||||||
for (i = 0; i < ctx->Count; i++) {
|
for (i = 0; i < ctx->count; i++) {
|
||||||
res = Audio_IsCompleted(handle, i, finished);
|
res = Audio_IsCompleted(handle, i, finished);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
if (!(*finished)) return 0;
|
if (!(*finished)) return 0;
|
||||||
@ -404,7 +404,7 @@ static cc_result Audio_AllCompleted(AudioHandle handle, cc_bool* finished) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct AudioFormat* Audio_GetFormat(AudioHandle handle) {
|
struct AudioFormat* Audio_GetFormat(AudioHandle handle) {
|
||||||
return &Audio_Contexts[handle].Format;
|
return &audioContexts[handle].format;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_StopAndClose(AudioHandle handle) {
|
cc_result Audio_StopAndClose(AudioHandle handle) {
|
||||||
@ -419,19 +419,19 @@ cc_result Audio_StopAndClose(AudioHandle handle) {
|
|||||||
*------------------------------------------------------Soundboard---------------------------------------------------------*
|
*------------------------------------------------------Soundboard---------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct Sound {
|
struct Sound {
|
||||||
struct AudioFormat Format;
|
struct AudioFormat format;
|
||||||
cc_uint8* Data; cc_uint32 Size;
|
cc_uint8* data; cc_uint32 size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define AUDIO_MAX_SOUNDS 10
|
#define AUDIO_MAX_SOUNDS 10
|
||||||
struct SoundGroup {
|
struct SoundGroup {
|
||||||
String Name; int Count;
|
String name; int count;
|
||||||
struct Sound Sounds[AUDIO_MAX_SOUNDS];
|
struct Sound sounds[AUDIO_MAX_SOUNDS];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Soundboard {
|
struct Soundboard {
|
||||||
RNGState Rnd; int Count;
|
RNGState rnd; int count;
|
||||||
struct SoundGroup Groups[AUDIO_MAX_SOUNDS];
|
struct SoundGroup groups[AUDIO_MAX_SOUNDS];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define WAV_FourCC(a, b, c, d) (((cc_uint32)a << 24) | ((cc_uint32)b << 16) | ((cc_uint32)c << 8) | (cc_uint32)d)
|
#define WAV_FourCC(a, b, c, d) (((cc_uint32)a << 24) | ((cc_uint32)b << 16) | ((cc_uint32)c << 8) | (cc_uint32)d)
|
||||||
@ -459,19 +459,19 @@ static cc_result Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
|
|||||||
if ((res = Stream_Read(stream, tmp, sizeof(tmp)))) return res;
|
if ((res = Stream_Read(stream, tmp, sizeof(tmp)))) return res;
|
||||||
if (Stream_GetU16_LE(&tmp[0]) != 1) return WAV_ERR_DATA_TYPE;
|
if (Stream_GetU16_LE(&tmp[0]) != 1) return WAV_ERR_DATA_TYPE;
|
||||||
|
|
||||||
snd->Format.Channels = Stream_GetU16_LE(&tmp[2]);
|
snd->format.Channels = Stream_GetU16_LE(&tmp[2]);
|
||||||
snd->Format.SampleRate = Stream_GetU32_LE(&tmp[4]);
|
snd->format.SampleRate = Stream_GetU32_LE(&tmp[4]);
|
||||||
/* tmp[8] (6) alignment data and stuff */
|
/* tmp[8] (6) alignment data and stuff */
|
||||||
|
|
||||||
bitsPerSample = Stream_GetU16_LE(&tmp[14]);
|
bitsPerSample = Stream_GetU16_LE(&tmp[14]);
|
||||||
if (bitsPerSample != 16) return WAV_ERR_SAMPLE_BITS;
|
if (bitsPerSample != 16) return WAV_ERR_SAMPLE_BITS;
|
||||||
size -= WAV_FMT_SIZE;
|
size -= WAV_FMT_SIZE;
|
||||||
} else if (fourCC == WAV_FourCC('d','a','t','a')) {
|
} else if (fourCC == WAV_FourCC('d','a','t','a')) {
|
||||||
snd->Data = (cc_uint8*)Mem_TryAlloc(size, 1);
|
snd->data = (cc_uint8*)Mem_TryAlloc(size, 1);
|
||||||
snd->Size = size;
|
snd->size = size;
|
||||||
|
|
||||||
if (!snd->Data) return ERR_OUT_OF_MEMORY;
|
if (!snd->data) return ERR_OUT_OF_MEMORY;
|
||||||
return Stream_Read(stream, snd->Data, size);
|
return Stream_Read(stream, snd->data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip over unhandled data */
|
/* Skip over unhandled data */
|
||||||
@ -497,11 +497,11 @@ static cc_result Sound_ReadWave(const String* filename, struct Sound* snd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct SoundGroup* Soundboard_Find(struct Soundboard* board, const String* name) {
|
static struct SoundGroup* Soundboard_Find(struct Soundboard* board, const String* name) {
|
||||||
struct SoundGroup* groups = board->Groups;
|
struct SoundGroup* groups = board->groups;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < board->Count; i++) {
|
for (i = 0; i < board->count; i++) {
|
||||||
if (String_CaselessEquals(&groups[i].Name, name)) return &groups[i];
|
if (String_CaselessEquals(&groups[i].name, name)) return &groups[i];
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -528,28 +528,28 @@ static void Soundboard_Init(struct Soundboard* board, const String* boardName, S
|
|||||||
|
|
||||||
group = Soundboard_Find(board, &name);
|
group = Soundboard_Find(board, &name);
|
||||||
if (!group) {
|
if (!group) {
|
||||||
if (board->Count == Array_Elems(board->Groups)) {
|
if (board->count == Array_Elems(board->groups)) {
|
||||||
Chat_AddRaw("&cCannot have more than 10 sound groups"); return;
|
Chat_AddRaw("&cCannot have more than 10 sound groups"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
group = &board->Groups[board->Count++];
|
group = &board->groups[board->count++];
|
||||||
/* NOTE: This keeps a reference to inside buffer of files */
|
/* NOTE: This keeps a reference to inside buffer of files */
|
||||||
group->Name = name;
|
group->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group->Count == Array_Elems(group->Sounds)) {
|
if (group->count == Array_Elems(group->sounds)) {
|
||||||
Chat_AddRaw("&cCannot have more than 10 sounds in a group"); return;
|
Chat_AddRaw("&cCannot have more than 10 sounds in a group"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd = &group->Sounds[group->Count];
|
snd = &group->sounds[group->count];
|
||||||
res = Sound_ReadWave(&file, snd);
|
res = Sound_ReadWave(&file, snd);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
Logger_Warn2(res, "decoding", &file);
|
Logger_Warn2(res, "decoding", &file);
|
||||||
Mem_Free(snd->Data);
|
Mem_Free(snd->data);
|
||||||
snd->Data = NULL;
|
snd->data = NULL;
|
||||||
snd->Size = 0;
|
snd->size = 0;
|
||||||
} else { group->Count++; }
|
} else { group->count++; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,8 +565,8 @@ static struct Sound* Soundboard_PickRandom(struct Soundboard* board, cc_uint8 ty
|
|||||||
group = Soundboard_Find(board, &name);
|
group = Soundboard_Find(board, &name);
|
||||||
if (!group) return NULL;
|
if (!group) return NULL;
|
||||||
|
|
||||||
idx = Random_Next(&board->Rnd, group->Count);
|
idx = Random_Next(&board->rnd, group->count);
|
||||||
return &group->Sounds[idx];
|
return &group->sounds[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -589,27 +589,27 @@ CC_NOINLINE static void Sounds_Fail(cc_result res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct AudioFormat* fmt, int volume) {
|
static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct AudioFormat* fmt, int volume) {
|
||||||
void* data = snd->Data;
|
void* data = snd->data;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
if ((res = Audio_SetFormat(output->Handle, fmt))) { Sounds_Fail(res); return; }
|
if ((res = Audio_SetFormat(output->Handle, fmt))) { Sounds_Fail(res); return; }
|
||||||
|
|
||||||
/* copy to temp buffer to apply volume */
|
/* copy to temp buffer to apply volume */
|
||||||
if (volume < 100) {
|
if (volume < 100) {
|
||||||
if (output->BufferSize < snd->Size) {
|
if (output->BufferSize < snd->size) {
|
||||||
/* TODO: check if we can realloc NULL without a problem */
|
/* TODO: check if we can realloc NULL without a problem */
|
||||||
if (output->Buffer) {
|
if (output->Buffer) {
|
||||||
output->Buffer = Mem_Realloc(output->Buffer, snd->Size, 1, "sound temp buffer");
|
output->Buffer = Mem_Realloc(output->Buffer, snd->size, 1, "sound temp buffer");
|
||||||
} else {
|
} else {
|
||||||
output->Buffer = Mem_Alloc(snd->Size, 1, "sound temp buffer");
|
output->Buffer = Mem_Alloc(snd->size, 1, "sound temp buffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data = output->Buffer;
|
data = output->Buffer;
|
||||||
|
|
||||||
Mem_Copy(data, snd->Data, snd->Size);
|
Mem_Copy(data, snd->data, snd->size);
|
||||||
Volume_Mix16((cc_int16*)data, snd->Size / 2, volume);
|
Volume_Mix16((cc_int16*)data, snd->size / 2, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = Audio_BufferData(output->Handle, 0, data, snd->Size))) { Sounds_Fail(res); return; }
|
if ((res = Audio_BufferData(output->Handle, 0, data, snd->size))) { Sounds_Fail(res); return; }
|
||||||
if ((res = Audio_Play(output->Handle))) { Sounds_Fail(res); return; }
|
if ((res = Audio_Play(output->Handle))) { Sounds_Fail(res); return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,7 +628,7 @@ static void Sounds_Play(cc_uint8 type, struct Soundboard* board) {
|
|||||||
snd = Soundboard_PickRandom(board, type);
|
snd = Soundboard_PickRandom(board, type);
|
||||||
if (!snd) return;
|
if (!snd) return;
|
||||||
|
|
||||||
fmt = snd->Format;
|
fmt = snd->format;
|
||||||
volume = Audio_SoundsVolume;
|
volume = Audio_SoundsVolume;
|
||||||
outputs = fmt.Channels == 1 ? monoOutputs : stereoOutputs;
|
outputs = fmt.Channels == 1 ? monoOutputs : stereoOutputs;
|
||||||
|
|
||||||
@ -696,7 +696,7 @@ static void Sounds_Init(void) {
|
|||||||
static const String dig = String_FromConst("dig_");
|
static const String dig = String_FromConst("dig_");
|
||||||
static const String step = String_FromConst("step_");
|
static const String step = String_FromConst("step_");
|
||||||
|
|
||||||
if (digBoard.Count || stepBoard.Count) return;
|
if (digBoard.count || stepBoard.count) return;
|
||||||
Soundboard_Init(&digBoard, &dig, &files);
|
Soundboard_Init(&digBoard, &dig, &files);
|
||||||
Soundboard_Init(&stepBoard, &step, &files);
|
Soundboard_Init(&stepBoard, &step, &files);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user