Lab 7 Music v4
Lab 7 Music v4
Purpose
This Lab uses the analog output of myDAQ to generate an audio signal
from a LabVIEW keyboard (Fig. 1) of one or two octaves. A small
electronic audio amplifier adds plenty of volume.
Equipment
• NI myDAQ
• 3.5 mm Sub-Minature Stereo Cable (comes with NI myDAQ)
• iPod or Other Music Source and Earphones
• Stereo Computer Speaker Set (optional)
• LM386 or TI TPA301 Audio Amplifier
• Resistor: 10 kΩ Pot
• Capacitors: 1 µF, 1 nF, and 47 nF
• Capacitors (electrolytic): Three 10 µF
• 8Ω Speaker
• Stereo Audio Sub-Miniature Socket
© National Instruments Corporation 1
Lab 7. Let’s Make a Little Noise
• Solderless Breadboard
Connect your iPod output to the myDAQ (Audio In socket). Connect your
earphones or external speakers to myDAQ (Audio Out) Socket.
Start playing a favorite song on the iPod. Sound will tell you that the iPod
signal is being streamed from your iPod through a LabVIEW program and
back out to the earphones/speakers.
Audio also can be played from a LabVIEW program to the analog output
channel 0 (pins AO1 and AGND). Using two alligator cables, connect
these two pins to your earphone or speaker cable.
Launch the function generator FGEN and set it to Sine, 1000 Hz, and
0.5 Vpp.
Press [Run] and hear the sine wave signal in your speakers or earphone.
Now that the audio channels are set to go, let’s build a LabVIEW program
to generate some sounds.
The Keyboard
Load the program Piano.vi and look at the front panel (see Fig.1).
2 ni.com
Lab 7. Let’s Make a Little Noise
A keyboard for one octave is made up of seven white keys and five black
keys. The extra white key on the right side has been added so you can go
from middle C (C4) to the higher C note (C5). The frequency for C5 is
exactly twice the frequency for C4. The keys are just LabVIEW Boolean
indicators shaped, colored, and placed into a keyboard arrangement.
Whenever a key is pressed via the mouse pointer, a note is played to the
analog output pins (AO 1 and AGND).
Look at the block diagram for the program Piano.vi, as shown in Fig. 2.
The musical note frequencies are stored in an array called ‘Notes’. The
notes are entered in the array in the same sequence as the keys are laid
out on the keyboard.
Example:
Middle C (C4) is element 0 of the array (261.63 Hz).
The keys have a mechanical action of ‘Switch Until Released’. The output
is ‘True’ as long as a key is pressed. The keys C, C#, …, C’ are built into a
Boolean array whose value is 0 until a key is pressed. The Search 1D
Array VI returns a value of –1 (no key pressed) or the integer number
related to the key position. This number becomes an index into the ‘Notes’
array to find the note frequency. The frequency data packet then passes
on to the function generator (FGEN), which produces the sound and
outputs it to the analog output sockets AO 0 and AGND.
You soon will hear the limitations of having only one octave.
Reference: http://www.techlib.com/electronics/audioamps.html
You will need the LM386 IC, a few resistors and capacitors, a small
speaker, and a power supply. NI myDAQ can provide +15 and
–15 V at 2 ma. We will use the +15 V on the sockets labeled +15 V and
AGND. The input for the amplifier will come from myDAQ analog output
sockets AO 0 and AGND. You can use the myDAQ DMM(Ω) software
instrument to verify the values of all your chosen resistors. The values of
the capacitors are not critical, so the values stamped on the package are
good enough. However, if you wish to measure the capacitors, you can
use the Bode Analyzer (see Lab 2) and the –3 dB cutoff point (or 45
degree phase point) to calculate the capacitance.
Inject a small signal (0.2 Vpp) into the circuit input from the FGEN. Adjust
the 10 kΩ pot for a comfortable output. Measure the circuit gain, and
compare it with the expected gain.
Once the amplifier is tested, then it is time to replace the FGEN signal with
the program Piano.vi and make some noise.
6 ni.com
Lab 7. Let’s Make a Little Noise
Let’s use myDAQ to explore this idea. The FGEN can only output on one
channel, AO 0. However, the iPod connector has two outputs (stereo) with
a separate channel for each ear. The arbitrary waveform generator (ARB)
has two outputs. Let’s put a pure sine wave into one channel (left ear) and
our composite waveform into the other channel (right ear). Now it will be
easy to hear the difference.
Note: If you are not familiar with the ARB, check out the reference
http://Decibel.ni.com/content/docs/DOC-12941.
Note: Use the folder icon to navigate to where your .wdt files are stored.
The update rate is 20 k samples per second (S/s) and run continuously.
Click on [Run] and explore the differences. Can you hear which channel is
the sine wave and which is the composite wave? Try changing the update
rate. Any difference?
8 ni.com