Presentation is loading. Please wait.

Presentation is loading. Please wait.

This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during.

Similar presentations


Presentation on theme: "This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during."— Presentation transcript:

1 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. Stereo Sound repositioning using hardware FIFO buffers Details of Laboratory 2 M. R. Smith, Electrical and Computer Engineering University of Calgary, Alberta, Canada smithmr @ ucalgary.ca

2 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 2 / 47 To be tackled today zConcept of Lab. 1 -- Software FIFO stack ySoftware Circular Buffers -- 2 approaches yFIFO stacks allowing the modeling of audio channels associated with sound positioning through delays zConcept of Lab. 2 -- Hardware FIFO stack ySame code except for variants of new routine yCompare software and hardware circular buffers yDeveloping new code in Assembly code yDelay line as FIR, FIR coeffs in dm or pm space zHardware circular Buffer Concepts introduced zRecap of hand-in for Laboratories 1 and 2

3 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 3 / 47 Labs. 1 and 2 -- delay line -- Concept zNo delay between left/right ear sound arrivals -- then sound perceived in centre of head zDelay in right ear sound arrival will shift sound to left as “sound” seems to get to left ear first O DELAY DELAY1 DELAY2

4 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 4 / 47 Laboratory 1 zImplemented software circular buffer yMemory Moves yPointer Moves yProfile the 2 algorithms in “C” and assembly code y“predicted” maximum number of delay intervals before would overflow time available in 44kHz ISR yPredicted Overflow = sound distortion in Lab. 1 when running ON-LINE with a LOCAL_SOURCE or CODEC_SOURCE (in stereo) zIn laboratory 3 will be implementing 4 delay lines with far more complex access (FIR filters) with ever item in FIFO continually accessed. Need faster algorithmic approach taking advantage of ADSP2106X architecture.

5 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 5 / 47 Delay by Moving Memory Elements Require 2 * (LD + RD - 2) memory operations Delay “C” Code described in earlier lecture Must be completed within 1/2 of interrupt period when interrupts occurring at 44 kHz If have 40MHz SHARC processor -- 1 cycle per instruction Less than 500 cycles available

6 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 6 / 47 Modeling Audio Channel Delays using Mass Memory Moves #define MAXDELAY 0x80 void MemoryMove_LeftDelay(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; // Insert new value into the back of the FIFO delay line left_delayline[0 + delay] = (float) *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = (int) left_delayline[0]; // Update the FIFO delay line using inefficient memory moves for (count = 0; count < delay; count++) left_delayline[count] = left_delayline[count + 1]; }

7 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 7 / 47 A2 A11 Input ptOutput pt A3 A12 Output pt A13 A4 Output pt A14 A5 Output pt Input pt Gets nasty when need to access more than one value from delay line (e.g. during FIR -- Lab. 3)

