Преглед изворни кода

Add status and position functions to AudioPlaySdRaw

dds
PaulStoffregen пре 11 година
родитељ
комит
5164e6177a
2 измењених фајлова са 24 додато и 3 уклоњено
  1. +19
    -2
      play_sd_raw.cpp
  2. +5
    -1
      play_sd_raw.h

+ 19
- 2
play_sd_raw.cpp Прегледај датотеку

release(block); release(block);
block = NULL; block = NULL;
} }
file_offset = 0;
file_size = 0;
} }




stop(); stop();
rawfile = SD.open(filename); rawfile = SD.open(filename);
if (!rawfile) { if (!rawfile) {
Serial.println("unable to open file");
//Serial.println("unable to open file");
return false; return false;
} }
Serial.println("able to open file");
file_size = rawfile.size();
file_offset = 0;
//Serial.println("able to open file");
playing = true; playing = true;
return true; return true;
} }
if (rawfile.available()) { if (rawfile.available()) {
// we can read more data from the file... // we can read more data from the file...
n = rawfile.read(block->data, AUDIO_BLOCK_SAMPLES*2); n = rawfile.read(block->data, AUDIO_BLOCK_SAMPLES*2);
file_offset += n;
for (i=n/2; i < AUDIO_BLOCK_SAMPLES; i++) { for (i=n/2; i < AUDIO_BLOCK_SAMPLES; i++) {
block->data[i] = 0; block->data[i] = 0;
} }
} }
} }


#define B2M (uint32_t)((double)4294967296000.0 / AUDIO_SAMPLE_RATE_EXACT / 2.0) // 97352592

uint32_t AudioPlaySdRaw::positionMillis(void)
{
return ((uint64_t)file_offset * B2M) >> 32;
}

uint32_t AudioPlaySdRaw::lengthMillis(void)
{
return ((uint64_t)file_size * B2M) >> 32;
}




+ 5
- 1
play_sd_raw.h Прегледај датотеку

void begin(void); void begin(void);
bool play(const char *filename); bool play(const char *filename);
void stop(void); void stop(void);
bool isPlaying(void) { return playing; }
uint32_t positionMillis(void);
uint32_t lengthMillis(void);
virtual void update(void); virtual void update(void);
private: private:
File rawfile; File rawfile;
audio_block_t *block; audio_block_t *block;
uint32_t file_size;
uint32_t file_offset;
bool playing; bool playing;
bool paused;
}; };


#endif #endif

Loading…
Откажи
Сачувај