Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab. 2 Modeling an audio channel with delays on ADSP21061

Similar presentations


Presentation on theme: "Lab. 2 Modeling an audio channel with delays on ADSP21061"— Presentation transcript:

1 Lab. 2 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. 2 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 Essence of Lab. 2 – see web for precise details
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 3 -- same as Lab. 2 but using custom DSP features of the processor for implementing “circular buffers” Details of “main.cpp”,“processsound.c” and audio libraries. 1/15/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 1/15/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 1/15/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 1/15/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 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

7 Better Algorithm -- Channel Delay
< LEFT DELAY > < R. DELAY > Requires 2 * (Max(LD, RD) - 2) memory operations Don’t use this approach in Lab. 2, we are trying to look At other issues and other efficiencies 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

8 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 -----> 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

9 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)? 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

10 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 ?? cycles available 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

11 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]; } 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

12 Alternative approach Software Circular Buffer
Output POINTER Input POINTER < DELAY > Output value Input value Output POINTER++ Input POINTER++ 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

13 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. 4 – uses 32 pointer operations) 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

14 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; } 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

15 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. 3 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

16 Prelaboratory 2 -- done in “C”
Check web page for exact details Hand-in by 2 p.m. for immediate marking (100% time penalty) Test “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 2 channel (as ear can’t hear absolute delays only relative delays Remember ONLY 20 floating licenses 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. 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

17 Lab. 2 -- 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. 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith -- *

18 Lab. 2 -- Audio Channel Delay modeling on ADSP21061 processor
* 07/16/96 Lab Audio Channel Delay modeling on ADSP21061 processor Profile 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. 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith -- *

19 Files used in every lab. main.c process.c and fasterchannelmodels.asm
Activates the sound sources and audio channel modeling process.c and fasterchannelmodels.asm The algorithms used in the audio channel modeling processdefs.h Constants used to define the channel modeling operations 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

20 main.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 ************* #define DELAYUNITS 44 AttachSoundSource(whichsource, ……); MySetUp( ) while (ReadSoundSource(&channel_one, &channel_two) != 0){ ProcessSound(channel_one, channel_two, &left_channel, &right_channel); WriteSoundSource(left_channel, right_channel); } 1/15/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 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

22 Processsound.cpp -- 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; 1/15/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. See the lab. notes for a “quick and easy” process to switch back and forth between C++ and assembly code 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

24 Another useful utility
VisualDSP has the ability to “profile” how long you spent accessing instructions in any given range of memory Identify the start and end of your program – start and end of a loop Profile the code Only makes sense when you know “exactly” how many times the code is being executed in theory 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

25 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( ) 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

26 Profiling a range -- 2 -- Find Start
1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

27 Profiling a range -- 3 -- Find End
1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

28 Analysis of Profile Range -- 4
Select VIEW | DEBUG |PROFILE 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --

29 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? 1/15/2019 ENCM SHARC Audio Channel Modeling in Lab 1 Copyright M. Smith --


Download ppt "Lab. 2 Modeling an audio channel with delays on ADSP21061"

Similar presentations


Ads by Google