📄 dtmf_generator.c
字号:
/*****************************************************************************/
/* */
/* FILENAME */
/* dtmf_generator */
/* */
/* DESCRIPTION */
/* Generate dual tones as produced by a touch-tone telephone. */
/* Uses a sampling rate of 48000 Hz (48 kHz). */
/* */
/* */
/* REVISION */
/* Revision: 1.00 */
/* Author : Richard Sikora */
/*---------------------------------------------------------------------------*/
/* */
/* HISTORY */
/* Revision 1.00 */
/* 12th January 2006. Created by Richard Sikora. */
/* */
/*****************************************************************************/
#include <stdio.h> /* Required for functions printf() and puts() */
/*****************************************************************************/
/* */
/* The name of the following header file will change if used as part of a */
/* different project. The new project xxxx will use xxxxcfg.h instead. */
/* */
/*****************************************************************************/
#include "dtmf_generatorcfg.h"
/*
* The 6713 DSK Board Support Library is divided into several modules, each
* of which has its own include file. The file dsk6713.h must be included
* in every program that uses the BSL. This example also includes
* dsk6713_aic23.h because it uses the AIC23 codec module.
*/
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "aic23_config.h"
#include "bargraph.h"
#include "sinewaves.h"
#include "stereo.h"
#include "switches.h"
#define SAMPLES_PER_SECOND 48000
#define GAIN 32767
/*****************************************************************************/
/* Variables */
/*****************************************************************************/
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
Int16 mono_input;
/*****************************************************************************/
/* Subroutine to generate tones with 100 ms on, 900 ms off. */
/*****************************************************************************/
int dial_tone_generator(void)
{
static unsigned int counter = 0;
int return_value;
if ( counter < 4800)
{
counter++;
return_value = 1; /* Return 1 for 0 to 100 ms */
}
else if ( counter < 48000)
{
counter++;
return_value = 0; /* Return 0 for 100 ms to 1000 ms */
}
else
{
counter = 0;
return_value = 0; /* End of sequence. Go back to beginning */
}
return(return_value);
}
/*****************************************************************************/
/* main() */
/*****************************************************************************/
void main(void)
{
DSK6713_AIC23_CodecHandle hCodec;
long i;
unsigned int switch_value;
Uint32 temp; /* For 32-bit reads from codec */
int update;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec for line input */
hCodec = DSK6713_AIC23_openCodec(0, &aic23_config_line);
/* Alternately, start the codec for microphone input */
//hCodec = DSK6713_AIC23_openCodec(0, &aic23_config_microphone);
/* Display project details on Stdout. \n is important. */
puts("TMS320C6713 DSK: DTMF Generator. Bargraph at 6dB intervals.\n");
/* Read input and send to output for 600 seconds */
for ( i = 0; i < 600 * SAMPLES_PER_SECOND; i++)
{
/* Read left channel */
while (!DSK6713_AIC23_read(hCodec, &temp ));
left_input = (Int16) temp;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, left_output ));
/* Read user switches and display status on Stdout*/
switch_value = switch_status_display();
/* Read right channel */
while (!DSK6713_AIC23_read(hCodec, &temp ));
right_input = (Int16) temp;
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, right_output ));
/* Processing for left channel goes here */
if ( 0 == switch_value)
{
/* Generate continuous single tone 697 Hz, magnitude GAIN */
left_output = generate_sinewave_1 (697, GAIN);
right_output = left_output;
}
else if ( 1 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 697 Hz and 1209 Hz */
left_output = generate_sinewave_1 (697, GAIN);
right_output = generate_sinewave_2 (1209, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 2 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 697 Hz and 1336 Hz */
left_output = generate_sinewave_1 (697, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 3 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 697 Hz and 1477 Hz */
left_output = generate_sinewave_1 (697, GAIN);
right_output = generate_sinewave_2 (1477, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 4 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 770 Hz and 1209 Hz */
left_output = generate_sinewave_1 (770, GAIN);
right_output = generate_sinewave_2 (1209, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 5 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 770 Hz and 1366 Hz */
left_output = generate_sinewave_1 (770, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 6 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 770 Hz and 1477 Hz */
left_output = generate_sinewave_1 (770, GAIN);
right_output = generate_sinewave_2 (1477, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 7 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 852 Hz and 1209 Hz */
left_output = generate_sinewave_1 (852, GAIN);
right_output = generate_sinewave_2 (1209, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 8 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 852 Hz and 1336 Hz */
left_output = generate_sinewave_1 (852, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 9 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 7852 Hz and 1477 Hz */
left_output = generate_sinewave_1 (852, GAIN);
right_output = generate_sinewave_2 (1477, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 10 == switch_value)// phim *
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 941 Hz and 1209 Hz */
left_output = generate_sinewave_1 (941, GAIN);
right_output = generate_sinewave_2 (1209, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 11 == switch_value)// phim 0
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 941 Hz and 1336 Hz */
left_output = generate_sinewave_1 (941, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 12 == switch_value)// phim #
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 941 Hz and 1477 Hz */
left_output = generate_sinewave_1 (941, GAIN);
right_output = generate_sinewave_2 (1477, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 13 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 941+1% Hz and 1336 Hz */
left_output = generate_sinewave_1 (940+9, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 14 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 940 + 2% Hz and 1366 Hz */
left_output = generate_sinewave_1 (940 + 19, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
else if ( 15 == switch_value)
{
update = dial_tone_generator();
if ( update )
{
/* Generate 100 ms pulses dual tone 940 +3% Hz and 1336 Hz */
left_output = generate_sinewave_1 (940 + 28, GAIN);
right_output = generate_sinewave_2 (1336, GAIN);
}
else
{
/* 900 ms of silence */
left_output = 0;
right_output = 0;
}
}
/* Display on bargraph at 6dB intevals */
bargraph_6dB( left_output, right_output);
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
puts("TMS320C6713 DSK has terminated\n");
}
/******************************************************************************/
/* End of dtmf_generator.c */
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -