<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/technology/cnxml/schema/dtd/0.5/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" id="new">
  <name>[ mini-project ] "The Whistler" virtual musical instrument (VMI) in LabVIEW</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2007/08/23 10:23:13.123 GMT-5</md:created>
  <md:revised>2007/11/07 14:36:43.527 US/Central</md:revised>
  <md:authorlist>
      <md:author id="doering">
      <md:firstname>Ed</md:firstname>
      
      <md:surname>Doering</md:surname>
      <md:email>doering@rose-hulman.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="doering">
      <md:firstname>Ed</md:firstname>
      
      <md:surname>Doering</md:surname>
      <md:email>doering@rose-hulman.edu</md:email>
    </md:maintainer>
    <md:maintainer id="eluther">
      <md:firstname>Erik</md:firstname>
      <md:othername>B</md:othername>
      <md:surname>Luther</md:surname>
      <md:email>erik.luther@ni.com</md:email>
    </md:maintainer>
    <md:maintainer id="SShearman">
      <md:firstname>Sam</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Shearman</md:surname>
      <md:email>sam.shearman@ni.com</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>envelope generator</md:keyword>
    <md:keyword>LabVIEW</md:keyword>
    <md:keyword>MIDI Jam Session</md:keyword>
    <md:keyword>vibrato</md:keyword>
    <md:keyword>virtual musical instrument</md:keyword>
  </md:keywordlist>

  <md:abstract>An individual who can whistle with vibrato can be well-modeled by a sinusoidal oscillator, an attack-sustain-release envelope with a moderate attack and release time, and a low-frequency sinusoidal frequency modulation. In this mini-project you will develop code to model the whistler as a LabVIEW "virtual musical instrument" (VMI) to be "played" by a MIDI file.</md:abstract>
</metadata>

<content>

<table id="labview_banner" frame="none"><tgroup cols="2">
<colspec rowsep="0" colsep="0"/> <colspec colwidth="6in" rowsep="0" colsep="0"/>
<tbody>
  <row>
    <entry morerows="3"><media type="image/png" src="LabVIEWq.png"/></entry>
    <entry> This module refers to LabVIEW, a software development environment that features a graphical programming language.
       Please see the <cnxn document="m15428">LabVIEW QuickStart Guide</cnxn> module for tutorials and documentation that will help you:</entry>
  </row>
  <row> <entry>• Apply LabVIEW to Audio Signal Processing </entry> </row>
  <row> <entry>• Get started with LabVIEW</entry> </row>
  <row> <entry>• Obtain a fully-functional evaluation edition of LabVIEW</entry> </row>
</tbody>
</tgroup>
</table>


<section id="sec1">
<name>Objective</name>

<para id="par2">An individual who can whistle with vibrato can be well-modeled by a sinusoidal oscillator, an attack-sustain-release envelope with a moderate attack and release time, and a low-frequency sinusoidal frequency modulation. In this mini-project you will develop code to model the whistler as a LabVIEW <term>virtual musical instrument</term> (<term>VMI</term>) to be "played" by a MIDI file.</para>

</section>

<section id="sec3">
<name>Prerequisite Modules</name>

<para id="par4">If you have not done so already, please study the pre-requisite module <cnxn document="m15496">Vibrato Effect</cnxn>. 
If you are relatively new to LabVIEW, consider taking the course <cnxn document="col10440">LabVIEW Techniques for Audio Signal Processing</cnxn> 
which provides the foundation you need to complete this mini-project activity, including working with arrays, creating subVIs, 
playing an array to the soundcard, and saving an array as a .wav sound file.</para>

</section>

<section id="sec5">
<name>Deliverables</name>

<list id="list6" type="bulleted">

<item> All LabVIEW code that you develop (block diagrams and front panels) </item>
<item> All generated sounds in .wav format  </item>
<item> Any plots or diagrams requested </item>
<item> Summary write-up of your results </item>

</list>

</section>

<section id="sec7">
<name>Part 1: Tone Generator with Vibrato</name>

