%% $RCSfile: sdspvidly2.tlc,v $ %% $Revision: 1.7 $ %% $Date: 2000/05/09 18:55:45 $ %% %% Dale Shpak, R. Firtion %% Copyright (c) 1995-2000 The MathWorks, Inc. %% %% Abstract: Variable integer delay %% %implements sdspvidly2 "C" %include "dsplib.tlc" %include "dsp_ic.tlc" %% Function: BlockTypeSetup ================================================ %% Abstract: %% %function BlockTypeSetup(block, system) void %% Render the roundDelayValue function %% First, cache the function prototype for roundDelayValue: %% %openfile RoundDelayBuff extern int roundDelayValue(const real_T *delay, int_T dmax); %closefile RoundDelayBuff % %% Next, cache the roundDelayValue function itself: %% %openfile RoundDelayBuff /* Function: roundDelayValue * Rounds the delay values if they are greater than the maximum * or are not whole numbers. */ extern int roundDelayValue(const real_T *delay, int_T dmax) { /* Get rounded delay time: */ int_T dly = (int_T) (*delay + 0.5); /* Clip delay time to legal range: [0,dmax] */ dly = (dly < 0 ? 0 : (dly > dmax ? dmax : dly)); return(dly); } /* roundDelayValue */ %closefile RoundDelayBuff % %endfunction %% BlockTypeSetup %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Name the S-function parameters %function BlockInstanceSetup (block, system) void %% %assign INPORT = 0 %assign DELAY_PORT = 1 %assign OUTPORT = 0 %assign BUFF_OFFSET = block.DWork[0] %assign BUFF = block.DWork[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 dmax = SFcnParamSettings.maxDelay %assign buffLen = dmax + 1 %assign isFrame = LibBlockInputSignalIsFrameData(INPORT) %assign nChans = SFcnParamSettings.ICs_nChans %assign nSamps = portWidth / nChans %assign incrementDelayPerChannel = SFcnParamSettings.incrementDelayPerChannel %assign incrementDelayPerSample = SFcnParamSettings.incrementDelayPerSample %assign block = block + INPORT + OUTPORT + DELAY_PORT + BUFF_OFFSET + BUFF \ + portWidth + dtype_in + dmax + buffLen \ + 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 Variable Integer Delay (%) - % */ %% % = %; %% % %endfunction %% Function: Outputs =========================================================== %% %function Outputs(block, system) Output %% %assign delayLen = LibDataInputPortWidth(DELAY_PORT) %% { /* DSP Blockset Variable Integer Delay (%) - % */ %% %% Block could be multirate if and only if it has more than %% one input port (eg, a "Delay" input). If it is multirate, %% generate "sample hit" conditional so code executes at the %% block's base rate, and not the overall model base rate. %% %assign differentPortRates = !LibIsSFcnSingleRate(block) %% %if differentPortRates if (%) { % %endif % *u = %; real_T *delayPort = %; %if (incrementDelayPerSample || incrementDelayPerChannel) real_T *dtmp = delayPort; %endif % *buff = %; int_T *bufoff = (int_T *)%; % *y = %; %% %if (!incrementDelayPerSample && !incrementDelayPerChannel) int_T dly = roundDelayValue(delayPort,%); %endif %% int_T i,j; { int_T ti; for (i=0; i++ < %; ) { /* Record input samples */ int_T buffstart = *bufoff; %if (incrementDelayPerChannel) int_T dly = roundDelayValue(dtmp++, %); %endif %% for (j=0; j++ < %; ) { %if (incrementDelayPerSample) int_T dly = roundDelayValue(dtmp++,%); %endif %% /* Rotate the circular buffer */ if (++buffstart == %) buffstart = 0; *(buff + buffstart) = *u++; %% %% ti = buffstart - dly; if (ti < 0) ti += %; *y++ = *(buff + ti); } buff += %; %if (incrementDelayPerSample && delayLen == nSamps) /* Bump pointer back to beginning of delay vector */ dtmp = delayPort; %endif } } %% *bufoff += %; while (*bufoff >= %) *bufoff -= %; %if differentPortRates } %endif } %endfunction %% Outputs %% [EOF] sdspvidly2.tlc