forked from W4D/soundcube-firmware
better audio with only a few glitches left
This commit is contained in:
@ -17,7 +17,8 @@ class RingBuffer{
|
||||
bool push(T data){
|
||||
if(counter < bufferSize){
|
||||
buffer[write] = data;
|
||||
write = (write+1) % bufferSize;
|
||||
write++; // % bufferSize;
|
||||
if(write == bufferSize) write = 0;
|
||||
counter++;
|
||||
return true;
|
||||
}
|
||||
@ -25,11 +26,12 @@ class RingBuffer{
|
||||
}
|
||||
|
||||
T pop(){
|
||||
T retval;
|
||||
T retval = 0;
|
||||
if(counter > 0) {
|
||||
counter--;
|
||||
retval = buffer[read];
|
||||
read = (read+1) % bufferSize;
|
||||
read++;// % bufferSize;
|
||||
if(read == bufferSize) read = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#define AURAL 1
|
||||
#define UI_SAMPLERATE 22050
|
||||
|
||||
#define BUFFERSIZE 1024
|
||||
#define BUFFERSIZE 64
|
||||
#define NSTREAMS 8
|
||||
|
||||
int16_t buffer[BUFFERSIZE];
|
||||
@ -100,7 +100,7 @@ void codec_transmit() {
|
||||
int16_t sample = 0;
|
||||
int j = active % NSTREAMS;
|
||||
sample = stream[j].get();
|
||||
buffer[i] += sample;
|
||||
buffer[i] = sample >> 2;
|
||||
}
|
||||
|
||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||
@ -236,12 +236,12 @@ void setup() {
|
||||
i2s.setDIN(14);
|
||||
i2s.setBCLK(16); // Note: LRCLK = BCLK + 1
|
||||
i2s.setMCLK(18);
|
||||
i2s.setMCLKmult(256); // 12.288.000Hz
|
||||
i2s.setMCLKmult(512); // 256 = 12.288.000Hz 512 = 25Mhz
|
||||
|
||||
i2s.swapClocks();
|
||||
i2s.setBitsPerSample(16);
|
||||
|
||||
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||
i2s.setBuffers(6, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||
|
||||
if(!i2s.begin(48000)){
|
||||
Serial.println("I2S error!");
|
||||
@ -269,7 +269,8 @@ void setup() {
|
||||
Serial.print(stream[i].wavefile.blockalign);
|
||||
Serial.println(" bytes");
|
||||
|
||||
//stream[i].play();
|
||||
stream[i].play();
|
||||
stream[i].wavefile.loop = true;
|
||||
} else {
|
||||
Serial.println("file loading error");
|
||||
}
|
||||
@ -423,13 +424,24 @@ void loop() {
|
||||
if(i2s.getOverflow()) Serial.println("overflow");
|
||||
if(i2s.getUnderflow()) Serial.println("underflow");
|
||||
|
||||
delay(20); // wait 1ms
|
||||
//delay(20); // wait 1ms
|
||||
|
||||
}
|
||||
|
||||
void setup1(){
|
||||
|
||||
// while(1){
|
||||
// if(streams_loaded){
|
||||
// int16_t l, r;
|
||||
// i2s.read16(&l, &r);
|
||||
|
||||
// int j = active % NSTREAMS;
|
||||
// l = stream[j].get() >> 2;
|
||||
// r = stream[j].get() >> 2;
|
||||
|
||||
// i2s.write16(l, r);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void loop1(){
|
||||
|
||||
}
|
||||
@ -110,7 +110,7 @@ class WaveStream{
|
||||
WaveStream(){}
|
||||
|
||||
void begin(){
|
||||
wavefile.buffer.setSize(16384);
|
||||
wavefile.buffer.setSize(24000);
|
||||
wavefile.buffer.begin();
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ class WaveStream{
|
||||
void stream(){
|
||||
if(!wavefile.buffer.isFull() && playing){
|
||||
int cnt = 0;
|
||||
while (!wavefile.buffer.isFull() && cnt < 4096) {
|
||||
while (!wavefile.buffer.isFull() && cnt < 6000) {
|
||||
wavefile.readblock();
|
||||
cnt++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user