audio_standalone.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
  36. PlayMusicStream(music);
  37. printf("\nPress s or d to play sounds...\n");
  38. while (key != KEY_ESCAPE)
  39. {
  40. if (kbhit()) key = getch();
  41. if (key == 's')
  42. {
  43. PlaySound(fxWav);
  44. key = 0;
  45. }
  46. if (key == 'd')
  47. {
  48. PlaySound(fxOgg);
  49. key = 0;
  50. }
  51. UpdateMusicStream(music);
  52. }
  53. UnloadSound(fxWav); // Unload sound data
  54. UnloadSound(fxOgg); // Unload sound data
  55. UnloadMusicStream(music); // Unload music stream data
  56. CloseAudioDevice();
  57. printf("\n\nPress ENTER to close...");
  58. getchar();
  59. return 0;
  60. }