audio_standalone.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*******************************************************************************************
  2. *
  3. * raylib [audio] example - Using audio module as standalone module
  4. *
  5. * NOTE: This example does not require any graphic device, it can run directly on console.
  6. *
  7. * [audio] module requires some external libs:
  8. * OpenAL Soft - Audio device management lib (http://kcat.strangesoft.net/openal.html)
  9. * stb_vorbis - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
  10. * jar_xm - XM module file loading
  11. * jar_mod - MOD audio file loading
  12. *
  13. * Compile audio module using:
  14. * gcc -c audio.c stb_vorbis.c -Wall -std=c99 -DAUDIO_STANDALONE
  15. *
  16. * Compile example using:
  17. * gcc -o $(NAME_PART).exe $(FILE_NAME) audio.o stb_vorbis.o -lopenal32 -std=c99
  18. *
  19. * This example has been created using raylib 1.5 (www.raylib.com)
  20. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  21. *
  22. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  23. *
  24. ********************************************************************************************/
  25. #include <stdio.h>
  26. #include <conio.h> // Windows only, no stardard library
  27. #include "audio.h"
  28. #define KEY_ESCAPE 27
  29. int main()
  30. {
  31. // Initialization
  32. //--------------------------------------------------------------------------------------
  33. unsigned char key;
  34. InitAudioDevice();
  35. Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
  36. Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
  37. Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
  38. PlayMusicStream(music);
  39. printf("\nPress s or d to play sounds...\n");
  40. //--------------------------------------------------------------------------------------
  41. // Main loop
  42. while (key != KEY_ESCAPE)
  43. {
  44. if (kbhit()) key = getch();
  45. if (key == 's')
  46. {
  47. PlaySound(fxWav);
  48. key = 0;
  49. }
  50. if (key == 'd')
  51. {
  52. PlaySound(fxOgg);
  53. key = 0;
  54. }
  55. UpdateMusicStream(music);
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. UnloadSound(fxWav); // Unload sound data
  60. UnloadSound(fxOgg); // Unload sound data
  61. UnloadMusicStream(music); // Unload music stream data
  62. CloseAudioDevice();
  63. //--------------------------------------------------------------------------------------
  64. return 0;
  65. }