annotate playercode/load_wav.c @ 21:eb5b14d0e054

Makefile unneeded rule mikmodux.h Fix MODULE
author darius
date Fri, 24 Apr 1998 08:04:39 +0000
parents 5d614bcc4287
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
1 /*
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
2
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3 Name: LOAD_WAV.C
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5 Description:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6 WAV Streaming Audio Loader / Player
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9 All compilers -- All systems (hopefully)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
10
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
11 */
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
12
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
13 #include "mikmod.h"
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
14 #include <string.h>
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
15
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
16
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17 typedef struct
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 { CHAR rID[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19 ULONG rLen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20 CHAR wID[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 CHAR fID[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22 ULONG fLen;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 UWORD wFormatTag;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 UWORD nChannels;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 ULONG nSamplesPerSec;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26 ULONG nAvgBytesPerSec;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 UWORD nBlockAlign;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 UWORD nFormatSpecific;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 } WAV;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
30
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
31
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 BOOL WAV_Load(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 SAMPLE *si;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 static WAV wh;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 static CHAR dID[4];
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
37
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
38 // read wav header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 _mm_read_string(wh.rID,4,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 wh.rLen = _mm_read_I_ULONG(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 _mm_read_string(wh.wID,4,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43 _mm_read_string(wh.fID,4,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44 wh.fLen = _mm_read_I_ULONG(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 wh.wFormatTag = _mm_read_I_UWORD(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 wh.nChannels = _mm_read_I_UWORD(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 wh.nSamplesPerSec = _mm_read_I_ULONG(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 wh.nAvgBytesPerSec = _mm_read_I_ULONG(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49 wh.nBlockAlign = _mm_read_I_UWORD(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 wh.nFormatSpecific = _mm_read_I_UWORD(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 // check it
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
53
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
54 if( feof(stream_fp) ||
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55 memcmp(wh.rID,"RIFF",4) ||
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 memcmp(wh.wID,"WAVE",4) ||
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57 memcmp(wh.fID,"fmt ",4) )
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 _mm_errno = MMERR_UNKNOWN_WAVE_TYPE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
61 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
62
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
63 // skip other crap
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 _mm_fseek(stream_fp,wh.fLen-16,SEEK_CUR);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 _mm_read_string(dID,4,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 if( memcmp(dID,"data",4) )
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69 { _mm_errno = MMERR_UNKNOWN_WAVE_TYPE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 if(wh.nChannels > 1)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 { _mm_errno = MMERR_UNKNOWN_WAVE_TYPE;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75 return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78 // printf("wFormatTag: %x\n",wh.wFormatTag);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 // printf("blockalign: %x\n",wh.nBlockAlign);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 // prinff("nFormatSpc: %x\n",wh.nFormatSpecific);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 if((si=(SAMPLE *)_mm_calloc(1,sizeof(SAMPLE)))==NULL) return NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
83
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
84 si->speed = wh.nSamplesPerSec/wh.nChannels;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85 si->volume = 64;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 si->length = _mm_read_I_ULONG(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 if(wh.nBlockAlign==2)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90 { si->flags = SF_16BITS | SF_SIGNED;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91 si->length>>=1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
93
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
94 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
95 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
96
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
97