audiotest.c
4.42 KB
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
#include <ultra64.h>
#include "testDriver.h"
#define AI_BUF_MAX 500 /* 440ɬʬ */
#define VOLMAX 5000
#define SEIGEN ZARU_SINWAVE
#define NOKOGIRI ZARU_SAWWAVE
#define SANKAKU ZARU_TRIWAVE
#define KUKEI ZARU_RCTWAVE
#define ONLYL ZARU_ONLYL
#define ONLYR ZARU_ONLYR
#define PI 3.14159265358979
typedef struct
{
s16 leftSound;
s16 rightSound;
} soundElement_t;
typedef union
{
soundElement_t ele[AI_BUF_MAX];
long long int force_structure_alignment;
} aiBuffer;
aiBuffer audioBuf;
void audioTest(u32 sound, u32 length, int freq_sample)
{
u32 i;
u32 j;
u32 count=0;
int sin_sample=44;
if (freq_sample > 0) sin_sample = 44100 / freq_sample;
i=0;
switch(sound)
{
case ONLYR:
while(i<440)
{
for(j=0; j<sin_sample; j++)
{
audioBuf.ele[i].leftSound = 0;
audioBuf.ele[i].rightSound = (s16)(VOLMAX*sinf(2*PI*j/44));
i++;
}
}
break;
case ONLYL:
while(i<440)
{
for(j=0; j<sin_sample; j++)
{
audioBuf.ele[i].leftSound = (s16)(VOLMAX*sinf(2*PI*j/44));
audioBuf.ele[i].rightSound =0;
i++;
}
}
break;
case SEIGEN:
while(i<440)
{
for(j=0; j<sin_sample; j++)
{
audioBuf.ele[i].leftSound = (s16)(VOLMAX*sinf(2*PI*j/44));
audioBuf.ele[i].rightSound = (s16)(VOLMAX*sinf(2*PI*j/44));
i++;
}
}
break;
case NOKOGIRI:
#ifdef NOKOGIRI_PLUS
while(i<440)
{
for(j=0; j<44; j++)
{
audioBuf.ele[i].leftSound = (s16)(VOLMAX - (float)(VOLMAX*j/43));
audioBuf.ele[i].rightSound = (s16)(VOLMAX - (float)(VOLMAX*j/43));
i++;
}
}
#else
while(i<440)
{
for(j=0; j<44; j++)
{
audioBuf.ele[i].leftSound = (s16)(VOLMAX - (float)(VOLMAX*j/21.5F));
audioBuf.ele[i].rightSound = (s16)(VOLMAX - (float)(VOLMAX*j/21.5F));
i++;
}
}
#endif
break;
case SANKAKU:
while(i<440)
{
for(j=0; j<22; j++)
{
audioBuf.ele[i].leftSound = (s16)(2*VOLMAX*j/21) - VOLMAX;
audioBuf.ele[i].rightSound = (s16)(2*VOLMAX*j/21) - VOLMAX;
i++;
}
for(j=0; j<22; j++)
{
audioBuf.ele[i].leftSound = -(s16)(2*VOLMAX*j/21) + VOLMAX;
audioBuf.ele[i].rightSound = -(s16)(2*VOLMAX*j/21) + VOLMAX;
i++;
}
}
break;
case KUKEI:
while(i<440)
{
for(j=0; j<22; j++)
{
audioBuf.ele[i].leftSound=VOLMAX;
audioBuf.ele[i].rightSound=VOLMAX;
i++;
}
for(j=0; j<22; j++)
{
audioBuf.ele[i].leftSound=-VOLMAX;
audioBuf.ele[i].rightSound=-VOLMAX;
i++;
}
}
break;
}
#if 0
if(sound == NOKOGIRI)
{
for(i=0; i<440; i++)
{
rmonPrintf("ele[%d].left = %d\n", i, audioBuf.ele[i].leftSound);
}
}
#endif
osAiSetFrequency(44100);
osWritebackDCacheAll();
osAiSetNextBuffer((void *)&audioBuf, 440*4);
osAiSetNextBuffer((void *)&audioBuf, 440*4);
for(i=0; i<length; i++)
{
while(osAiGetStatus() & AI_STATUS_FIFO_FULL)
;
osAiSetNextBuffer((void *)&audioBuf, 440*4);
pause_start(0);
}
}
#define AUDIO_PERIOD 256*4
#define REPEAT_TIMES 3
extern unsigned char CfbTestArea[];
#include "my_sound.h"
int my_aitest(int which)
{
int len, i, repeat=REPEAT_TIMES;
u16 *snd_buf = (u16 *) CfbTestArea;
u8 *snd, *end;
u64 wait;
switch (which) {
case ONLYR:
len = sizeof(right_sound);
snd = right_sound;
for (i=0; i<len*2; i+=2) {
snd_buf[i+1] = ((u16)snd[i+1] << 8) | snd[i];
snd_buf[i] = 0;
}
break;
case ONLYL:
len = sizeof(left_sound);
snd = left_sound;
for (i=0; i<len*2; i+=2) {
snd_buf[i] = ((u16)snd[i+1] << 8) | snd[i];
snd_buf[i+1] = 0;
}
break;
default:
len = sizeof(stero_sound);
snd = stero_sound;
for (i=0; i<len*2; i+=2)
snd_buf[i+1] = snd_buf[i] = ((u16)snd[i+1] << 8) | snd[i];
repeat = 1;
break;
}
osAiSetFrequency(22050);
osWritebackDCacheAll();
for (i=0; i<repeat; i++) {
snd = (u8 *) CfbTestArea;
end = snd + (len << 1);
while (snd < end) {
osAiSetNextBuffer(snd, AUDIO_PERIOD);
while(osAiGetStatus() & AI_STATUS_FIFO_FULL);
snd += AUDIO_PERIOD;
}
wait = OS_CYCLES_TO_USEC(osGetTime()) + 200000;
while (OS_CYCLES_TO_USEC(osGetTime()) < wait);
}
return 0;
}