summaryrefslogtreecommitdiffstats
path: root/FFT_Test/runfft.hcc
blob: e54be268f827fce6595924d477a8a25646b0151e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*! \file runfft.hcc
 *
 * \section generic	This module will handle the audio I/O. It will ensure the 
 *			audiosamples are correctly buffered and fed correctly to the FFT.\n
 *			This module will also handle the output of the modified audio samples.
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author M. Lauwerijssen 
 * \date 20041110
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041110: M. Lauwerijssen\n	Initial version
 *
 ********************************************************************/


#include <stdlib.hch>
#include "pal_master.hch"

#include "configuration.hch"
#if USE_RUNFFT
#include "fft.hch"
#include "debug.hch"

/*
 * Forward declarations
 */
static macro expr ClockRate = PAL_ACTUAL_CLOCK_RATE;

extern mpram DualPortInputRam AudioIn;
extern mpram DualPortOutputRam AudioOut;

extern chan unsigned 1 AudioOutReady;
chan unsigned 1 AudioInReady;

#if HARDWARE_MULTIPLY
signed 18 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;

signed 18 *audioptr_out1,*audioptr_out2;

unsigned 6 *displayptr1,*displayptr2,*displayptr3,*displayptr4;
#else
signed 16 *audioptr_in1,*audioptr_in2,*audioptr_in3,*audioptr_in4;

signed 16 *audioptr_out1,*audioptr_out2;

#endif

/*! \fn		macro proc  audio_main(AUDIOIN, AUDIOOUT);
 * \brief	
 * 
 * \param	AUDIOIN		Handle to audio-input
 * \param	AUDIOOUT	Handle to audio-output
 *
 * \return	Never Returns.
 * \retval	void
 */
macro proc audio_main(AUDIOIN, AUDIOOUT)
{
	unsigned 6 sample_count;

	unsigned 1 FFT_Sync;
	macro expr OW = PalAudioOutGetMaxDataWidthCT ();
	macro expr IW = PalAudioInGetMaxDataWidthCT  ();
	signed LeftNew, RightNew;
	signed Output_sample;

  	//pointers for double and quadruple buffering:
  	audioptr_in1 = &AudioIn.audio_io[0];
  	audioptr_in2 = &AudioIn.audio_io[64];
  	audioptr_in3 = &AudioIn.audio_io[128];
  	audioptr_in4 = &AudioIn.audio_io[192];

  	audioptr_out1 = &AudioOut.audio_io[0];
  	audioptr_out2 = &AudioOut.audio_io[64];

  	FFT_Sync=0;
par
{
	for(;;)//Notify FFT loop.
	{
		if (FFT_Sync)	//if 64 samples are read from ADC...
		{
			par
			{
				// switch pointers 
	    			audioptr_in1 = audioptr_in2;
				audioptr_in2 = audioptr_in3;
				audioptr_in3 = audioptr_in4;
				audioptr_in4 = audioptr_in1;
				
				audioptr_out1 = audioptr_out2;
				audioptr_out2 = audioptr_out1;
				
				FFT_Sync = 0;
			}
			AudioInReady ! sync;
	
    		}
		else
			delay;
	}	

	for(sample_count=0;;)//Audiosampling loop
	{
		if (!FFT_Sync)
		{
			par
			{
				seq
				{
					PalAudioInRead(AUDIOIN, &LeftNew, &RightNew);
#if HARDWARE_MULTIPLY 					
					audioptr_in1[sample_count] = LeftNew;//drop 2 LSB's
#else
					audioptr_in1[sample_count] = (LeftNew\\2);//drop 2 LSB's
#endif
					sample_count++; 
    					if (!sample_count) 
					{
						FFT_Sync = 1; 
					}
				}
				seq
				{
					Output_sample = audioptr_out2[sample_count];
				}
			}
		}
		else
		{
			delay;
		}
	}
	for(;;)//Audio output-loop
	{
		PalAudioOutWrite(AUDIOOUT,(signed OW)(Output_sample @ 0),(signed OW)(Output_sample @ 0));
	}
}//end par
}// end function
#endif