This commit is contained in:
Ray 2023-12-14 15:32:45 +01:00
commit d29b36310f
7 changed files with 54 additions and 38 deletions

1
.gitignore vendored
View File

@ -54,6 +54,7 @@ packages/
*.bc
*.so
*.so.*
*.dll
# Ignore wasm data in examples/
examples/**/*.wasm

View File

@ -2,7 +2,7 @@
*
* raylib [audio] example - Music stream processing effects
*
* Example originally created with raylib 4.2, last time updated with raylib 4.2
* Example originally created with raylib 4.2, last time updated with raylib 5.0
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
@ -13,7 +13,7 @@
#include "raylib.h"
#include <stdlib.h> // Required for: NULL
#include <stdlib.h> // Required for: NULL
// Required delay effect variables
static float *delayBuffer = NULL;
@ -149,13 +149,17 @@ static void AudioProcessEffectLPF(void *buffer, unsigned int frames)
static const float cutoff = 70.0f / 44100.0f; // 70 Hz lowpass filter
const float k = cutoff / (cutoff + 0.1591549431f); // RC filter formula
// Converts the buffer data before using it
float *bufferData = (float *)buffer;
for (unsigned int i = 0; i < frames*2; i += 2)
{
float l = ((float *)buffer)[i], r = ((float *)buffer)[i + 1];
const float l = bufferData[i];
const float r = bufferData[i + 1];
low[0] += k * (l - low[0]);
low[1] += k * (r - low[1]);
((float *)buffer)[i] = low[0];
((float *)buffer)[i + 1] = low[1];
bufferData[i] = low[0];
bufferData[i + 1] = low[1];
}
}
@ -176,4 +180,4 @@ static void AudioProcessEffectDelay(void *buffer, unsigned int frames)
delayBuffer[delayWriteIndex++] = ((float *)buffer)[i + 1];
if (delayWriteIndex == delayBufferSize) delayWriteIndex = 0;
}
}
}

View File

@ -39,7 +39,6 @@ int main(void)
.vResolution = 1200, // Vertical resolution in pixels
.hScreenSize = 0.133793f, // Horizontal size in meters
.vScreenSize = 0.0669f, // Vertical size in meters
.vScreenCenter = 0.04678f, // Screen center in meters
.eyeToScreenDistance = 0.041f, // Distance between eye and display in meters
.lensSeparationDistance = 0.07f, // Lens separation distance in meters
.interpupillaryDistance = 0.07f, // IPD (distance between pupils) in meters

View File

@ -484,7 +484,6 @@ typedef struct VrDeviceInfo {
int vResolution; // Vertical resolution in pixels
float hScreenSize; // Horizontal size in meters
float vScreenSize; // Vertical size in meters
float vScreenCenter; // Screen center in meters
float eyeToScreenDistance; // Distance between eye and display in meters
float lensSeparationDistance; // Lens separation distance in meters
float interpupillaryDistance; // IPD (distance between pupils) in meters
@ -1481,6 +1480,7 @@ RLAPI const char *TextToUpper(const char *text); // Get upp
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
RLAPI int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)
//------------------------------------------------------------------------------------
// Basic 3d Shapes Drawing Functions (Module: models)

View File

@ -1192,8 +1192,8 @@ VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device)
// NOTE: Camera movement might seem more natural if we model the head.
// Our axis of rotation is the base of our head, so we might want to add
// some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions.
config.viewOffset[0] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
config.viewOffset[1] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
config.viewOffset[0] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
config.viewOffset[1] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
// Compute eyes Viewports
/*

View File

@ -1421,6 +1421,28 @@ int TextToInteger(const char *text)
return value*sign;
}
float TextToFloat(const char *text)
{
float value = 0.0f;
float sign = 1.0f;
if ((text[0] == '+') || (text[0] == '-'))
{
if (text[0] == '-') sign = -1;
text++;
}
int i = 0;
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10.0f + (float)(text[i] - '0');
if (text[i++] != '.') return value*sign;
float divisor = 10.0f;
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i)
{
value += ((float)(text[i] - '0'))/divisor;
divisor = divisor*10.0f;
}
return value;
}
#if defined(SUPPORT_TEXT_MANIPULATION)
// Copy one string to another, returns bytes copied
int TextCopy(char *dst, const char *src)

View File

@ -1959,29 +1959,24 @@ void ImageBlurGaussian(Image *image, int blurSize) {
float avgG = 0.0f;
float avgB = 0.0f;
float avgAlpha = 0.0f;
int convolutionSize = blurSize+1;
int convolutionSize = blurSize;
for (int i = 0; i < blurSize+1; i++)
for (int i = 0; i < blurSize; i++)
{
avgR += pixelsCopy1[row*image->width + i].x;
avgG += pixelsCopy1[row*image->width + i].y;
avgB += pixelsCopy1[row*image->width + i].z;
avgAlpha += pixelsCopy1[row*image->width + i].w;
}
}
pixelsCopy2[row*image->width].x = avgR/convolutionSize;
pixelsCopy2[row*image->width].y = avgG/convolutionSize;
pixelsCopy2[row*image->width].z = avgB/convolutionSize;
pixelsCopy2[row*image->width].w = avgAlpha/convolutionSize;
for (int x = 1; x < image->width; x++)
for (int x = 0; x < image->width; x++)
{
if (x-blurSize >= 0)
if (x-blurSize-1 >= 0)
{
avgR -= pixelsCopy1[row*image->width + x-blurSize].x;
avgG -= pixelsCopy1[row*image->width + x-blurSize].y;
avgB -= pixelsCopy1[row*image->width + x-blurSize].z;
avgAlpha -= pixelsCopy1[row*image->width + x-blurSize].w;
avgR -= pixelsCopy1[row*image->width + x-blurSize-1].x;
avgG -= pixelsCopy1[row*image->width + x-blurSize-1].y;
avgB -= pixelsCopy1[row*image->width + x-blurSize-1].z;
avgAlpha -= pixelsCopy1[row*image->width + x-blurSize-1].w;
convolutionSize--;
}
@ -1999,7 +1994,7 @@ void ImageBlurGaussian(Image *image, int blurSize) {
pixelsCopy2[row*image->width + x].z = avgB/convolutionSize;
pixelsCopy2[row*image->width + x].w = avgAlpha/convolutionSize;
}
}
}
// Vertical motion blur
for (int col = 0; col < image->width; col++)
@ -2008,9 +2003,9 @@ void ImageBlurGaussian(Image *image, int blurSize) {
float avgG = 0.0f;
float avgB = 0.0f;
float avgAlpha = 0.0f;
int convolutionSize = blurSize+1;
int convolutionSize = blurSize;
for (int i = 0; i < blurSize+1; i++)
for (int i = 0; i < blurSize; i++)
{
avgR += pixelsCopy2[i*image->width + col].x;
avgG += pixelsCopy2[i*image->width + col].y;
@ -2018,19 +2013,14 @@ void ImageBlurGaussian(Image *image, int blurSize) {
avgAlpha += pixelsCopy2[i*image->width + col].w;
}
pixelsCopy1[col].x = (unsigned char) (avgR/convolutionSize);
pixelsCopy1[col].y = (unsigned char) (avgG/convolutionSize);
pixelsCopy1[col].z = (unsigned char) (avgB/convolutionSize);
pixelsCopy1[col].w = (unsigned char) (avgAlpha/convolutionSize);
for (int y = 1; y < image->height; y++)
for (int y = 0; y < image->height; y++)
{
if (y-blurSize >= 0)
if (y-blurSize-1 >= 0)
{
avgR -= pixelsCopy2[(y-blurSize)*image->width + col].x;
avgG -= pixelsCopy2[(y-blurSize)*image->width + col].y;
avgB -= pixelsCopy2[(y-blurSize)*image->width + col].z;
avgAlpha -= pixelsCopy2[(y-blurSize)*image->width + col].w;
avgR -= pixelsCopy2[(y-blurSize-1)*image->width + col].x;
avgG -= pixelsCopy2[(y-blurSize-1)*image->width + col].y;
avgB -= pixelsCopy2[(y-blurSize-1)*image->width + col].z;
avgAlpha -= pixelsCopy2[(y-blurSize-1)*image->width + col].w;
convolutionSize--;
}
if (y+blurSize < image->height)