revert audio sound loading changes

This commit is contained in:
iann 2025-11-13 11:40:31 -06:00
parent b3c25186d9
commit ea6e3a88a0
2 changed files with 2 additions and 31 deletions

View File

@ -4,7 +4,7 @@
* *
* Example complexity rating: [] 1/4 * Example complexity rating: [] 1/4
* *
* Example originally created with raylib 1.1, last time updated with raylib 6.0 * Example originally created with raylib 1.1, last time updated with raylib 3.5
* *
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software * BSD-like license that allows static linking with closed source software
@ -14,8 +14,6 @@
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#include <stdlib.h> // Required for: malloc(), free()
#include <string.h> // Required for: memcpy()
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
@ -34,17 +32,6 @@ int main(void)
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
bool soundReversed = false;
float *soundData = malloc(sizeof(float)*fxWav.frameCount*fxWav.stream.channels);
float *scratchSoundData = malloc(sizeof(float)*fxWav.frameCount*fxWav.stream.channels);
Wave wave = LoadWave("resources/sound.wav");
// Sounds always have 32bit sampleSize:
WaveFormat(&wave, fxWav.stream.sampleRate, 32, fxWav.stream.channels);
memcpy(soundData, wave.data, sizeof(float)*fxWav.frameCount*fxWav.stream.channels);
UnloadWave(wave);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -53,18 +40,6 @@ int main(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_R))
{
soundReversed = !soundReversed;
for (unsigned int i = 0; i < fxWav.frameCount; i++)
{
unsigned int src = (soundReversed)? fxWav.frameCount - 1 - i : i;
// Sounds always have STEREO channels:
scratchSoundData[i * fxWav.stream.channels + 0] = soundData[src * fxWav.stream.channels + 0];
scratchSoundData[i * fxWav.stream.channels + 1] = soundData[src * fxWav.stream.channels + 1];
}
UpdateSound(fxWav, scratchSoundData, fxWav.frameCount);
}
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -76,9 +51,7 @@ int main(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText(TextFormat("Press R to REVERSE the WAV sound : "), 120, 220, 20, LIGHTGRAY); DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
DrawText((soundReversed)? "BACKWARDS" : "FORWARDS", 525, 220, 20, (soundReversed)? MAROON : DARKGREEN);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 260, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -86,8 +59,6 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
free(soundData);
free(scratchSoundData);
UnloadSound(fxWav); // Unload sound data UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data UnloadSound(fxOgg); // Unload sound data

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB