Open Source Tomb Raider Engine
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.

Sound.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*!
  2. * \file Sound.cpp
  3. * \brief This is the audio manager Unit Test
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <Sound.h>
  11. /*!
  12. * \brief Sound Unit Test
  13. * \param argc Number of arguments. Has to be > 1
  14. * \param argv Argument array. argv[1] will be played as wav file
  15. * \returns always zero
  16. */
  17. int main(int argc, char* argv[])
  18. {
  19. Sound snd;
  20. FILE *f;
  21. unsigned int l;
  22. unsigned char *buf;
  23. int id, ret;
  24. if (argc > 1)
  25. {
  26. snd.init();
  27. printf("Loading %s\n", argv[1]);
  28. ret = snd.addFile(argv[1], &id, snd.SoundFlagsNone);
  29. printf("Load returned %i\n", ret);
  30. printf("Playing %u::%s\n", id, argv[1]);
  31. snd.play(id);
  32. printf("Waiting...\n");
  33. sleep(1);
  34. f = fopen(argv[1], "rb");
  35. if (f)
  36. {
  37. fseek(f, 0, SEEK_END);
  38. l = ftell(f);
  39. fseek(f, 0, SEEK_SET);
  40. buf = new unsigned char[l];
  41. fread(buf, l, 1, f);
  42. fclose(f);
  43. printf("Loading buffer of %s\n", argv[1]);
  44. ret = snd.addWave(buf, l, &id, snd.SoundFlagsNone);
  45. printf("Load returned %i\n", ret);
  46. printf("Playing buffer of %u::%s\n", id, argv[1]);
  47. snd.play(id);
  48. delete [] buf;
  49. printf("Waiting...\n");
  50. sleep(1);
  51. }
  52. }
  53. else
  54. {
  55. printf("%s filename.wav\n", argv[0]);
  56. }
  57. return 0;
  58. }