comparison playercode/stream.c @ 4:5d614bcc4287

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