raylib/examples/ex08_audio.c

60 lines
2.3 KiB
C
Raw Normal View History

2013-11-24 23:30:05 +04:00
/*******************************************************************************************
*
2013-11-29 00:16:31 +04:00
* raylib example 08 - Audio loading and playing
2013-11-24 23:30:05 +04:00
*
2013-12-01 15:34:31 +04:00
* NOTE: This example requires OpenAL32 dll installed (or in the same folder)
*
2013-11-29 00:16:31 +04:00
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
2013-11-24 23:30:05 +04:00
*
2013-11-29 00:16:31 +04:00
* Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
2013-11-24 23:30:05 +04:00
*
********************************************************************************************/
#include "raylib.h"
int main()
{
2013-11-29 00:16:31 +04:00
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib example 08 - audio loading and playing");
InitAudioDevice(); // Initialize audio device
2013-11-29 00:16:31 +04:00
2013-12-01 15:34:31 +04:00
Sound fx = LoadSound("resources/weird.wav"); // Load WAV audio file
2013-11-29 00:16:31 +04:00
//--------------------------------------------------------------------------------------
2013-11-24 23:30:05 +04:00
// Main game loop
2013-11-29 00:16:31 +04:00
while (!WindowShouldClose()) // Detect window close button or ESC key
2013-11-24 23:30:05 +04:00
{
2013-11-29 00:16:31 +04:00
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) PlaySound(fx); // Play the sound!
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the SOUND!", 240, 200, 20, LIGHTGRAY);
EndDrawing();
2013-11-29 00:16:31 +04:00
//----------------------------------------------------------------------------------
}
2013-11-29 00:16:31 +04:00
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fx); // Unload sound data
CloseAudioDevice(); // Close audio device
CloseWindow(); // Close window and OpenGL context
2013-11-29 00:16:31 +04:00
//--------------------------------------------------------------------------------------
2013-11-24 23:30:05 +04:00
return 0;
}