Skip to content

Commit 18cfbef

Browse files
vO.9
1 parent c44171f commit 18cfbef

File tree

5 files changed

+204
-350
lines changed

5 files changed

+204
-350
lines changed

examples/LUXE/record1/record1.ino

Lines changed: 0 additions & 73 deletions
This file was deleted.

examples/LUXE/record2/record2.ino

Lines changed: 0 additions & 141 deletions
This file was deleted.

examples/LUXE/record1-V2/record1-V2.ino renamed to examples/LUXE/record_external_mic/record_external_mic.ino

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// If the jack is plugged in <==> head phones and external microphone
66
// else <==> internal microphone and speaker
7-
//
7+
//
88
///////////////////////////////////////////////
99

1010

@@ -20,12 +20,12 @@ bool jack = false;
2020
I2SClass i2s;
2121

2222
ES8388 es;
23-
uint8_t *wav_buffer;
24-
size_t wav_size;
23+
uint8_t *wav_buffer;
24+
size_t wav_size;
2525

2626
void setup() {
2727
Serial.begin(115200);
28-
////// GPIOs init
28+
////// GPIOs init
2929
// power enable
3030
gpio_reset_pin(GPIO_PA_EN);
3131
gpio_set_direction(GPIO_PA_EN, GPIO_MODE_OUTPUT);
@@ -35,77 +35,55 @@ void setup() {
3535
gpio_reset_pin(BUTTON_PAUSE);
3636
gpio_set_direction(BUTTON_PAUSE, GPIO_MODE_INPUT);
3737
gpio_set_pull_mode(BUTTON_PAUSE, GPIO_PULLUP_ONLY);
38-
38+
3939

4040
// Jack_Detect
4141
gpio_reset_pin(Jack_Detect);
4242
gpio_set_direction(Jack_Detect, GPIO_MODE_INPUT);
43-
gpio_set_pull_mode(Jack_Detect, GPIO_PULLUP_ONLY);
43+
gpio_set_pull_mode(Jack_Detect, GPIO_PULLUP_ONLY);
44+
4445

45-
46-
//////I2S init
46+
//////I2S init
4747
i2s.setPins(I2S_BCLK, I2S_LRCK, I2S_SDOUT, I2S_SDIN, I2S_MCLK);
4848

49-
if (!i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) {
49+
if (!i2s.begin(I2S_MODE_STD, 22050, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) {
5050
Serial.println("Failed to initialize I2S!");
5151
while (1); // do nothing
5252
}
5353

5454
Serial.printf("Connect to ES8388 codec... ");
5555
while (not es.begin(IIC_DATA, IIC_CLK))
5656
{
57-
Serial.printf("Failed!\n");
58-
delay(1000);
57+
Serial.printf("Failed!\n");
58+
delay(1000);
5959
}
6060
Serial.printf("OK\n");
61+
// managing audio input/output
62+
es.volume(ES8388::ES_MAIN, 100);
63+
es.volume(ES8388::ES_OUT1, volume);
64+
es.microphone_volume(microVol);
65+
es.select_external_microphone();
6166
}
6267

6368
void loop() {
6469

65-
// managing audio input/output
66-
es.volume(ES8388::ES_MAIN, 100);
67-
es.microphone_volume(microVol);
68-
es.mute(ES8388::ES_MAIN, false);
69-
es.ALC(true);
70-
71-
72-
73-
if (gpio_get_level(Jack_Detect) == 0)
74-
{
75-
if(!jack)
76-
{
77-
printf("jack\n");
78-
es.select_out2();
79-
es.volume(ES8388::ES_OUT2, volume);
80-
gpio_set_level(GPIO_PA_EN, LOW);
81-
es.select_external_microphone();
82-
jack = true;
83-
}
84-
}
85-
else
86-
{
87-
if(jack)
88-
{
89-
printf("speaker\n");
90-
es.select_out1();
91-
es.volume(ES8388::ES_OUT1, volume);
92-
gpio_set_level(GPIO_PA_EN, HIGH);
93-
es.select_internal_microphone();
94-
jack = false;
95-
}
96-
}
9770

98-
99-
if (gpio_get_level(BUTTON_PAUSE) == 0)
71+
if (gpio_get_level(BUTTON_PAUSE) == 0)
10072
{
101-
while(gpio_get_level(BUTTON_PAUSE) == 0) delay(10);
102-
printf("recording...\n");
103-
// Record 5 seconds of audio data
104-
wav_buffer = i2s.recordWAV(5, &wav_size);
105-
delay(2000);
106-
printf("playing... %d\n", wav_size);
107-
i2s.playWAV(wav_buffer, wav_size);
73+
while (gpio_get_level(BUTTON_PAUSE) == 0) delay(10);
74+
printf("recording...\n");
75+
// Record 5 seconds of audio data
76+
wav_buffer = i2s.recordWAV(5, &wav_size);
77+
delay(2000);
78+
//enable audio amp
79+
gpio_set_level(GPIO_PA_EN, HIGH);
80+
81+
printf("playing... %d\n", wav_size);
82+
i2s.playWAV(wav_buffer, wav_size);
83+
84+
//disable audio amp
85+
gpio_set_level(GPIO_PA_EN, LOW);
10886
}
10987

110-
delay(100);
111-
}
88+
delay(100);
89+
}

0 commit comments

Comments
 (0)