raylib/examples/audio_sound_loading.c

67 lines
2.5 KiB
C
Raw Normal View History

2013-11-24 23:30:05 +04:00
/*******************************************************************************************
*
* raylib [audio] example - Sound loading and playing
2013-11-24 23:30:05 +04:00
*
* NOTE: This example requires OpenAL Soft library installed
2013-12-01 15:34:31 +04:00
*
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
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
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;
2014-09-30 01:41:05 +04:00
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
2014-09-30 01:41:05 +04:00
InitAudioDevice(); // Initialize audio device
2014-09-30 01:41:05 +04:00
2017-01-22 17:31:56 +03:00
Sound fxWav = LoadSound("resources/audio/sound.wav"); // Load WAV audio file
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
2016-01-16 14:52:55 +03:00
SetTargetFPS(60);
2013-11-29 00:16:31 +04:00
//--------------------------------------------------------------------------------------
2014-09-30 01:41:05 +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(fxWav); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
2013-11-29 00:16:31 +04:00
//----------------------------------------------------------------------------------
2014-09-30 01:41:05 +04:00
2013-11-29 00:16:31 +04:00
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
2014-09-30 01:41:05 +04:00
2013-11-29 00:16:31 +04:00
ClearBackground(RAYWHITE);
2014-09-30 01:41:05 +04: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-30 01:41:05 +04:00
EndDrawing();
2013-11-29 00:16:31 +04:00
//----------------------------------------------------------------------------------
}
2013-11-29 00:16:31 +04:00
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
2014-09-30 01:41:05 +04:00
2013-11-29 00:16:31 +04:00
CloseAudioDevice(); // Close audio device
2014-09-30 01:41:05 +04:00
CloseWindow(); // Close window and OpenGL context
2013-11-29 00:16:31 +04:00
//--------------------------------------------------------------------------------------
2014-09-30 01:41:05 +04:00
2013-11-24 23:30:05 +04:00
return 0;
}