All pastes #544019 Raw Edit

Something

public text v1 · immutable
·published 2007-06-06 07:58 UTC
rendered paste body
#include <stdio.h>
#include <csl.h>
#include <dsk6713_aic23.h>
#include <dsk6713_led.h>
#include <dsk6713_dip.h>


float baseVolume=2.0f;
float balance=0.5f;
int echoDelay = 16000;
float echoGain = 0.5f;
int isActive = 1;
int hasEcho = 1;

#define BUFFER_BITS 18
#define BUFFER_SIZE (1<<BUFFER_BITS)
#define IDX_MASK  (BUFFER_SIZE-1)
#pragma DATA_SECTION (linputbuffer, ".SDRAM$heap");
#pragma DATA_SECTION (loutputbuffer,".SDRAM$heap");
#pragma DATA_SECTION (rinputbuffer, ".SDRAM$heap");
#pragma DATA_SECTION (routputbuffer,".SDRAM$heap");

float linputbuffer[BUFFER_SIZE];
float loutputbuffer[BUFFER_SIZE];
float rinputbuffer[BUFFER_SIZE];
float routputbuffer[BUFFER_SIZE];
float *inputbuffer, *outputbuffer;
int bufferIndex = 0;

float min( float a, float b )
{
	return ( a < b ) ? a : b;
}

float max( float a, float b )
{
	return ( a > b ) ? a : b;
}

float workingValue;

void tune( float volume )
{
	workingValue *= volume;
}

void echo( int delay, float gain )
{
	workingValue += gain * inputbuffer[( bufferIndex - delay ) & IDX_MASK];
}

void multiecho( int delay, float gain )
{
	workingValue += gain * outputbuffer[( bufferIndex - delay ) & IDX_MASK];
}

int main(){
	
	DSK6713_AIC23_CodecHandle handle;
	Uint32 val;
	
	/* Codec configuration settings */
	DSK6713_AIC23_Config config = {
    0x0017, // 0 DSK6713_AIC23_LEFTINVOL  Left line input channel volume
    0x0017, // 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume
    0x00d8, // 2 DSK6713_AIC23_LEFTHPVOL  Left channel headphone volume
    0x00d8, // 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume
    0x0011, // 4 DSK6713_AIC23_ANAPATH    Analog audio path control
    0x0000, // 5 DSK6713_AIC23_DIGPATH    Digital audio path control
    0x0000, // 6 DSK6713_AIC23_POWERDOWN  Power down control
    0x0043, // 7 DSK6713_AIC23_DIGIF      Digital audio interface format
    0x0001, // 8 DSK6713_AIC23_SAMPLERATE Sample rate control
    0x0001  // 9 DSK6713_AIC23_DIGACT     Digital interface activation
	};
	
	DSK6713_init();
	DSK6713_DIP_init();
	DSK6713_LED_init();
	DSK6713_LED_off(0);
	DSK6713_LED_off(1);
	DSK6713_LED_off(2);
	DSK6713_LED_off(3);
	
	handle = DSK6713_AIC23_openCodec(0, &config);
	
	//Fill up the buffer
	for(bufferIndex = 0; bufferIndex < BUFFER_SIZE; bufferIndex++){
		Uint32 val;
		while(!DSK6713_AIC23_read(handle, &val));
		loutputbuffer[bufferIndex]=linputbuffer[bufferIndex]=(float)((signed short)val);
		while(!DSK6713_AIC23_read(handle, &val));
		routputbuffer[bufferIndex]=rinputbuffer[bufferIndex]=(float)((signed short)val);
	}
	while( isActive )
	{
		inputbuffer = linputbuffer;
		outputbuffer = loutputbuffer;
		while(!DSK6713_AIC23_read(handle, &val));
		workingValue = (float)((signed short)(val));
		linputbuffer[bufferIndex] = workingValue;


		if( hasEcho )
		{
			multiecho( echoDelay, echoGain );
		}

		loutputbuffer[bufferIndex] = workingValue;
		tune( min( balance * 2.0f, 1.0f ) * baseVolume );
		while(!DSK6713_AIC23_write(handle, (signed short) workingValue));
	



		inputbuffer = rinputbuffer;
		outputbuffer = routputbuffer;
		while(!DSK6713_AIC23_read(handle, &val));
		workingValue = (float)((signed short)(val));
		rinputbuffer[bufferIndex] = workingValue;

		if( hasEcho ){
			multiecho( echoDelay, echoGain );
		}

		routputbuffer[bufferIndex] = workingValue;
		tune( min( (1.0f-balance) * 2.0f, 1.0f ) * baseVolume );
		while(!DSK6713_AIC23_write(handle, (signed short) workingValue));


		isActive = DSK6713_DIP_get( 3 );
		
		hasEcho=DSK6713_DIP_get( 0 );

		if( hasEcho )
		{
			DSK6713_LED_on(0);
		}
		else
		{
			DSK6713_LED_off(0);
		}
		

		bufferIndex = ( bufferIndex + 1 ) & IDX_MASK;
	}

	/* Close the codec */
    DSK6713_AIC23_closeCodec(handle);
}