2
0

ex08_audio.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*******************************************************************************************
  2. *
  3. * raylib example 08 - Audio loading and playing
  4. *
  5. * NOTE: This example requires OpenAL32 dll installed (or in the same folder)
  6. *
  7. * This example has been created using raylib 1.0 (www.raylib.com)
  8. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. *
  10. * Copyright (c) 2013 Ramon Santamaria (Ray San - [email protected])
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. int main()
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib example 08 - audio loading and playing");
  21. InitAudioDevice(); // Initialize audio device
  22. Sound fx = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
  23. //--------------------------------------------------------------------------------------
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. if (IsKeyPressed(KEY_SPACE)) PlaySound(fx); // Play the sound!
  30. //----------------------------------------------------------------------------------
  31. // Draw
  32. //----------------------------------------------------------------------------------
  33. BeginDrawing();
  34. ClearBackground(RAYWHITE);
  35. DrawText("Press SPACE to PLAY the SOUND!", 240, 200, 20, LIGHTGRAY);
  36. EndDrawing();
  37. //----------------------------------------------------------------------------------
  38. }
  39. // De-Initialization
  40. //--------------------------------------------------------------------------------------
  41. UnloadSound(fx); // Unload sound data
  42. CloseAudioDevice(); // Close audio device
  43. CloseWindow(); // Close window and OpenGL context
  44. //--------------------------------------------------------------------------------------
  45. return 0;
  46. }