Inter-IC声音protoc总线(i2)是一种沟通ol for transferring digital audio signal. Using an I2S-based digital-to-analog convertor (DAC), you can play high-quality audio from Raspberry Pi™.
Mount a DAC HAT on your Raspberry Pi.
Connect a pair of speakers or headphones to the analog audio output of the DAC HAT.
Configure your Raspberry Pi hardware as described inHardware Setup.
Note
Ensure that you install the Raspbian image provided by MathWorks®.
In the MATLAB®Command Window, type thelistAudioDevices
command. If this command lists your audio device, skip the steps in this section and directly perform the steps inPlay Audio in Simulink.
Open an SSH command-line session as described inOpen Command-Line Session with Raspberry Pi Hardware.
In the terminal, typesudo nano /boot/config.txt
to edit theconfig.txt
file.
To enable the I2S interface in the Raspberry Pi device tree, uncomment the linedtparam=i2s=on
in the hardware interface section of the file.
To configure the HiFiBerry DAC, adddtoverlay=hifiberry-dacplus
in the lirc-rpi module section of the file.
To disable the onboard ALSA audio devices for Raspberry Pi, comment out the linedtparam=audio=on
in the enable audio section.
Disconnect Raspberry Pi from your computer and connect it again.
Warning
Ensure that the DAC HAT is still mounted on Raspberry Pi.
Configure your Simulink®model to run on Raspberry Pi as described inModel Configuration Simulink Support Package for Raspberry Pi Hardware.
Add anALSA Audio Playbackblock to the model.
Open theALSA Audio Playbackblock in your model. Specify the device number of the DAC HAT in theDevice nameparameter.
If you do not know the device number of DAC, use thelistAudioDevices
function as described inList Available ALSA Audio Output Devices. The resulting structured array displays the device number of your DAC.
On theHardwaretab of the toolstrip, in theModesection, selectRun on board
, and then selectBuild, Deploy & Start. This action builds, downloads, and runs the model on the Raspberry Pi hardware. The audio starts playing.