audiotest.c
2.81 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
#include <ultra64.h>
#include "zaru.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)
{
u32 i;
u32 j;
u32 count=0;
i=0;
switch(sound)
{
case ONLYR:
while(i<440)
{
for(j=0; j<44; 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<44; 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<44; 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);
}
}