1 | /******************************************************************************************* |
2 | * |
3 | * raylib [audio] example - Sound loading and playing |
4 | * |
5 | * This example has been created using raylib 1.0 (www.raylib.com) |
6 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
7 | * |
8 | * Copyright (c) 2014 Ramon Santamaria (@raysan5) |
9 | * |
10 | ********************************************************************************************/ |
11 | |
12 | #include "raylib.h" |
13 | |
14 | int main(void) |
15 | { |
16 | // Initialization |
17 | //-------------------------------------------------------------------------------------- |
18 | const int screenWidth = 800; |
19 | const int screenHeight = 450; |
20 | |
21 | InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing" ); |
22 | |
23 | InitAudioDevice(); // Initialize audio device |
24 | |
25 | Sound fxWav = LoadSound("resources/sound.wav" ); // Load WAV audio file |
26 | Sound fxOgg = LoadSound("resources/tanatana.ogg" ); // Load OGG audio file |
27 | |
28 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
29 | //-------------------------------------------------------------------------------------- |
30 | |
31 | // Main game loop |
32 | while (!WindowShouldClose()) // Detect window close button or ESC key |
33 | { |
34 | // Update |
35 | //---------------------------------------------------------------------------------- |
36 | if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound |
37 | if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound |
38 | //---------------------------------------------------------------------------------- |
39 | |
40 | // Draw |
41 | //---------------------------------------------------------------------------------- |
42 | BeginDrawing(); |
43 | |
44 | ClearBackground(RAYWHITE); |
45 | |
46 | DrawText("Press SPACE to PLAY the WAV sound!" , 200, 180, 20, LIGHTGRAY); |
47 | DrawText("Press ENTER to PLAY the OGG sound!" , 200, 220, 20, LIGHTGRAY); |
48 | |
49 | EndDrawing(); |
50 | //---------------------------------------------------------------------------------- |
51 | } |
52 | |
53 | // De-Initialization |
54 | //-------------------------------------------------------------------------------------- |
55 | UnloadSound(fxWav); // Unload sound data |
56 | UnloadSound(fxOgg); // Unload sound data |
57 | |
58 | CloseAudioDevice(); // Close audio device |
59 | |
60 | CloseWindow(); // Close window and OpenGL context |
61 | //-------------------------------------------------------------------------------------- |
62 | |
63 | return 0; |
64 | } |