📄 audioeffect.c
字号:
/*****************************************************************************/
/* FILENAME */
/* AudioEffect.c */
/* */
/* DESCRIPTION */
/* Audio effect illustration project based on TMS320C5416 DSK. */
/* */
/* VERSION */
/* 1.01 */
/* */
/* AUTHOR */
/* Bao Xiaojing */
/* */
/* REVISION HISTORY */
/* VER DATE AUTHOR DESCRIPTION */
/* ------------------------------------------------------------------------ */
/* 1.01 2008.12.06 Bao Xiaojing Update 3 audio effects. */
/* 1.00 2002.10.30 Richard Sikora Initial version. */
/* */
/*****************************************************************************/
#include <stdio.h> // Required for functions printf() and puts()
#include "AudioEffectcfg.h"
#include "dsk5416.h"
#include "dsk5416_pcm3002.h"
#include "bargraph.h"
#include "switches.h"
#include "stereo.h"
#include "FIR_filters_asm.h"
#include "blackman_low_pass_filter_1000Hz.h"
// Configuration setup of registers of PCM3002 Codec
DSK5416_PCM3002_Config setup = {
0x1FF, // Set-Up Reg 0 - Left channel DAC attenuation
0x1FF, // Set-Up Reg 1 - Right channel DAC attenuation
0x0, // Set-Up Reg 2 - Various ctl e.g. power-down modes
0x0 // Set-Up Reg 3 - Codec data format control
};
#define DELAY_TIME 12000
#define MAX_DELAY 12001
signed int delay_array[MAX_DELAY]; // Buffer for maximum delay of 1 second
// delayed_input()
// ---------------
// Take oldest sample from the array and replace with the newest
// Uses a circular buffer because a straight buffer would be too slow.
signed int delayed_input(signed int latest_input, unsigned int delay_time)
{
signed int return_value;
static unsigned int index = 0; // Static to retain value between calls
return_value = delay_array[index]; // Take oldest sample
delay_array[index] = latest_input; // Overwrite with latest input
if (index < (delay_time - 1))
{
index++; // Not at end of buffer. Point to next element
}
else
{
index = 0; // Go back to beginning of buffer
}
return(return_value);
}
// delay_array_clear()
// -------------------
// Fill delay array with zeroes to prevent noise / clicks.
void delay_array_clear(void)
{
int i;
for ( i = 0 ; i < MAX_DELAY ; i++)
{
delay_array[i] = 0; // Initialize array to all zeroes
}
}
// For compatibility with pcm3002 read / write, these variables must
// be declared as Int16 or short int, rather than int.
Int16 left_input;
Int16 left_output;
Int16 right_input;
Int16 right_output;
// shift_channel()
// ---------------
// Attentuate one channel and amplify the other channel periodically.
void shift_channel(void)
{
static unsigned long cnt = 1;
static signed int dir = 1;
unsigned int att;
att = (unsigned int) (cnt / 20000);
left_output = left_input >> att;
right_output = right_input >> (5 - att);
cnt += dir;
if (cnt == 99999)
{
dir = -1;
}
if (cnt == 1)
{
dir = 1;
}
}
// UserTask()
// ----------
// The main user task.
// Note that this task is not called by main(). It is scheduled by DSP/BIOS
void UserTask()
{
DSK5416_PCM3002_CodecHandle hCodec;
unsigned int flag;
unsigned int switch_value;
signed int mono_input;
signed long output;
puts("TMS320C5416 DSK: Audio effect project started\n");
delay_array_clear();
flag = 1;
// Start the codec
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
while (flag)
{
// Read left input channel
while (!DSK5416_PCM3002_read16(hCodec, &left_input));
// Output to left output channel
while (!DSK5416_PCM3002_write16(hCodec, left_output));
// Read right input channel
while (!DSK5416_PCM3002_read16(hCodec, &right_input));
// Output to right output channel
while (!DSK5416_PCM3002_write16(hCodec, right_output));
// Read user switches on DSK and display their meaning on Stdout.
switch_value = switch_status_display();
// Where required, generate mono input from left input and right input
mono_input = stereo_to_mono ( left_input, right_input);
// Digital Signal Processing
if (switch_value == 15)
{
// Straight through stereo. No electronic crossover
left_output = left_input ;
right_output = right_input ;
left_output >>= 1;
right_output >>= 1; // Attenuate slightly
}
else if (switch_value == 14)
{
// Crossover at 1000 Hz
output = FIR_dual_filter_asm( &blackman_low_pass_filter_1000Hz[0],
mono_input);
left_output = (signed int) (output & 0xFFFF ); // Treble channel
right_output = (signed int) (output >> 16 ); // Bass channel
}
else if (switch_value == 13)
{
shift_channel();
}
else if (switch_value == 11)
{
// Output delayed
right_output = mono_input + delayed_input( mono_input, DELAY_TIME);
left_output = left_input;
left_output >>= 1;
right_output >>= 1; // Attenuate slightly
}
else if (switch_value == 7)
{
flag = 0;
}
// Display greater of two outputs on bargraph
bargraph ( left_output, right_output);
}
// Finished processing. Close the codec
DSK5416_PCM3002_closeCodec(hCodec);
puts("TMS320C5416 DSK: Audio effect project stopped\n");
}
// main()
void main()
{
// Initialize the board support library
// There is no need to initialize the DIP switches and the LEDs
DSK5416_init();
// All other functions are scheduled by DSP/BIOS
}
/******************************************************************************/
/* End of AudioEffect.c */
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -