📄 sinewaves.c
字号:
/*****************************************************************************/
/* */
/* FILENAME */
/* sinewaves.c */
/* */
/* DESCRIPTION */
/* Sinewave generation for the TMS320C6713 DSK. */
/* */
/* Generates two sinewaves of adjustable frequency using sine() function */
/* in sine.c */
/* */
/* The frequency of range of the sine wave is 10 Hz to 8000 Hz. */
/* */
/* REVISION */
/* Revision: 1.00 */
/* Author : Richard Sikora */
/*---------------------------------------------------------------------------*/
/* */
/* HISTORY */
/* */
/* 8th January 2006. Created by Richard Sikora from TMS320C55510 code. */
/* */
/*****************************************************************************/
#include <stdio.h> /* Required for functions printf() and puts() */
/*****************************************************************************/
/* generate_sinewave_1() */
/*---------------------------------------------------------------------------*/
/* */
/* Generate a sinewave. */
/* */
/* */
/* PARAMETER 1: The frequency of the sinewave between 10 Hz and 16000 Hz. */
/* PARAMETER 2: The maximum amplitude of the sinewave between 1 to 32767. */
/* */
/*****************************************************************************/
signed int generate_sinewave_1( signed int frequency,
signed int amplitude)
{
int sinusoid;
int result;
static short int count = 0;
/* Multiply frequency by scaling factor of 32767 / 48000 */
result = ( frequency * 22368 ) >> 14 ;
if ( result > 32767)
{
result = 32767; /* Maximum value for highest frequency */
}
else if ( 0 == result)
{
result = 1; /* Minimum value for lowest fequency */
}
else if ( result < -32767)
{
result = -32767;
}
count += result;
count &= 0xFFFF; /* Limit size to 16 bits */
sinusoid = sine ( count);
if ( amplitude > 32767 )
{
amplitude = 32767; /* Range limit amplitude */
}
/* Scale sine wave to have maximum value set by amplitude */
result = ( sinusoid * amplitude ) >> 15;
return ( result );
}
/*****************************************************************************/
/* generate_sinewave_2() */
/*---------------------------------------------------------------------------*/
/* */
/* Generate a second sinewave. */
/* */
/* */
/* PARAMETER 1: The frequency of the sinewave between 10 Hz and 16000 Hz. */
/* PARAMETER 2: The maximum amplitude of the sinewave between 1 to 32767. */
/* */
/*****************************************************************************/
signed int generate_sinewave_2( signed int frequency,
signed int amplitude)
{
int sinusoid;
int result;
static int count = 0;
/* Multiply frequency by scaling factor of ratio 32767 / 48000 */
result = ( frequency * 22368 ) >> 14 ;
if ( result > 32767)
{
result = 32767; /* Maximum value for highest frequency */
}
else if ( 0 == result)
{
result = 1; /* Minimum value for lowest fequency */
}
else if ( result < -32767)
{
result = -32767;
}
count += result;
count &= 0xFFFF; /* Limit size to 16 bits */
/* Obtain sine of input */
sinusoid = sine ( count);
if ( amplitude > 32767 )
{
amplitude = 32767; /* Range limit amplitude */
}
/* Scale sine wave to have maximum value set by amplitude */
result = ( sinusoid * amplitude ) >> 15;
return ( result );
}
/******************************************************************************/
/* End of sinewaves.c */
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -