-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
236 lines (187 loc) · 5.53 KB
/
main.c
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//////////////////////////////////////////////////////////////////////////////
// *
// * Predmetni projekat iz predmeta
// * APS / PNRSuOS
// *
// * Godina: 2022
// *
// * Zadatak:
// * Autor: Tamara Banovac EE30/2018
// *
// *
//////////////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "ezdsp5535.h"
#include "ezdsp5535_i2c.h"
#include "aic3204.h"
#include "ezdsp5535_aic3204_dma.h"
#include "ezdsp5535_i2s.h"
#include "gen_sinus.h"
#include "sine_table.h"
#include "notes.h"
#include "fur_elise.h"
#include "math.h"
/* Frekvencija odabiranja */
#define SAMPLE_RATE 48000L
#define PI 3.14159265
static WAV_HEADER outputWAVhdr;
static WAV_HEADER inputWAVhdr;
/* Niz za smestanje odbiraka ulaznog signala */
#pragma DATA_ALIGN(InputBufferL,4)
Int16 InputBufferL[AUDIO_IO_SIZE];
#pragma DATA_ALIGN(InputBufferR,4)
Int16 InputBufferR[AUDIO_IO_SIZE];
/* Niz za smestanje odbiraka izlaznog signala */
#pragma DATA_ALIGN(OutputBufferL,4)
Int16 OutputBufferL[AUDIO_IO_SIZE];
#pragma DATA_ALIGN(OutputBufferR,4)
Int16 OutputBufferR[AUDIO_IO_SIZE];
float buffer1[AUDIO_IO_SIZE];
float buffer2[AUDIO_IO_SIZE];
float buffer3[AUDIO_IO_SIZE];
float buffer4[AUDIO_IO_SIZE];
float buffer5[AUDIO_IO_SIZE];
Int16 buffer1_int[AUDIO_IO_SIZE];
Int16 buffer2_int[AUDIO_IO_SIZE];
Int16 buffer3_int[AUDIO_IO_SIZE];
Int16 buffer4_int[AUDIO_IO_SIZE];
Int16 buffer5_int[AUDIO_IO_SIZE];
Int16 outputBuffer[AUDIO_IO_SIZE];
float reconstructed_sine[AUDIO_IO_SIZE];
float noise[AUDIO_IO_SIZE];
float SNRq[48]; //jer prvi ton ima 48 blokova pa da nadjem prosecan SNR
void main( void )
{
Int16 i, j,m,k,l,p;
float amplitude = 1.0;
float f0 = 0.0;
Int16 phase1=0;
Int16 phase2=0;
Int16 phase3=0;
Int16 phase4=0;
Int16 phase5=0;
float SNR=0.0;
/* Initialize BSL */
EZDSP5535_init( );
/* Initialise hardware interface and I2C for code */
aic3204_hardware_init();
aic3204_set_input_filename("../input1.wav");
aic3204_set_output_filename("../out_signal2.wav");
/* Initialise the AIC3204 codec */
aic3204_init();
aic3204_dma_init();
/* Citanje zaglavlja ulazne datoteke */
aic3204_read_wav_header(&inputWAVhdr);
/* Popunjavanje zaglavlja izlazne datoteke */
outputWAVhdr = inputWAVhdr;
/* Zapis zaglavlja izlazne datoteke */
aic3204_write_wav_header(&outputWAVhdr);
for(i=192; i<furEliseLength; i++)
{
for(j=0; j<692; j++)
{
m=furEliseNotes0[j].time;
k=furEliseNotes0[j].time+furEliseNotes0[j].duration;
if(i>=m && i<k)
{
f0=note_to_freq(furEliseNotes0[j].note);
phase1 = (i - furEliseNotes0[j].time) * AUDIO_IO_SIZE;
gen_sinus_table(AUDIO_IO_SIZE, amplitude, f0/SAMPLE_RATE, phase1, buffer1);
ADSR(buffer1, AUDIO_IO_SIZE, phase1, furEliseNotes0[j].duration);
break;
}
}
for(j=0; j<274; j++)
{
if(i>=furEliseNotes1[j].time && i<(furEliseNotes1[j].time+furEliseNotes1[j].duration))
{
f0=note_to_freq(furEliseNotes1[j].note);
phase2 = (i - furEliseNotes1[j].time) * AUDIO_IO_SIZE;
gen_sinus_table(AUDIO_IO_SIZE, amplitude, f0/SAMPLE_RATE, phase2, buffer2);
ADSR(buffer2, AUDIO_IO_SIZE, phase2, furEliseNotes1[j].duration);
break;
}
}
for(j=0; j<60; j++)
{
if(i>=furEliseNotes2[j].time && i<(furEliseNotes2[j].time+furEliseNotes2[j].duration))
{
f0=note_to_freq(furEliseNotes2[j].note);
phase3 = (i - furEliseNotes2[j].time) * AUDIO_IO_SIZE;
gen_sinus_table(AUDIO_IO_SIZE, amplitude, f0/SAMPLE_RATE, phase3, buffer3);
ADSR(buffer3, AUDIO_IO_SIZE, phase3, furEliseNotes2[j].duration);
break;
}
}
for(j=0; j<40; j++)
{
if(i>=furEliseNotes3[j].time && i<(furEliseNotes3[j].time+furEliseNotes3[j].duration))
{
f0=note_to_freq(furEliseNotes3[j].note);
phase4 = (i - furEliseNotes3[j].time) * AUDIO_IO_SIZE;
gen_sinus_table(AUDIO_IO_SIZE, amplitude, f0/SAMPLE_RATE, phase4, buffer4);
ADSR(buffer4, AUDIO_IO_SIZE, phase4, furEliseNotes3[j].duration);
break;
}
}
for(j=0; j<6; j++)
{
if(i>=furEliseNotes4[j].time && i<(furEliseNotes4[j].time+furEliseNotes4[j].duration))
{
f0=note_to_freq(furEliseNotes4[j].note);
phase5 = (i - furEliseNotes4[j].time) * AUDIO_IO_SIZE;
gen_sinus_table(AUDIO_IO_SIZE, amplitude, f0/SAMPLE_RATE, phase5, buffer5);
ADSR(buffer5, AUDIO_IO_SIZE, phase5, furEliseNotes4[j].duration);
break;
}
}
for (j = 0; j < AUDIO_IO_SIZE; j++)
{
buffer1_int[j]=quantB(buffer1[j],15);
buffer1_int[j]=clipB(buffer1_int[j],14);
buffer2_int[j]=quantB(buffer2[j],15);
buffer2_int[j]=clipB(buffer2_int[j],14);
buffer3_int[j]=quantB(buffer3[j],15);
buffer3_int[j]=clipB(buffer3_int[j],14);
buffer4_int[j]=quantB(buffer4[j],15);
buffer4_int[j]=clipB(buffer4_int[j],14);
buffer5_int[j]=quantB(buffer5[j],15);
buffer5_int[j]=clipB(buffer5_int[j],14);
outputBuffer[j]=buffer1_int[j]+buffer2_int[j]+buffer3_int[j]+buffer4_int[j]+buffer5_int[j];
}
aic3204_write_block(outputBuffer, outputBuffer);
/*
//SNR
for(l = 0; l < AUDIO_IO_SIZE; l++)
{
reconstructed_sine[l] = reconstructB(buffer1_int[l], 15);
}
for(l = 0; l < AUDIO_IO_SIZE; l++)
{
noise[l] = reconstructed_sine[l]-buffer1[l];
}
SNRq[p]=snr(reconstructed_sine, noise, AUDIO_IO_SIZE); //to je za jedan blok
p=p+1;
if(p==48)
{
for(l=0;l<48;l++)
{
SNR+=SNRq[l];
}
SNR=SNR/48; //prosecan sum za prvi ton
}
//SNR
*/
for (j = 0; j < AUDIO_IO_SIZE; j++)
{
buffer1[j]=0;
buffer2[j]=0;
buffer3[j]=0;
buffer4[j]=0;
buffer5[j]=0;
}
}
aic3204_disable();
printf( "\n***Program has Terminated***\n" );
SW_BREAKPOINT;
}