Raspberry Pi Setup I2S

At this time, Jessie Raspbery Pi kernel does not support mono audio out of the I2S interface, you can only play stereo, so any mono audio files may need conversion to stereo!

Fast Install

Luckily its quite easy to install support for I2S DACs on Raspbian Jessie.
These instructions are totally cribbed from the PhatDAC instructions at the lovely folks at Pimoroni!
Run the following from your Raspberry Pi with Internet connectivity:

curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash
adafruit_products_quickinstall.png
You will need to reboot once installed.
adafruit_products_reboot.png
You must reboot to enable the speaker hardware!
After rebooting, log back in and re-run the script again…It will ask you if you want to test the speaker. Say yes and listen for audio to come out of your speakers…
adafruit_products_spkrtest.png
In order to have volume control appear in Raspbian desktop or Retropie you must reboot a second time after doing the speaker test, with sudo reboot
You can then go to the next page on testing and optimizing your setup. Skip the rest of this page onDetailed Installation if the script worked for you!

Detailed Install

If, for some reason, you can’t just run the script and you want to go through the install by hand – here’s all the steps!

Update /etc/modprobe.d (if it exists)

Log into your Pi and get into a serial console (either via a console cable, the TV console, RXVT, or what have you)
Edit the raspi blacklist with
sudo nano /etc/modprobe.d/raspi-blacklist.conf

adafruit_products_blacklist.png
If the file is empty, just skip this step
However, if you see the following lines:
blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804
adafruit_products_empty.png
Update the lines by putting a # before each line
adafruit_products_blacklisted.png
Save by typing Control-X Y <return>

Disable headphone audio (if it’s set)

Edit the raspi modules list with
sudo nano /etc/modules
If the file is empty, just skip this step
However, if you see the following line:
snd_bcm2835

adafruit_products_sndmod.png
Put a # in front of it
adafruit_products_nosnd.png
and save with Control-X Y <return>

Create asound.conf file

Edit the raspi modules list with
sudo nano /etc/asound.conf
This file ought to be blank!

adafruit_products_newasound.png
Copy and paste the following text into the file
  1. pcm.speakerbonnet {
  2. type hw card 0
  3. }
  4.  
  5. pcm.dmixer {
  6. type dmix
  7. ipc_key 1024
  8. ipc_perm 0666
  9. slave {
  10. pcm “speakerbonnet”
  11. period_time 0
  12. period_size 1024
  13. buffer_size 8192
  14. rate 44100
  15. channels 2
  16. }
  17. }
  18.  
  19. ctl.dmixer {
  20. type hw card 0
  21. }
  22.  
  23. pcm.softvol {
  24. type softvol
  25. slave.pcm “dmixer”
  26. control.name “PCM”
  27. control.card 0
  28. }
  29.  
  30. ctl.softvol {
  31. type hw card 0
  32. }
  33.  
  34. pcm.!default {
  35. type plug
  36. slave.pcm “softvol”
  37. }
adafruit_products_asound.png
Save the file as usual

Add Device Tree Overlay

Edit your Pi configuration file with
sudo nano /boot/config.txt
And scroll down to the bottom. If you see a line that says: dtparam=audio=on 

adafruit_products_dtover.png
Disable it by putting a # in front.
Then add:
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap

on the next line. Save the file.
adafruit_products_conf.png
Reboot your Pi with sudo reboot

from:https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/raspberry-pi-usage