選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

69 行
1.1KB

  1. #include "Audio.h"
  2. #include "arm_math.h"
  3. #include "utility/dspinst.h"
  4. void AudioPlaySDcardRAW::begin(void)
  5. {
  6. playing = false;
  7. if (block) {
  8. release(block);
  9. block = NULL;
  10. }
  11. }
  12. bool AudioPlaySDcardRAW::play(const char *filename)
  13. {
  14. stop();
  15. rawfile = SD.open(filename);
  16. if (!rawfile) {
  17. Serial.println("unable to open file");
  18. return false;
  19. }
  20. Serial.println("able to open file");
  21. playing = true;
  22. return true;
  23. }
  24. void AudioPlaySDcardRAW::stop(void)
  25. {
  26. __disable_irq();
  27. if (playing) {
  28. playing = false;
  29. __enable_irq();
  30. rawfile.close();
  31. } else {
  32. __enable_irq();
  33. }
  34. }
  35. void AudioPlaySDcardRAW::update(void)
  36. {
  37. unsigned int i, n;
  38. // only update if we're playing
  39. if (!playing) return;
  40. // allocate the audio blocks to transmit
  41. block = allocate();
  42. if (block == NULL) return;
  43. if (rawfile.available()) {
  44. // we can read more data from the file...
  45. n = rawfile.read(block->data, AUDIO_BLOCK_SAMPLES*2);
  46. for (i=n/2; i < AUDIO_BLOCK_SAMPLES; i++) {
  47. block->data[i] = 0;
  48. }
  49. transmit(block);
  50. release(block);
  51. } else {
  52. rawfile.close();
  53. playing = false;
  54. }
  55. }