|
|
@ -11,6 +11,7 @@ void Speak::begin(void) { |
|
|
|
// Enable speaker
|
|
|
|
M5.Axp.SetSpkEnable(true); |
|
|
|
|
|
|
|
|
|
|
|
i2s_driver_uninstall(SPEAK_I2S_NUMBER); |
|
|
|
i2s_config_t i2s_config = { |
|
|
|
.mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 设置I2S工作模式
|
|
|
@ -25,7 +26,7 @@ void Speak::begin(void) { |
|
|
|
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); |
|
|
|
i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置
|
|
|
|
i2s_config.tx_desc_auto_clear = true; // Enables auto-cleanup descriptors for understreams. 开启欠流自动清除描述符
|
|
|
|
// i2s_config.fixed_mclk = 0;
|
|
|
|
i2s_config.fixed_mclk = 0; |
|
|
|
|
|
|
|
// Install and drive I2S. 安装并驱动I2S
|
|
|
|
i2s_driver_install(SPEAK_I2S_NUMBER, &i2s_config, 0, NULL); |
|
|
@ -41,30 +42,83 @@ void Speak::begin(void) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Speak::welcome(void) { |
|
|
|
void Speak::speak_menu(uint8_t menu_selected) { |
|
|
|
if(menu_selected == MENU_RC_CONTROLLER) { |
|
|
|
speak("rccalibration.raw"); |
|
|
|
} else if(menu_selected == MENU_BLUETOOTH) { |
|
|
|
speak("bluetooth.raw"); |
|
|
|
} else if(menu_selected == MENU_STICK_CALIBRATION) { |
|
|
|
speak("stickcalibration.raw"); |
|
|
|
} else if(menu_selected == MENU_STICK_POSITIONS) { |
|
|
|
speak("stickpositions.raw"); |
|
|
|
} else if(menu_selected == MENU_TRIMS) { |
|
|
|
speak("trims.raw"); |
|
|
|
} else if(menu_selected == MENU_WIFI) { |
|
|
|
speak("wifi.raw"); |
|
|
|
} else if(menu_selected == MENU_RX_BINDING) { |
|
|
|
speak("rxbinding.raw"); |
|
|
|
} else if(menu_selected == MENU_RF_SETTINGS) { |
|
|
|
speak("rfsettings.raw"); |
|
|
|
} else if(menu_selected == MENU_RF_SCANNERS) { |
|
|
|
speak("rfscanners.raw"); |
|
|
|
} else if(menu_selected == MENU_SAVE_SETTINGS) { |
|
|
|
speak("savesettings.raw"); |
|
|
|
} else if(menu_selected == MENU_RESET) { |
|
|
|
speak("reset.raw"); |
|
|
|
} else if(menu_selected == MENU_REBOOT) { |
|
|
|
speak("reboot.raw"); |
|
|
|
} else if(menu_selected == MENU_POWER_OFF) { |
|
|
|
speak("poweroff.raw"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Speak::speak_misc(uint8_t phrase) { |
|
|
|
if(phrase == PHRASE000) { |
|
|
|
speak("systemshuttingdown.raw"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Speak::speak(String filename) { |
|
|
|
size_t bytes_written = 0; |
|
|
|
filename = "/" + filename; |
|
|
|
|
|
|
|
// Loading file from LittleFS to memory
|
|
|
|
File soundfile = LITTLEFS.open("/welcome.raw", FILE_READ); |
|
|
|
File soundfile = LITTLEFS.open(filename, FILE_READ); |
|
|
|
uint16_t samples_read = 0; |
|
|
|
uint32_t soundfile_size = soundfile.size(); |
|
|
|
uint32_t file_position = 0; |
|
|
|
|
|
|
|
// WAVFileReader *reader = new WAVFileReader();
|
|
|
|
Serial.println("Reading...."); |
|
|
|
uint8_t *samples = (uint8_t *)malloc(1024 * sizeof(uint8_t) * 2); |
|
|
|
uint8_t *original; |
|
|
|
int16_t *samples = (int16_t *)malloc(1024 * sizeof(int16_t) * 2); |
|
|
|
int16_t *original; |
|
|
|
|
|
|
|
original = samples; |
|
|
|
|
|
|
|
int16_t data_high, data_low, data; |
|
|
|
|
|
|
|
while(true) { |
|
|
|
samples_read = 0; |
|
|
|
for(uint16_t samples_count = 0; samples_count < 1024 ; samples_count++) { |
|
|
|
for(uint32_t samples_count = 0; samples_count < 1024 ; samples_count++) { |
|
|
|
if(!soundfile.available()) { |
|
|
|
break; |
|
|
|
} |
|
|
|
// *samples++ = soundfile.read();
|
|
|
|
// Serial.println(samples[samples_read])
|
|
|
|
uint8_t data = soundfile.read(); |
|
|
|
// int16_t data = soundfile.read() | soundfile.read() << 8;
|
|
|
|
data_low = soundfile.read(); |
|
|
|
if(soundfile.available()) { |
|
|
|
data_high = soundfile.read(); |
|
|
|
} else { |
|
|
|
data_high = 0; |
|
|
|
} |
|
|
|
|
|
|
|
data = data_low | data_high << 8; |
|
|
|
|
|
|
|
// Lower sound ??
|
|
|
|
data = data * 2.5; |
|
|
|
samples[samples_count * 2] = data; |
|
|
|
samples[samples_count * 2 + 1] = data; |
|
|
|
samples_read++; |
|
|
@ -76,10 +130,10 @@ void Speak::welcome(void) { |
|
|
|
// Serial.println("Loop break...");
|
|
|
|
break; |
|
|
|
} |
|
|
|
// Serial.println("After line 67");
|
|
|
|
// Serial.println("After line 67")
|
|
|
|
// Serial.println(file_position);
|
|
|
|
|
|
|
|
i2s_write(SPEAK_I2S_NUMBER, samples, samples_read * sizeof(uint8_t) * 2, &bytes_written, portMAX_DELAY); |
|
|
|
i2s_write(SPEAK_I2S_NUMBER, samples, samples_read * sizeof(int16_t) * 2, &bytes_written, portMAX_DELAY); |
|
|
|
// Serial.println("After sound...");
|
|
|
|
|
|
|
|
samples = original; |
|
|
@ -93,16 +147,11 @@ void Speak::welcome(void) { |
|
|
|
|
|
|
|
// Stops
|
|
|
|
soundfile.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/***
|
|
|
|
while(soundfile.available()) { |
|
|
|
soundfileR[file_position] = soundfile.read(); |
|
|
|
file_position++; |
|
|
|
} |
|
|
|
***/ |
|
|
|
|
|
|
|
Serial.println("DONE"); |
|
|
|
// i2s_write(SPEAK_I2S_NUMBER, soundfile, soundfile_size, &bytes_written, portMAX_DELAY);
|
|
|
|
void Speak::welcome(void) { |
|
|
|
speak("welcome.raw"); |
|
|
|
} |
|
|
|
|
|
|
|
void Speak::dingdong(void) { |
|
|
|