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.

78 lines
3.2 KiB

пре 4 година
пре 2 година
пре 2 година
пре 3 година
пре 5 година
пре 3 година
пре 5 година
  1. /*******************************************************************************************
  2. *
  3. * raylib [audio] example - Multichannel sound playing
  4. *
  5. * Example originally created with raylib 3.0, last time updated with raylib 3.5
  6. *
  7. * Example contributed by Chris Camacho (@chriscamacho) and reviewed by Ramon Santamaria (@raysan5)
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2019-2023 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
  26. InitAudioDevice(); // Initialize audio device
  27. Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
  28. Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
  29. SetSoundVolume(fxWav, 0.2f);
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
  38. if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
  39. //----------------------------------------------------------------------------------
  40. // Draw
  41. //----------------------------------------------------------------------------------
  42. BeginDrawing();
  43. ClearBackground(RAYWHITE);
  44. DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
  45. DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
  46. DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY);
  47. DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. StopSoundMulti(); // We must stop the buffer pool before unloading
  54. UnloadSound(fxWav); // Unload sound data
  55. UnloadSound(fxOgg); // Unload sound data
  56. CloseAudioDevice(); // Close audio device
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }