m5stack / M5Unified

Unified library for M5Stack series
MIT License
276 stars 48 forks source link

M5CoreS3 speaker issue #98

Closed SalloCs closed 4 months ago

SalloCs commented 5 months ago

Hi. I have tried to play some tones, under 1kHz the output is very noisy. I tried with standard configs too, the result didn't change much. Can you give me any suggestions? (IDF 4.4.5, M5unified 0.1.12)

                                                      `void Init()
                                                      {
                                                          initArduino();    
                                                          M5.begin();
                                                          M5.Power.begin(); 
                                                          auto spk_cfg = M5.Speaker.config();
                                                          spk_cfg.dma_buf_len = 1024;
                                                          spk_cfg.dma_buf_count = 2;
                                                          spk_cfg.magnification = 1;
                                                          spk_cfg.stereo = true;    

                                                          M5.Speaker.config(spk_cfg);
                                                          M5.Speaker.begin();

                                                          M5.Speaker.setVolume(230);
                                                          int x = 0;
                                                          while (x<3)
                                                          {
                                                              M5.Speaker.tone(466, 1000); 
                                                              M5.delay(1000);
                                                              vTaskDelay(2000);
                                                              x++;
                                                          }`

image

lovyan03 commented 4 months ago

Hello, @SalloCs

The speakers installed in the M5Stack are small, so they can easily produce high-pitched sounds, but they don't produce very strong bass sounds.

The tone function is designed to output a waveform that is close to a sine wave, but if you turn the volume up too much, the waveform will saturate and become close to a square wave. The closer you get to a square wave, the more noticeable the harmonic frequencies will be. Small speakers naturally have stronger overtone frequencies.

If you want clearer and bass sound, we recommend connecting external speakers using module RCA or similar.

Then, please note the following points:

  M5.begin();
//M5.Power.begin();  // ← no need this.
  auto spk_cfg = M5.Speaker.config();
  spk_cfg.dma_buf_len = 256;  // ← 1024 is too big.
  spk_cfg.dma_buf_count = 8;  // ← 2 is too little.
  spk_cfg.stereo = false;     // ← CoreS3 is Mono.
SalloCs commented 4 months ago

Thank you for your reply. It seems that the speaker was an issue.