forked from W4D/soundcube-firmware
wave file parser WIP
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#include "codec.h"
|
#include "codec.h"
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
|
#include "wavestream.h"
|
||||||
|
|
||||||
#define HAPTIC 1
|
#define HAPTIC 1
|
||||||
#define AURAL 1
|
#define AURAL 1
|
||||||
@ -26,6 +27,8 @@ int16_t buffer2[ECHO];
|
|||||||
|
|
||||||
RingBuffer<int16_t> ringbuffer[NSTREAMS];
|
RingBuffer<int16_t> ringbuffer[NSTREAMS];
|
||||||
|
|
||||||
|
WaveStream stream;
|
||||||
|
|
||||||
File streams[NSTREAMS];
|
File streams[NSTREAMS];
|
||||||
bool streams_loaded = false;
|
bool streams_loaded = false;
|
||||||
|
|
||||||
|
|||||||
101
soundcube-firmware/wavestream.h
Normal file
101
soundcube-firmware/wavestream.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SD.h>
|
||||||
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
|
struct WaveFile{
|
||||||
|
File file;
|
||||||
|
|
||||||
|
bool load(File _file){
|
||||||
|
file = _file;
|
||||||
|
|
||||||
|
file.seek(0, SeekSet);
|
||||||
|
uint8_t start[4];
|
||||||
|
uint8_t size[4];
|
||||||
|
uint8_t wave[4];
|
||||||
|
|
||||||
|
// RIFF Header
|
||||||
|
file.read(start, 4);
|
||||||
|
if(strcmp("RIFF", (const char*)start) != 0) return false;
|
||||||
|
|
||||||
|
file.seek(4, SeekSet);
|
||||||
|
file.read(size, 4);
|
||||||
|
length = (size[3] << 24 + size[2] << 16 + size[1] << 8 + size[0]) - 8;
|
||||||
|
|
||||||
|
file.seek(8, SeekSet);
|
||||||
|
file.read(wave, 4);
|
||||||
|
if(strcmp("WAVE", (const char*)wave) != 0) return false;
|
||||||
|
|
||||||
|
// FORMAT
|
||||||
|
uint8_t fmt[4];
|
||||||
|
uint8_t fmtLen[4];
|
||||||
|
uint8_t fmtTag[2];
|
||||||
|
uint8_t fmtChannels[2];
|
||||||
|
uint8_t fmtSamplerate[4];
|
||||||
|
uint8_t fmtBytesPerSecond[4];
|
||||||
|
uint8_t fmtBlockalign[2];
|
||||||
|
uint8_t fmtBitsPerSample[2];
|
||||||
|
|
||||||
|
file.seek(12, SeekSet);
|
||||||
|
file.read(fmt, 4);
|
||||||
|
if(strcmp("fmt ", (const char*)fmt) != 0) return false;
|
||||||
|
|
||||||
|
file.seek(20, SeekSet);
|
||||||
|
file.read(fmtTag, 4);
|
||||||
|
format = fmtTag[1] << 8 + fmtTag[0];
|
||||||
|
if(format != 0x0001) return false;
|
||||||
|
|
||||||
|
file.seek(22, SeekSet);
|
||||||
|
file.read(fmtChannels, 2);
|
||||||
|
channels = fmtChannels[1] << 8 + fmtChannels[0];
|
||||||
|
|
||||||
|
file.seek(24, SeekSet);
|
||||||
|
file.read(fmtSamplerate, 4);
|
||||||
|
samplerate = fmtSamplerate[3] << 24 + fmtSamplerate[2] << 16 + fmtSamplerate[1] << 8 + fmtSamplerate[0];
|
||||||
|
|
||||||
|
file.seek(32, SeekSet);
|
||||||
|
file.read(fmtBlockalign, 2);
|
||||||
|
blockalign = fmtBlockalign[1] << 8 + fmtBlockalign[0];
|
||||||
|
|
||||||
|
file.seek(34, SeekSet);
|
||||||
|
file.read(fmtBitsPerSample, 2);
|
||||||
|
bitspersample = fmtBitsPerSample[1] << 8 + fmtBitsPerSample[0];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t format = 0;
|
||||||
|
uint32_t length = 0;
|
||||||
|
uint16_t channels = 0;
|
||||||
|
uint32_t samplerate = 0;
|
||||||
|
uint16_t blockalign = 0;
|
||||||
|
uint16_t bitspersample = 0;
|
||||||
|
|
||||||
|
RingBuffer<int16_t> buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WaveStream{
|
||||||
|
public:
|
||||||
|
WaveStream(){}
|
||||||
|
|
||||||
|
void begin(){}
|
||||||
|
void update(){}
|
||||||
|
|
||||||
|
bool load(int stream, File wavefile){
|
||||||
|
if(stream < 0 || stream > 7) return false;
|
||||||
|
if(!wavefiles[stream].load(wavefile)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start(int stream){}
|
||||||
|
void stop(int stream){}
|
||||||
|
void pause(int stream){}
|
||||||
|
|
||||||
|
void stopAll(){}
|
||||||
|
void startAll(){}
|
||||||
|
void pauseAll(){}
|
||||||
|
|
||||||
|
private:
|
||||||
|
WaveFile wavefiles[8];
|
||||||
|
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user