<?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 (55x)</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2007/10/08 14:46:09.219 GMT-5</md:created>
  <md:revised>2007/10/11 15:12:07.065 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="tbshen">
      <md:firstname>Thomas</md:firstname>
      
      <md:surname>Shen</md:surname>
      <md:email>tbshen@uiuc.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="tbshen">
      <md:firstname>Thomas</md:firstname>
      
      <md:surname>Shen</md:surname>
      <md:email>tbshen@uiuc.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <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: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.      </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"/>. Store the samples in a buffer in SDRAM with alignment <code>0x40000h</code>. Do this by adding a line in your <code>userlinker.cmd</code> file to create a new section in memory:

Allocate a buffer of the size you need in the assembly file. Be sure to place it in the section you just created.

Since the memory address is now greater than 16-bits, you will need to do a <code>MOV dbl()</code> in order to get the full address into an auxiliary register.
	</para>
	<code type="block">.bigbuffer:  align=0x40000 {} &gt; SDRAM</code><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?) If you want, you may assume the delay will be a power-of-2 for easier implementation.
	</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>
