|
-
-
- #include <Arduino.h>
- #include "play_serialflash_raw.h"
- #include "spi_interrupt.h"
-
-
- void AudioPlaySerialflashRaw::begin(void)
- {
- playing = false;
- file_offset = 0;
- file_size = 0;
- }
-
-
- bool AudioPlaySerialflashRaw::play(const char *filename)
- {
- stop();
- AudioStartUsingSPI();
- rawfile = SerialFlash.open(filename);
- if (!rawfile) {
-
- AudioStopUsingSPI();
- return false;
- }
- file_size = rawfile.size();
- file_offset = 0;
-
- playing = true;
- return true;
- }
-
- void AudioPlaySerialflashRaw::stop(void)
- {
- __disable_irq();
- if (playing) {
- playing = false;
- __enable_irq();
- rawfile.close();
- AudioStopUsingSPI();
- } else {
- __enable_irq();
- }
- }
-
-
- void AudioPlaySerialflashRaw::update(void)
- {
- unsigned int i, n;
- audio_block_t *block;
-
-
- if (!playing) return;
-
-
- block = allocate();
- if (block == NULL) return;
-
- if (rawfile.available()) {
-
- n = rawfile.read(block->data, AUDIO_BLOCK_SAMPLES*2);
- file_offset += n;
- for (i=n/2; i < AUDIO_BLOCK_SAMPLES; i++) {
- block->data[i] = 0;
- }
- transmit(block);
- } else {
- rawfile.close();
- AudioStopUsingSPI();
- playing = false;
-
- }
- release(block);
- }
-
- #define B2M (uint32_t)((double)4294967296000.0 / AUDIO_SAMPLE_RATE_EXACT / 2.0)
-
- uint32_t AudioPlaySerialflashRaw::positionMillis(void)
- {
- return ((uint64_t)file_offset * B2M) >> 32;
- }
-
- uint32_t AudioPlaySerialflashRaw::lengthMillis(void)
- {
- return ((uint64_t)file_size * B2M) >> 32;
- }
-
|