<?xml version="1.0" encoding="utf-8"?>
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:q="http://cnx.rice.edu/qml/1.0" id="m10480" module-id="" cnxml-version="0.6">
  
  <title>Audio Effects: Using External Memory</title>
  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4">
  <!-- WARNING! The 'metadata' section is read only. Do not edit below.
       Changes to the metadata section in the source will not be saved. -->
  <md:content-id>m10480</md:content-id>
  <md:title>Audio Effects: Using External Memory</md:title>
  <md:version>2.17</md:version>
  <md:created>2002/02/01</md:created>
  <md:revised>2009/06/03 15:28:15.412 GMT-5</md:revised>
  <md:authorlist>
    <md:author id="dljones">
        <md:firstname>Douglas</md:firstname>
        <md:othername>L.</md:othername>
        <md:surname>Jones</md:surname>
        <md:fullname>Douglas L. Jones</md:fullname>
        <md:email>dl-jones@uiuc.edu</md:email>
    </md:author>
    <md:author id="appadwed">
        <md:firstname>Swaroop</md:firstname>
        <md:surname>Appadwedula</md:surname>
        <md:fullname>Swaroop Appadwedula</md:fullname>
        <md:email>appadwed@uiuc.edu</md:email>
    </md:author>
    <md:author id="mjberry">
        <md:firstname>Matthew</md:firstname>
        <md:othername>J.</md:othername>
        <md:surname>Berry</md:surname>
        <md:fullname>Matthew Berry</md:fullname>
        <md:email>mjberry@uiuc.edu</md:email>
    </md:author>
    <md:author id="markhaun">
        <md:firstname>Mark</md:firstname>
        <md:othername>A.</md:othername>
        <md:surname>Haun</md:surname>
        <md:fullname>Mark Haun</md:fullname>
        <md:email>markhaun@uiuc.edu</md:email>
    </md:author>
    <md:author id="moussa">
        <md:firstname>Dima</md:firstname>
        <md:surname>Moussa</md:surname>
        <md:fullname>Dima Moussa</md:fullname>
        <md:email>dmoussa@uiuc.edu</md:email>
    </md:author>
    <md:author id="dsachs">
        <md:firstname>Daniel</md:firstname>
        <md:othername>Grobe</md:othername>
        <md:surname>Sachs</md:surname>
        <md:fullname>Daniel Sachs</md:fullname>
        <md:email>sachs@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>
  <md:maintainerlist>
    <md:maintainer id="dljones">
        <md:firstname>Douglas</md:firstname>
        <md:othername>L.</md:othername>
        <md:surname>Jones</md:surname>
        <md:fullname>Douglas L. Jones</md:fullname>
        <md:email>dl-jones@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="appadwed">
        <md:firstname>Swaroop</md:firstname>
        <md:surname>Appadwedula</md:surname>
        <md:fullname>Swaroop Appadwedula</md:fullname>
        <md:email>appadwed@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mjberry">
        <md:firstname>Matthew</md:firstname>
        <md:othername>J.</md:othername>
        <md:surname>Berry</md:surname>
        <md:fullname>Matthew Berry</md:fullname>
        <md:email>mjberry@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="markhaun">
        <md:firstname>Mark</md:firstname>
        <md:othername>A.</md:othername>
        <md:surname>Haun</md:surname>
        <md:fullname>Mark Haun</md:fullname>
        <md:email>markhaun@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="dsachs">
        <md:firstname>Daniel</md:firstname>
        <md:othername>Grobe</md:othername>
        <md:surname>Sachs</md:surname>
        <md:fullname>Daniel Sachs</md:fullname>
        <md:email>sachs@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mrussell">
        <md:firstname>Mike</md:firstname>
        <md:surname>Russell</md:surname>
        <md:fullname>Mike Russell</md:fullname>
        <md:email>merussel@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="butala">
        <md:firstname>Mark</md:firstname>
        <md:othername>D.</md:othername>
        <md:surname>Butala</md:surname>
        <md:fullname>Mark Butala</md:fullname>
        <md:email>butala@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="rlmorris">
        <md:firstname>Robert</md:firstname>
        <md:othername>L.</md:othername>
        <md:surname>Morrison</md:surname>
        <md:fullname>Robert Morrison</md:fullname>
        <md:email>rlmorris@uiuc.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  <md:license href="http://creativecommons.org/licenses/by/1.0"/>
  <md:licensorlist>
    <md:licensor id="dljones">
        <md:firstname>Douglas</md:firstname>
        <md:othername>L.</md:othername>
        <md:surname>Jones</md:surname>
        <md:fullname>Douglas L. Jones</md:fullname>
        <md:email>dl-jones@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="appadwed">
        <md:firstname>Swaroop</md:firstname>
        <md:surname>Appadwedula</md:surname>
        <md:fullname>Swaroop Appadwedula</md:fullname>
        <md:email>appadwed@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="mjberry">
        <md:firstname>Matthew</md:firstname>
        <md:othername>J.</md:othername>
        <md:surname>Berry</md:surname>
        <md:fullname>Matthew Berry</md:fullname>
        <md:email>mjberry@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="markhaun">
        <md:firstname>Mark</md:firstname>
        <md:othername>A.</md:othername>
        <md:surname>Haun</md:surname>
        <md:fullname>Mark Haun</md:fullname>
        <md:email>markhaun@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="moussa">
        <md:firstname>Dima</md:firstname>
        <md:surname>Moussa</md:surname>
        <md:fullname>Dima Moussa</md:fullname>
        <md:email>dmoussa@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="dsachs">
        <md:firstname>Daniel</md:firstname>
        <md:othername>Grobe</md:othername>
        <md:surname>Sachs</md:surname>
        <md:fullname>Daniel Sachs</md:fullname>
        <md:email>sachs@uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="jake">
        <md:firstname>Jake</md:firstname>
        <md:surname>Janevitz</md:surname>
        <md:fullname>Jake Janovetz</md:fullname>
        <md:email>jake@janovetz.com</md:email>
    </md:licensor>
    <md:licensor id="kramer">
        <md:firstname>Michael</md:firstname>
        <md:othername>L.</md:othername>
        <md:surname>Kramer</md:surname>
        <md:fullname>Michael Kramer</md:fullname>
        <md:email>kramer@ifp.uiuc.edu</md:email>
    </md:licensor>
    <md:licensor id="bwade">
        <md:firstname>Brian</md:firstname>
        <md:surname>Wade</md:surname>
        <md:fullname>Brian Wade</md:fullname>
        <md:email>bwade@uiuc.edu</md:email>
    </md:licensor>
  </md:licensorlist>
  <md:keywordlist>
    <md:keyword>audio effects</md:keyword>
    <md:keyword>delay</md:keyword>
    <md:keyword>DSP</md:keyword>
    <md:keyword>echo</md:keyword>
    <md:keyword>external memory</md:keyword>
    <md:keyword>memory map</md:keyword>
    <md:keyword>READPROG</md:keyword>
    <md:keyword>WRITPROG</md:keyword>
  </md:keywordlist>
  <md:subjectlist>
    <md:subject>Science and Technology</md:subject>
  </md:subjectlist>
  <md:abstract>You will implement three audio effects: a fixed-length delay, a variable-length delay, and a feedback-echo.  All require storing many samples in external memory.</md:abstract>
  <md:language>en</md:language>
  <!-- WARNING! The 'metadata' section is read only. Do not edit above.
       Changes to the metadata section in the source will not be saved. -->
