<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<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/" id="m10480">
  
  <name>Audio Effects: Using External Memory</name>
  <metadata>
  <md:version>2.14</md:version>
  <md:created>2002/02/01</md:created>
  <md:revised>2004/02/25 11:07:13.411 US/Central</md:revised>
  <md:authorlist>
      <md:author id="dljones">
      <md:firstname>Douglas</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Jones</md:surname>
      <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: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: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:email>markhaun@uiuc.edu</md:email>
    </md:author>
      <md:author id="moussa">
      <md:firstname>Dima</md:firstname>
      
      <md:surname>Moussa</md:surname>
      <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:email>sachs@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="mjberry">
      <md:firstname>Matthew</md:firstname>
      <md:othername>J.</md:othername>
      <md:surname>Berry</md:surname>
      <md:email>mjberry@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="appadwed">
      <md:firstname>Swaroop</md:firstname>
      
      <md:surname>Appadwedula</md:surname>
      <md:email>appadwed@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:email>markhaun@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="dljones">
      <md:firstname>Douglas</md:firstname>
      <md:othername>L.</md:othername>
      <md:surname>Jones</md:surname>
      <md:email>dl-jones@uiuc.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mrussell">
      <md:firstname>Mike</md:firstname>
      
      <md:surname>Russell</md:surname>
      <md:email>merussel@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:email>sachs@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: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:email>rlmorris@uiuc.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>delay</md:keyword>
    <md:keyword>memory map</md:keyword>
    <md:keyword>external memory</md:keyword>
    <md:keyword>audio effects</md:keyword>
    <md:keyword>echo</md:keyword>
    <md:keyword>READPROG</md:keyword>
    <md:keyword>WRITPROG</md:keyword>
    <md:keyword>DSP</md:keyword>
  </md:keywordlist>

  <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>
</metadata>




  <content>

    <section id="sec1">
      <name>Introduction</name>
      <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 <cnxn document="m10823">Core File: Accessing External Memory on TI
	TMS320C54x</cnxn> for a description and examples of accessing
	external memory.
      </para>
    </section>
    <section id="sectionb">
      <name>Delay and Echo Implementation</name>
      <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">
	<name>Fixed-length delay implementation</name>
	<para id="para18">
	  First, implement the 131,072-sample delay shown in <cnxn target="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 type="image/png" src="delay.png"/>
	  <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">
	<name>Variable-delay implementation</name>
	<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">
	<name>Feedback-echo implementation</name>
	<para id="paraecho1">
	  Last, copy and modify your code so that the value taken from
	  the end of the variable delay from <cnxn target="section8">Variable-delay implementation</cnxn> 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. <cnxn target="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 type="image/png" src="echo.png"/>
	  <caption>Feedback Echo</caption>
	</figure>
      </section>
    </section>
  </content>
  
</document>
