%% $RCSfile: sdspvidly.tlc,v $ %% $Revision: 1.8 $ %% $Date: 1999/03/24 14:57:43 $ %% %% Dale Shpak %% July 17, 1998 %% Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved. %% %% Abstract: Variable integer delay %% %implements sdspvidly "C" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Name the S-function parameters %function BlockInstanceSetup (block, system) void %% %% %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %% Abstract: %% Initialize the delay buffer and counters to their initial values. %% %function InitializeConditions(block, system) Output %% We do not support discontiguous inputs %assign INPORT = 0 %assign DELAY_PORT = 1 %if (!IsInputPortContiguous(block,INPORT) || !IsInputPortContiguous(block,DELAY_PORT)) % %endif %% %assign BUFF_OFFSET = block.DWork[0] %assign DELAY_ELEMS = block.DWork[1] %assign PORT_WIDTH = LibDataInputPortWidth(INPORT) %assign NUM_CHANS = CAST("Number", SFcnParamSettings.nChans) %assign IC = SFcnParamSettings.IC %assign IC_COMPLEX = TYPE(IC[0]) == "Complex" %assign DATA_COMPLEX = LibBlockInputSignalIsComplex(INPORT) %assign NUM_IC = SIZE(IC, 1) %assign DMAX = SFcnParamSettings.maxDelay %assign BUFF_LEN = DMAX + 1 %assign NIC1 = SFcnParamSettings.nIC1 %assign NIC2 = SFcnParamSettings.nIC2 %assign NUM_IC = NIC1 * NIC2 %% %if (NUM_CHANS == -1) %assign NUM_CHANS = PORT_WIDTH %endif %if (DATA_COMPLEX) %assign DAT_T = "creal_T" %else %assign DAT_T = "real_T" %endif %if (IC_COMPLEX) %assign IC_T = "creal_T" %else %assign IC_T = "real_T" %endif %% { /* DSP Blockset Variable Integer Delay (%) - % */ %% % = %; { %if (NIC1 * NIC2 > 1) %assign astr = "" %assign count = 0 %if (DATA_COMPLEX) creal_T ic[%] = { %foreach Col = NIC1 %foreach Row = NIC2 %if (IC_COMPLEX) %assign astr = astr + "{%,%}" %else %assign astr = astr + "{%,0.0}" %endif %assign count = count + 1 %if (count < NUM_IC) %assign astr = astr + "," %else %assign astr = astr + "};" %endif %endforeach % %assign astr = "" %endforeach %else real_T ic[%] = { %foreach Col = NIC1 %foreach Row = NIC2 %assign astr = astr + "%" %assign count = count + 1 %if (count < NUM_IC) %assign astr = astr + "," %else %assign astr = astr + "};" %endif %endforeach % %assign astr = "" %endforeach %endif %endif %assign numElements = LibBlockDWorkWidth(DELAY_ELEMS) % *buff = %; %if (NUM_IC == 0) int_T j; for (j=0; j < %; j++) *buff++ = %; %elseif (NIC1 * NIC2 == 1) /* Use a single IC for all states */ int_T j; %if (DATA_COMPLEX) %if (IC_COMPLEX) const creal_T ic = {%,%}; %else const creal_T ic = {%,0.0}; %endif for (j=0; j < %; j++) *buff++ = ic; %else for (j=0; j < %; j++) *buff++ = %; %endif %elseif(NIC2 == 1) /* For each channel, use a single IC for every delay element */ int_T i, j; for (i=0; i < %; i++) { for (j=0; j < %; j++) *buff++ = ic[i]; ++buff; } %else /* * Matrix of IC's: * Assume maxDELAY rows and numCHANS columns (MATLAB) */ int_T i, j; for (i=0; i < %; i++) { const % *icp = ic + i; for (j=0; j < %; j++) { *buff++ = *icp; icp += %; } ++buff; } %endif } } %endfunction %% Function: Outputs =========================================================== %% %function Outputs(block, system) Output %% %assign INPORT = 0 %assign DELAY_PORT = 1 %assign OUTPORT = 0 %assign BUFF_OFFSET = block.DWork[0] %assign DELAY_ELEMS = block.DWork[1] %assign PORT_WIDTH = LibDataInputPortWidth(INPORT) %assign COMPLEX = LibBlockInputSignalIsComplex(INPORT) %assign DMAX = SFcnParamSettings.maxDelay %assign UPDATE_SAMP = SFcnParamSettings.UpdatePerSample %assign BUFF_LEN = DMAX + 1 %assign NUM_CHANS = CAST("Number", SFcnParamSettings.nChans) %% %if (COMPLEX) %assign DAT_T = "creal_T" %else %assign DAT_T = "real_T" %endif %if (NUM_CHANS == -1) %assign NUM_CHANS = PORT_WIDTH %endif %assign FRAME = PORT_WIDTH / NUM_CHANS %% %assign CHAN_ROLL = 2 %% { /* DSP Blockset Variable Integer Delay (%) - % */ % *x = %; real_T *delay = %; % *buff = %; % *y = %; int_T dly; %if (!UPDATE_SAMP) dly = (int_T) (*delay + 0.5); /* Get rounded delay time */ /* Clip delay time to legal range: [0,dmax] */ dly = (dly < 0 ? 0 : (dly > % ? % : dly)); %endif %roll sigIdx1 = [ 1:% ], lc1 = CHAN_ROLL, block, "InlineRoller" { %if (UPDATE_SAMP) real_T *dtmp = delay; %endif int_T ti; int_T buffstart = %; %roll sigIdx2 = [ 1:% ], lc2 = CHAN_ROLL, block, "InlineRoller" /* Rotate circular buffer */ if (++buffstart == %) buffstart = 0; *(buff + buffstart) = *x++; %if (UPDATE_SAMP) dly = (int_T) (*dtmp++ + 0.5); /* Get rounded delay time */ /* Clip delay time to legal range: [0,dmax] */ dly = (dly < 0 ? 0 : (dly > % ? % : dly)); %endif ti = buffstart - dly; if (ti < 0) ti += %; /* Get required delayed value for output */ *y++ = *(buff + ti); %endroll %% FRAME %if (NUM_CHANS > 1) buff += %; %endif } %endroll %% CHANNELS % += %; %if (FRAME > BUFF_LEN) while (% >= %) % -= %; %else if (% >= %) % -= %; %endif } %endfunction %% Outputs %% [EOF] sdspvidly.tlc