8 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 8 / 47 Audio channel delay modeled using software circular buffers void SoftCircularBuffer_LeftDelay(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; static float *left_pt_out = &left_delayline[0]; (Points to most delayed sample) static float *overflow_pt = &left_delayline[MAXDELAY]; float *left_pt_in = left_pt_out + delay;// CAREFULL point offset size if (left_pt_in >= overflow_pt) left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line *left_pt_in = (float) *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = (int) *left_pt_out; // Update the FIFO delay line using pointer arithmetic for circ. Buff left_pt_out++; if (left_pt_out >= overflow_pt) left_pt_out = left_pt_out - MAXDELAY; } // SPEED OF CODE -- INDEPENDENT OF DELAY SIZE

9 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 9 / 47 Timing for the 2 software algorithms zMemory moves yLD + RD - 2 memory access operations y2 * (LD + RD - 2) instructions roughly zPointers -- software circular buffers y4 pointer update operations y4 point checks for out of bounds zNow multiple this by needing to simulate several sound positions and use FIR filters y40 pointer update and checks with one 40-tap FIR yFIR filters are typically 200 or 300 taps -- just not going to be enough time

10 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 10 / 47 Audio channel delay modeled using FIR filter and software FIFO void FIRfilter(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; static float *left_pt_out = &left_delayline[0]; Points to most delayed sample static float *overflow_pt = &left_delayline[MAXDELAY]; static float left_coffs[FIRLENGTH] = {See Bessinger Thesis}; float *coeff_pt = &left_coeffs[0];// Why not static variable? float *left_pt_in = left_pt_out + delay; float *temp_pt; if (left_pt_in >= *overflow_pt) left_pt_in = left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line and zero channel *left_pt_in = (float) *channel_one; sum = 0.0; // Calculate the FIR filter result temp_pt = *left_pt_out;// Get to start of FIR data (delay line) for (count = 0; count < FIRLENGTH; count++) { sum = sum + *coeff_pt++ * *temp_pt++; if (temp_pt >= overflow_pt) temp_pt = temp_pt - MAXDELAY; } left_pt_out++; if (left_pt_out >= *overflow_pt) left_pt_out = left_pt_out - MAXDELAY; *channel_one = (int) sum; }

11 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 11 / 47 Theory of hardware circular buffers xB4 = 0x4000 xL4 = 0x3 xI4 = 0x4001 zR2 = 0; zR4 = dm(I4, PLUS1DM); I4 0x4001 used zR2 = R2 + R4; I4 becomes 0x4002 zR4 = dm(I4, PLUS1DM); I4 0x4002 used zR2 = R2 + R4; I4 becomes 0x4003 - 3 = 0x4000 zR4 = dm(I4, PLUS1DM); I4 0x4000 used zR2 = R2 + R4; I4 becomes 0x4001 etc ….

12 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 12 / 47 Other places where Circular buffers are needed Delay lines -- moving through delay line in steps of 1 x0, x1, x2, x3, x4, x5, x6, x7, x8 Matrix multiplication operations A0 A1 A2x0x1x2 A3 A4 A5x3x4x5 A6 A7 A8x6x7x8 A0*x1, A1*A4, A2*x7 then A3*x1, A4*A14, A5*x7 Moving through 1st memory array in steps of 1 A= dm(I1, 3) Moving through 2nd memory array in steps of 3 x= dm(I2, 3) x0, x1, x2, x3, x4, x5, x6, x7, x8, x0, x1, x2 etc

13 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 13 / 47 21k Processor architecture

14 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 14 / 47 DAG generator architecture zAnimation from SHARCNavigator from Web zAlso see DSP workshop book and exercises

15 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 15 / 47 4 Key Elements of the DAG zIndex Register yPointer -- Used to access the value at the memory location in the “array zModify Register yUsed to offset, post-increment, pre-increment index register IN SAME DAG M2 can be used with I5 but not with I8

16 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 16 / 47 4 Key Elements of the DAG zBase Register yPointer -- Set to start of array yNORMALLY IGNORED yCareful -- Setting this register automatically sets the CORRESPONDING index register zLength Register yNORMALLY SET TO 0 -- OR ELSE yMaking the length register non-zero AUTOMATICALLY ACTIVATES circular buffer operations yWorks with CORRESPONDING index and base register

17 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 17 / 47 Simple circular buffer example zFollowing example would give a garbage answer without circular buffers being in operation int array[10]; int pt = &array[0]’ int count; int sum = 0; for (count = 0; count < 30; count = count + 3) { sum = sum + pt; pt = pt + 3; } Implemented using “post modify” M4 = 3; Then the following in loop R2 = dm(I4, M4); R3 = R3 + R2

18 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 18 / 47 Set BASE (B2) to start of the array Set MODIFY (any M in DAG1) to 3 -- must use POST-MODIFY That automatically set INDEX (I2) to start of the array Set LENGTH (L2) to 10 -- NOT 0x10 --must be L2 0x1000 0x310

19 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 19 / 47 0x1000 0x310 First Memory access using I2 0x1000 ADD I2 to M2 (withing DAG)0x1000 + 3 =0x1003 Checknew I2 < B2 + I2 ? Update I2 = 0x1003 R = dm(I2, M2) -- post modify

20 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 20 / 47 0x10000x10030x310 Second Memory access using I2 0x1003 ADD I2 to M2 (with DAG)0x1000 + 0x3 = 0x1006 Check (new I2 < B2 + L2) and update I2 = 0x1006 Ditto third access using I2 leaving I2 = 0x1009 R = dm(I2, M2) -- post modify

21 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 21 / 47 0x10000x10090x310 Fourth Memory access using I2 I2 = 0x1009 new I2 = I2 + M2 0x1009 + 0x3 = 0x100C Check (new I2 < B2 + L2) NO!!! Adjust and Update new I2 = (newI2 - B2) % L2 + B2 new I2 = 0x1002 0x1002 R = dm(I2, M2) -- post modify

22 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 22 / 47 Circular Buffer Operations zModifynew I2 = I2 + M2 zIs new I2 >= B2 + L2 yYes new I2 = (I2 - B2) % L2 + B2 zMight be decrementing zIs new I2 < B2 yYesnew I2 = B2 + L2 - (I2 - B2) % L2 zThink this is the equivalent of 63 68k instructions occurring in a parallel (no-overhead) with out operations

23 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 23 / 47 Lab. 2 -- Speed Improvements zTest Lab. 1 algorithms -- memory delay and software circular buffers yIn “C” yIn “Assembly code” zImplements hardware circular buffer yDirect approach ySimulate first yThen test in real-time zBIG PROBLEM -- we need to use registers for buffers, yet these registers are also in use for the rest of “C”

24 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 24 / 47 Audio channel delay modeled using software circular buffers void SoftCircularBuffer_LeftDelay(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; static float *left_pt_out = &left_delayline[0]; (Points to most delayed sample) static float *overflow_pt = &left_delayline[MAXDELAY]; float *left_pt_in = left_pt_out + delay;// CAREFULL point offset size if (left_pt_in >= overflow_pt) left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line *left_pt_in = (float) *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = (int) *left_pt_out; // Update the FIFO delay line using pointer arithmetic for circ. Buff left_pt_out++; if (left_pt_out >= overflow_pt) left_pt_out = left_pt_out - MAXDELAY; } // SPEED OF CODE -- INDEPENDENT OF DELAY SIZE

25 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 25 / 47 Approach zCan’t do it in “C” -- must be equivalent of “C” but in assembly code zEnter into subroutine as normal with static parameters stored zSave B4 zSet up B4, I4, L4 and M4 for circular buffers and use then zRecover B4, set L4 = 0 zWhat is in ISR?

26 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 26 / 47 HARDWARE circular buffers -- DIRECT void SoftCircularBuffer_LeftDelay(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; static float *left_pt_out = &left_delayline[0]; (Points to most delayed sample) static float *overflow_pt = &left_delayline[MAXDELAY]; Save B4, save L4? B4 = &left_delay_line[0]; (Sets I4 = B4) L4 = MAXDELAY; float *pt_in_I4 = left_pt_out pt_in_I4 = pt_in_I4 + delay; // CAREFULL DAG math not ALU Math if (pt_in_I4 >= overflow_pt) pt_in_I4 - MAXDELAY; // Insert new value into the back of the FIFO delay line *pt_in_I4 = (float) *channel_one; // Grab delayed value from the front of the FIFO delay line *channel_one = (int) *left_pt_out; // Update the FIFO delay line using pointer arithmetic for circ. Buff left_pt_out++; if (left_pt_out >= overflow_pt) left_pt_out = left_pt_out - MAXDELAY; Recover B4 and L4 } // SPEED OF CODE -- INDEPENDENT OF DELAY SIZE

27 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 27 / 47 Audio channel delay modeled using FIR filter and hardware FIFO void FIRfilter(int delay, int *channel_one) { int count; static float left_delayline[MAXDELAY] = {0}; static float *left_pt_out = &left_delayline[0]; Points to most delayed sample static float *overflow_pt = &left_delayline[MAXDELAY]; static float left_coffs[FIRLENGTH] = {See Bessinger Thesis}; float *coeff_pt = &left_coeffs[0];// Why not static variable? float *left_pt_in = left_pt_out + delay; float *temp_pt; if (left_pt_in >= *overflow_pt) left_pt_in = left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line and zero channel *left_pt_in = (float) *channel_one; sum = 0.0; // Calculate the FIR filter result temp_pt = *left_pt_out;// Get to start of FIR data (delay line) for (count = 0; count < FIRLENGTH; count++) { sum = sum + *coeff_pt++ * *temp_pt++; if (temp_pt >= overflow_pt) temp_pt = temp_pt - MAXDELAY; } left_pt_out++; if (left_pt_out >= *overflow_pt) left_pt_out = left_pt_out - MAXDELAY; *channel_one = (int) sum; }

28 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 28 / 47 Lab. 2 -- Speed Improvements zTest Lab. 1 algorithms -- memory delay and software circular buffers yIn “C” yIn “Assembly code” zImplements hardware circular buffer yUse alternate DAG registers -- second set yI2 (M2, B2, L2) and I3 (M3, B3, L3) yAlso using some normal DAG and R registers ySimulate first yThen test in real-time

29 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 29 / 47 Lab. 2 -- Speed Improvements zTest Lab. 1 algorithms -- memory delay and software circular buffers yIn “C” yIn “Assembly code” zImplements hardware circular buffer yMethod 1 -- Direct yMethod 2 -- Use alternate DAG registers -- second set xI2 (M2, B2, L2) and I3 (M3, B3, L3) xAlso using some normal DAG and R registers xSimulate first xThen test in real-time

30 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 30 / 47 Alternate DAGS --Key Issues zMust set up circular buffers in a different way zWhen doing Method2HardwareBuffers( ) yNeed to switch to alternate buffers -- MODE ySwitch away from alternate buffers -- MODE zBig problem -- what if program is already using alternate buffers for some things and we are within an ISR ySave Existing Mode (to memory or register) ySwitch yRecover old mode

31 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 31 / 47 Lab2_2001main.c -- Page 1 void main(void) { SmithUtilitiesIRQ(whichsource); SetLocalSourceBuffers(); SetUpCircularBuffersForHardwareFIFO (processvar1, leftdelay_array ); // 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); }

32 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 32 / 47 Lab2_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 & 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) { /* HANDLED IN ASSEMBLY CODE */ delay is specified elsewhere (as hardware set up) HardwareCircularBuffer_LeftDelay(&channel_one); } }// Have finished modifying the channels *left_channel = channel_one; *right_channel = channel_two; if ((sound_source & RIGHT_ONLY) *left_channel = 0; }

33 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 33 / 47 Setting up circular buffers An example used in LOCAL_SOURCE #define TOalternateDAG3_0()bit set MODE1 SRD1L; nop #define FROMalternateDAG3_0() bit clr MODE1 SRD1L; nop // Set up some register names for doing circular buffers // base register int *left_notebase = GARBAGE; #define left_notebase b0 // length register int left_notelength = GARBAGE; #define left_notelength l0 // circular buffer pointer register int *left_notept = GARBAGE; #define left_notept i0 // base register int *right_notebase = GARBAGE; #define right_notebase b1 // length register int right_notelength = GARBAGE; #define right_notelength l1 // circular buffer pointer register int *right_notept = GARBAGE; #define right_notept i1 OBVIOUSLY YOUR CODE CAN’T USE ALTERNATE REGISTERS B0 and B1 AS THE LOCAL_SOURCE.DLB IS ALREADY USING THEM

34 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 34 / 47 Setting up circular buffers An example used in LOCAL_SOURCE.segment/pm seg_pmco;.global_SetLocalSourceBuffers;// void SetLocalSourceBuffers(void); _SetLocalSourceBuffers: // Switch to different DAG registers during interrupts // Note that Rn and Fn registers still the same as // used by the “C” utilities // so Rn and Fn must be saved to the stack if used inside any routine TOalternateDAG3_0(); left_notelength = BUFF_LEN;// Set left_note[] up as circ. buffer left_notebase =_left_notebuff; right_notelength = BUFF_LEN;// Set right_note[] up as circ. buffer right_notebase =_right_notebuff; FROMalternateDAG3_0(); Don’t use Alternate DAG registers 5 to 7 (Why not? ) What if we interrupted an ISR that had already switched DAGs?

35 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 35 / 47 What you will need to do SetUpCircularBuffersForHardwareFIFO (processvar1, leftdelay_array ); ySwitch to alternate DAG registers yPoint B2 to start of left_array (I2 follows) xB2 will be the “output” pointer yPoint B3 to start of left_array and then modify to be the “input pointer” yRemember that since using alternate DAGs then not clear if M6 = 1 etc still valid for use -- Suspect will be sometimes. Set up M3 = 1 for safety ySet up the length registers properly L? and L?

36 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 36 / 47 Write the set-up code.segment/pm seg_pmco;.global_SetLocalSourceBuffers; _SetLocalSourceBuffers: // non-volatile Rn and Fn must be saved to the stack SAVE initial MODE1 -- Look at manual TOalternateDAG3_0(); left_notelength = BUFF_LEN; left_notebase =_left_notebuff; right_notelength = BUFF_LEN; right_notebase =_right_notebuff; RECOVER initial MODE1 Set initial MODE1 Don’t use Alternate DAG registers 5 to 7 (Why not? )

37 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 37 / 47 HardwareCircularBuffer_LeftDelay(&channel_one); zPut the value into the hardware FIFO array zPull the value out of the hardware FIFO array zAdjust both pointers and let the hardware handle the wrap-around issue

38 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 38 / 47 Audio channel delay modeled using FIR filter and hardware FIFO void FIRfilter(int delay, int *channel_one) { int count; // static float left_delayline[MAXDELAY] = {0}; Done during set up // static float *left_pt_out = &left_delayline[0]; Points to most delayed sample Done during set up // static float *overflow_pt = &left_delayline[MAXDELAY]; Done during set up // static float left_coffs[FIRLENGTH] = {See Bessinger Thesis}; Done during set up // float *coeff_pt = &left_coeffs[0];// Done during set up // float *left_pt_in = left_pt_out + delay; Done during set up // float *temp_pt; Done during set up // if (left_pt_in >= *overflow_pt) left_pt_in = left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line and zero channel *left_pt_in = (float) *channel_one; sum = 0.0; // Calculate the FIR filter result temp_pt = *left_pt_out;// Get to start of FIR data (delay line) for (count = 0; count < FIRLENGTH; count++) { sum = sum + *coeff_pt++ * *temp_pt++; if (temp_pt >= overflow_pt) temp_pt = temp_pt - MAXDELAY; } left_pt_out++; if (left_pt_out >= *overflow_pt) left_pt_out = left_pt_out - MAXDELAY; *channel_one = (int) sum; CAREFUL OF ONE-OFF and unexpected bugs }

39 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 39 / 47 Write the FIFO code

40 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 40 / 47 HardwareCircularBuffer_LeftDelay(&channel_one); zPut the value into the hardware FIFO array zPull the value out of the hardware FIFO array zAdjust both pointers and let the hardware handle the wrap- around issue zMidterm question? yRather wasteful to use 2 pointers to access one array. (Remember later will want to have a total of 4 delay lines (FIR) and a number of delay lines used in COMB filters etc yCan you write the code (using ONLY POST MODIFY) to use one pointer for both input and output yIs the code any slower?

41 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 41 / 47 Write the setup code using 1 pointer

42 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 42 / 47 Write the FIFO code with 1 pointer

43 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 43 / 47 Interesting Side-issue!!!! This is in the middle of a interrupt service routine and we are passing parameters!! zInterrupt Service Routines communicate with the main program using semaphores and messages that are global variables zInterrupt Service Routines happen “when they want to” so you can’t code in any parameter passing. zAll the above is true -- but we are still passing parameters in an ISR -- HOW COME!!

44 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 44 / 47 Audio channel delay modeled using FIR filter, hardware FIFO, dm and pm void FIRfilter(int delay, int *channel_one) { int count; static dm float left_delayline[MAXDELAY] = {0}; static dm float *left_pt_out = &left_delayline[0]; Points to most delayed sample static dm float *overflow_pt = &left_delayline[MAXDELAY]; static pm float left_coffs[FIRLENGTH] = {See Bessinger Thesis}; pm float *coeff_pt = &left_coeffs[0];// Why not static variable? dm float *left_pt_in = left_pt_out + delay; pm float *temp_pt; if (left_pt_in >= *overflow_pt) left_pt_in = left_pt_in - MAXDELAY; // Insert new value into the back of the FIFO delay line and zero channel *left_pt_in = (float) *channel_one; sum = 0.0; // Calculate the FIR filter result temp_pt = *left_pt_out;// Get to start of FIR data (delay line) for (count = 0; count < FIRLENGTH; count++) { sum = sum + *coeff_pt++ * *temp_pt++; if (temp_pt >= overflow_pt) temp_pt = temp_pt - MAXDELAY; } left_pt_out++; if (left_pt_out >= *overflow_pt) left_pt_out = left_pt_out - MAXDELAY; *channel_one = (int) sum; }

45 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 45 / 47 Lab. 1/2 -- Audio Channel Delay modeling on ADSP21061 processor zBuild variants of algorithms for FIFO (Delay Buffer) running on the simulator yMass Memory Move (written in “C” and “asm”) yFIFO using software circular buffer (written in “C” and “asm”) yFIFO using hardware circular buffer (direct and improved) (written in “asm”) yImplement delay as 30 tap FIR filter coefficients (1.0, 0.0, …….) yImplement delay as 30 tap FIR filter with FIR coeffs in pm space zFor the assembly code routine YOU wrote, calculate the number of cycles spend inside the FIFO routines for delays of size 0, 100 and 200. zGraph 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. yOverflow = predicted sound distortion running ON-LINE with a MONO | LEFT_DELAY | LOCAL_SOUND source.

46 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 46 / 47 Lab. 1 / 2 -- Audio Channel Delay modeling on ADSP21061 processor zProfile the 7 algorithms on the simulator to determine the actual time spend in the FIFO routines. yCompare to your predictions. (Don’t change (fake) your predictions). yGraph the results. Use the graph to “predict” when distortions would occur in a real time implementation. zOverflow = predicted sound distortion running ON-LINE with a MONO | LEFT_DELAY | LOCAL_SOUND source. zCheck your predictions by running the LOCAL_SOUND program using MONO | LEFTDELAY options zWrite a (short) report analysing the laboratory results. What are you forgetting when timing, what inefficiencies

47 6/3/2015 ENCM515 -- Hardware FIFO buffers -- Details of Lab. 2 Copyright M. Smith -- smithmr@ucalgary,ca 47 / 47 Tackled today zConcept of Lab. 1 -- Software FIFO stack ySoftware Circular Buffers -- 2 approaches yFIFO stacks allowing the modeling of audio channels associated with sound positioning through delays zConcept of Lab. 2 -- Hardware FIFO stack yCompare software and hardware circular buffers yDeveloping new code in Assembly code yDelay line as FIR, FIR coeffs in dm or pm space zHardware circular Buffer Concepts introduced zRecap of hand-in for Laboratories 1 and 2


Download ppt "This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep track of these action items during."

Similar presentations


Ads by Google