-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathau_channel.h
54 lines (43 loc) · 1.14 KB
/
au_channel.h
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
#include <stdio.h>
#include <string.h>
#include "config.h"
#define b2l(A) ((((unsigned short)(A) & 0xff00) >> 8) | (((unsigned short)(A) & 0x00ff) << 8))
#define WAV_HEADER_SIZE 44
typedef struct {
int sampleRate;
int nChannels;
long nSamples;
} WavInfo;
FILE* AuChannelOpen (const char* filename, WavInfo* info)
{
unsigned char header[WAV_HEADER_SIZE];
FILE *handle;
if (!strcmp(filename,"-"))
handle = stdin;
else
handle = fopen(filename, "rb");
if(!handle)
return NULL;
if(fread(header, 1, WAV_HEADER_SIZE, handle) != WAV_HEADER_SIZE)
return 0;
info->nSamples = (header[4] | (header[5] << 8) | (header[6] << 16) | (header[7] << 24)) + 8;
info->nChannels = header[22] | header[23] << 8;
info->sampleRate = header[24] | header[25] << 8 | header[26] << 12 | header[27] << 16;
return handle;
}
void AuChannelClose (FILE *audioChannel)
{
fclose(audioChannel);
}
size_t AuChannelReadShort(FILE *audioChannel, short *samples, int nSamples, int *readed)
{
*readed = fread(samples, 2, nSamples, audioChannel);
#ifdef _BE_ARCH
{
int i;
for(i = 0; i < *readed; i++)
samples[i] = b2l(samples[i]);
}
#endif
return *readed <= 0;
}