Download presentation
Presentation is loading. Please wait.
Published byErik Orsós Modified over 5 years ago
1
Lab. 1 Modeling an audio channel with delays on ADSP21061
* 07/16/96 This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during your presentation In Slide Show, click on the right mouse button Select “Meeting Minder” Select the “Action Items” tab Type in action items as they come up Click OK to dismiss this box This will automatically create an Action Item slide at the end of your presentation with your points entered. Lab. 1 Modeling an audio channel with delays on ADSP21061 M. R. Smith, Electrical and Computer Engineering University of Calgary, Alberta, Canada ucalgary.ca *
2
To be tackled today Concept of Lab. 1
Build variants of algorithms for FIFO (Delay Buffer) Mass Memory Move (written in “C” -- provided) Mass Memory Move (written in “asm” -- direct translation) FIFO using software circular buffer (written in “C” -- provided) FIFO using software circular buffer (written in “asm” -- direct translation) Test that algorithms work correctly using “OFF-LINE” (using the board in the lab. and the simulator outside) Time the various algorithms -- How good is “optimizing compiler” compared to hand-coding. Test the effect in an “audio-sense” using “LOCAL” and CODEC”. Here the effect of “length of time in ISR” becomes important for sound quality Laboratory 2 -- same as Lab. 1 but using custom DSP features of the processor for implementing “circular buffers” Details of “2001main.c”,“channelmodels.c” and audio libraries. 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
3
Labs. 1 and 2 -- Model channel delays
No delay between left/right ear sound arrivals -- then sound perceived in centre of head Delay introduced into right ear sound channel will shift sound to left as “sound” seems to get to left ear first. DELAY1 O DELAY DELAY2 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
4
Sound Source Left Ear Right Ear Sound Source Left Ear Right Ear
ProcessSound(channel1_in, channel2_out, *outleft, *outright) Left Ear Right Ear 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
5
Basic Algorithm -- Channel Delays
Input LEFT < LEFT DELAY > Output DELAYED LEFT Input RIGHT < DELAY > Output DELAYED RIGHT 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
6
Basic Algorithm -- Channel Delay
< LEFT DELAY > < DELAY > Requires 2 * (LD + RD - 2) memory operations 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
7
Physics of the Problem <---- Posn (P) ---> Sound Source
Dright = SQRT(D^2 + (P - 0.1)^2) Dleft = SQRT(D^2 + (P + 0.1)^2) Dleft Dright D HEAD < cm -----> 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
8
Relative Delay Necessary
Distance to Sound Sound Time Delay = Speed of Sound Left/Right Delay Algorithm Delay = Sampling Rate Left/Right Delay = (Dleft_distance - Dright_distance) / Speed of Sound Two sound sources -- imply two relative delays Speed of sound = 300 m/s Sampling Rate = 44 kHz Calculate Number of Delays needed for D = 0, D = 1 m when sound source position varies (P = 0, P = 0.1, P = 0.2)? 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
9
Handle Channel Delay -- Can it be done?
< LEFT/RIGHT DELAYS > “C” Code for channel delay algorithm described in previous lecture Requires 2 * (LD + RD - 2) memory operations of the form R0 = dm(1, I4); dm(I4, 1) = R in loop (Why not use dm(-1, I4) = dm(I4, 1) ? ) To avoid audio distortion, the algorithms must be completed within 1/2 of interrupt period when interrupts occurring at 44 kHz If have 40MHz SHARC processor cycle per instruction Less than 500 cycles available 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
10
Modeling Audio Channel Delays using Mass Memory Moves
#define MAXDELAY 0x80 void MemoryMove_LeftDelay(int process_var1, int *channel_one) { int count; static int left_delayline[MAXDELAY] = {0}; // Insert new value into the back of the FIFO delay line left_delayline[0 + process_var1] = *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = left_delayline[0]; // Update the FIFO delay line using inefficient memory moves for (count = 0; count < process_var1; count++) left_delayline[count] = left_delayline[count + 1]; } 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
11
Alternative approach Software Circular Buffer
Output POINTER Input POINTER < DELAY > Output value Input value Output POINTER++ Input POINTER++ 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
12
Output pt Input pt A2 Output pt Input pt A3 Output pt Input pt A4
Gets nasty when need to access more than one value from delay line (e.g. during FIR -- Lab. 3) 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
13
Audio channel delay modeled using software circular buffers
void SoftCircularBuffer_LeftDelay(int process_var1, int *channel_one) { int count; static int left_delayline[MAXDELAY] = {0}; static int *left_pt_in = &left_delayline[0 + process_var1]; ? legal static int *left_pt_out = &left_delayline[0]; static int *overflow_pt = &left_delayline[MAXDELAY]; ? why // One out problem? MAXDELAY - 1, MAXDELAY, MAXDELAY + 1? // Insert new value into the back of the FIFO delay line *left_pt_in = *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = *left_pt_out; // Update the FIFO delay line using pointer arithmetic for circ. Buff left_pt_in++; if (left_pt_in >= overflow_pt) left_pt_in = left_pt_in - MAXDELAY; } 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
14
Timing for the algorithms
Memory moves LD + RD - 2 memory access operations 2 * (LD + RD - 2) instructions roughly Expect to find sound distortions for large delays Pointers -- software circular buffers 4 pointer update operations 4 point checks for out of bounds Pointers -- hardware circular buffers NO OVERHEAD AT ALL -- Lab. 2 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
15
Prelaboratory 1 -- done in “C”
Check web page for exact details Hand-in by 2 p.m. for immediate marking (100% time penalty) Test “C-algorithms” for implementing the audio channel delay (Using memory moves and software circular buffers to handle FIFO implementation) Simulation -- not hardware Model delay in only 1 channel (as ear can’t hear absolute delays only relative delays Remember ONLY 20 floating licences Test means -- Provide screen dumps showing plots of input, left output and right output array for IMPULSE input for various delays (0, 100, 200 samples) -- Profile information would also be good. 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
16
Lab. 1 -- Audio Channel Delay modeling on ADSP21061 processor
* 07/16/96 Lab Audio Channel Delay modeling on ADSP21061 processor Build variants of algorithms for FIFO (Delay Buffer) running on the simulator Mass Memory Move (written in “C” -- provided) Mass Memory Move (written in “asm” -- direct translation) FIFO using software circular buffer (written in “C” -- provided) FIFO using software circular buffer (written in “asm” -- direct translation) For the assembly code routine YOU wrote, calculate the number of cycles spend inside the FIFO routines for delays of size 0, 100 and 200. Graph the results. Use the graph to “predict” maximum number of delay intervals before will be in FIFO routine for more than half 1/2 of the time available from 44kHz interrupt handler. Overflow = predicted sound distortion running ON-LINE with a MONO | LEFT_DELAY | LOCAL_SOUND source. 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith -- *
17
Lab. 1 -- Audio Channel Delay modeling on ADSP21061 processor
* 07/16/96 Lab Audio Channel Delay modeling on ADSP21061 processor Profile the 4 algorithms on the simulator to determine the actual time spend in the FIFO routines. Compare to your predictions. (Don’t change (fake) your predictions). Graph the results. Use the graph to “predict” when distortions would occur in a real time implementation. Overflow = predicted sound distortion running ON-LINE with a MONO | LEFT_DELAY | LOCAL_SOUND source. Check your predictions by running the LOCAL_SOUND program using MONO | LEFTDELAY options Write a (short) report analysing the laboratory results. 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith -- *
18
Order of Lab. hand-in -- Labs 1/2 at the same time
Cover letter with hand-written and signed note that is your own group’s work and that you have not allowed others to use the material. Include your name, lab. section and lab. station so can hand back more easily. “C” code for memorymove and softcirc routines -- don’t calculate time spent in routine. Assembly code for memorymove (lab. 1), softcirc (lab. 1) and hardcirc (lab. 2) routines showing calculation of time spend in these specific routines along side the code. Remember cache overheads etc. Recommend using “hardware loops” Graph and associated predictions for above Profiling information for 9 routines (C-code with and without optimization) Graph and associated predictions for above (C on DSP1.0 and DSP2.0) Comparison between timing predictions and actual timing -- you could expect to be within in 1 cycle (explanation in Lab. 1, prediction in Lab. 4) Explain discrepancies --- most of them anyway. Results from Audio Test for channel breakdown predictions Don’t spend too much time here. An accuracy of TU is more than adequate as we don’t really know how much time is available in ISR Marking sheet for report, Marking sheet showing demo’s to T.A.’s 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
19
Files used in every lab. 2001main.c
Activates the sound sources and audio channel modeling channelmodels.c and fasterchannelmodels.asm The algorithms used in the audio channel modeling processdefs.h Constants used to define the channel modeling operations ADSP-21061interrupts.ldf ADSP21061 Architectural File for EZ-LITE SHARC 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
20
2001main.c -- Page 1 void main(void) {
// Set the WHICHSOURCE option as -D WHICHSOURCE=??? as a COMPILER option // Other options available for sources #if (WHICHSOURCE & LOCAL_SOURCE) // Weird mono and stereo source whichsource = LOCAL_SOURCE | FM_STEREO; #elif (WHICHSOURCE & CODEC_SOURCE) // Hook up CD stereo (need cable) whichsource = CODEC_SOURCE | FM_STEREO; #elif (WHICHSOURCE & OFFLINE_SOURCE) // For testing without the hardware whichsource = OFFLINE_SOURCE | SQUAREWAVE | FM_STEREO; #endif SmithUtilitiesIRQ(whichsource); SetLocalSourceBuffers(); // DO NOT ADD lines between AttachSoundSource() and while-loop ************* #define DELAYUNITS 44 #define IIR_COEFF 0.1 AttachSoundSource(whichsource, DELAYUNITS, IIR_COEFF); while (ReadSoundSource(&channel_one, &channel_two) != 0){ ProcessSound(channel_one, channel_two, &left_channel, &right_channel); WriteSoundSource(left_channel, right_channel); } 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
21
processdefs.h file -- Constants
SOUND SOURCES OFFLINE_SOURCE 0x LOCAL_SOURCE 0x CODEC_SOURCE 0x STEREO 0x MONO 0x FM_STEREO 0x LEFT_ONLY 0x RIGHT_ONLY 0x LEFT_DELAY 0x RIGHT_DELAY 0x SINEWAVE 0x IMPULSE 0x SQUAREWAVE 0x USERDEFINED 0x AUDIO CHANNEL CHARACTERISTICS MOVEDELAY 0x SOFTWARE_CIRCBUFFERDELAY x HARDWARE_CIRCBUFFERDELAY 0x OVERSIMPLEIIR 0x FIRFILTER 0x IIRFILTER 0x // Use your own defined characteristics USER1 0x USER x USER3 0x USER4 0x DON’T CHANGE/ADD TO THESE CONSTANTS -- ALL THE UTILITIES RELY ON THEM 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
22
2001main.c -- Page 2 extern int sound_source, process_var1; // Globals set by ActivateSound( ) extern float process_var2; void ProcessSound(int channel_one, int channel_two, int *left_channel, int *right_channel) { if (sound_source & FM_STEREO) DecodeFMSTEREO(channel_two_strength, &channel_one, &channel_two); if (sound_source & OVERSIMPLEIIR) OverSimpleIIR(/* IIRcoeff */ process_var2, &channel_one, &channel_two); if ((sound_source & LEFT_DELAY) == LEFT_DELAY) { if ((sound_source & MOVEDELAY) == MOVEDELAY) MemoryMove_LeftDelay(process_var1, &channel_one); else if ((sound_source & SOFTWARE_CIRCBUFFERDELAY) { SoftCircularBuffer_LeftDelay(process_var1, &channel_one); } else if (sound_source & HARDWARE_CIRCBUFFERDELAY) { printf("Hardware Circular buffer delay_line operations defined in Lab. 2"); exit(0); } // Have finished modifying the channels *left_channel = channel_one; *right_channel = channel_two; if ((sound_source & RIGHT_ONLY) *left_channel = 0; 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
23
Switching between “C” version and “assembly code” version
Run the “C” code and get working. Make a copy of the “C” code into file lab1.asm Turn all code into comment statements Do a “1-to-1” translation of “C” into assembly code. Apply your PSP to avoid the standard errors. Assemble/link and record syntax errors that need to be added to PSP process. Use #if USE_C / #endif statements around “C” code and #if USE_ASM / #endif in “.asm” file 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
24
Audio channel delay modeled using software circular buffers
#if USE_C void SoftCircularBuffer_LeftDelay(int process_var1, int *channel_one) { int count; static int left_delayline[MAXDELAY] = {0}; static int *left_pt_in = &left_delayline[0 + process_var1]; ? legal static int *left_pt_out = &left_delayline[0]; static int *overflow_pt = &left_delayline[MAXDELAY]; ? why // One out problem? MAXDELAY - 1, MAXDELAY, MAXDELAY + 1? // Insert new value into the back of the FIFO delay line *left_pt_in = *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = *left_pt_out; // Update the FIFO delay line using pointer arithmetic for circ. Buff left_pt_in++; if (left_pt_in >= overflow_pt) left_pt_in = left_pt_in - MAXDELAY; } #endif 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
25
Lab1_Offline.dpj using “C”
Files needed in Lab. 1 Lab1_Offline.dpj using “C” 2001main.c channelmodels.c lab1.asm ADSP-21061interrupts.ldf general_library.dlb offline_library.dlb All files compiled using compiler options -D WHICHSOURCE= OFFLINE_SOURCE -D USE_C HINT -- BUILD ALL Offline.dpj with “asm” 2001main.c channelmodels.c lab1.asm ADSP-21061interrupts.ldf general_library.dlb offline_library.dlb All files compiled using compiler options -D WHICHSOURCE= OFFLINE_SOURCE -D USE_ASM HINT -- BUILD ALL 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
26
Building the OFFLINE project
Windows -- Programs | Visual |Environment VisualDSP -- File | New | Project Save as lab1.dpj in lab1 directory Project Options -- KEY Processor ADSP-21061 Type DSP executable Configuration Debug Compiler Options -- Add -D WHICHSOURCE= OFFLINE_SOURCE D USE_C or -D USE_ASM Use the + icon to add the six files Force “rebuild all” option 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
27
Tackled today Concept of Lab. 1
Build variants of algorithms for FIFO (Delay Buffer) Mass Memory Move (written in “C” -- provided) Mass Memory Move (written in “asm” -- direct translation) FIFO using software circular buffer (written in “C” -- provided) FIFO using software circular buffer (written in “asm” -- direct translation) Test that algorithms work correctly using “OFF-LINE” (using the board in the lab. and the simulator outside) Time the various algorithms -- How good is “optimizing compiler” compared to hand-coding. Test the effect in an “audio-sense” using “LOCAL” and CODEC”. Here the effect of “length of time in ISR” becomes important for sound quality Laboratory 2 -- same as Lab. 1 but using custom DSP features of the processor for implementing “circular buffers” Details of “2001main.c”,“channelmodels.c” and audio libraries. 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
28
Profiling -- Adding a range
Ranges can be in PM or DM memory Don’t forget to enable profiling and THEN run the program Don’t profile the call from main( ) 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
29
Profiling a range -- 2 -- Find Start
4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
30
Profiling a range -- 3 -- Find End
4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
31
Analysis of Profile Range -- 4
Select VIEW | DEBUG |PROFILE 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
32
Analysis of Profile Range -- 5
Tells us very little, except that only small part of this program (768 points only) Cycles -- time including clashes? Exec Count -- instructions Read? Read Count and Write Count? 4/13/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.