Skip to content

Commit

Permalink
changes: * prevent clic-noise in beginning of playback
Browse files Browse the repository at this point in the history
           ! issue bug report upstream
             * first playback after init of class (call of constructor)
             * may be similar like earlephilhower/ESP8266Audio#406
           ! may be check whether this is hardware dependend; may be just internal speaker affected and line out of RCA module not
           ! may be check wheteher use mic at same time as playback, could avoid i2s re-config and thus clic-noise
             * see schreibfaul1/ESP32-audioI2S#604
             * problem is there is i2s config we don't have control of
           ! may be use i2s_write(...) with a zero buffer instead of connect, loop and stop playing
         * prevent clic-noise in beginning of recorded file by skipping some data
  • Loading branch information
drtrigon committed Dec 15, 2023
1 parent 3db5e7f commit 38f5952
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 628 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ The simple GUI is specifically designed for children, who are able to choose a s
## Credit
This project uses the [M5Core2](https://github.com/m5stack/M5Core2) library to access peripherals and [ESP32-audioI2S](https://github.com/schreibfaul1/ESP32-audioI2S) for high quality audio replay.
The beautiful [Giraffe](https://publicdomainvectors.org/en/free-clipart/Cartoon-giraffe-image/49785.html) logo is taken from publicdomainvectors.org. The buttons are based on the [Tabler](https://github.com/tabler/tabler-icons) icon set.
Text-to-speech synthesis using [ttsfree.com](https://ttsfree.com/text-to-speech/german).


23 changes: 13 additions & 10 deletions notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ changes: * improve handling of empty playlists/folders
* https://forum.arduino.cc/t/runtime-remove-and-insert-a-sd-card/313386
* https://github.com/greiman/SdFat


(--- new v12 ---)
--- new v12 ---
changes: * add gain by bit shifting for recorded data (4x)
! suppress initial click by ommitting first few millisecs or everything until amplitude below given threshold
* voice messsage during startup if battery level is low
Expand All @@ -208,24 +207,28 @@ changes: * add gain by bit shifting for recorded data (4x)
! may be add beeps by using sequence (see rec_play); pause, i2s_write(sin(...)), resume (do not change i2s config)
! may be colorize battery icons (low; red / ok; green / may be intermediate; yellow/orange)
! may be add battery level message to startNextSong(), startPrevSong() before playback (how to loop()?)
* prevent clic-noise in beginning of playback
! issue bug report upstream
* first playback after init of class (call of constructor)
* may be similar like https://github.com/earlephilhower/ESP8266Audio/issues/406
! may be check whether this is hardware dependend; may be just internal speaker affected and line out of RCA module not
! may be check wheteher use mic at same time as playback, could avoid i2s re-config and thus clic-noise
* see https://github.com/schreibfaul1/ESP32-audioI2S/discussions/604
* problem is there is i2s config we don't have control of
! may be use i2s_write(...) with a zero buffer instead of connect, loop and stop playing
* prevent clic-noise in beginning of recorded file by skipping some data


(--- new v13 ---)


problem: knacken bei replay des ersten titels nach i2s driver install...?
-> immer erstes playback nach 'new Audio()'
-> 'updateVolume' nach 'initializeHardware' macht es schlimmer...?
-> https://github.com/earlephilhower/ESP8266Audio/issues/406
-> volume auf 0, dann wieder auf vorherigen wert setzen während start von playback...?

use mic at same time as playback, could also avoid i2s re-config and thus "knacken" (siehe oben)
-> https://github.com/schreibfaul1/ESP32-audioI2S/discussions/604
ev. record und sleep-mode buttons tauschen?!


versuchen espuino auf m5core2 zu portieren und dann dieses GUI inkl. nachtlicht zu mergen

send to bluetooth speaker (sink) - is it also possible to send to multiple, say 2, 3, ... (more?) - also add simple menu for pairing
how to get (raw) data from esp32-audioi2s?

build 3D case to print (incl. speaker)

Expand Down
15 changes: 11 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ void CPlayer::initializeHardware()
// RCA Module 13.2 (can be used at same time)
m_audio->setPinout(19, 0, 2); // I2S_BCLK, I2S_LRC, I2S_DOUT
#endif
// prevent clic-noise when setting volume after init of audio lib (work-a-round)
m_audio->setVolume(0);
m_audio->connecttoFS(SPIFFS, "audio-battery.mp3"); // any file available can be used
for (uint8_t i = 0; i < 100; ++i) // 50 iterations should be enough, take x2
m_audio->loop();
m_audio->stopSong();
m_audio->setVolume(m_currentVolume);

vibrate();
Expand Down Expand Up @@ -429,9 +435,7 @@ void CPlayer::handleTouchEvents()
vibrate();
m_songFiles.push_back(rec_name);
m_activeSongIdx[m_activeSongIdxIdx] = m_songFiles.size() - 2;
// m_audio->setVolume(0);
startNextSong();
// m_audio->setVolume(m_currentVolume);
}
}
else if ((105 <= touchPoint.x) && (touchPoint.x <= 205)) // BtnB
Expand Down Expand Up @@ -746,15 +750,19 @@ void CPlayer::rec_record(const char *filepath) { // see https://github.com/m5st

uint16_t microphonedata0[DATA_SIZE/2 * 1]; // DATA_SIZE = 1024 (must be multiple of 2 as data actually is 16 bit!)
int data_offset = 0;
size_t byte_read;

File file = SD.open(filepath, FILE_WRITE);
file.seek(44); // before 44 is the header that gets written in the end

M5.Spk.InitI2SSpeakOrMic(MODE_MIC); // install mic i2s driver

// supress clic-noise in recorded file, by skipping some data (1 buffer)
i2s_read(Speak_I2S_NUMBER, (char *)(microphonedata0),
DATA_SIZE, &byte_read, (100 / portTICK_RATE_MS));

M5.Lcd.fillCircle(280, 80, 10, TFT_RED);

size_t byte_read;
while (1) {
i2s_read(Speak_I2S_NUMBER, (char *)(microphonedata0),
DATA_SIZE, &byte_read, (100 / portTICK_RATE_MS));
Expand All @@ -777,7 +785,6 @@ void CPlayer::rec_record(const char *filepath) { // see https://github.com/m5st
// ALTERNATIVE: RESTART AND PLAY LAST SONG BY STORING ITS INDEX IN CONFIGURATION !!!
// ACHTUNG MACHT EV. PROBLEME - EINZELNE BEFEHLE HERAUSNEHMEN...?!
initializeHardware();
// updateVolume(0);

M5.Lcd.fillCircle(280, 80, 10, TFT_BLACK);
}
Expand Down
Loading

0 comments on commit 38f5952

Please sign in to comment.