Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/tools/sdk-tools/adpcm/sampleio.c
7861 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include "vadpcm.h"
4
5
static void fmtchan(s32 size, u8 *p, s32 *data, s32 stride)
6
{
7
s32 i;
8
s32 c;
9
10
for (i = 0; i < size; i++)
11
{
12
c = *data++;
13
if (c < -0x7fff)
14
{
15
c = -0x7fff;
16
}
17
if (c >= 0x8000)
18
{
19
c = 0x7fff;
20
}
21
p[0] = c >> 8;
22
p[1] = c;
23
p += stride;
24
}
25
}
26
27
void writeout(FILE *outfd, s32 size, s32 *l_out, s32 *r_out, s32 chans)
28
{
29
static u8 obuf[0x1000];
30
s32 i;
31
32
switch (chans)
33
{
34
case 2:
35
fmtchan(size, obuf, l_out, chans * 2);
36
fmtchan(size, obuf + 2, r_out, chans * 2);
37
if (outfd != NULL)
38
{
39
if ((i = fwrite(obuf, 1, size * 4, outfd)) != size * 4)
40
{
41
fprintf(stderr, "write error %d\n", i);
42
exit(1);
43
}
44
}
45
break;
46
47
case 1:
48
fmtchan(size, obuf, l_out, 2);
49
if (outfd != NULL)
50
{
51
if ((i = fwrite(obuf, 1, size * 2, outfd)) != size * 2)
52
{
53
fprintf(stderr, "write error %d\n", i);
54
exit(1);
55
}
56
}
57
break;
58
59
default:
60
fprintf(stderr, "Error in number of channels\n");
61
exit(1);
62
}
63
}
64
65