-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
AudioGeneratorWAVStatic.h
62 lines (47 loc) · 1.89 KB
/
AudioGeneratorWAVStatic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
AudioGeneratorWAV
Audio output generator that reads 8 and 16-bit WAV files
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOGENERATORWAVSTATIC_H
#define _AUDIOGENERATORWAVSTATIC_H
#include "AudioGenerator.h"
class AudioGeneratorWAVStatic : public AudioGenerator
{
public:
virtual ~AudioGeneratorWAVStatic() override;
virtual bool begin(AudioFileSource *source, AudioOutput *output) override;
virtual bool loop() override;
virtual bool stop() override;
virtual bool isRunning() override;
private:
bool ReadU32(uint32_t *dest) { return file->read(reinterpret_cast<uint8_t*>(dest), 4); }
bool ReadU16(uint16_t *dest) { return file->read(reinterpret_cast<uint8_t*>(dest), 2); }
bool ReadU8(uint8_t *dest) { return file->read(reinterpret_cast<uint8_t*>(dest), 1); }
bool GetBufferedData(int bytes, void *dest);
bool ReadWAVInfo();
protected:
// WAV info
uint16_t channels;
uint32_t sampleRate;
uint16_t bitsPerSample;
uint32_t availBytes;
// We need to buffer some data in-RAM to avoid doing 1000s of small reads
//uint32_t buffSize;
//uint8_t *buff;
uint16_t buffPtr;
uint16_t buffLen;
static const uint16_t BUFFER_SIZE = 256;
uint8_t buff[BUFFER_SIZE];
};
#endif