<para id="par8">In this part you will create a basic tone generator with vibrato. The tone generator will be a sinusoid of the form <m:math>
 <m:semantics>
  <m:mrow>
   <m:mi>y</m:mi><m:mo stretchy="false">(</m:mo><m:mi>t</m:mi><m:mo stretchy="false">)</m:mo><m:mo>=</m:mo><m:mi>sin</m:mi><m:mo>⁡</m:mo><m:mo stretchy="false">(</m:mo><m:mi>ϕ</m:mi><m:mo stretchy="false">(</m:mo><m:mi>t</m:mi><m:mo stretchy="false">)</m:mo><m:mo stretchy="false">)</m:mo>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math>, where the phase function <m:math>
 <m:semantics>
  <m:mrow>
   <m:mi>ϕ</m:mi><m:mo stretchy="false">(</m:mo><m:mi>t</m:mi><m:mo stretchy="false">)</m:mo>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math>  has the following form (<cnxn target="eqn-phi-of-t"/>):</para>

<equation id="eqn-phi-of-t">

<m:math>
 <m:semantics>
  <m:mrow>
   <m:mi>ϕ</m:mi><m:mo stretchy="false">(</m:mo><m:mi>t</m:mi><m:mo stretchy="false">)</m:mo><m:mo>=</m:mo><m:mn>2</m:mn><m:mi>π</m:mi><m:msub>
    <m:mi>f</m:mi>
    <m:mn>0</m:mn>
   </m:msub>
   <m:mi>t</m:mi><m:mo>+</m:mo><m:mi>Δ</m:mi><m:mi>f</m:mi><m:mi>sin</m:mi><m:mo>⁡</m:mo><m:mo stretchy="false">(</m:mo><m:mn>2</m:mn><m:mi>π</m:mi><m:msub>
    <m:mi>f</m:mi>
    <m:mi>R</m:mi>
   </m:msub>
   <m:mi>t</m:mi><m:mo stretchy="false">)</m:mo>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math>
</equation>

<para id="par10">where <m:math>
 <m:semantics>
  <m:mrow>
   <m:msub>
    <m:mi>f</m:mi>
    <m:mn>0</m:mn>
   </m:msub>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math> is the tone frequency, <m:math>
 <m:semantics>
  <m:mrow>
   <m:mi>Δ</m:mi><m:mi>f</m:mi>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math>  is the frequency deviation (vibrato depth), and <m:math>
 <m:semantics>
  <m:mrow>
   <m:msub>
    <m:mi>f</m:mi>
    <m:mi>R</m:mi>
   </m:msub>
    </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math> is the vibrato rate in Hz.

Use the "Play Waveform" Express VI to listen to your end result <m:math>
 <m:semantics>
  <m:mrow>
   <m:mi>y</m:mi><m:mo stretchy="false">(</m:mo><m:mi>t</m:mi><m:mo stretchy="false">)</m:mo>
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math> , and experiment with the parameters to find suitable values for rate and depth to simulate the sound of a whistler.

Refer to the screencast video in the module <cnxn document="m15493">Frequency Modulation (FM) Techniques in LabVIEW</cnxn> 
for coding tips for this part.</para>

</section>

<section id="sec11">
<name>Part 2: Attack-Sustain-Release Envelope Generator</name>

<para id="par12">Create LabVIEW code to generate a time-varying intensity envelope for the overall attack, sustain, and decay of the note.
Your code will require attack time and decay time (both in seconds), as well as the total number of required samples, and will produce an envelope composed of three straight-line segments as plotted in <cnxn target="img-ASRenv"/>.</para>

<figure id="img-ASRenv">
<media type="image/png" src="lfmod_MP-sing-ASR.png">
   </media>
<caption>
   Attack-Sustain-Release envelope
</caption>
</figure>

<para id="par14">The maximum intensity is fixed at 0 dB, and the minimum intensity is -40 dB. The attack and release times are fixed parameters that you adjust, and the sustain time is "stretchable" depending on the total number of required samples. If you have the inclination, make your envelope generator more robust so that it can handle the situation where the requested number of samples is less than the number of samples required for your attack and release intervals.</para>

</section>

<section id="sec15">
<name>Part 3: Attenuator</name>

<para id="par16">Create LabVIEW code that accepts an "amplitude" parameter in the range 0 to 1 and converts this parameter to attenuation in the range -40 dB to 0 dB. The amplitude parameter will ultimately be supplied by MIDI_JamSession and represents the MIDI "note-on" velocity. Your code will map linear velocity onto a logarithmic intensity.</para>

</section>

<section id="sec17">
<name>Part 4: Overall Amplitude Envelope</name>

<para id="par18">Combine the code fragments you developed in Parts 2 and 3 to create an overall intensity envelope. Remember that when you use  intensity values in decibels, you simply <emphasis>add</emphasis> them together. Next, "undo" the equation for decibels to convert the intensity envelope into an amplitude envelope (hint: you need a value of "20" someplace).

Choose a representative set of parameter values and plot your overall intensity envelope and your overall amplitude envelope.
</para>

</section>

<section id="sec19">
<name>Part 5: Whistler VMI</name>

<para id="par20">Design a <term>virtual musical instrument</term> (<term>VMI</term> for short) that sounds like someone whistling with vibrato. Your VMI will be played by "MIDI Jam Session." If necessary, visit <cnxn document="m15053">MIDI Jam Session</cnxn>, download the application VI .zip file, and view the screencast video in that module to learn more about the application and how to create an instrument subVI, or VMI. Your VMI will accept parameters that specify frequency, amplitude, and length of a single note, and will produce an array of audio samples corresponding to a single note.

Use the tone generator you developed in Part 1, and apply the amplitude envelope you generated in Part 4. You may wish to keep all of your parameters as front-panel controls and add the "Play Waveform" Express VI to listen to your VMI during development. Adjust the parameters to obtain pleasing and realistic settings, then convert the front-panel controls to constants and remove "Play Waveform." Your finished VMI must not contain any front panel controls or indicators beyond those provided in the prototype instrument.

Choose a suitable MIDI file and use MIDI_JamSession to play your whistler VMI. MIDI files that contain a solo instrument, slow tempo, and long sustained notes  likely produce better results, for example, Johann Pachelbel's "Canon in D." Try
<link src="http://www.classicalguitarmidi.com/subivic/Pachelbel_Canon_in_D.mid">Pachelbel_Canon_in_D.mid</link> at
the <link src="http://www.classicalguitarmidi.com">Classical Guitar MIDI Archives</link>. You can also find a more extensive
collection at <link src="http://www.classicalarchives.com">ClassicalArchives.com</link>, specifically
<link src="http://www.classicalarchives.com/midi/p.html">Pachelbel MIDI files</link>.

Create a .wav file of your finished work.</para>

</section>

<section id="sec21">
<name>Optional: Modifications to Basic Whistler VMI</name>

<para id="par22">Following are some suggested modifications you could try for your basic whistler VMI:</para>

<list id="list23" type="bulleted">

<item> Make the vibrato rate proportional to the intensity envelope. This characteristic is common for vocalists and many types of instrumentalists. </item>
<item> Make the vibrato depth proportional to the intensity envelope. This is another characteristic common for vocalists and many types of instrumentalists. </item>
<item> Vary either the vibrato rate or depth (or possibly both) according to the "amplitude" parameter provided by the prototype VMI. For example, higher amplitudes could be mapped to a faster rate or more depth. </item>
<item> Duplicate the tone generator two more times with frequencies of <m:math>
 <m:semantics>
  <m:mrow>
   <m:mn>2</m:mn><m:msub>
    <m:mi>f</m:mi>
    <m:mn>0</m:mn>
   </m:msub>
   
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math> and <m:math>
 <m:semantics>
  <m:mrow>
   <m:mn>3</m:mn><m:msub>
    <m:mi>f</m:mi>
    <m:mn>0</m:mn>
   </m:msub>
   
  </m:mrow>
 <m:annotation encoding="MathType-MTEF">
 </m:annotation>
 </m:semantics>
</m:math>
 and intensities of -10 dB and -20 dB, respectively, to create some overtones. Each of the tone generators should have the same vibrato rate and depth. The overtones  make the whistler sound a bit more like a flute or a singing voice. </item>

</list>

</section>

</content>
</document>
