annotate playercode/stream.c @ 22:d9f79436e0af default tip

Makefile Add ranlib for the library
author darius
date Fri, 24 Apr 1998 08:05:26 +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 File: STREAM.C
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
3
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
4 Description:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
5 Streaming Audio module for MikMod.
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
6
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
7 Portability:
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
8 All compilers - All systems
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
9
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
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 int stream_bufsize = 100; // in 1/100th seconds
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
17
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
18 static BOOL is_streaming = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
19 static MSTREAM *firststream = NULL;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
20
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
21 static BOOL active;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
22
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
23 FILE *stream_fp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
24 SLONG stream_seekpos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
25 SLONG stream_reppos;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
26
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
27 void MikMod_RegisterStream(MSTREAM *stream)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
28 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
29 MSTREAM *cruise = firststream;
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 if(cruise!=NULL)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
32 { while(cruise->next!=NULL) cruise = cruise->next;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
33 cruise->next = stream;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
34 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
35 firststream = stream;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
36 }
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
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
39 BOOL Stream_PlayFN(CHAR *filename)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
40 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
41 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
42 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
43
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
44
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
45 BOOL Stream_PlayFP(FILE *fp)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
46 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
47 BOOL ok;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
48 MSTREAM *l;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
49
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
50 stream_fp = fp;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
51 _mm_errno = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
52 _mm_critical = 0;
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 _mm_iobase_setcur(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
55
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
56 // Try to find a loader that recognizes the stream
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
57
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
58 for(l=firststream; l!=NULL; l=l->next)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
59 { _mm_rewind(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
60 if(l->Test()) break;
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 if(l==NULL)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
64 { _mm_errno = MMERR_NOT_A_STREAM;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
65 if(_mm_errorhandler!=NULL) _mm_errorhandler();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
66 _mm_iobase_revert();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
67 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
68 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
69
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
70 // init stream loader and load the header
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
71 if(l->Init())
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
72 { _mm_rewind(stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
73 ok = l->Load();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
74 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
75
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
76 // free loader allocations
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
77 l->Cleanup();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
78
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
79 if(!ok)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
80 { _mm_iobase_revert();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
81 return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
82 }
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 //loadbuf = _mm_malloc(8192);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
85
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
86 _mm_iobase_revert();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
87 active = 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
88 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
89 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
90
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
91
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
92 BOOL Stream_Init(ULONG speed, UWORD flags)
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 // size = size of buffer in 1/100th seconds
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 if(is_streaming) md_driver->StreamExit();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
98 if(md_driver->StreamInit(speed,flags)) return 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
99 is_streaming = 1;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
100
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
101 return 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
102 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
103
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
104
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
105 void Stream_Exit(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
106 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
107 if(is_streaming) md_driver->StreamExit();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
108 is_streaming = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
109 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
110
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
111
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
112 static ULONG last = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
113
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
114 void Stream_Update(void)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
115 {
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
116 ULONG curr;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
117 ULONG todo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
118
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
119 curr = md_driver->StreamGetPosition();
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
120 if(curr==last) return;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
121
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
122 if(curr>last)
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
123 { todo = curr-last;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
124 //SL_LoadStream(,vstream.infmt,vstream.flags,todo,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
125 last += todo;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
126 //if(last>=vstream.size) last = 0;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
127 } else
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
128 { //todo = vstream.size-last;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
129 //SL_LoadStream(&vstream.buffer[last],vstream.infmt,vstream.flags,todo,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
130 //SL_LoadStream(vstream.buffer,vstream.infmt,vstream.flags,curr,stream_fp);
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
131 last = curr;
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
132 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
133 }
5d614bcc4287 Initial entry of mikmod into the CVS tree.
darius
parents:
diff changeset
134