forked from W4D/soundcube-firmware
waves playing again, still xruns
This commit is contained in:
@ -47,9 +47,9 @@ class TLV320AIC3204{
|
|||||||
// POWER and CM
|
// POWER and CM
|
||||||
cw(0x00, 0x01); // select page 1
|
cw(0x00, 0x01); // select page 1
|
||||||
cw(0x01, 0b00001000); // disable weak (crude) AVdd connection to DVdd
|
cw(0x01, 0b00001000); // disable weak (crude) AVdd connection to DVdd
|
||||||
cw(0x02, 0b00000001); // enable internal AVdd LDO and enable analog blocks
|
cw(0x02, 0b01011001); // enable internal AVdd LDO and enable analog blocks
|
||||||
cw(0x09, 0b00001100); // power up LOL, LOR, power down MAL, MAR, HPL, HPR
|
cw(0x09, 0b00001100); // power up LOL, LOR, power down MAL, MAR, HPL, HPR
|
||||||
cw(0x0a, 0b00001000); // set full chip CM to 0.75V
|
cw(0x0a, 0b01000000); // set full chip CM to 0.75V
|
||||||
cw(0x47, 0b00110011); // analog input quick charge time 1.6ms
|
cw(0x47, 0b00110011); // analog input quick charge time 1.6ms
|
||||||
|
|
||||||
// ROUTING
|
// ROUTING
|
||||||
|
|||||||
@ -18,18 +18,13 @@
|
|||||||
#define AURAL 1
|
#define AURAL 1
|
||||||
#define UI_SAMPLERATE 22050
|
#define UI_SAMPLERATE 22050
|
||||||
|
|
||||||
#define SIZE 1024
|
#define BUFFERSIZE 1024
|
||||||
#define RINGBUFFER 16384
|
|
||||||
#define ECHO 24000
|
|
||||||
|
|
||||||
#define NSTREAMS 8
|
#define NSTREAMS 8
|
||||||
|
|
||||||
int16_t buffer[SIZE];
|
int16_t buffer[BUFFERSIZE];
|
||||||
int16_t buffer2[ECHO];
|
|
||||||
|
|
||||||
WaveStream stream[NSTREAMS];
|
WaveStream stream[NSTREAMS];
|
||||||
|
|
||||||
//File streams[NSTREAMS];
|
|
||||||
bool streams_loaded = false;
|
bool streams_loaded = false;
|
||||||
|
|
||||||
I2S i2s(INPUT_PULLUP);
|
I2S i2s(INPUT_PULLUP);
|
||||||
@ -101,28 +96,18 @@ size_t count;
|
|||||||
size_t tape_write = 0;
|
size_t tape_write = 0;
|
||||||
|
|
||||||
void codec_transmit() {
|
void codec_transmit() {
|
||||||
// for(int i = 0; i < count; i++){
|
|
||||||
// buffer2[tape_write] = buffer[i];
|
|
||||||
// tape_write++;
|
|
||||||
// if(tape_write == ECHO) tape_write = 0;
|
|
||||||
|
|
||||||
// int tape_read = tape_write + 1;
|
|
||||||
// if(tape_read < 0) tape_read += ECHO;
|
|
||||||
// buffer[i] += buffer2[tape_read % ECHO];
|
|
||||||
// }
|
|
||||||
|
|
||||||
for(int i = 0; i < count; i++){
|
for(int i = 0; i < count; i++){
|
||||||
int16_t sample = 0;
|
int16_t sample = 0;
|
||||||
int j = active % NSTREAMS;
|
int j = active % NSTREAMS;
|
||||||
sample = stream[j].get();
|
sample = stream[j].get();
|
||||||
buffer[i] += (sample);
|
buffer[i] += sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void codec_receive(){
|
void codec_receive(){
|
||||||
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
count = i2s.read((uint8_t *)&buffer, BUFFERSIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
||||||
for(int i = 0; i < count; i++){
|
for(int i = 0; i < count; i++){
|
||||||
buffer[i] *= -1;
|
buffer[i] *= -1;
|
||||||
}
|
}
|
||||||
@ -256,7 +241,7 @@ void setup() {
|
|||||||
i2s.swapClocks();
|
i2s.swapClocks();
|
||||||
i2s.setBitsPerSample(16);
|
i2s.setBitsPerSample(16);
|
||||||
|
|
||||||
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
|
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||||
|
|
||||||
if(!i2s.begin(48000)){
|
if(!i2s.begin(48000)){
|
||||||
Serial.println("I2S error!");
|
Serial.println("I2S error!");
|
||||||
@ -265,13 +250,29 @@ void setup() {
|
|||||||
|
|
||||||
if(sdInitialized) {
|
if(sdInitialized) {
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
stream[i].begin();
|
||||||
char filename[40];
|
char filename[40];
|
||||||
sprintf(filename, "/sound/%d.wav", i+1);
|
sprintf(filename, "/sound/%d.wav", i+1);
|
||||||
if(SD.exists(filename)){
|
if(SD.exists(filename)){
|
||||||
stream[i].load(SD.open(filename));
|
bool loaded = stream[i].load(SD.open(filename));
|
||||||
stream[i].begin();
|
|
||||||
|
if(loaded) {
|
||||||
|
Serial.print("file read: ");
|
||||||
|
Serial.print(stream[i].wavefile.length);
|
||||||
|
Serial.print(" bytes | ");
|
||||||
|
Serial.print(stream[i].wavefile.samplerate);
|
||||||
|
Serial.print(" kHz | ");
|
||||||
|
Serial.print(stream[i].wavefile.bitspersample);
|
||||||
|
Serial.print(" bits | ");
|
||||||
|
Serial.print(stream[i].wavefile.channels);
|
||||||
|
Serial.print(" channels | ");
|
||||||
|
Serial.print(stream[i].wavefile.blockalign);
|
||||||
|
Serial.println(" bytes");
|
||||||
|
|
||||||
//stream[i].play();
|
//stream[i].play();
|
||||||
Serial.println(stream[i].wavefile.blockalign);
|
} else {
|
||||||
|
Serial.println("file loading error");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int k = 0; k < 3; k++){
|
for(int k = 0; k < 3; k++){
|
||||||
digitalWrite(6, HIGH);
|
digitalWrite(6, HIGH);
|
||||||
@ -386,6 +387,11 @@ void loop() {
|
|||||||
|
|
||||||
Serial.println(codec.getVolumeL());
|
Serial.println(codec.getVolumeL());
|
||||||
|
|
||||||
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
stream[i].pause();
|
||||||
|
}
|
||||||
|
stream[active % NSTREAMS].play();
|
||||||
|
|
||||||
buttonChanged = false;
|
buttonChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,6 +414,15 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
if(streams_loaded) {
|
||||||
|
for(int i = 0; i < NSTREAMS; i++){
|
||||||
|
stream[i].stream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i2s.getOverflow()) Serial.println("overflow");
|
||||||
|
if(i2s.getUnderflow()) Serial.println("underflow");
|
||||||
|
|
||||||
delay(20); // wait 1ms
|
delay(20); // wait 1ms
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,9 +431,5 @@ void setup1(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop1(){
|
void loop1(){
|
||||||
if(streams_loaded) {
|
|
||||||
for(int i = 0; i < NSTREAMS; i++){
|
|
||||||
stream[i].stream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -6,25 +6,33 @@
|
|||||||
struct WaveFile{
|
struct WaveFile{
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
|
char cstart[4];
|
||||||
|
char cwave[4];
|
||||||
|
char cfmt[4];
|
||||||
|
|
||||||
bool load(File _file){
|
bool load(File _file){
|
||||||
file = _file;
|
file = _file;
|
||||||
|
|
||||||
file.seek(0, SeekSet);
|
// RIFF Header
|
||||||
uint8_t start[4];
|
uint8_t start[4];
|
||||||
uint8_t size[4];
|
uint8_t size[4];
|
||||||
uint8_t wave[4];
|
uint8_t wave[4];
|
||||||
|
|
||||||
// RIFF Header
|
file.seek(0, SeekSet);
|
||||||
file.read(start, 4);
|
file.read(start, 4);
|
||||||
if(strcmp("RIFF", (const char*)start) != 0) return false;
|
|
||||||
|
memcpy(cstart, start, 4);
|
||||||
|
|
||||||
|
if(strcmp("RIFF", cstart) != 0) return false;
|
||||||
|
|
||||||
file.seek(4, SeekSet);
|
file.seek(4, SeekSet);
|
||||||
file.read(size, 4);
|
file.read(size, 4);
|
||||||
length = (size[3] << 24 + size[2] << 16 + size[1] << 8 + size[0]) - 8;
|
length = (size[3] << 24) + (size[2] << 16) + (size[1] << 8) + size[3] - 8;
|
||||||
|
|
||||||
file.seek(8, SeekSet);
|
file.seek(8, SeekSet);
|
||||||
file.read(wave, 4);
|
file.read(wave, 4);
|
||||||
if(strcmp("WAVE", (const char*)wave) != 0) return false;
|
memcpy(cwave, wave, 4);
|
||||||
|
if(strcmp("WAVE", cwave) != 0) return false;
|
||||||
|
|
||||||
// FORMAT
|
// FORMAT
|
||||||
uint8_t fmt[4];
|
uint8_t fmt[4];
|
||||||
@ -38,28 +46,30 @@ struct WaveFile{
|
|||||||
|
|
||||||
file.seek(12, SeekSet);
|
file.seek(12, SeekSet);
|
||||||
file.read(fmt, 4);
|
file.read(fmt, 4);
|
||||||
if(strcmp("fmt ", (const char*)fmt) != 0) return false;
|
memcpy(cfmt, fmt, 4);
|
||||||
|
|
||||||
|
if(strcmp("fmt ", cfmt) != 0) return false;
|
||||||
|
|
||||||
file.seek(20, SeekSet);
|
file.seek(20, SeekSet);
|
||||||
file.read(fmtTag, 4);
|
file.read(fmtTag, 4);
|
||||||
format = fmtTag[1] << 8 + fmtTag[0];
|
format = (fmtTag[1] << 8) + fmtTag[0];
|
||||||
if(format != 0x0001) return false;
|
if(format != 0x0001) return false;
|
||||||
|
|
||||||
file.seek(22, SeekSet);
|
file.seek(22, SeekSet);
|
||||||
file.read(fmtChannels, 2);
|
file.read(fmtChannels, 2);
|
||||||
channels = fmtChannels[1] << 8 + fmtChannels[0];
|
channels = (fmtChannels[1] << 8) + fmtChannels[0];
|
||||||
|
|
||||||
file.seek(24, SeekSet);
|
file.seek(24, SeekSet);
|
||||||
file.read(fmtSamplerate, 4);
|
file.read(fmtSamplerate, 4);
|
||||||
samplerate = fmtSamplerate[3] << 24 + fmtSamplerate[2] << 16 + fmtSamplerate[1] << 8 + fmtSamplerate[0];
|
samplerate = (fmtSamplerate[3] << 24) + (fmtSamplerate[2] << 16) + (fmtSamplerate[1] << 8) + fmtSamplerate[0];
|
||||||
|
|
||||||
file.seek(32, SeekSet);
|
file.seek(32, SeekSet);
|
||||||
file.read(fmtBlockalign, 2);
|
file.read(fmtBlockalign, 2);
|
||||||
blockalign = fmtBlockalign[1] << 8 + fmtBlockalign[0];
|
blockalign = (fmtBlockalign[1] << 8) + fmtBlockalign[0];
|
||||||
|
|
||||||
file.seek(34, SeekSet);
|
file.seek(34, SeekSet);
|
||||||
file.read(fmtBitsPerSample, 2);
|
file.read(fmtBitsPerSample, 2);
|
||||||
bitspersample = fmtBitsPerSample[1] << 8 + fmtBitsPerSample[0];
|
bitspersample = (fmtBitsPerSample[1] << 8) + fmtBitsPerSample[0];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -70,9 +80,11 @@ struct WaveFile{
|
|||||||
file.read(samplebyte, blockalign);
|
file.read(samplebyte, blockalign);
|
||||||
if(!file.available() && loop) file.seek(44, SeekSet);
|
if(!file.available() && loop) file.seek(44, SeekSet);
|
||||||
|
|
||||||
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
|
for(int i = 0; i < blockalign; i+=2){
|
||||||
|
int16_t sample = (samplebyte[i+1] << 8) + samplebyte[i];
|
||||||
buffer.push(sample);
|
buffer.push(sample);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int16_t get(){
|
int16_t get(){
|
||||||
return buffer.pop();
|
return buffer.pop();
|
||||||
@ -98,7 +110,8 @@ class WaveStream{
|
|||||||
WaveStream(){}
|
WaveStream(){}
|
||||||
|
|
||||||
void begin(){
|
void begin(){
|
||||||
wavefile.buffer.setSize(8192);
|
wavefile.buffer.setSize(16384);
|
||||||
|
wavefile.buffer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load(File _wavefile){
|
bool load(File _wavefile){
|
||||||
@ -107,16 +120,18 @@ class WaveStream{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void play(){playing = true;}
|
void play(){playing = true;}
|
||||||
|
|
||||||
void stop(){
|
void stop(){
|
||||||
playing = false;
|
playing = false;
|
||||||
wavefile.stop();
|
wavefile.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause(){playing = false;}
|
void pause(){playing = false;}
|
||||||
|
|
||||||
void stream(){
|
void stream(){
|
||||||
if(!wavefile.buffer.isFull() && playing){
|
if(!wavefile.buffer.isFull() && playing){
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (!wavefile.buffer.isFull() && cnt < 10000) {
|
while (!wavefile.buffer.isFull() && cnt < 4096) {
|
||||||
wavefile.readblock();
|
wavefile.readblock();
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user