Skip to content

Sound output

Doug edited this page Oct 26, 2022 · 5 revisions

SndPlayer class - main 'player' and audio driver

This driver 'runs the show', which is based on reading an MP3 file and processing it:

The driver accepts the following inputs, which are checked after each MP3 block is processed.

  • START - this will start the playback from the current position. If the file is not open, then we open the file (playback starts at the begining!)
  • PAUSE - this pauses the playback at the current position.
  • REWIND- this closes the file
  • SETVALUE - this is present to control the volume. Not currently implemented (though it could be using the MAX983571 chip

This driver reads a .mp3 file from flash, and decodes it using the 'minimp3.h' library, downloaded from github. (yes, the 'library' is in a single .h file!)

As each block of data is decoded, we convert it to stereo if needed. We also do some basic averaging to determine what eye and jaw movements are desired, and send appropriate commands to those modules via the switchboard.

Output is sent to a MAX98357A class D amplifier chip via the I2S module on the ESP32.

  • The MP3 converter combined with our driver can accept either stereo or mono. If mono, we copy the 1st channel to the 2nd to internally convert to a stereo signal.
  • As we are reading and converting, we check for the start/stop button.
  • 'startPlayerTask' instantiates an 'Output' derived class to output the PWM data thru the selected audio device (see USE_I2S macro in config.h)

The I2S module is configured to drive the MAX983571:

MAX983571

The MAX983571 chip is used to amplify the output from Skulldougery to a level that can drive a speaker. It is a one-channel amplifier, although it is configured (in this application) to mix both left and right channels.

It is mounted on a PC board (similar to Adafruit Product Id 3006) with an 7 pin in-line header for the digital inputs. These directly connect to corresponding pins on the chip:

The pin-out is as follows (looking at component side of board with pins towards you):

  • 1 LRC (connect to ESP32 as the 'word select' pin)
  • 2 BCLK (Bit Clock - directly from ESP32)
  • 3 DIN (Digital input - directly from ESP32)
  • 4 GAIN (Gain control) leave unconnected - options are:
    • 15 Db is connect to ground thru 100k resistor
    • 12 Db if connected to ground
    • 9 Db if unconnected.
    • 3 DB if connect to Vdd thru 100K resistor
  • 5 SU The chip docs call this ~SD_MODE. Connect through 'large' resistor (>1Meg) to 5v Vdd. This selects stero input, mix to mono output. NOTE: The chip can be shut down by bringing this pin low!
  • 6 Ground
  • 7 VIN (MAX is 6V). We will drive from the 5v supply.
Clone this wiki locally