</metadata>

<content>

    <section id="sec1">
      <title>Introduction</title>
      <para id="para1">
	Many audio effects require storing thousands of samples in
	memory on the DSP.  Because there is not enough memory on the
	DSP microprocessor itself to store so many samples, external
	memory must be used.
      </para>
      <para id="para2">
	In this exercise, you will use external memory to implement a
	long audio delay and an audio echo.  Refer to <link document="m10823">Core File: Accessing External Memory on TI
	TMS320C54x</link> for a description and examples of accessing
	external memory.
      </para>
    </section>
    <section id="sectionb">
      <title>Delay and Echo Implementation</title>
      <para id="para17">
	You will implement three audio effects: a long, fixed-length
	delay, a variable-length delay, and a feedback-echo.
      </para>
      <section id="section7">
	<title>Fixed-length delay implementation</title>
	<para id="para18">
	  First, implement the 131,072-sample delay shown in <link target-id="fig1"/> using the <code>READPROG</code> and
	  <code>WRITPROG</code> macros.  Use memory locations
	  <code>010000h</code>-<code>02ffffh</code> in external
	  Program RAM to do this; you may also want to use the
	  <code>dld</code> and <code>dst</code> opcodes to store and
	  retrieve the 32-bit addresses for the accumulators. Note
	  that these two operations store the words in memory in
	  big-endian order, with the high-order word first.
	</para>
	<figure id="fig1">
	  <media id="id1164115359815" alt="">
            <image src="delay.png" mime-type="image/png"/>
            <image src="delay.eps" mime-type="application/postscript"/>
          </media>
	  <caption>Fixed-Length Delay</caption>
	</figure>
	<para id="para19">
	  Remember that arithmetic operations that act on the
	  accumulators, such as the <code>add</code> instruction,
	  operate on the complete 32- or 40-bit value. Also keep in
	  mind that since 131,072 is a power of two, you can use
	  masking (via the <code>and</code> instruction) to implement
	  the circular buffer easily.  This delay will be easy to
	  verify on the oscilloscope. (How long, in seconds, do you
	  expect this delay to be?)
	</para>
      </section>
      <section id="section8">
	<title>Variable-delay implementation</title>
	<para id="para20">
	  Once you have your fixed-length delay working, make a copy
	  and modify it so that the delay can be changed to any length
	  between zero (or one) and 131,072 samples by changing the
	  value stored in one double-word pair in memory. You should
	  keep the buffer length equal to 131,072 and change only your
	  addressing of the sample being read back; it is more
	  difficult to change the buffer size to a length that is not
	  a power of two.
	</para>
	<para id="para21">
	  Verify that your code works as expected by timing the delay
	  from input to output and ensuring that it is approximately
	  the correct length.
	</para>
      </section>
      <section id="echo">
	<title>Feedback-echo implementation</title>
	<para id="paraecho1">
	  Last, copy and modify your code so that the value taken from
	  the end of the variable delay from <link target-id="section8">Variable-delay implementation</link> is
	  multiplied by a gain factor and then added back into the
	  input, and the result is both saved into the delay line and
	  sent out to the digital-to-analog converters. <link target-id="fig2"/> shows the block diagram.  (It
	  may be necessary to multiply the input by a gain as well to
	  prevent overflow.)  This will make a one-tap feedback echo,
	  an simple audio effect that sounds remarkably good.  To test
	  the effect, connect the DSP EVM input to a CD player or
	  microphone and connect the output to a loudspeaker.  Verify
	  that the echo can be heard multiple times, and that the
	  spacing between echoes matches the delay length you have
	  chosen.
	</para>
	<figure id="fig2">
	  <media id="id1164115359778" alt="">
            <image src="echo.png" mime-type="image/png"/>
            <image src="echo.eps" mime-type="application/postscript"/>
          </media>
	  <caption>Feedback Echo</caption>
	</figure>
      </section>
    </section>
  </content>
  
</document>
