From 2d5c8e61b1d34b9b482b807f5bef555f532533fd Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 May 2017 14:16:53 +0200 Subject: Some code tweaks --- src/audio.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index d63047a8..e8e80985 100644 --- a/src/audio.c +++ b/src/audio.c @@ -570,7 +570,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels) // NOTE: Only supported mono <--> stereo if (wave->channels != channels) { - void *data = malloc(wave->sampleCount*channels*wave->sampleSize/8); + void *data = malloc(wave->sampleCount*wave->sampleSize/8*channels); if ((wave->channels == 1) && (channels == 2)) // mono ---> stereo (duplicate mono information) { @@ -607,7 +607,7 @@ Wave WaveCopy(Wave wave) { Wave newWave = { 0 }; - newWave.data = malloc(wave.sampleCount*wave.channels*wave.sampleSize/8); + newWave.data = malloc(wave.sampleCount*wave.sampleSize/8*wave.channels); if (newWave.data != NULL) { @@ -632,7 +632,7 @@ void WaveCrop(Wave *wave, int initSample, int finalSample) { int sampleCount = finalSample - initSample; - void *data = malloc(sampleCount*wave->channels*wave->sampleSize/8); + void *data = malloc(sampleCount*wave->sampleSize/8*wave->channels); memcpy(data, (unsigned char*)wave->data + (initSample*wave->channels*wave->sampleSize/8), sampleCount*wave->channels*wave->sampleSize/8); @@ -849,7 +849,7 @@ void UpdateMusicStream(Music music) bool active = true; // NOTE: Using dynamic allocation because it could require more than 16KB - void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.channels*music->stream.sampleSize/8, 1); + void *pcm = calloc(AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, 1); int numBuffersToProcess = processed; int samplesCount = 0; // Total size of data steamed in L+R samples for xm floats, @@ -1245,23 +1245,19 @@ static Wave LoadWAV(const char *fileName) // NOTE: Using stb_vorbis library static Wave LoadOGG(const char *fileName) { - Wave wave; + Wave wave = { 0 }; stb_vorbis *oggFile = stb_vorbis_open_filename(fileName, NULL, NULL); - if (oggFile == NULL) - { - TraceLog(WARNING, "[%s] OGG file could not be opened", fileName); - wave.data = NULL; - } + if (oggFile == NULL) TraceLog(WARNING, "[%s] OGG file could not be opened", fileName); else { stb_vorbis_info info = stb_vorbis_get_info(oggFile); - + wave.sampleRate = info.sample_rate; wave.sampleSize = 16; // 16 bit per sample (short) wave.channels = info.channels; - wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile); + wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile); // Independent by channel float totalSeconds = stb_vorbis_stream_length_in_seconds(oggFile); if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio length is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds); -- cgit v1.2.3 From 3861bc80f273452837be3561ed236d79fcc62660 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 00:55:47 +0200 Subject: StopMusicStream() review --- src/audio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index e8e80985..2393e5a4 100644 --- a/src/audio.c +++ b/src/audio.c @@ -810,7 +810,8 @@ void StopMusicStream(Music music) for (int i = 0; i < MAX_STREAM_BUFFERS; i++) { - alBufferData(music->stream.buffers[i], music->stream.format, pcm, AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, music->stream.sampleRate); + UpdateAudioStream(music->stream, pcm, AUDIO_BUFFER_SIZE); + //alBufferData(music->stream.buffers[i], music->stream.format, pcm, AUDIO_BUFFER_SIZE*music->stream.sampleSize/8*music->stream.channels, music->stream.sampleRate); } free(pcm); @@ -853,7 +854,7 @@ void UpdateMusicStream(Music music) int numBuffersToProcess = processed; int samplesCount = 0; // Total size of data steamed in L+R samples for xm floats, - //individual L or R for ogg shorts + // individual L or R for ogg shorts for (int i = 0; i < numBuffersToProcess; i++) { -- cgit v1.2.3 From 822c2ddad59e9839aeb029f5a3dc26681188612b Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 02:47:44 +0200 Subject: Some defines tweaks for consistency --- src/audio.c | 4 ++-- src/core.c | 12 ++++++------ src/rlgl.c | 18 +++++++----------- src/rlgl.h | 8 +++----- 4 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index 2393e5a4..39befbbc 100644 --- a/src/audio.c +++ b/src/audio.c @@ -79,7 +79,7 @@ #include "utils.h" // Required for: fopen() Android mapping #endif -#ifdef __APPLE__ +#if defined(__APPLE__) #include "OpenAL/al.h" // OpenAL basic header #include "OpenAL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work) #else @@ -1326,7 +1326,7 @@ void TraceLog(int msgType, const char *text, ...) va_list args; int traceDebugMsgs = 0; -#ifdef DO_NOT_TRACE_DEBUG_MSGS +#if defined(DO_NOT_TRACE_DEBUG_MSGS) traceDebugMsgs = 0; #endif diff --git a/src/core.c b/src/core.c index 459b99fb..1448743f 100644 --- a/src/core.c +++ b/src/core.c @@ -118,7 +118,7 @@ //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management - #ifdef(__linux__) + #if defined(__linux__) #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window #include // which are required for hiding mouse @@ -668,7 +668,7 @@ int GetScreenHeight(void) void ShowCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux__ + #if defined(__linux__) XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window)); #else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); @@ -681,7 +681,7 @@ void ShowCursor() void HideCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux__ + #if defined(__linux__) XColor col; const char nil[] = {0}; @@ -1679,7 +1679,7 @@ static void InitGraphicsDevice(int width, int height) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above! // Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE -#ifdef __APPLE__ +#if defined(__APPLE__) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires #else glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above! @@ -1964,7 +1964,7 @@ static void InitGraphicsDevice(int width, int height) // Set viewport parameters static void SetupViewport(void) { -#ifdef __APPLE__ +#if defined(__APPLE__) // Get framebuffer size of current window // NOTE: Required to handle HighDPI display correctly on OSX because framebuffer // is automatically reasized to adapt to new DPI. @@ -3279,7 +3279,7 @@ static void *GamepadThread(void *arg) // Plays raylib logo appearing animation static void LogoAnimation(void) { -#ifndef PLATFORM_WEB +#if !defined(PLATFORM_WEB) int logoPositionX = screenWidth/2 - 128; int logoPositionY = screenHeight/2 - 128; diff --git a/src/rlgl.c b/src/rlgl.c index 1dc83314..edf9e60b 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -67,12 +67,12 @@ #include // Required for: strcmp(), strlen(), strtok() [Used only in extensions loading] #include // Required for: atan2() -#ifndef RLGL_STANDALONE +#if !defined(RLGL_STANDALONE) #include "raymath.h" // Required for: Vector3 and Matrix functions #endif #if defined(GRAPHICS_API_OPENGL_11) - #ifdef __APPLE__ + #if defined(__APPLE__) #include // OpenGL 1.1 library for OSX #else #include // OpenGL 1.1 library @@ -84,7 +84,7 @@ #endif #if defined(GRAPHICS_API_OPENGL_33) - #ifdef __APPLE__ + #if defined(__APPLE__) #include // OpenGL 3 library for OSX #else #define GLAD_IMPLEMENTATION @@ -1286,21 +1286,17 @@ void rlglLoadExtensions(void *loader) { #if defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_33) // NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions) - #ifndef __APPLE__ + #if !defined(__APPLE__) if (!gladLoadGLLoader((GLADloadproc)loader)) TraceLog(WARNING, "GLAD: Cannot load OpenGL extensions"); else TraceLog(INFO, "GLAD: OpenGL extensions loaded successfully"); - #endif -#if defined(GRAPHICS_API_OPENGL_21) - #ifndef __APPLE__ + #if defined(GRAPHICS_API_OPENGL_21) if (GLAD_GL_VERSION_2_1) TraceLog(INFO, "OpenGL 2.1 profile supported"); - #endif -#elif defined(GRAPHICS_API_OPENGL_33) - #ifndef __APPLE__ + #elif defined(GRAPHICS_API_OPENGL_33) if(GLAD_GL_VERSION_3_3) TraceLog(INFO, "OpenGL 3.3 Core profile supported"); else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); + #endif #endif -#endif // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object diff --git a/src/rlgl.h b/src/rlgl.h index 300949f9..b51d1c49 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -59,12 +59,10 @@ #ifndef RLGL_H #define RLGL_H -#ifndef RLGL_STANDALONE - #include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog() -#endif - -#ifdef RLGL_STANDALONE +#if defined(RLGL_STANDALONE) #define RAYMATH_STANDALONE +#else + #include "raylib.h" // Required for: Model, Shader, Texture2D, TraceLog() #endif #include "raymath.h" // Required for: Vector3, Matrix -- cgit v1.2.3