Project Wiring
Connect your Pico 2 board to an I2S DAC or I2S Amplifier using the following pins:
- Connect Pico GP16 to I2S Bit Clock (BCLK)
- Connect Pico GP17 to I2S Word Select (WSEL)
- Connect Pico GP18 to I2S Data (DAT)
- Connect Pico GND to GND
- Connect your I2S board to appropriate power & speakers or headphones
Next, connect at least one but up to 16 trigger buttons or switches. All of the pins from GP0 to GP15 are for audio triggers. For each button or switch:
- Connect one side of the switch to one of the GPx pins
- Connect the other side of the switch to GND
The sample project includes sound files for 12 different triggers on pins GP0 through GP11. The diagram only shows a few buttons, but any or all of the first 16 GPIO pins GP0 through GP15 can be used.
Preparing Audio Files
You can use the software of your choice to prepare audio files for CircuitPython Audio FX. If you don't already have software for recording & saving sound samples, you might want to try the open source Audacity, which runs on Linux, Mac and Windows.
For a given project, all the audio files have to have the same key specifications:
- sample rate (e.g., 8kHz, 11.025kHz, 16kHz)
- number of samples (mono or stereo)
- bit depth (8-bit unsigned or 16-bit signed)
While WAV files are supported, the Pico 2's CIRCUITPY drive has a capacity of only about 3 megabytes, so you will probably want to load up with compressed MP3 files instead.
The amount of audio you can load in MP3 format depends on the bit rate. For 128 kbit/second "CD quality" MP3 files (44.1kHz, stereo, 16-bit), you can store about a total of 3 minutes of audio. If you go for a lower quality file such as 32kbit/second (16kHz, mono, 16-bit) you can have over 10 minutes of sound files.
The MP3 bitrate is separate from the sample rate. A higher bitrate means the file takes up more kB per second of audio, but the audio fidelity improves with a higher bitrate. Within a project, MP3 files can have different bitrates. For example, your project can include a file with a 16kHz sample rate encoded at 32kbit/s bitrate alongside a file with a 16kHz sample rate and a 64kbit/s bitrate.
A project can mix MP3 files and WAV files but the channel count and sample rate must be the same, and the wave files must be 16-bit signed files.
The included sample files are all 16kHz mono 16-bit MP3s encoded at 32 kbit/s.
Naming audio files
The name of your audio file controls when and how it will be played.
The name of an audio file is divided into several parts:
- The trigger number, T00 through T15
- The kind of trigger:
- Empty, for a basic trigger (starts playing once when its trigger is pressed)
- HOLDL for a hold looping trigger (plays in a loop while trigger is pressed)
- LATCH for a toggle looping trigger (starts playing in a loop when trigger is pressed, stops next time trigger is pressed)
- NEXT# for a sequential trigger (plays NEXT0, then NEXT1, up to NEXT9, then back to NEXT0Â each time its trigger is pressed)
- RAND# for random trigger (randomly chooses among RAND0, RAND1 up to RAND9, each time its trigger is pressed)
- The file extension, .WAV or .MP3
Filenames are not case dependent, so you can have T00RAND9.MP3 or T00rand9.Mp3 and it will work the same way.
If several kinds of trigger all appear for the same trigger number, only one of them will be used. For example if you have both T15HOLDL.mp3 and T15.mp3 (two different trigger types for one trigger number), one or the other will be used, but not both. Similarly, if you have both T14.mp3 and T14.wav, one or the other will be used, but not both (two different file extensions for the same file).
The demonstration files show all the different kinds of triggers, including:
- T00.mp3: A basic trigger on pin GP0
- T01RAND0.mp3 through T01RAND4.mp3: A random trigger on pin GP1
- T04HOLDL.mp3: A hold looping trigger on pin GP4
- T05NEXT0.mp3 through T05NEXT2.mp3: A sequential trigger on pin GP5
- T06LATCH.mp3: A latching looping trigger on pin GP6
Polyphony & Precedence
In code.py there is a configurable number for the maximum polyphony, or the maximum number of different sound files that can be played simultaneously. There's a second limit for the number of simultaneous mp3 files that can be played, because each "MP3 Decoder" object requires a substantial amount of RAM.
When a new sound file is triggered, but the maximum number are already playing, here's what happens: Of the currently playing sounds the one with the highest trigger number is stopped, and then the new sound is started.
So imagine that you have polyphony of 2 (the default), and sounds T05 and T06 are playing. When you trigger another channel, whether it's T02 or T15, then the T06 sound is stopped and the new sound file is started.
Audio file maximums
The maximum audio files that can be played depend on
- format: wav vs mp3
- bit rate & sample rate
- audio volume & clipping when mixing many samples
As a guideline a non-overclocked RP2350 can successfully play 2 320kbit/s MP3 files or 8 32kbit/s MP3 files from internal flash. With overclocking, you can go further.
There's room in the RP2350 RAM for up to 9 MP3 decoder objects, but this has to be reduced somewhat to allow for a complex code.py program. The soft maximum of 4 in the code.py is probably a bit too restrictive.
Page last edited October 17, 2024
Text editor powered by tinymce.