1/*******************************************************************************************
2*
3* raylib [audio] example - Multichannel sound playing
4*
5* This example has been created using raylib 2.6 (www.raylib.com)
6* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7*
8* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5)
9*
10* Copyright (c) 2019 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5)
11*
12********************************************************************************************/
13
14#include "raylib.h"
15
16int main(void)
17{
18 // Initialization
19 //--------------------------------------------------------------------------------------
20 const int screenWidth = 800;
21 const int screenHeight = 450;
22
23 InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
24
25 InitAudioDevice(); // Initialize audio device
26
27 Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
28 Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
29
30 SetSoundVolume(fxWav, 0.2);
31
32 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
33 //--------------------------------------------------------------------------------------
34
35 // Main game loop
36 while (!WindowShouldClose()) // Detect window close button or ESC key
37 {
38 // Update
39 //----------------------------------------------------------------------------------
40 if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
41 if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
42 //----------------------------------------------------------------------------------
43
44 // Draw
45 //----------------------------------------------------------------------------------
46 BeginDrawing();
47
48 ClearBackground(RAYWHITE);
49
50 DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
51 DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
52 DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
53
54 DrawText(FormatText("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
55
56 EndDrawing();
57 //----------------------------------------------------------------------------------
58 }
59
60 // De-Initialization
61 //--------------------------------------------------------------------------------------
62 StopSoundMulti(); // We must stop the buffer pool before unloading
63
64 UnloadSound(fxWav); // Unload sound data
65 UnloadSound(fxOgg); // Unload sound data
66
67 CloseAudioDevice(); // Close audio device
68
69 CloseWindow(); // Close window and OpenGL context
70 //--------------------------------------------------------------------------------------
71
72 return 0;
73}
74