Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] - update all examples with the same structure #469

Open
schmurtzm opened this issue Dec 22, 2021 · 0 comments
Open

[Request] - update all examples with the same structure #469

schmurtzm opened this issue Dec 22, 2021 · 0 comments

Comments

@schmurtzm
Copy link

schmurtzm commented Dec 22, 2021

Hi,
it could be really useful that we update all the examples in the library in the same way to allow for new users to test quickly on ESP8266 or ESP32, with or without internal DAC.

I make a proposition :

Introduction :

/****************************************************************************/
/*  Here, example readme                                                    */
/*                                                                          */
/*                                                                          */
/*  Released under GPL v2                                                   */
/*  Credits...                                                              */
/***************************************************************************

  ______    _____   _____    ____    ___  
 |  ____|  / ____| |  __ \  |___ \  |__ \ 
 | |__    | (___   | |__) |   __) |    ) |
 |  __|    \___ \  |  ___/   |__ <    / / 
 | |____   ____) | | |       ___) |  / /_ 
 |______| |_____/  |_|      |____/  |____|
 
+-----------------+-----------------+--------------+--------------------+
|   audio pins    |  External DAC   | Internal DAC |       No DAC       |
+-----------------+-----------------+--------------+--------------------+
| DAC - LCK(LRC)  | GPIO25          | NA           | NA                 |
| DAC - BCK(BCLK) | GPIO26          | NA           | NA                 |
| DAC - I2So(DIN) | GPIO22          | NA           | NA                 |
| speaker L       | NA (on the DAC) | GPIO25       | GPIO22 (L&R mixed) |
| speaker R       | NA (on the DAC) | GPIO26       | GPIO22 (L&R mixed) |
+-----------------+-----------------+--------------+--------------------+

  ______    _____   _____     ___    ___      __      __  
 |  ____|  / ____| |  __ \   / _ \  |__ \    / /     / /  
 | |__    | (___   | |__) | | (_) |    ) |  / /_    / /_  
 |  __|    \___ \  |  ___/   > _ <    / /  | '_ \  | '_ \ 
 | |____   ____) | | |      | (_) |  / /_  | (_) | | (_) |
 |______| |_____/  |_|       \___/  |____|  \___/   \___/ 


+-----------------+-----------------+------------------------+
|   audio pins    |  External DAC   |         No DAC         |
+-----------------+-----------------+------------------------+
| DAC - LCK(LRC)  | GPIO2 (D4)      | NA                     |
| DAC - BCK(BCLK) | GPIO15 (D8)     | NA                     |
| DAC - I2So(DIN) | GPIO3 (RX)      | NA                     |
| speaker L       | NA (on the DAC) | GPIO3 (RX) (L&R mixed) |
| speaker R       | NA (on the DAC) | GPIO3 (RX) (L&R mixed) |
+-----------------+-----------------+------------------------+
To Upload to an ESP8266 module or board:

  - Set CPU Frequency to 160MHz ( Arduino IDE: Tools > CPU Frequency )
  - Set IwIP to V2 Higher Bandwidth ( Arduino IDE: Tools > IwIP Variant )
  - Press "Upload"
*/

Library and global declaration :

// Please select one of these options
#define USE_NO_DAC           // uncomment to use no DAC, using software-simulated delta-sigma DAC
//#define USE_EXTERNAL_DAC     // uncomment to use external I2S DAC 
//#define USE_INTERNAL_DAC     // uncomment to use the internal DAC of the ESP32 (not available on ESP8266)

#ifdef ESP32
    #include <WiFi.h>
#else
    #include <ESP8266WiFi.h>
#endif


#ifdef USE_NO_DAC
    #include "AudioOutputI2SNoDAC.h"
#else
    #include "AudioOutputI2S.h"
#endif


#ifdef USE_NO_DAC
    AudioOutputI2SNoDAC     *out = NULL;
#else
    AudioOutputI2S          *out = NULL;
#endif

A little boot sound to test sound at start

void playBootSound()
{
      const char  RTTLsound[] PROGMEM = "5thSymph:d=16,o=5,b=130:g,g,g,4d#,4p,f,f,f,4d";
      file_progmem = new AudioFileSourcePROGMEM(RTTLsound, strlen_P(RTTLsound));
      rtttl = new AudioGeneratorRTTTL();
      rtttl->begin(file_progmem, out);
}

Setup() part :

#ifdef USE_INTERNAL_DAC
    out = new AudioOutputI2S(0, 1);  //use the internal DAC : channel 1 (gpio25) , channel 2 (gpio26) 
    Serial.println(F("Using the internal DAC of the ESP32 : \r\n speaker L -> GPIO25 \r\n speaker R -> GPIO26"));
#elif defined USE_EXTERNAL_DAC
    out = new AudioOutputI2S();
    #ifdef ESP32
      Serial.println(F("Using I2S output on ESP32 : please connect your DAC to pins : "));
      Serial.println(F("LCK(LRC) -> GPIO25  \r\n BCK(BCLK) -> GPIO26 \r\n I2So(DIN) -> GPIO22"));
    #else    // we are on ESP8266
      Serial.println(F("Using I2S output on ESP8266 : please connect your DAC to pins : "));
      Serial.println(F("LCK(LRC) -> GPIO2 (D4) \r\n BCK(BCLK) -> GPIO15 (D8) \r\n I2So(DIN) -> GPIO3 (RX)"));
    #endif    // end of #ifdef ESP32
#else  // we don't use DAC, using software-simulated delta-sigma DAC
    out = new AudioOutputI2SNoDAC();
    #ifdef ESP32
      Serial.println(F("Using No DAC output on ESP32, audio output on pins \r\n speaker L & R -> GPIO22"));
    #else
      Serial.println(F("Using No DAC output on ESP8266, audio output on pins \r\n speaker L & R -> GPIO3 (RX)"));
    #endif
    Serial.println(F("Don't try and drive the speaker pins can't give enough current to drive even a headphone well and you may end up damaging your device"));
#endif

// out->SetGain(volume_level);    // Specify Volume between 0 and 1.0
// out->SetChannels(2);    // Specify the channel(1) or (2)
// out->SetBitsPerSample(16);    //  Specify bits per sample generally 8 or 16
// out->SetRate(44100);      // Specify the rate here : 8000 ,22050 , 44100 , 48000

 playBootSound();

With this each user can adapt easily the examples to their hardware and needs.
Any comments or additional ideas ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant