wave

Capsim Block Documentation

Short Description

This star simulates a wave generator.

Top
Parameters
Num Description Type Name Default Value
0 total number of samples to output int numberOfSamples 128
1 Wave type:0=sine,1=cos,2=sqr,3=triangle,4=sawtooth int waveType 0
2 Samples per period. float period 1.0
3 Peak value. float peak 1.0
4 pace rate to determine how many samples to output float paceRate 1.0
5 number of samples on the first call if paced int samplesFirstTime 128
Top
States
Num Type Name Initial Value Description
0 float count
1 float halfPeriod
2 float radFreq
3 float slope
4 int samplesOutput 0
5 float paceInTotal 0.0
6 int outputTarget NUMBER_SAMPLES_PER_VISIT
7 int numberInputBuffers
8 int numberOutputBuffers
9 int pass 0
Top

Declarations


 

	int i,j;
	float waveValue;
	float theta;



Top

Initialization Code



 

        /* 
	 * note and store the number of output buffers 
	 */
        if((numberOutputBuffers = NO_OUTPUT_BUFFERS() ) <= 0) {
                fprintf(stdout,"wave: no output buffers\n");
                return(1); /* no output buffers */
        }
	if ((waveType >= 0) && (waveType <= 4))
		;
	else
	{
		fprintf(stderr,"Error in wave (2) \n");
		return(2);
	}
	if (period <= 0.0)
	{
		fprintf(stderr,"Error in wave (3) \n");
		return(3);
	}
	radFreq = (2*PI)/period;
	count = 0.0;
	halfPeriod = period/2.0;
	slope = 0.0;
	if (waveType == 3)
		slope = 4*peak/period;
	if (waveType == 4)
		slope = 2*peak/period;
	/*
	 * pacer code
	 */
        numberInputBuffers = NO_INPUT_BUFFERS();
        if(numberInputBuffers == 1)
           outputTarget = samplesFirstTime;
        else
           outputTarget = numberOfSamples;
        if(outputTarget > numberOfSamples)
           outputTarget = numberOfSamples;
        if(paceRate < 0) paceRate = -paceRate;




Top

Main Code



 

	/*
	 * check pacer
	 */
        if(numberInputBuffers == 1) {
           while(IT_IN(0))
                paceInTotal += 1.0;
           if(pass == 1) {
                outputTarget = samplesFirstTime + (int) (paceRate *
                                paceInTotal + 0.5);
                if(outputTarget > numberOfSamples && numberOfSamples > 0)
                       outputTarget = numberOfSamples;
	   }
	}
        pass = 1;
        i = 0;
 
	/* generate NUMBER_SAMPLES_PER_VISIT samples, then return */
        while(samplesOutput < outputTarget) {
                /* 
		 * return if all samples have been output 
		 */
                if(++i > NUMBER_SAMPLES_PER_VISIT) return(0);

			
		count = count + 1.0;
		if(count > period)
			count = count - period;
 
		switch(waveType) {
			     case  WAVE_SINE:	
				theta = count * radFreq;
				waveValue = peak*sin(theta);
				break;
			     case WAVE_COSINE:
				theta = count * radFreq;
				waveValue = peak*cos(theta);
				break;
			     case WAVE_SQUARE:
				if (count < halfPeriod)
					waveValue = peak;
				else
					waveValue = -1.0*peak;
				break;
			     case WAVE_TRIANGLE:
				if (count < halfPeriod)
					waveValue = slope*count - peak;
				else
					waveValue = peak-slope
						*(count-halfPeriod);
				break;
			      case WAVE_SAWTOOTH: 
				waveValue = slope*count - peak;
				break;
		}
		for(j=0; j
    
Top

Wrapup Code



 





Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* wave.s */
/***************************************************************
				wave.s 	
****************************************************************
This star simulates a wave generator.  
	waveType	wave description
	---------------------------------------
	0		sine
	1		cosine
	2		square
	3		triangle
	4		sawtooth
Notes:
Pacer support.
Auto fan-out. 
CONTROL PARAMETERS:
	numberOfSamples     = total number of samples to output.
	paceRate          = multiplies the number of samples received 
			     on pace input (if connected) to determine 
			     how many samples to output.
	samplesFirstTime = the number of samples to put out on the
			     first call if pace input connected. It can
			     be zero. negative values = 0.
CONTROL DESCRIPTION:
If the pace input is not connected:
      The numberOfSamples parameter sets the maximum number of samples
	that the star will output. If numberOfSamples < 0, an indefinite
	number of samples can be output.
      The star will output a maximum of NUMBER_SAMPLES_PER_VISIT on each call.
If the pace input is connected:
      The numberOfSamples parameter sets the maximum number of samples
        that the star will output. If num_samplesOutput < 0, an infinite
	number of samples can be output.
      The pace input paces the number of output samples on each call.
      At each call of the star all samples are read from the pace input
	and a running total of how many there have been is kept.
      An outputTarget  is computed at each pass = pace_input_total *
	paceRate. If paceRate < 0, the absolute value is used.
      On the first call:
	output = lesser of (samplesFirstTime, numberOfSamples)
      On subsequent calls:
	output = lesser of (NUMBER_SAMPLES_PER_VISIT, outputTarget)
	   outputTarget = samplesFirstTime +
		 paceRate * pace_input_total - to that point
      The total number of samples that will be output:
	samplesOutput_total = lesser of (numberOfSamples,
		     samplesFirstTime + paceRate * pace_input_total)

wave


This star simulates a wave generator.  
	waveType	wave description
	---------------------------------------
	0		sine
	1		cosine
	2		square
	3		triangle
	4		sawtooth
Notes:
Pacer support.
Auto fan-out. 
CONTROL PARAMETERS:
	numberOfSamples     = total number of samples to output.
	paceRate          = multiplies the number of samples received 
			     on pace input (if connected) to determine 
			     how many samples to output.
	samplesFirstTime = the number of samples to put out on the
			     first call if pace input connected. It can
			     be zero. negative values = 0.
CONTROL DESCRIPTION:
If the pace input is not connected:
      The numberOfSamples parameter sets the maximum number of samples
	that the star will output. If numberOfSamples < 0, an indefinite
	number of samples can be output.
      The star will output a maximum of NUMBER_SAMPLES_PER_VISIT on each call.
If the pace input is connected:
      The numberOfSamples parameter sets the maximum number of samples
        that the star will output. If num_samplesOutput < 0, an infinite
	number of samples can be output.
      The pace input paces the number of output samples on each call.
      At each call of the star all samples are read from the pace input
	and a running total of how many there have been is kept.
      An outputTarget  is computed at each pass = pace_input_total *
	paceRate. If paceRate < 0, the absolute value is used.
      On the first call:
	output = lesser of (samplesFirstTime, numberOfSamples)
      On subsequent calls:
	output = lesser of (NUMBER_SAMPLES_PER_VISIT, outputTarget)
	   outputTarget = samplesFirstTime +
		 paceRate * pace_input_total - to that point
      The total number of samples that will be output:
	samplesOutput_total = lesser of (numberOfSamples,
		     samplesFirstTime + paceRate * pace_input_total)


Programmer: 	Prayson W. Pate
Date:		August 18, 1987
Modified: 	Sasan H. Ardalan	

*/