forked from W4D/soundcube-firmware
The beginnings of codec.h
This commit is contained in:
@ -7,21 +7,33 @@
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
#define SIZE 256
|
||||
#define SIZE 16
|
||||
#define ECHO 192000
|
||||
int16_t buffer[SIZE];
|
||||
int16_t buffer2[ECHO];
|
||||
|
||||
int16_t volume = 0;
|
||||
size_t count;
|
||||
size_t tape_write = 0;
|
||||
|
||||
void codec_transmit() {
|
||||
for(int i = 0; i < count; i++){
|
||||
buffer[i] *= -1;
|
||||
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];
|
||||
}
|
||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||
}
|
||||
|
||||
void codec_receive(){
|
||||
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
||||
for(int i = 0; i < count; i++){
|
||||
buffer[i] *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
void cw(unsigned char first, unsigned char second){
|
||||
@ -99,11 +111,11 @@ void setup() {
|
||||
|
||||
// ROUTING
|
||||
cw(0x00, 0x01); // select page 1
|
||||
cw(0x34, 0b11000000); // LEFT MICPGA P route IN1L to LEFT_P with 40k input impedance
|
||||
cw(0x36, 0b11000000); // LEFT MICPGA M route CM to LEFT_M with 20k input impedance
|
||||
cw(0x34, 0b10000000); // LEFT MICPGA P route IN1L to LEFT_P with 40k input impedance
|
||||
//cw(0x36, 0b11000000); // LEFT MICPGA M route CM to LEFT_M with 20k input impedance
|
||||
//cw(0x36, 0b00000011); // LEFT MICPGA M route CM to LEFT_M with 20k input impedance
|
||||
cw(0x37, 0b11000000); // RIGHT MICPGA P route IN1R to RIGHT_P with 20k input impedance
|
||||
cw(0x39, 0b11000000); // RIGHT MICPGA M route CM to RIGHT_M with 20k input impedance
|
||||
cw(0x37, 0b10000000); // RIGHT MICPGA P route IN1R to RIGHT_P with 20k input impedance
|
||||
//cw(0x39, 0b11000000); // RIGHT MICPGA M route CM to RIGHT_M with 20k input impedance
|
||||
//cw(0x39, 0b00000011); // RIGHT MICPGA M route CM to RIGHT_M with 20k input impedance
|
||||
cw(0x3a, 0b00111100); // connect IN2, IN3 weakly to CM
|
||||
|
||||
@ -123,7 +135,7 @@ void setup() {
|
||||
cw(0x13, 0x82); // MADC 2
|
||||
cw(0x14, 0b10000000); // OSR ADC 128
|
||||
//cw(0x14, 0b01000000); // OSR ADC 128
|
||||
cw(0x3d, 0b00000010); // ADC PRB_R3 = 11, PRB_R2 = 10, PRB_R1 = 01
|
||||
cw(0x3d, 0b00000001); // ADC PRB_R3 = 11, PRB_R2 = 10, PRB_R1 = 01
|
||||
|
||||
cw(0x00, 0x01); // select page 1
|
||||
cw(0x3d, 0b00000000); // ADC PTM_R4
|
||||
@ -135,7 +147,7 @@ void setup() {
|
||||
cw(0x0d, 0x00); // OSR DAC 128
|
||||
cw(0x0e, 0x80); // OSR DAC 128
|
||||
cw(0x1b, 0b00000000); // word length 16bits
|
||||
cw(0x3c, 0b00000011); // PRB_P3
|
||||
cw(0x3c, 0b00000001); // PRB_P3
|
||||
|
||||
cw(0x00, 0x01); // select page 1
|
||||
cw(0x7b, 0b00000001); // set REF charging time to 40ms
|
||||
@ -200,39 +212,11 @@ void setup() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int32_t last = 0;
|
||||
int frame = 0;
|
||||
|
||||
void loop() {
|
||||
int16_t l, r;
|
||||
//i2s.read16(&l, &r);
|
||||
|
||||
// float sine_pos = (2.0f * M_PI * 1000.0f * (float)frame) / (float)48000;
|
||||
// l = (int16_t)(sin(sine_pos) * 8192.0f);
|
||||
// r = l;
|
||||
|
||||
//i2s.write16(l*-1, r*-1);
|
||||
|
||||
// volume += l + r;
|
||||
// if(millis() - last > 1000){
|
||||
// Serial.println(volume);
|
||||
// volume = 0;
|
||||
// last = millis();
|
||||
|
||||
// // STATUS FLAGS
|
||||
// Serial.println("CODEC STATUS");
|
||||
// cw(0x00, 0x00); // select page 0
|
||||
// Serial.println("ADC Flags");
|
||||
// cr(0x24, 1);
|
||||
// Serial.println("DAC Flags");
|
||||
// cr(0x25, 1);
|
||||
// Serial.println("P0_42 - Sticky Flags");
|
||||
// cr(0x2A, 1);
|
||||
// Serial.println("P0_43 - Interrupt Flags");
|
||||
// cr(0x2B, 1);
|
||||
// Serial.println("P0_44 - Sticky Flags");
|
||||
// cr(0x2C, 1);
|
||||
|
||||
// }
|
||||
frame++;
|
||||
if(frame == 48000) frame = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user