mp3stream.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Created by Jordy Sipkema on 28/03/16.
  3. //
  4. #include "mp3stream.h"
  5. #include <sys/thread.h>
  6. // Prototypes - Functions for internal use only! (They wont be visible outside this file!)
  7. THREAD(Mp3Player, args);
  8. void setVolume(void);
  9. // Variables
  10. static bool stream_stopped = false;
  11. static bool stream_isplaying = false;
  12. static u_char VS_volume = 7; //[0-15]; (Default volume = 7 (50%) )
  13. bool play(FILE *stream)
  14. {
  15. NutThreadCreate("Mp3Player", Mp3Player, stream, 512);
  16. printf("Mp3Player thread created. Device should start playing the stream.\n");
  17. return true;
  18. }
  19. u_char volumeUp(void)
  20. {
  21. if (VS_volume >= 16)
  22. return VS_volume;
  23. //else:
  24. ++VS_volume;
  25. VS_volume = VS_volume % 17;
  26. setVolume();
  27. return VS_volume;
  28. }
  29. u_char volumeDown(void)
  30. {
  31. if (VS_volume <= 0)
  32. return VS_volume;
  33. //else:
  34. --VS_volume;
  35. VS_volume = VS_volume % 17;
  36. setVolume();
  37. return VS_volume;
  38. }
  39. void setVolume(void){
  40. VsSetVolume((127 - (VS_volume * 8)) % 128);
  41. }
  42. THREAD(Mp3Player, args)
  43. {
  44. FILE *stream = (FILE *)args;
  45. size_t rbytes = 0;
  46. char *mp3buf;
  47. int result = false;
  48. int nrBytesRead = 0;
  49. unsigned char iflag;
  50. //Whatevahhh
  51. }
  52. void killPlayerThread(void)
  53. {
  54. stream_stopped = true;
  55. }