%% $RCSfile: sdsprebuff2.tlc,v $ %% $Revision: 1.9 $ %% $Date: 2000/04/11 17:53:19 $ %% %% Copyright (c) 1995-1999 The MathWorks, Inc. %% %% Abstract: Convert a frame to a smaller or larger size with optional overlap. %implements sdsprebuff2 "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %assign INPORT = 0 %assign OUTPORT = 0 %assign block = block + INPORT + OUTPORT %if !IsInputPortContiguous(block,INPORT) % %endif %assign cplx_in = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign dtype_in = cplx_in ? "creal_T" : "real_T" %assign inWidth = CAST("Number",LibDataInputPortWidth(INPORT)) %assign isMultiRate = !LibIsSFcnSingleRate(block) %assign isMultiTasking = IsModelMultiTasking() %assign isFrame = LibBlockInputSignalIsFrameData(INPORT) %assign dims = LibBlockInputSignalDimensions(INPORT) %assign nChans = (isFrame) ? dims[1]: inWidth %assign F = (isFrame) ? dims[0] : 1 %assign dims_out = LibBlockOutputSignalDimensions(OUTPORT) %assign N = LibBlockOutputSignalIsFrameData(OUTPORT) ? dims_out[0] : 1 %assign V = CAST("Number",SFcnParamSettings.OVERLAP[0]) %assign B = isMultiRate ? ((F<=N) ? N : ( ((F%N)==0) ? F : F+N-V)) : V %assign bufLen = (F<=N) ? N+B : F+B %assign IS_BUFFERING_WITH_NONSCALAR_OUTPUT = ((F==1) && (N>1)) %assign IS_REBUFFERING = ((F != 1) && (N != 1)) %assign IS_DIFFERING_FRAME_SIZES = (F != N) %assign IS_FRAME_UNBUFF_NOLAP_INDIVISIBLE_FRAMES = ((F > N) && (V == 0) && (F%N != 0)) %assign IS_FRAME_BUFF_NOLAP = ((F < N) && (V == 0)) %assign IS_OVERLAP = (V > 0) %assign needICs = \ ( isMultiTasking && \ (isMultiRate || \ IS_DIFFERING_FRAME_SIZES \ ) \ || \ !isMultiTasking && \ ( IS_BUFFERING_WITH_NONSCALAR_OUTPUT || \ IS_REBUFFERING && \ ( IS_FRAME_UNBUFF_NOLAP_INDIVISIBLE_FRAMES || \ IS_FRAME_BUFF_NOLAP || \ IS_OVERLAP \ ) \ ) \ ) %% %assign block = block + cplx_in + dtype_in + inWidth \ + nChans + N + V + F + B + bufLen \ + isMultiRate + isMultiTasking + needICs %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %% Abstract: %% %function InitializeConditions(block, system) Output /* DSP Blockset Rebuffer (%) - % */ %if V < 0 %% Don't initialize DWork if it is not present (i.e., no underlap): % = 0; %endif %if (!isMultiTasking && (F > 1) && (N == 1) && (V == 0) ) % = 0; /* Reset counter */ %endif %if (needICs) %% %assign IC = SFcnParamSettings.IC %assign ic_cplx = TYPE(SFcnParamSettings.IC[0]) == "Complex" %assign ic_rows = SFcnParamSettings.IC_ROWS %assign ic_cols = SFcnParamSettings.IC_COLS %assign numIC = SIZE(SFcnParamSettings.IC,1) %assign dtype_ic = ic_cplx ? "creal_T" : "real_T" { %if numIC > 1 const % \ %endif %% % *inBuf; %if nChans != 1 int_T n; for (n=0; n<%; n++) { inBuf = % + (%*n); %else inBuf = %; %endif %% %if (numIC <= 1) %% %if numIC == 0 %assign IC_re = 0.0 %assign IC_im = 0.0 %else %assign IC_re = REAL(IC[0]) %if !ic_cplx %assign IC_im = 0.0 %else %assign IC_im = IMAG(IC[0]) %endif %endif { /* Scalar IC */ int_T i; for (i=0; i++ < %; ) { %if !cplx_in *inBuf++ = %; %else inBuf->re = %; (inBuf++)->im = %; %endif } } %else { %if (numIC == F) || (numIC == N) /* Vector IC */ int_T i; for (i=0; i < %; i++) { %else /* Matrix IC */ int_T i; %% move pointer for each channel %if isMultiRate for (i=n*%<((F<=N) ? N : F)> ; i < (n+1)*%; i++) { %else for (i=n*%<((F<=N) ? N : F)> ; i < (n*%<((F<=N) ? N : F)>)+%; i++) { %endif %% %endif %if !cplx_in *inBuf++ = ic[i]; %else inBuf->re = %<(ic_cplx) ? "ic[i].re" : "ic[i]">; (inBuf++)->im = %<(ic_cplx) ? "ic[i].im" : 0.0>; %endif } } %endif %% %if nChans != 1 } %% for loop closing brace inBuf -= %<(nChans-1)*bufLen>; %endif %% %assign OUTBUF_PTR = 0 %assign INBUF_PTR = 1 %% % = inBuf; % = \ (%%<((V<=0) ? "" : "+ %")>); } %endif %% needICs %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Rebuffer (%) - % */ { %% %if (needICs) % %else % *y = (% *)(%); % *u = (% *)(%); %% %if isMultiRate %assign InportHit = LibIsSFcnSampleHit("InputPortIdx0") %assign OutportHit = LibIsSFcnSampleHit("OutputPortIdx0") %if ( (N-V)/F < 1) %% Slow to Fast block if (%) { %else %% Fast to Slow block if (%) { %endif %endif %if( (F == 1) && (N == 1) ) %if (nChans > 1) int_T n; for (n = 0; n < %; n++) { %endif *y++ = *u++; %if (nChans > 1) } %endif %else int_T c; int_T i; %if (nChans > 1) %assign chanLoopOpening = "int_T n;\n\n" ... "for (n = 0; n < %; n++) {\n" %assign chanLoopClosing = "}" %else %assign chanLoopOpening = "" %assign chanLoopClosing = "" %endif %\ c = %; for (i=0; i<%; i++) { %if (nChans > 1) *y++ = u[n*% + c++]; %else *y++ = u[c++]; %endif if (c == %) c = 0; } %\ % = c; %endif %if isMultiRate } %endif %endif } %endfunction %% Outputs %% [EOF] sdsprebuff.tlc %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Local Functions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Need ICs %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: needICs_output %function needICs_output(block) Output %assign OUTBUF_PTR = 0 %assign INBUF_PTR = 1 %% %if V > 0 %assign V_tmp = "- %" %else %assign V_tmp = "" %endif %% %% %% %% %% Input Hit: %% %if !LibIsSFcnSingleRate(block) if (%) { %else { %endif %% %if V < 0 /* Underlap: only works when buffering scalar inputs */ %++; if (% > %) { /* Skip this sample because of negative overlap */ if (% == %) { % = 0; } } else { %% %endif % *u = %; % *inBuf; %% %if nChans > 1 int_T n; for (n=0; n<%; n++) { % *topBuf = % + (n*%); % *endBuf = topBuf + %; /* Get the original input pointer relative to this channel */ inBuf = (% *)% + (n*%); %else % *topBuf = %; % *endBuf = topBuf + %; /* Get the original input pointer relative to this channel */ inBuf = (% *)%; %endif %% /* Copy F samples */ { const int_T nSampsAtBot = (endBuf-inBuf); int_T nSamps = %; int_T i; if (nSampsAtBot <= nSamps) { /* Need to wrap inBuf pointer */ for (i=0; i++ < nSampsAtBot; ) { *inBuf++ = *u++; } inBuf = topBuf; nSamps -= nSampsAtBot; } for (i=0; i++ < nSamps; ) { *inBuf++ = *u++; } } %if nChans > 1 /* Update inBuf pointer relative to the first channel */ inBuf -= %<(nChans-1)*bufLen>; } %% for nChans loop closing brace %endif %% % = inBuf; %% %if V<0 } %% if v<0 else closing brace %endif } %% Output Hit: %% %if !LibIsSFcnSingleRate(block) if (%) { %else { %endif %% % *y = %; % *outBuf; %% %if nChans > 1 int_T n; for (n=0; n<%; n++) { % *topBuf = % + (n*%); % *endBuf = topBuf + %; %if V > 0 /* Get the original output pointer relative to this channel * and back it up V samples: */ %endif outBuf = (% *)% + (n*%); outBuf = ((outBuf %) < topBuf) ? (endBuf-(topBuf-(outBuf %))) : (outBuf %); %else % *topBuf = %; % *endBuf = topBuf + %; %if V > 0 /* Get the original output pointer relative to this channel * and back it up V samples: */ %endif outBuf = (% *)%; outBuf = ((outBuf %) < topBuf) ? (endBuf-(topBuf-(outBuf %))) : (outBuf %); %endif %% /* Read % samples: */ { const int_T nSampsAtBot = (endBuf-outBuf); int_T nSamps = %; int_T i; if ( nSampsAtBot <= % ) { /* Need to wrap pointer */ /* Copy all samples left in buffer before wrapping pointer */ for (i=0; i++ 1 } %% for loop closing brace /* Update outBuf pointer relative to the first channel */ outBuf -= %<(nChans-1)*bufLen>; %endif %% % = outBuf; } %endfunction %% needICs_output