%% $RCSfile: sdspdly2.tlc,v $ %% $Revision: 1.14 $ %% $Date: 2000/08/22 14:39:29 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Integer delay %implements sdspdly2 "C" %include "dsplib.tlc" %include "dsp_ic.tlc" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: Name the S-function parameters %% %function BlockInstanceSetup (block, system) void %% %assign INPORT = 0 %assign OUTPORT = 0 %assign IS_DIRECT_FEED = CAST("Boolean",(SFcnParamSettings.IsDirectFeedThrough == "Yes")) %assign delayLen = SIZE(SFcnParamSettings.Delays, 1) %assign portWidth = LibDataInputPortWidth(INPORT) %assign cplx_in = LibBlockInputSignalIsComplex(INPORT) %% %assign sl_dtype_in = LibBlockInputSignalDataTypeName(INPORT,"%") %assign dtype_in = (cplx_in) ? "c" + sl_dtype_in : sl_dtype_in %assign isFrame = LibBlockInputSignalIsFrameData(INPORT) %assign nChans = SFcnParamSettings.ICs_nChans %assign nSamps = portWidth / nChans %assign buflen = LibBlockDWorkWidth(BUFF)/nChans %assign incrementDelayPerChannel = SFcnParamSettings.incrementDelayPerChannel %assign incrementDelayPerSample = SFcnParamSettings.incrementDelayPerSample %assign block = block + INPORT + OUTPORT + IS_DIRECT_FEED + portWidth \ + dtype_in + buflen + delayLen + isFrame \ + nChans + nSamps + incrementDelayPerChannel \ + incrementDelayPerSample %% Setup the initial condition handler: %% % %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %% Abstract: %% Initialize the delay buffer and counters to their initial values. %% %function InitializeConditions(block, system) Output /* DSP Blockset Delay (%) - % */ %% %assign extra = (IS_DIRECT_FEED) ? 1 : (portWidth / nChans) %% % = %; %% % %% %endfunction %% Function: Update =========================================================== %% %function Update(block, system) Output %% %if (!IS_DIRECT_FEED) /* DSP Blockset Delay (%) - % */ %if ((nSamps==1) && (nChans==1)) /* Scalar input */ { int_T bufferStart = %; if (++bufferStart == %) bufferStart = 0; % = %; %++; while (% >= %) % -= %; } %elseif (nSamps==1) %% Sample-based non-scalar input %% or Frame-based row input /* %-channel input (1 sample per channel) */ { % *u = %; int_T bufferStart = %; int_T i; if (++bufferStart == %) bufferStart = 0; %assign indexString="bufferStart + i" for (i=0; i < %; i += %) { % = *u++; } %++; while (% >= %) % -= %; } %elseif (nChans==1) /* Frame-based column input (1 channel, % samples) */ { % *u = %; int_T bufferStart = %; int_T j = %; while (j-- > 0) { if (++bufferStart == %) bufferStart = 0; % = *u++; } % += %; while (% >= %) % -= %; } %else /* Frame-based %-by-% matrix input */ { % *u = %; int_T i; for (i=0; i < %; i += %) { /* Channel loop */ int_T bufferStart = %; int_T j = %; %assign indexString="bufferStart + i" while (j-- > 0) { /* Sample loop */ if (++bufferStart == %) bufferStart = 0; % = *u++; } } % += %; while (% >= %) % -= %; } %endif %else %% Block is in direct feedthrough mode - no update code required %endif %endfunction %% Update %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Delay (%) - % */ %% SCENARIO-SPECIFIC CODE: %% Valid scenarios: %% %% - Scalar input and scalar delay %% - Multi-channel input, 1 sample per channel, scalar delay %% - Multi-channel input, 1 sample per channel, non-scalar delay %% - Frame-based col vector input, scalar delay %% - Frame-based col vector input, column delay %% - Frame-based full-matrix input, scalar delay %% - Frame-based full-matrix input, row delay %% - Frame-based full-matrix input, column delay %% - Frame-based full-matrix input, matrix delay %% %if (nChans==1) && (nSamps==1) %% %% SCALAR INPUT AND SCALAR DELAY %% % %elseif (nSamps == 1) %% %% MULTI-CHANNEL SINGLE-SAMPLE CASES (nChans > 1; nSamps == 1) %% %if (incrementDelayPerSample == 0) && (incrementDelayPerChannel == 0) % %else % %endif %else %% %% FRAME-BASED CASES (nChans >= 1; nSamps > 1) %% %if nChans==1 %% SINGLE-CHANNEL FRAME-BASED CASE (FRAME-BASED COL VECTOR INPUT) %if (incrementDelayPerSample == 0) % %else % %endif %else %% FRAME-BASED FULL MATRIX INPUT %if (incrementDelayPerSample == 0) && (incrementDelayPerChannel == 0) % %elseif (incrementDelayPerSample == 0) && (incrementDelayPerChannel == 1) % %elseif (incrementDelayPerSample == 1) && (incrementDelayPerChannel == 0) && (delayLen == nSamps) % %else % %endif %endif %endif %endfunction %% Outputs %% Function: ScalarInputScalarDelay ========================================================== %% %function ScalarInputScalarDelay(block) Output %% %% nChans = 1; nSamps = 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = F; %% isFrame = F or T; %% %if (!IS_DIRECT_FEED) %% %% Block is NOT in direct feedthrough mode %% %if (% == 1) /* Scalar input, scalar delay (1 sample) */ { int_T ti = %; %else /* Scalar input, scalar delay (% samples) */ { int_T ti = % - %; %endif if (ti < 0) ti += %; % = %; } %else %% %% Block is in direct feedthrough mode %% /* Scalar input, zero delay */ % = %; %endif %endfunction %% ScalarInputScalarDelay %% Function: MultiChannelInputScalarDelay ========================================================== %% %function MultiChannelInputScalarDelay(block) Output %% %% nChans > 1; nSamps = 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = F; %% %if (!IS_DIRECT_FEED) %% %% Block is NOT in direct feedthrough mode %% %if (% == 1) /* %-channel input (1 sample per channel), scalar delay (1 sample) */ { int_T ti = %; %else /* %-channel input (1 sample per channel), scalar delay (% samples) */ { int_T ti = % - %; %endif % *y = %; int_T i; if (ti < 0) ti += %; %assign indexString = "ti + i" for (i=0; i < %; i += % ) { /* Channel loop */ *y++ = %; } } %else /* %-channel input (1 sample per channel), zero delay */ { % *u = %; % *y = %; int_T i = %; while (i-- > 0) { /* Channel loop */ *y++ = *u++; } } %endif %endfunction %% MultiChannelInputScalarDelay %% Function: MultiChannelInputNonScalarDelay ========================================================== %% %function MultiChannelInputNonScalarDelay(block) Output /* %-channel input (1 sample per channel), non-scalar delay */ { static % %% %% nChans > 1; nSamps = 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = T; %% %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T i; for (i=0; i < %; i++) { /* Channel loop */ int_T ti = % - delay[i] + 1; if (ti < 0) ti += %; %assign indexString = "ti + i*"+"%" *y++ = %; } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; int_T bufferStart = %; int_T i; if (++bufferStart == %) bufferStart = 0; for (i=0; i < %; i++) { /* Channel loop */ int_T ti = bufferStart - delay[i]; if (ti < 0) ti += %; %assign indexString1 = "bufferStart + i*"+"%" %assign indexString2 = "ti + i*"+"%" % = *u++; *y++ = %; } %++; while (% >= %) % -= %; } %endif %endfunction %% MultiChannelInputNonScalarDelay %% Function: FrameColumnInputScalarDelay ========================================================== %% %function FrameColumnInputScalarDelay(block) Output %% %% nChans = 1; nSamps > 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = F; %% isFrame = T; %% %if (% == 1) /* Frame-based column input (1 channel, % samples), scalar delay (1 sample) */ { %else /* Frame-based column input (1 channel, % samples), scalar delay (% samples) */ { %endif %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T j = 0; while (j++ < %) { /* Channel loop */ int_T ti = % - % + j; if (ti < 0) ti += %; *y++ = %; } } %else %% %% Direct feedthrough mode, delay is zero %% % *u = %; % *y = %; int_T j = %; %if (% == 0) while (j-- > 0) { /* Channel loop */ *y++ = *u++; } %else int_T bufferStart = %; while (j-- > 0) { /* Channel loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - %; if (ti < 0) ti += %; % = *u++; *y++ = %; } %endif % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameColumnInputScalarDelay %% Function: FrameColumnInputColumnDelay ========================================================== %% %function FrameColumnInputColumnDelay(block) Output /* Frame-based column input (1 channel, % samples), col delay vector */ { static % %% %% nChans = 1; nSamps > 1; %% incrementDelayPerSample = T; incrementDelayPerChannel = F; %% isFrame = T; %% %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T j = 0; while (j++ < %) { /* Channel loop */ int_T ti = % - delay[j-1] + j; if (ti < 0) ti += %; *y++ = %; } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; int_T bufferStart = %; int_T j = 0; while (j < %) { /* Channel loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - delay[j++]; if (ti < 0) ti += %; % = *u++; *y++ = %; } % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameColumnInputColumnDelay %% Function: FrameMatrixInputScalarDelay ========================================================== %% %function FrameMatrixInputScalarDelay(block) Output %% %% nChans > 1; nSamps > 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = F; %% isFrame = T; %% %if (% == 1) /* Frame-based %-by-% matrix input, scalar delay (1 sample) */ { %else /* Frame-based %-by-% matrix input, scalar delay (% samples) */ { %endif %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T i; for (i=0; i < %; i += %) { /* Channel loop */ int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti = % - % + j; if (ti < 0) ti += %; %assign indexString = "ti + i" *y++ = %; } } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; %if (% == 0) int_T i = %; while (i-- > 0) { /* Loop over %-by-% matrix elements */ *y++ = *u++; } %else int_T i; for (i=0; i < %; i += %) { /* Channel loop */ int_T bufferStart = %; int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - %; if (ti < 0) ti += %; %assign indexString1 = "bufferStart + i" %assign indexString2 = "ti + i" % = *u++; *y++ = %; } } %endif % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameMatrixInputScalarDelay %% Function: FrameMatrixInputRowDelay ========================================================== %% %function FrameMatrixInputRowDelay(block) Output /* Frame-based %-by-% matrix input, row delay vector */ { static % %% %% nChans > 1; nSamps > 1; %% incrementDelayPerSample = F; incrementDelayPerChannel = T; %% isFrame = T; %% %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T i; for (i=0; i < %; i++) { /* Channel loop */ int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti = % - delay[i] + j; if (ti < 0) ti += %; %assign indexString = "ti + i*"+"%" *y++ = %; } } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; int_T i; for (i=0; i < %; i++) { /* Channel loop */ int_T bufferStart = %; int_T j = %; while (j-- > 0) { /* Sample loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - delay[i]; if (ti < 0) ti += %; %assign indexString1 = "bufferStart + i*"+"%" %assign indexString2 = "ti + i*"+"%" % = *u++; *y++ = %; } } % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameMatrixInputRowDelay %% Function: FrameMatrixInputColDelay ========================================================== %% %function FrameMatrixInputColDelay(block) Output /* Frame-based %-by-% matrix input, col delay vector */ { static % %% %% nChans > 1; nSamps > 1; %% incrementDelayPerSample = T; incrementDelayPerChannel = F; %% isFrame = T; %% %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T i; for (i=0; i < %; i += %) { /* Channel loop */ int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti = % - delay[j-1] + j; if (ti < 0) ti += %; %assign indexString = "ti + i" *y++ = %; } } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; int_T i; for (i=0; i < %; i += %) { /* Channel loop */ int_T bufferStart = %; int_T j = 0; while (j < %) { /* Sample loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - delay[j++]; if (ti < 0) ti += %; %assign indexString1 = "bufferStart + i" %assign indexString2 = "ti + i" % = *u++; *y++ = %; } } % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameMatrixInputColDelay %% Function: FrameMatrixInputMatrixDelay ========================================================== %% %function FrameMatrixInputMatrixDelay(block) Output /* Frame-based %-by-% matrix input, matrix delay */ { static % %% %% nChans > 1; nSamps > 1; %% incrementDelayPerSample = T; incrementDelayPerChannel = F; %% isFrame = T; %% %if (!IS_DIRECT_FEED) %% %% Direct feedthrough? NO %% % *y = %; int_T i; for (i=0; i < %; i++) { /* Channel loop */ int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti = % - delay[i*% + j - 1] + j; if (ti < 0) ti += %; %assign indexString = "ti + i*"+"%" *y++ = %; } } } %else %% %% Direct feedthrough mode %% % *u = %; % *y = %; int_T i; for (i=0; i < %; i++) { /* Channel loop */ int_T bufferStart = %; int_T j = 0; while (j++ < %) { /* Sample loop */ int_T ti; if (++bufferStart == %) bufferStart = 0; ti = bufferStart - delay[i*% + j - 1]; if (ti < 0) ti += %; %assign indexString1 = "bufferStart + i*"+"%" %assign indexString2 = "ti + i*"+"%" % = *u++; *y++ = %; } } % += %; while (% >= %) % -= %; } %endif %endfunction %% FrameMatrixInputMatrixDelay %% [EOF] sdspdly2.tlc