audio_standalone.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. unsigned char key;
  32. InitAudioDevice();
  33. Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
  34. Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
  35. PlayMusicStream(0, "resources/audio/guitar_noodling.ogg");
  36. printf("\nPress s or d to play sounds...\n");
  37. while (key != KEY_ESCAPE)
  38. {
  39. if (kbhit()) key = getch();
  40. if (key == 's')
  41. {
  42. PlaySound(fxWav);
  43. key = 0;
  44. }
  45. if (key == 'd')
  46. {
  47. PlaySound(fxOgg);
  48. key = 0;
  49. }
  50. UpdateMusicStream(0);
  51. }
  52. UnloadSound(fxWav); // Unload sound data
  53. UnloadSound(fxOgg); // Unload sound data
  54. CloseAudioDevice();
  55. printf("\n\nPress ENTER to close...");
  56. getchar();
  57. return 0;
  58. }