This is only a preview of the August 2018 issue of Silicon Chip. You can view 41 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Brainwave Monitor – see what’s happening in your brain":
Items relevant to "Miniature, high performance sound effects module":
Items relevant to "Turn any PC into a media centre – with remote control!":
Items relevant to "Bedroom (or any room!) no-connection door alarm":
Purchase a printed copy of this issue for $10.00. |
Super
Digital
SOUND
EFFECTS
Module
It’s not just for model trains! by Tim Blythman & Nicholas Vinen
Despite its miniscule size this is, by far, the most powerful sound
effects module ever published in Australia . . . and we haven’t seen
anything else to match it – anywhere in the world! It can be loaded
with dozens of sound effects or audio tracks, short or long, with a
virtually unlimited playback time and advanced controls. Have a
look at the features and specifications: you’ll be amazed!
Y
ou won’t believe that such a
tiny board (just 58 x 24 x 7mm
including the microSD card)
could give such spectacular performance and versatility.
It’s so tiny it can fit inside really small
spaces, such as the inside of a model
locomotive (hint?!).
But despite its size, it is feature
packed, with the ability to read and
play back a large number of WAV files
from an SD card, including the ability
to play several simultaneously (digitally mixed together).
It has advanced sound looping support, the ability to speed up and slow
down playback and the ability to select from multiple sounds for a single
input, round-robin style or randomly.
And the sample length can range
42
Silicon Chip
from a fraction of a second to many
hours.
While it is obviously ideal for model
railway sound effects (it can not only
fit inside HO-scale [and larger] locomotives but can also be triggered by a
DCC decoder).
As an example of what it could do
for a model railway layout, you could
set up one channel to provide an engine sound which includes start-up
and shut-down sounds, when the loco
starts and stops moving, and with a
sound that changes in pitch with the
speed of a wheel.
You could then have other channels
which overlay the engine sound with a
horn, the sound of brakes squealing, an
announcement or just about anything
else you can think of or need. And because it operates from a very wide supply voltage (5.5-18V DC or even a pair
of AAA or AA batteries) there are arguably no applications it can’t handle.
But its uses are much wider than
model railway layouts; in fact, it suits
just about any application where sound
files are required.
Shown here life size, the new Super
Digital Sound Effects Module is tiny
enough to fit just about anywhere . . .
For instance:
Australia’s electronics magazine
• triggering a sound effect when a door
siliconchip.com.au
is opened or closed (a great one for
Star Trek fans!),
• as part of a child’s toy,
• to make a novelty greeting card,
• to make announcements in an elevator,
• as part of a vending machine,
• as an audio guide or to play sounds
for museum exhibits.
The possibilities are practically limitless. We’re sure there’s another two
or fifty rolling around in your head
right now!
It will, without any add-ons, directly
drive an external 8Ω speaker with its
inbuilt 1.2W audio amplifier. And the
sound is great!
If a speaker is too thick for any particular application, the Super Sound
Effects Module can drive a piezo
transducer (although, of course, the
Super Sound Effects Module sound
quality will not be anywhere near as
good). The sounds can be triggered by
switches, relays or the outputs of a microcontroller.
Compare this to a commercial-available sound effects module for a model
locomotive. These typically cost over
$100 and include engine sounds, horn
or whistle sounds, brake sounds and
others depending on the model. And
they’re most unlikely to have the versatility or features this module offers!
Check out these features & specifications!
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
16-bit digital-to-analog converter with 47kHz sampling rate
Onboard 1.2W audio amplifier capable of directly driving an 8-ohm speaker
MicroSD card slot for sound storage (some built-in sounds provided)
Four-channel audio mixing
Multiple sound looping options including “attack-sustain-release” mode
Seven digital trigger inputs, triggered on a low or high level
Each input can trigger one or many sounds (round-robin or randomly selected)
Variable playback speed option, based on an analog voltage or pulse rate
Plays 8-bit or 16-bit WAV files with sampling rates of 1-64kHz
Supports mono or stereo PCM (uncompressed) files; stereo files are downmixed to mono
Two supply options: 2.0-3.6V battery or 5.5-18V DC input
Very low idle current (<10µA when battery powered, <1mA from DC input)
Typical power consumption while operation: ~40mA (depends on volume,
speaker type etc)
Typical start-up delay: <0.5s from sleep mode, <0.1s from idle mode
Based on a low-power PIC32 running at 24MHz
Onboard error/activity LED
Configured via text file on microSD card
While the sounds themselves are important, the way they are played back
and mixed adds to the effect. This module has eight different playback styles
that can be configured, incorporating
How it works
multiple sounds for each input.
The basic circuit arrangement is
For example, a horn or whistle sound
shown in the block diagram, Fig.1. The
typically rises in volume, maintains
Super Sound Effects Module is based
a level, then fades away slowly. One
on PIC32 microcontroller IC1, which
of the inputs on the Super Sound Efreads ordinary WAV files from the mifects Module can be set up to provide
croSD card and plays them back when
this effect. For example, we can cretriggered via one of
ate three separate
its digital inputs.
sound files: one for
Once the audio
the rising part, one
data has been read
for the steady part,
off the SD card and
and one for the fadprocessed, it is fed
ing part.
to I2S-input digitalWhen the apto-analog converter
propriate input is
(DAC) IC2 and then
pulled low, the
to 1.2W audio amplirising level sound
fier chip IC3, which
plays. While the
can drive a small (or
input remains low,
large) speaker or a
the steady sound is
piezo transducer.
repeated as often
There are two powas necessary and
er supply options
finally, the fading
shown in Fig.1, one
sound is played
for a nominally 3V
when the input is
battery and one for a Fig.1: this shows how PIC32 microcontroller IC1 communicates with a
released.
5.5-18V DC supply; microSD card using one of its two hardware SPI interfaces. The other is
This mode is
there will be more configured in I2S mode and drives the DAC, IC2.
called “ASR”,
siliconchip.com.au
details on these options later.
The Super Sound Effects Module is
not just limited to simply playing one
of seven sounds.
By means of a simple text-based
configuration file that is saved on the
card, the operation of each of the seven trigger inputs can be customised
to play back one of several sounds
or a series of sounds with separate
volume and mode configurations for
each input.
Australia’s electronics magazine
August 2018 43
short for Attack, Sustain, Release,
which describes the three phases of
the overall sound effect. This style
also suits generating sound effects for
equipment such as compressors and
dynamic brakes, which all have a characteristic ramp-up, hold and fade-away
sequence.
Engine sounds are usually heard
continuously, and there is an option to
loop a sound as long as an input is triggered, or to alternate this with another
sound that loops while the input is not
triggered. There is also an option for
a sound to play once when triggered,
which is perfect for announcements
and other one-off effects such as coupler clash or guard’s whistle.
There are two more options, similar to the loop and single modes mentioned above. They more or less work
in the same fashion, but if the input is
released during playback, the sound
stops immediately.
If one sound is triggered while another is still playing, normally they will be
mixed together so that you hear them
simultaneously. But this can lead to
volume overload and distortion.
So each trigger input can specify
a playback volume for the associated
sounds, adjusted over a range of 256
steps. This allows the right balance
of sounds to be set up. There is also
a master volume setting which affects
all sounds.
Since the unit is configured through
a file on the SD card, that lets you easily
combine the many available options to
suit your particular application, whatever it might be.
For example, a single WAV file running in “cropped single” mode is ideal
for a custom birthday card powered by
a battery, as the sound will only play
Fig.2: compare this complete circuit diagram to the block diagram, Fig.1. Either REG1 or REG3 is fitted (not both) to
provide the 5V rail which powers IC2 and IC3. The seven series resistors between IC1 and CON4 help to protect IC1
against damage from static electricity or voltages outside its normal operating range of 0-3V or 0-3.3V (depending on
the supply option).
44
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
once when triggered and will stop
when the card is shut, preventing unnecessary battery drain.
The use of up to seven WAV files in
single or looped playback mode can
provide seven custom voice prompts
or warning sounds controlled by separate triggers. These could even include
DTMF tone sequences (there are online
DTMF tone generators available) which
automatically dial a preset phone number, with the unit’s output fed into a
telephone line through an appropriate
coupling method.
It isn’t even necessary to have more
than one WAV file on the card to use all
the inputs. Each input can be set to use
the same WAV file in different modes
or at different volumes. We’ll go into
the detail of what each of these modes
does and how they are set up later on.
General operating concept
The circuit diagram, Fig.2, shows
the overall configuration of the Super
Sound Effects Module. At its heart is
PIC32MM0256GPM028 microcontroller IC1, featuring 256kB of flash program storage and 32kB of RAM. The
combination of a 32-bit processor and
ample RAM are essential to the effective sampling and mixing required by
this project.
The PIC32MM series is designed for
compact low power applications and
runs at only 24MHz from an internal
fast RC oscillator (8MHz), with the oscillator’s output multiplied by a PLL
(phase-locked loop). The large flash
storage space allows us to fit the required software along with a few “bonus” samples which can be used without an SD card inserted.
The PIC communicates with an SD
card inserted into micro socket CON1
using one of its two hardware SPI ports.
Besides the four usual SPI lines (clock,
data in, data out and select), there is
just one additional connection to the
SD card socket, allowing the micro to
sense the state of its “card detect” microswitch.
This pin is shorted to ground when a
card is inserted and is otherwise open
circuit. An internal pull-up current is
enabled by the software in IC1 which
holds this pin high when the card detect switch is open, allowing the software to read the digital pin state and
determine whether a card is present.
Once the audio data has been read off
the SD card and processed by the micro, it is fed to a stereo digital-to-analog
siliconchip.com.au
The reverse side of the Digital Sound
Effects PCB has a few components
fitted including switches S1 & S2.
converter, IC2 (CS4334). The sound effects module operates in mono but most
good quality audio DACs are stereo so
we simply feed the chip identical data
for each channel (this is a hardware option on the micro) and use just one of
the DAC’s outputs (AOUTL) at pin 8.
The audio from this pin is fed to
a mono bridged amplifier IC, IC3
(IS31AP4991). The audio signal is
AC-coupled with a 10µF capacitor as
the DC bias levels of the DAC and amplifier will not necessarily be the same
(although they will both be similar, at
around 2.5V).
The signal also passes through a
22kΩ series resistor which forms a lowpass filter with the two capacitors connected to IC3’s pin 3 inverting input,
as well as setting the bridged amplifier gain to two times, as it is the same
value as the 22kΩ resistor from the pin
2 output back to the inverting input.
The 22kΩ series resistor and 100pF
capacitor to ground form a low-pass
filter with a -3dB point of 22kHz, reducing the DAC’s sampling artefacts.
The 330pF capacitor across the 22kΩ
feedback resistor also provides a lowpass filtering effect as well as helping
to stabilise the amplifier and prevent
oscillation.
A 1µF capacitor from pin 5 of IC3 to
ground stabilises its half-supply reference, helping to prevent any noise
which may be present on its supply
rail from being injected into the amplified outputs. It also has a 1µF supply bypass capacitor close to the IC, to
provide it with bursts of current during
audio transients. IC3 drives the 8-ohm
speaker directly, which is connected to
its bridge output pins 6 and 2, via pin
header CON2.
The amplifier IC is capable of directly driving an 8Ω speaker to more than
1W, assuming the power supply is capable of delivering the current. Depending on how the circuit is powered, the
supply may not be capable of delivering the required current of 250mA or
more. In this case, a higher impedance
speaker can be used, or a resistor can be
Australia’s electronics magazine
connected in series with the speaker to
limit peak currents; more on this later.
Alternatively, you can connect a
piezo transducer in place of the speaker. The sound quality will not be as
good but the efficiency is higher and the
amplifier has no trouble driving such a
load (which is capacitive).
Digital audio interface
We operate the DAC (IC2) with a sampling rate of 46.875kHz. This may seem
like an odd value; more typical sampling rates would be 44.1kHz (as used
for CDs) or 48kHz (as used for DVDs).
The reason for the unusual value is that
this is an integral fraction of the maximum clock speed of the microcontroller, IC1 (24MHz). Hence, it can easily
be produced by the micro using one of
its internal timers/counters.
The DAC IC requires a “master clock”
which is a multiple of the sampling
rate and the multiple must be one of
several fixed ratios supported by the
IC, specifically, 128, 192, 256, 384 or
512 times. If we run the micro at the
full 24MHz and choose the 512 times
value for the master clock, that allows
us to have a sampling rate of 46.875kHz
(24MHz ÷ 512) and this is the one that
we have chosen.
The other multiplier values give a
higher sampling rate unless we lower
the microcontroller clock speed but
that would then slow down its processing. So we decided that the values
specified above were the best choices.
As well as the master clock signal,
which is fed to its pin 4, IC2 expects
16-bit digital audio data in I2S format
fed to pins 1-3, where pin 1 is the audio data input, pin 2 is the bit clock
(which runs at 32 times the sampling
rate, ie, for two channels with 16 bits
of data each) and pin 3 is the left/right
clock which runs at the sampling rate
and indicates when the left channel
data is on pin 1 (LRCK low) and when
it’s the right channel data (LRCK high).
Microcontroller IC1 has specific
hardware for generating digital audio
signals, including I2S format. It does
this using one of its two hardware SPI
(serial peripheral interface) units. I2S
is similar to SPI but there are a few
minor differences, such as the need to
generate the extra left/right clock output signal.
So the serial data (to pin 1 of IC2)
and bit clock (to pin 2) are generated
in virtually the same manner as they
would be in SPI mode, from output pin
August 2018 45
Parts list – Super Digital SFX
1 double-sided PCB, coded 01107181, 55 x 23.5mm
1 SMD microSD card socket (CON1) [Altronics P5717 or similar]
2 mini SMD two-pin tactile pushbutton switches (S1,S2) (optional)
[eg, Switchtech 1107G]
1 5-pin header (CON3) (optional, to program IC1)
1 speaker, size to suit (8Ω or greater) or piezo transducer (see text)
1 two cell AAA or AA battery holder (optional)
Semiconductors
1 PIC32MM0256GPM028-I/SS programmed with 0110718A.hex, SSOP-28 (IC1)
1 CS4334 16-bit stereo DAC, SOIC-8 (IC2)
1 IS31AP4991 mono bridged audio amplifier, SOIC-8 (IC3)
1 MCP1640 boost regulator, SOT-23-6 (REG1)*
1 MCP1700-3.3 LDO linear regulator, SOT-23 (REG2)
1 MCP1703-5 LDO linear regulator, SOT-223 (REG3)#
1 blue SMD LED, 3216/1206 package (LED1
1 1A schottky diode, DO-214AC (D1) [eg, SS14]#
# only required for 5.5-15V DC powered version
Capacitors (all SMD X7R ceramic, 6V, 2012/0805 size)
4 10µF
7 1µF 16V
1 330pF
1 100pF
Resistors (all SMD 1%, 2012/0805 size)
1 1MΩ
1 330kΩ
1 270kΩ
1 47kΩ
1 0Ω (LK1/LK2)
2 22kΩ
8 1kΩ
Inductors
1 4.7µH chip inductor, 3226/1210 size package, 1A+ (L1) [eg, Taiyo Yuden
CBC3225T4R7MR]* * only required for battery-powered version
6 of IC1 (configured as SDO) and pin
2 (configured as SCLK) respectively.
Pin 7 of IC1 would normally be the
SPI chip select (CS) output but in audio mode, this becomes LRCK.
The MCLK signal for IC2 is produced
from digital output pin 3 of IC1 but
does not come from the audio signal interface. Instead, this pin is configured
as a PWM output using a timer derived
from the micro’s system clock. Since
this same clock is used to generate the
I2S audio signal clocks, the signals are
synchronised and the ratios are locked.
When the DAC is not being used and
the micro is in sleep mode, since the
micro is no longer driving the MCLK
and LRCK pins with square waves, IC2
automatically goes into a low-power
sleep mode. The amplifier can also be
put into a low-power mode by the micro by pulling its shutdown input (pin
7) high. This is connected to digital
output RB5 (pin 11) on IC1.
but this can be inverted with a software option.
Each of these pins connects to a
digital input on the micro via a 1kΩ
resistor which is present to protect
the microcontroller in case a voltage
outside the range of 0-3V is applied to
one of these pins, by limiting the current through the micro’s input clamp
protection diodes.
Each of the micro’s seven digital trigger inputs is configured by the software
to be supplied with a small pull-up current which flows from VDD. This holds
those input high unless they are externally pulled low. So pin 1 on CON4 is
tied to ground so you can trigger the
sound (in the default mode) by shorting
pin 1 to one of the other pins.
This can also be done by an external
switch, relay or transistor. If onboard
tactile pushbuttons S1 and S2 are fitted, they can be used to trigger the first
two sound effects channels.
Trigger inputs
Power supply
Sound effects are triggered when
one of the digital input pins 2-8 on pin
header CON4 change state; normally
they are triggered by being pulled low
The power supply arrangement on
this board is a little complicated since
it is designed to be set up for two different power sources: either a battery
46
Silicon Chip
Australia’s electronics magazine
of around 3V (eg, 2 AA or AAA cells)
or a 5.5-18V DC supply from a plugpack, model railway train tracks (DC or
rectified and filtered AC) or the rectified and filtered output of a transformer or similar.
When powered from a ~3V battery,
link LK1 is shorted and thus microcontroller IC1 is powered directly off the
battery. When in sleep mode, it draws
a tiny amount of current (under 1µA)
so this connection will not drain the
battery.
Switching boost regulator REG1 is
also fitted for battery use. When in
sleep mode, the micro keeps this shut
down by driving its pin 3 enable input
low, from its RA2 digital output (pin 9).
When that output goes high, the boost
regulator is enabled and it produces 5V
at its pin 5 output.
No external transistors or diodes are
required since this is a synchronous
regulator, with all switching done internally. This also maximises efficiency. The external components that
are required are inductor L1 which is
used as an energy storage device and to
boost the voltage, 10µF ceramic input
bypass and output filter capacitors and
a 1MΩ/330kΩ resistive feedback divider which sets the output voltage to 5V.
The 5V supply then powers the DAC
(IC2) and audio amplifier (IC3). IC2
requires a 5V supply while IC3 can
operate from 2.7-5.5V but will have
a greater output swing and thus better power delivery when operating at
higher voltages.
This 5V supply is then reduced to
a regulated 3.3V supply to power the
microSD card by linear regulator REG3.
While boost regulator REG1 can
work with an input supply as low as
0.65V, since IC1 is also powered from
the battery this means the minimum
operating voltage is 2.0V.
Typical microSD cards will accept
signal levels down to 2.0V, although
they require a minimum supply voltage of 2.7V, so the card should not be
the limiting factor on the minimum
operating battery voltage.
With REG1 shut down, the only components drawing power are IC1 and
REG1, both of which have very low
current demand in the sleep/shutdown
state. Total standby current is just a
few microamps. Note though that this
has the disadvantage that the microSD
card must be initialised immediately
upon the device being triggered which
means there can be a delay in playsiliconchip.com.au
ing back the first sound. This can be
reduced by either pre-buffering some
sounds in RAM or by keeping the micro awake and the regulator active for
some time after each trigger even, so it’s
ready to be re-triggered. We’ll explain
these schemes in more detail later.
Alternative power supply
arrangement
If a higher supply voltage is available then boost regulator REG1 is not
necessary and should not be fitted. Reverse polarity protection diode D1 and
5V linear regulator REG3 are fitted instead. The DC supply is connected to
pin header CON5 and the 5V output
of REG3 powers IC2 and IC3.
REG2 supplies 3.3V to the microSD
card as before but in this case, LK2 is
inserted rather than LK1 and so microcontroller IC1 also runs from the
output of REG2.
With this supply configuration, the
sleep current is higher because IC2,
IC3, REG2 and REG3 are always powered however these are all capable of
entering low-power sleep mode or have
a low quiescent current.
The microSD card is also powered
continuously, however, this is kept in
a low-power standby state unless it is
actually being used.
So the sleep mode current with this
power supply arrangement is higher
than with a battery and depends on
how much current the SD card draws
in its idle state. IC2 draws around
45µA and an SD card is usually around
0.5mA in standby mode, for a total
that’s typically well under 1mA.
Note that REG3 is physically larger
than the other regulators (in an SOT223 package rather than SOT-23) and
it is soldered to a solid copper plane.
This is necessary since, at higher input voltages (eg, 12V), its dissipation
could be substantial.
During sound effect playback, the
circuit could draw more than 100mA
and with a 12V input and 5V output,
that’s in excess of 0.7W of dissipation.
Software details
The software for this project is quite
complex as it provides many different
configurable features and does a lot of
“real-time” processing in order to read
and play back multiple files with different sampling rates and looping options at the same time.
Practically all of the 32KB RAM is
used to buffer samples from the microSD card and the spare flash memory
is filled with some useful audio samples as well.
Initialisation
On startup, the software performs a
number of initialisation tasks. It needs
to set the initial state of the LED drive
pins, control pins for REG1 and IC3
and microSD card interface pins. Both
internal SPI peripherals need to be set
up as one is used for communication
with the SD card and the other, with
the DAC. They also have re-mappable
I/O pins so those need to be set to the
correct external pins.
Since the only interrupt service routine used by the software is for feeding
audio data to the DAC and this should
not be interrupted, the interrupt priority is set to the highest possible level.
It turns out that Audacity (by default) adds ‘dither’ to
files as it saves them to spread out quantisation errors
on downsampling. Unfortunately the dither is audible,
especially for 8-bit samples. To turn off dithering, select
Preferences from the Edit menu, and set Dither on Highquality Conversion (here, High-quality Conversion means
saving rather than playback) to none.
siliconchip.com.au
Pin 3 is set up as a 12MHz clock output to provide the master clock (MCLK)
for the DAC. This utilises the SCCP4
peripheral (single ended capture/compare/PWM) with a prescaler of 1:1 and
a period of two clocks (the system clock
is 24MHz). The rising edge register is
set to zero and the falling edge register to one, meaning that the output alternates on each clock pulse, giving a
12MHz square wave.
The microSD card requires power
before it can be initialised, so as soon
as the unit is triggered, the control pins
for REG1 and IC3 are brought high to
switch them on. The software then
checks the level on the microSD card
detect pin and flashes LED1 to indicate
an error if it is not found. The card initialisation procedure then starts and
once the card is ready, the configuration file is then found and loaded.
The configuration file consists of
lines of text which are then “parsed”
one at a time, to extract the required
settings, then stored in RAM to be referred to later.
Once that is complete, the interrupt
which produces I2S data for the DAC
is activated and then the Super Sound
Effects Module is ready to operate.
There are three 512-byte buffers for
each of the four playback channels (ie,
twelve buffers total). The interrupt service routine (ISR) checks whether there
is any audio data to be played back and
if so, applies the appropriate volume
for each channel and mixes the resulting samples.
The mixed sample value then has the
master volume applied and is clipped
to remain within the -32768 to +32767
You can see the difference by exporting a file of silence as
8-bit WAV before and after the change. Reopen the files (as
we have done here, and amplify each by 40dB. The one
without dither remains at zero, while the file with dither
has an obvious hiss. 16-bit files also have dither applied but
the effects will not be as pronounced as the effects for 8-bit
files.
Australia’s electronics magazine
August 2018 47
range for 16-bit audio data.
If any clipping occurs, a flag is set
which is picked up by the main loop
and it operates to reduce the overall
volume to limit distortion.
Main loop
With the DAC ISR handling audio
output, the main program loop continues running. In addition to checking for the clipping flag, it also monitors each of the triplets of audio buffers. If one becomes empty and there
is more data in the associated file, it
fetches more data from the SD card to
“refill” the buffer. This way, the ISR
never “runs out” of audio data until
it’s time to stop playback.
After it fetches the data, it then resamples that data (using linear interpolation) to match the DAC’s sampling
rate of 46.875kHz and also converts any
8-bit data to 16 bits, and stereo data is
downmixed to mono.
The optimum WAV file format for
use with this unit is 16-bit mono at
46.875kHz, as this will not normally
result in any re-sampling or downmixing. However, the use of 44.1kHz and
48kHz files will not result in much
degradation.
Once it has ensured that all the audio buffers have data as required, the
PIC then turns its attention to the seven
digital trigger inputs. The behaviour of
each input depends on the mode selected in the configuration file.
If it determines that an input has
been triggered, it then checks if one of
the four audio output channels is free.
If so, the free channel is set up to play
back the sound which has been configured to be triggered by this particular
input. In doing so, it fills up that output channel’s audio buffers before it
actually starts playback, so that it will
be able to fetch more data as they are
emptied over time.
Once the buffers are empty and the
source file(s) are exhausted, that channel is freed up for use by another sound
effect trigger in future.
If an input is set up with one of the
“attack-sustain-release” type configurations mentioned earlier then it is necessary to start playback of a second file
once the first one has finished. In this
case, as soon as the first file playback
is finished and an audio buffer is free,
the second file is opened and the audio buffer refilled. The same procedure
happens once the “sustain” sample has
finished playback.
48
Silicon Chip
If an input is set up to play files in
round-robin or random mode then
multiple files can be specified for that
input. In round robin mode, the first
time the input is triggered, the first file
is played back. The second time it is
triggered, the second file is played back
and so on until the last file is played
back, at which point the sequence restarts.
In random mode, a pseudo-random
number generator is used to select one
of the listed files to play back each time
that input is triggered. Each subsequent
trigger event may therefore trigger the
same sound again or a different sound;
there will be no obvious pattern.
If there is no audio being played
back, the main loop starts a timer. Once
that timer has reached a user-configured threshold, the unit goes into lowpower sleep mode, powering down the
SD card and anything else that’s under
the micro’s control (including itself!).
Because we are not writing anything
to the microSD card, the file handles
and configuration data will can remain
in RAM and do not have to be read off
the card again, saving some time next
time an input is triggered and the chip
comes out of sleep mode.
Changing playback pitch
The trigger inputs connected to pins
5 and 6 of CON4 (ie, pins 10 & 11 of
IC1) can also function as analog inputs. So one feature of the software is
the ability to reprogram either or both
of these inputs as analog voltage pins
which control the playback speed and
therefore pitch of the sounds triggered
on other channels.
If enabled, the software periodically
samples the voltages on the appropriate pin using IC1’s internal analog-todigital converter (ADC) and then uses
this to “tweak” the sampling rate that’s
being used to play back the sounds for
the configured channel.
For example, if we play it back at
half of the actual sampling rate then the
sounds will be one octave lower than
normal (and will take twice as long to
play back) while if we play it back at
double the actual sampling rate, the
sounds will be one octave higher and
it will take half as long to play back.
In reality, the sampling rate shift is
not normally this extreme but it allows
for engine sounds that change in pitch
with speed and so on.
The trigger input connected to pin
4 of CON4 (ie, pin 19 of IC1) can funcAustralia’s electronics magazine
tion as the clock input for IC1’s internal TIMER3 counter. This pin can be
configured as a pulse counter input
and the pulse rate (ie, frequency) can
then be used to vary the sound playback rate.
Regardless of whether you are using
an analog voltage or a pulse frequency
to vary the sound playback rate and
pitch, you can specify on a per-channel basis which is the controlling input, the control range of the voltage or
frequency and the percentage change
in playback rate which results.
Audible debugging
Since the unit has no display and
only one LED, which can indicate just
a few error conditions, we have also
programmed the chip with an audible debugging mode. When enabled,
it “speaks” its settings via the audio
output, so that you can check to see
whether it has been configured the way
you have intended.
We have implemented this feature
by using speech synthesiser software
to produce samples for all the necessary words and numbers and then
these have been stored in the PIC’s
flash memory.
So when you enable this mode,
called “speakback” in the configuration file, at power up it will audibly
list all of its settings and then you can
listen to the output and see whether
everything is as expected.
The only part of the configuration
which isn’t “spoken” is the file names.
Each file mentioned in the configuration file is checked to see if it appears
to be valid (ie, the name refers to a file
that’s stored on the SD card) and it will
then say “OK” or “not OK” depending
on whether the file has been found or
not. Otherwise, all configuration parameters are read out for you to check.
Once you’re happy that the configuration is correct, you can edit the config file and switch this mode back off,
to get normal operation.
Next month
Phew! That’s enough to digest for
one month . . . but having read all that,
we trust you’ll agree this is one very
clever little device (little being the operative!).
In part two next month, we will get
onto the fun part: putting it together
and full instructions for setting up
and using the new Super Sound Effects Module.
SC
siliconchip.com.au
|