You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.0 KiB

  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. #include "raylib.h"
  14. int main(void)
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. const int screenWidth = 800;
  19. const int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
  21. InitAudioDevice(); // Initialize audio device
  22. Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
  23. Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
  24. SetSoundVolume(fxWav, 0.2);
  25. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  26. //--------------------------------------------------------------------------------------
  27. // Main game loop
  28. while (!WindowShouldClose()) // Detect window close button or ESC key
  29. {
  30. // Update
  31. //----------------------------------------------------------------------------------
  32. if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
  33. if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
  40. DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
  41. DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
  42. DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
  43. EndDrawing();
  44. //----------------------------------------------------------------------------------
  45. }
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. StopSoundMulti(); // We must stop the buffer pool before unloading
  49. UnloadSound(fxWav); // Unload sound data
  50. UnloadSound(fxOgg); // Unload sound data
  51. CloseAudioDevice(); // Close audio device
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }