Files
raylib/examples/audio/audio_sound_loading.c

71 lines
2.8 KiB
C
Raw Normal View History

2013-11-24 20:30:05 +01:00
/*******************************************************************************************
*
* raylib [audio] example - sound loading
2013-11-24 20:30:05 +01:00
*
* Example complexity rating: [] 1/4
*
2022-07-20 01:28:37 +02:00
* Example originally created with raylib 1.1, last time updated with raylib 3.5
2013-11-24 20:30:05 +01:00
*
2022-07-20 01:28:37 +02:00
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
2013-11-24 20:30:05 +01:00
*
********************************************************************************************/
#include "raylib.h"
2022-06-21 19:53:18 +02:00
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
2019-05-20 16:36:42 +02:00
int main(void)
2013-11-24 20:30:05 +01:00
{
2013-11-28 21:16:31 +01:00
// Initialization
//--------------------------------------------------------------------------------------
2019-05-20 16:36:42 +02:00
const int screenWidth = 800;
const int screenHeight = 450;
2014-09-29 23:41:05 +02:00
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading");
2014-09-29 23:41:05 +02:00
InitAudioDevice(); // Initialize audio device
2014-09-29 23:41:05 +02:00
2017-04-08 23:31:58 +02:00
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
2019-05-20 16:36:42 +02:00
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
2013-11-28 21:16:31 +01:00
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
// Main game loop
2013-11-28 21:16:31 +01:00
while (!WindowShouldClose()) // Detect window close button or ESC key
2013-11-24 20:30:05 +01:00
{
2013-11-28 21:16:31 +01:00
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
2013-11-28 21:16:31 +01:00
//----------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-28 21:16:31 +01:00
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
2014-09-29 23:41:05 +02:00
2013-11-28 21:16:31 +01:00
ClearBackground(RAYWHITE);
2014-09-29 23:41:05 +02:00
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
2014-09-29 23:41:05 +02:00
EndDrawing();
2013-11-28 21:16:31 +01:00
//----------------------------------------------------------------------------------
}
2013-11-28 21:16:31 +01:00
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
2014-09-29 23:41:05 +02:00
2013-11-28 21:16:31 +01:00
CloseAudioDevice(); // Close audio device
2014-09-29 23:41:05 +02:00
CloseWindow(); // Close window and OpenGL context
2013-11-28 21:16:31 +01:00
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
return 0;
}