author | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-25 01:35:47 (UTC) |
commit | f180c1a5e8fc889ff1fb390d5cc94cdbc5085046 (patch) (unidiff) | |
tree | 5e9ea6f1313f4c33d57fb266523c1cfbe0826756 /core/multimedia/opieplayer/wavplugin | |
parent | c0446b55fc32b7fdea9f58db06e40da703f5e8ff (diff) | |
download | opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.zip opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.gz opie-f180c1a5e8fc889ff1fb390d5cc94cdbc5085046.tar.bz2 |
fucked up- no workie.. back out
Diffstat (limited to 'core/multimedia/opieplayer/wavplugin') (more/less context) (ignore whitespace changes)
5 files changed, 292 insertions, 147 deletions
diff --git a/core/multimedia/opieplayer/wavplugin/Makefile.in b/core/multimedia/opieplayer/wavplugin/Makefile.in index a46b925..bcbe7f2 100644 --- a/core/multimedia/opieplayer/wavplugin/Makefile.in +++ b/core/multimedia/opieplayer/wavplugin/Makefile.in | |||
@@ -79,33 +79,31 @@ listpromodules: | |||
79 | @echo | 79 | @echo |
80 | 80 | ||
81 | listallmodules: | 81 | listallmodules: |
82 | @echo | 82 | @echo |
83 | 83 | ||
84 | listaddonpromodules: | 84 | listaddonpromodules: |
85 | @echo | 85 | @echo |
86 | 86 | ||
87 | listaddonentmodules: | 87 | listaddonentmodules: |
88 | @echo | 88 | @echo |
89 | 89 | ||
90 | 90 | ||
91 | REQUIRES= | 91 | REQUIRES= |
92 | 92 | ||
93 | ####### Sub-libraries | 93 | ####### Sub-libraries |
94 | 94 | ||
95 | 95 | ||
96 | ###### Combined headers | 96 | ###### Combined headers |
97 | 97 | ||
98 | 98 | ||
99 | 99 | ||
100 | ####### Compile | 100 | ####### Compile |
101 | 101 | ||
102 | wavplugin.o: wavplugin.cpp \ | 102 | wavplugin.o: wavplugin.cpp \ |
103 | wavplugin.h \ | 103 | wavplugin.h |
104 | ../mediaplayerplugininterface.h | ||
105 | 104 | ||
106 | wavpluginimpl.o: wavpluginimpl.cpp \ | 105 | wavpluginimpl.o: wavpluginimpl.cpp \ |
107 | wavplugin.h \ | 106 | wavplugin.h \ |
108 | ../mediaplayerplugininterface.h \ | ||
109 | wavpluginimpl.h | 107 | wavpluginimpl.h |
110 | 108 | ||
111 | 109 | ||
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 7f63b3b..0be667f 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -1,341 +1,494 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | ||
21 | |||
22 | #include <stdio.h> | 20 | #include <stdio.h> |
23 | #include <stdarg.h> | 21 | #include <stdarg.h> |
24 | #include <stdlib.h> | 22 | #include <stdlib.h> |
25 | #include <errno.h> | 23 | #include <errno.h> |
26 | #include <unistd.h> | 24 | #include <unistd.h> |
27 | #include <qfile.h> | 25 | #include <qfile.h> |
28 | #include "wavplugin.h" | 26 | #include "wavplugin.h" |
29 | 27 | ||
30 | |||
31 | //#define debugMsg(a) qDebug(a) | 28 | //#define debugMsg(a) qDebug(a) |
32 | #define debugMsg(a) | 29 | #define debugMsg(a) |
33 | 30 | ||
34 | 31 | ||
35 | struct RiffChunk { | 32 | struct RiffChunk { |
36 | char id[4]; | 33 | char id[4]; |
37 | Q_UINT32 size; | 34 | Q_UINT32 size; |
38 | char data[4]; | 35 | char data[4]; |
39 | }; | 36 | }; |
40 | 37 | ||
41 | 38 | ||
42 | struct ChunkData { | 39 | struct ChunkData { |
43 | Q_INT16 formatTag; | 40 | Q_INT16 formatTag; |
44 | Q_INT16 channels; | 41 | Q_INT16 channels; |
45 | Q_INT32 samplesPerSec; | 42 | Q_INT32 samplesPerSec; |
46 | Q_INT32 avgBytesPerSec; | 43 | Q_INT32 avgBytesPerSec; |
47 | Q_INT16 blockAlign; | 44 | Q_INT16 blockAlign; |
48 | Q_INT16 wBitsPerSample; | 45 | Q_INT16 wBitsPerSample; |
49 | }; | 46 | }; |
50 | 47 | ||
51 | 48 | ||
52 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? | 49 | const int sound_buffer_size = 4096; |
53 | 50 | ||
54 | 51 | ||
55 | class WavPluginData { | 52 | class WavPluginData { |
56 | public: | 53 | public: |
57 | QFile *input; | 54 | QFile *input; |
58 | 55 | ||
59 | int wavedata_remaining; | 56 | int wavedata_remaining; |
60 | ChunkData chunkdata; | 57 | ChunkData chunkdata; |
61 | RiffChunk chunk; | 58 | RiffChunk chunk; |
62 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data | 59 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data |
63 | int out,max; | 60 | int out,max; |
64 | int samples_due; | 61 | int samples_due; |
65 | int samples; | 62 | int samples; |
66 | 63 | int freq; | |
64 | int chan; | ||
65 | int sampleRate; | ||
66 | int resolution; | ||
67 | |||
67 | WavPluginData() { | 68 | WavPluginData() { |
68 | max = out = sound_buffer_size; | 69 | max = out = sound_buffer_size; |
69 | wavedata_remaining = 0; | 70 | wavedata_remaining = 0; |
70 | samples_due = 0; | 71 | samples_due = 0; |
71 | samples = -1; | 72 | samples = -1; |
72 | } | 73 | } |
73 | 74 | ||
74 | // expands out samples to the frequency of 44kHz | 75 | // expands out samples to the frequency of 44kHz |
75 | bool add( short *output, long count, long& done, bool stereo ) | 76 | bool add( short *output, long count, long& done, bool stereo ) |
76 | { | 77 | { |
77 | done = 0; | 78 | qDebug("add"); |
78 | qApp->processEvents(); | 79 | done = 0; |
79 | 80 | ||
80 | if ( input == 0 ) { | 81 | if ( input == 0 ) { |
81 | qDebug("no input"); | 82 | qDebug("no input"); |
82 | return FALSE; | ||
83 | } | ||
84 | |||
85 | while ( count ) { | ||
86 | int l,r; | ||
87 | if ( getSample(l, r) == FALSE ) { | ||
88 | qDebug("didn't get sample"); | ||
89 | return FALSE; | 83 | return FALSE; |
90 | } | 84 | } |
91 | samples_due += chunkdata.samplesPerSec; | 85 | |
92 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | 86 | while ( count ) { |
93 | *output++ = l; | 87 | int l,r; |
94 | if ( stereo ) | 88 | if ( getSample(l, r) == FALSE ) { |
95 | *output++ = r; | 89 | qDebug("didn't get sample"); |
96 | samples_due -= chunkdata.samplesPerSec; | 90 | return FALSE; |
97 | count--; | 91 | } |
98 | done++; | 92 | samples_due += 44100; |
93 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | ||
94 | *output++ = l; | ||
95 | if ( stereo ) | ||
96 | *output++ = r; | ||
97 | samples_due -= chunkdata.samplesPerSec; | ||
98 | count--; | ||
99 | done++; | ||
100 | } | ||
99 | } | 101 | } |
102 | |||
103 | return TRUE; | ||
100 | } | 104 | } |
101 | return TRUE; | ||
102 | } | ||
103 | 105 | ||
104 | bool initialise() { | 106 | bool initialise() { |
105 | if ( input == 0 ) | 107 | qDebug("initialize"); |
106 | return FALSE; | 108 | if ( input == 0 ) |
109 | return FALSE; | ||
110 | |||
111 | wavedata_remaining = -1; | ||
112 | |||
113 | while ( wavedata_remaining == -1 ) { | ||
114 | // Keep reading chunks... | ||
115 | const int n = sizeof(chunk) - sizeof(chunk.data); | ||
116 | int t = input->readBlock( (char*)&chunk, n ); | ||
117 | if ( t != n ) { | ||
118 | if ( t == -1 ) | ||
119 | return FALSE; | ||
120 | return TRUE; | ||
121 | } | ||
122 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | ||
123 | samples = wavedata_remaining = chunk.size; | ||
124 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | ||
125 | char d[4]; | ||
126 | if ( input->readBlock(d,4) != 4 ) { | ||
127 | return FALSE; | ||
128 | } | ||
129 | if ( qstrncmp(d,"WAVE",4) != 0 ) { | ||
130 | // skip | ||
131 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { | ||
132 | return FALSE; | ||
133 | } | ||
134 | } | ||
135 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { | ||
136 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { | ||
137 | return FALSE; | ||
138 | } | ||
139 | #define WAVE_FORMAT_PCM 1 | ||
140 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | ||
141 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | ||
142 | return FALSE; | ||
143 | } | ||
144 | } | ||
107 | 145 | ||
108 | wavedata_remaining = -1; | ||
109 | 146 | ||
110 | while ( wavedata_remaining == -1 ) { | 147 | |
111 | // Keep reading chunks... | 148 | |
112 | const int n = sizeof(chunk) - sizeof(chunk.data); | 149 | else { |
113 | int t = input->readBlock( (char*)&chunk, n ); | 150 | // ignored chunk |
114 | if ( t != n ) { | 151 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { |
115 | if ( t == -1 ) | 152 | return FALSE; |
116 | return FALSE; | 153 | } |
117 | return TRUE; | 154 | } |
118 | } | 155 | } // while |
119 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | 156 | |
120 | samples = wavedata_remaining = chunk.size; | 157 | return TRUE; |
121 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | ||
122 | char d[4]; | ||
123 | if ( input->readBlock(d,4) != 4 ) { | ||
124 | return FALSE; | ||
125 | } | ||
126 | if ( qstrncmp(d,"WAVE",4) != 0 ) { | ||
127 | // skip | ||
128 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { | ||
129 | return FALSE; | ||
130 | } | ||
131 | } | ||
132 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { | ||
133 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { | ||
134 | return FALSE; | ||
135 | } | ||
136 | #define WAVE_FORMAT_PCM 1 | ||
137 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | ||
138 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | ||
139 | return FALSE; | ||
140 | } | ||
141 | } else { | ||
142 | // ignored chunk | ||
143 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { | ||
144 | return FALSE; | ||
145 | } | ||
146 | } | ||
147 | } // while | ||
148 | qDebug("bits %d", chunkdata.wBitsPerSample); | ||
149 | return TRUE; | ||
150 | } | 158 | } |
151 | 159 | ||
152 | 160 | ||
153 | // gets a sample from the file | 161 | // gets a sample from the file |
154 | bool getSample(int& l, int& r) | 162 | bool getSample(int& l, int& r) |
155 | { | 163 | { |
156 | l = r = 0; | 164 | l = r = 0; |
157 | 165 | ||
158 | if ( input == 0 ) | 166 | if ( input == 0 ) |
159 | return FALSE; | 167 | return FALSE; |
160 | 168 | ||
161 | if ( (wavedata_remaining < 0) || !max ) | 169 | if ( (wavedata_remaining < 0) || !max ) |
162 | return FALSE; | 170 | return FALSE; |
163 | 171 | ||
164 | if ( out >= max ) { | 172 | if ( out >= max ) { |
165 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); | 173 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); |
166 | 174 | ||
167 | wavedata_remaining -= max; | 175 | wavedata_remaining -= max; |
168 | 176 | ||
169 | out = 0; | 177 | out = 0; |
170 | if ( max <= 0 ) { | 178 | if ( max <= 0 ) { |
171 | max = 0; | 179 | max = 0; |
172 | return TRUE; | 180 | return TRUE; |
173 | } | 181 | } |
174 | } | 182 | } |
175 | if ( chunkdata.wBitsPerSample == 8 ) { | 183 | if ( resolution == 8 ) { |
176 | l = (data[out++] - 128) * 128; | 184 | l = (data[out++] - 128) * 128; |
177 | } else { | 185 | } else { |
178 | l = ((short*)data)[out/2]; | 186 | l = ((short*)data)[out/2]; |
179 | out += 2; | 187 | out += 2; |
180 | } | 188 | } |
181 | if ( chunkdata.channels == 1 ) { | 189 | if ( chan == 1 ) { |
182 | r = l; | 190 | r = l; |
183 | } else { | 191 | } else { |
184 | if ( chunkdata.wBitsPerSample == 8 ) { | 192 | if ( resolution == 8 ) { |
185 | r = (data[out++] - 128) * 128; | 193 | r = (data[out++] - 128) * 128; |
186 | } else { | 194 | } else { |
187 | r = ((short*)data)[out/2]; | 195 | r = ((short*)data)[out/2]; |
188 | out += 2; | 196 | out += 2; |
189 | } | 197 | } |
190 | } | 198 | } |
191 | return TRUE; | 199 | return TRUE; |
192 | } // getSample | 200 | } // getSample |
201 | |||
202 | ////////////////////////////////////////////////////// | ||
203 | int getWavSettings(int fd) | ||
204 | { //this came from wmrecord | ||
205 | |||
206 | char t1[4]; | ||
207 | unsigned long l1; | ||
208 | int found; | ||
209 | short fmt; | ||
210 | unsigned short ch, brate; | ||
211 | unsigned long srate; | ||
212 | |||
213 | |||
214 | /* First read in the RIFF identifier. If this is missing then the | ||
215 | * file is not a valid WAVE file. | ||
216 | */ | ||
217 | if (read(fd, t1, 4)<4) { | ||
218 | qDebug(" Could not read from sound file.\n"); | ||
219 | return -1; | ||
220 | } | ||
221 | if (strncmp(t1, "RIFF", 4)) { | ||
222 | qDebug(" not a valid WAV file.\n"); | ||
223 | return -1; | ||
224 | } | ||
225 | /* Advance the file pointer to the next relevant field. */ | ||
226 | lseek(fd, 4, SEEK_CUR); | ||
227 | /* Read in the WAVE identifier. */ | ||
228 | if (read(fd, t1, 4)<4) { | ||
229 | qDebug("Could not read from sound file.\n"); | ||
230 | return -1; | ||
231 | } | ||
232 | if (strncmp(t1, "WAVE", 4)) { | ||
233 | qDebug("not a valid WAV file.\n"); | ||
234 | return -1; | ||
235 | } | ||
193 | 236 | ||
237 | /* Search through the file for the format chunk. If the end of the | ||
238 | * file is reached without finding the chunk, then the file is not a | ||
239 | * valid WAVE file. | ||
240 | */ | ||
241 | found = 0; | ||
242 | while (!found) { | ||
243 | if (read(fd, t1, 4)<4) { | ||
244 | qDebug("Could not read from sound file.\n"); | ||
245 | return -1; | ||
246 | } | ||
247 | if (strncmp(t1, "fmt ", 4)) { | ||
248 | /* Determine the length of the chunk found and skip to the next | ||
249 | * chunk. The chunk length is always stored in the four bytes | ||
250 | * following the chunk id. | ||
251 | */ | ||
252 | if (read(fd, &l1, 4)<4) { | ||
253 | qDebug("Could not read from sound file.\n"); | ||
254 | return -1; | ||
255 | } | ||
256 | lseek(fd, l1, SEEK_CUR); | ||
257 | } | ||
258 | else { | ||
259 | /* This is the format chunk, which stores the playback settings | ||
260 | * for the recording. | ||
261 | */ | ||
262 | /* Skip the length field, since we don't really need it. */ | ||
263 | lseek(fd, 4, SEEK_CUR); | ||
264 | /* Read in the format tag. If it has a value of 1, then there is | ||
265 | * no compression and we can attempt to play the file | ||
266 | * back. Otherwise, return. | ||
267 | */ | ||
268 | if (read(fd, &fmt, 2)<2) { | ||
269 | qDebug("Could not read from format chunk.\n"); | ||
270 | return -1; | ||
271 | } | ||
272 | if (fmt != 1) { | ||
273 | qDebug("Wave file contains compressed data." | ||
274 | " Unable to continue.\n"); | ||
275 | return -1; | ||
276 | } | ||
277 | /* Get the stereo mode. */ | ||
278 | if (read(fd, &ch, 2)<2) { | ||
279 | qDebug("Could not read from format chunk.\n"); | ||
280 | return -1; | ||
281 | } | ||
282 | else { | ||
283 | chan = ch; | ||
284 | qDebug("File has %d channels", chan); | ||
285 | } | ||
286 | /* Get the sample rate. */ | ||
287 | if (read(fd, &srate, 4)<4) { | ||
288 | qDebug("Could not read from format chunk.\n"); | ||
289 | return -1; | ||
290 | } | ||
291 | else { | ||
292 | sampleRate = srate; | ||
293 | qDebug("File has samplerate of %d", sampleRate); | ||
294 | } | ||
295 | /* Get the bit rate. This is at the end of the format chunk. */ | ||
296 | lseek(fd, 6, SEEK_CUR); | ||
297 | if (read(fd, &brate, 2)<2) { | ||
298 | qDebug("Could not read from format chunk.\n"); | ||
299 | return -1; | ||
300 | } | ||
301 | else { | ||
302 | resolution = brate; | ||
303 | qDebug("File has bitrate of %d", resolution); | ||
304 | } | ||
305 | |||
306 | found++; | ||
307 | } | ||
308 | } | ||
309 | |||
310 | /* Search through the file for the data chunk. If the end of the | ||
311 | * file is reached without finding the chunk, then the file is not a | ||
312 | * valid WAVE file. | ||
313 | */ | ||
314 | found = 0; | ||
315 | while (!found) { | ||
316 | if (read(fd, t1, 4)<4) { | ||
317 | qDebug("Could not read from sound file.\n"); | ||
318 | return -1; | ||
319 | } | ||
320 | if (strncmp(t1, "data", 4)) { | ||
321 | /* Determine the length of the chunk found and skip to the next | ||
322 | * chunk. The chunk length is always stored in the four bytes | ||
323 | * following the chunk id. | ||
324 | */ | ||
325 | if (read(fd, &l1, 4)<4) { | ||
326 | qDebug("Could not read from sound file.\n"); | ||
327 | return -1; | ||
328 | } | ||
329 | lseek(fd, l1, SEEK_CUR); | ||
330 | } | ||
331 | else { | ||
332 | /* This is the data chunk, which stores the recording. */ | ||
333 | /* Get the length field. */ | ||
334 | if (read(fd, &l1, 4)<4) { | ||
335 | qDebug("Could not read from sound file.\n"); | ||
336 | return -1; | ||
337 | } | ||
338 | else { | ||
339 | samples =l1; | ||
340 | qDebug("file has length of %d\nlasting %d seconds",l1, (( l1 / sampleRate) / chan) / 2 ); // ???? | ||
341 | return l1; | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | ////////////////////////////////////////////////// | ||
194 | }; | 350 | }; |
195 | 351 | ||
196 | 352 | ||
197 | WavPlugin::WavPlugin() { | 353 | WavPlugin::WavPlugin() { |
198 | d = new WavPluginData; | 354 | d = new WavPluginData; |
199 | d->input = 0; | 355 | d->input = 0; |
200 | } | 356 | } |
201 | 357 | ||
202 | 358 | ||
203 | WavPlugin::~WavPlugin() { | 359 | WavPlugin::~WavPlugin() { |
204 | close(); | 360 | close(); |
205 | delete d; | 361 | delete d; |
206 | } | 362 | } |
207 | 363 | ||
208 | 364 | ||
209 | bool WavPlugin::isFileSupported( const QString& path ) { | 365 | bool WavPlugin::isFileSupported( const QString& path ) { |
210 | // qDebug( "WavPlugin::isFileSupported" ); | 366 | debugMsg( "WavPlugin::isFileSupported" ); |
211 | 367 | ||
212 | char *ext = strrchr( path.latin1(), '.' ); | 368 | char *ext = strrchr( path.latin1(), '.' ); |
213 | 369 | ||
214 | // Test file extension | 370 | // Test file extension |
215 | if ( ext ) { | 371 | if ( ext ) { |
216 | if ( strncasecmp(ext, ".raw", 4) == 0 ) | 372 | if ( strncasecmp(ext, ".raw", 4) == 0 ) |
217 | return TRUE; | 373 | return TRUE; |
218 | if ( strncasecmp(ext, ".wav", 4) == 0 ) | 374 | if ( strncasecmp(ext, ".wav", 4) == 0 ) |
219 | return TRUE; | 375 | return TRUE; |
220 | if ( strncasecmp(ext, ".wave", 4) == 0 ) | 376 | if ( strncasecmp(ext, ".wave", 4) == 0 ) |
221 | return TRUE; | 377 | return TRUE; |
222 | } | 378 | } |
223 | 379 | ||
224 | return FALSE; | 380 | return FALSE; |
225 | } | 381 | } |
226 | 382 | ||
227 | 383 | ||
228 | bool WavPlugin::open( const QString& path ) { | 384 | bool WavPlugin::open( const QString& path ) { |
229 | // qDebug( "WavPlugin::open" ); | 385 | qDebug( "WavPlugin::open" ); |
230 | 386 | ||
231 | d->max = d->out = sound_buffer_size; | 387 | d->max = d->out = sound_buffer_size; |
232 | d->wavedata_remaining = 0; | 388 | d->wavedata_remaining = 0; |
233 | d->samples_due = 0; | 389 | d->samples_due = 0; |
234 | 390 | ||
235 | d->input = new QFile( path ); | 391 | d->input = new QFile( path ); |
236 | if ( d->input->open(IO_ReadOnly) == FALSE ) { | 392 | if ( d->input->open(IO_ReadOnly) == FALSE ) { |
237 | qDebug("couldn't open file"); | 393 | qDebug("couldn't open file"); |
238 | delete d->input; | 394 | delete d->input; |
239 | d->input = 0; | 395 | d->input = 0; |
240 | return FALSE; | 396 | return FALSE; |
241 | } | 397 | } |
242 | 398 | ||
399 | // d->getWavSettings( d->input.handle()); | ||
243 | d->initialise(); | 400 | d->initialise(); |
244 | 401 | ||
245 | return TRUE; | 402 | return TRUE; |
246 | } | 403 | } |
247 | 404 | ||
248 | 405 | ||
249 | bool WavPlugin::close() { | 406 | bool WavPlugin::close() { |
250 | // qDebug( "WavPlugin::close" ); | 407 | qDebug( "WavPlugin::close" ); |
251 | 408 | ||
252 | d->input->close(); | 409 | d->input->close(); |
253 | delete d->input; | 410 | delete d->input; |
254 | d->input = 0; | 411 | d->input = 0; |
255 | return TRUE; | 412 | return TRUE; |
256 | } | 413 | } |
257 | 414 | ||
258 | 415 | ||
259 | bool WavPlugin::isOpen() { | 416 | bool WavPlugin::isOpen() { |
260 | // qDebug( "WavPlugin::isOpen" ); | 417 | qDebug( "WavPlugin::isOpen" ); |
261 | return ( d->input != 0 ); | 418 | return ( d->input != 0 ); |
262 | } | 419 | } |
263 | 420 | ||
264 | 421 | ||
265 | int WavPlugin::audioStreams() { | 422 | int WavPlugin::audioStreams() { |
266 | // qDebug( "WavPlugin::audioStreams" ); | 423 | qDebug( "WavPlugin::audioStreams" ); |
267 | return 1; | 424 | return 1; |
268 | } | 425 | } |
269 | 426 | ||
270 | 427 | ||
271 | int WavPlugin::audioChannels( int ) { | 428 | int WavPlugin::audioChannels( int ) { |
272 | // qDebug( "WavPlugin::audioChannels" ); | 429 | debugMsg( "WavPlugin::audioChannels" ); |
273 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples | 430 | return d->chan; |
274 | } | 431 | } |
275 | 432 | ||
276 | 433 | ||
277 | int WavPlugin::audioFrequency( int ) { | 434 | int WavPlugin::audioFrequency( int ) { |
278 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); | 435 | qDebug( "WavPlugin::audioFrequency" ); |
279 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 | 436 | return d->freq; |
280 | } | 437 | } |
281 | 438 | ||
282 | 439 | ||
283 | int WavPlugin::audioSamples( int ) { | 440 | int WavPlugin::audioSamples( int ) { |
284 | // qDebug( "WavPlugin::audioSamples" ); | 441 | qDebug( "WavPlugin::audioSamples" ); |
285 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, | 442 | return d->samples; |
286 | // Therefore if source is mono we will double the number of samples | 443 | // return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, |
444 | // // Therefore if source is mono we will double the number of samples | ||
287 | } | 445 | } |
288 | 446 | ||
289 | 447 | ||
290 | bool WavPlugin::audioSetSample( long, int ) { | 448 | bool WavPlugin::audioSetSample( long, int ) { |
291 | // qDebug( "WavPlugin::audioSetSample" ); | 449 | qDebug( "WavPlugin::audioSetSample" ); |
292 | return FALSE; | 450 | return FALSE; |
293 | } | 451 | } |
294 | 452 | ||
295 | 453 | ||
296 | long WavPlugin::audioGetSample( int ) { | 454 | long WavPlugin::audioGetSample( int ) { |
297 | // qDebug( "WavPlugin::audioGetSample" ); | 455 | qDebug( "WavPlugin::audioGetSample" ); |
298 | return 0; | 456 | return 0; |
299 | } | 457 | } |
300 | 458 | ||
301 | /* | 459 | /* |
302 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { | 460 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { |
303 | debugMsg( "WavPlugin::audioReadSamples" ); | 461 | debugMsg( "WavPlugin::audioReadSamples" ); |
304 | return FALSE; | 462 | return FALSE; |
305 | } | 463 | } |
306 | 464 | ||
307 | 465 | ||
308 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { | 466 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { |
309 | debugMsg( "WavPlugin::audioReReadSamples" ); | 467 | debugMsg( "WavPlugin::audioReReadSamples" ); |
310 | return FALSE; | 468 | return FALSE; |
311 | } | 469 | } |
312 | 470 | ||
313 | 471 | ||
314 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { | 472 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { |
315 | debugMsg( "WavPlugin::audioReadMonoSamples" ); | 473 | debugMsg( "WavPlugin::audioReadMonoSamples" ); |
316 | return !d->add( output, samples, samplesMade, FALSE ); | 474 | return !d->add( output, samples, samplesMade, FALSE ); |
317 | } | 475 | } |
318 | 476 | ||
319 | 477 | ||
320 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { | 478 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { |
321 | debugMsg( "WavPlugin::audioReadStereoSamples" ); | 479 | debugMsg( "WavPlugin::audioReadStereoSamples" ); |
322 | return !d->add( output, samples, samplesMade, TRUE ); | 480 | return !d->add( output, samples, samplesMade, TRUE ); |
323 | } | 481 | } |
324 | */ | 482 | */ |
325 | 483 | ||
326 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { | 484 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { |
327 | // qDebug( "WavPlugin::audioReadSamples" ); | 485 | qDebug( "WavPlugin::audioReadSamples" ); |
328 | return d->add( output, samples, samplesMade, channels != 1 ); | 486 | return d->add( output, samples, samplesMade, channels != 1 ); |
329 | } | 487 | } |
330 | 488 | ||
331 | double WavPlugin::getTime() { | 489 | double WavPlugin::getTime() { |
332 | // qDebug( "WavPlugin::getTime" ); | 490 | qDebug( "WavPlugin::getTime" ); |
333 | return 0.0; | 491 | return 0.0; |
334 | } | 492 | } |
335 | 493 | ||
336 | int WavPlugin::audioBitsPerSample( int ) { | ||
337 | // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); | ||
338 | return d->chunkdata.wBitsPerSample; // | ||
339 | } | ||
340 | |||
341 | 494 | ||
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.h b/core/multimedia/opieplayer/wavplugin/wavplugin.h index 6afd67e..19d1a8e 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.h +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.h | |||
@@ -1,81 +1,77 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | ||
21 | |||
22 | #ifndef WAV_PLUGIN_H | 20 | #ifndef WAV_PLUGIN_H |
23 | #define WAV_PLUGIN_H | 21 | #define WAV_PLUGIN_H |
24 | 22 | ||
25 | |||
26 | #include <qstring.h> | 23 | #include <qstring.h> |
27 | #include <qapplication.h> | 24 | #include <qapplication.h> |
28 | #include "../mediaplayerplugininterface.h" | 25 | #include <qpe/mediaplayerplugininterface.h> |
29 | 26 | ||
30 | 27 | ||
31 | // #define OLD_MEDIAPLAYER_API | 28 | // #define OLD_MEDIAPLAYER_API |
32 | 29 | ||
33 | 30 | ||
34 | class WavPluginData; | 31 | class WavPluginData; |
35 | 32 | ||
36 | 33 | ||
37 | class WavPlugin : public MediaPlayerDecoder { | 34 | class WavPlugin : public MediaPlayerDecoder { |
38 | 35 | ||
39 | public: | 36 | public: |
40 | WavPlugin(); | 37 | WavPlugin(); |
41 | ~WavPlugin(); | 38 | ~WavPlugin(); |
42 | 39 | ||
43 | const char *pluginName() { return "WavPlugin"; } | 40 | const char *pluginName() { return "WavPlugin"; } |
44 | const char *pluginComment() { return "This is a simple plugin for playing wav files"; } | 41 | const char *pluginComment() { return "This is a simple plugin for playing wav files"; } |
45 | double pluginVersion() { return 1.0; } | 42 | double pluginVersion() { return 1.0; } |
46 | 43 | ||
47 | bool isFileSupported( const QString& ); | 44 | bool isFileSupported( const QString& ); |
48 | bool open( const QString& ); | 45 | bool open( const QString& ); |
49 | bool close(); | 46 | bool close(); |
50 | bool isOpen(); | 47 | bool isOpen(); |
51 | const QString &fileInfo() { return strInfo = ""; } | 48 | const QString &fileInfo() { return strInfo = ""; } |
52 | 49 | ||
53 | // If decoder doesn't support audio then return 0 here | 50 | // If decoder doesn't support audio then return 0 here |
54 | int audioStreams(); | 51 | int audioStreams(); |
55 | int audioChannels( int stream ); | 52 | int audioChannels( int stream ); |
56 | int audioFrequency( int stream ); | 53 | int audioFrequency( int stream ); |
57 | int audioBitsPerSample( int stream ); | ||
58 | int audioSamples( int stream ); | 54 | int audioSamples( int stream ); |
59 | bool audioSetSample( long sample, int stream ); | 55 | bool audioSetSample( long sample, int stream ); |
60 | long audioGetSample( int stream ); | 56 | long audioGetSample( int stream ); |
61 | #ifdef OLD_MEDIAPLAYER_API | 57 | #ifdef OLD_MEDIAPLAYER_API |
62 | bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); | 58 | bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); |
63 | bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); | 59 | bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); |
64 | bool audioReadSamples( short *output, int channel, long samples, int stream ); | 60 | bool audioReadSamples( short *output, int channel, long samples, int stream ); |
65 | bool audioReReadSamples( short *output, int channel, long samples, int stream ); | 61 | bool audioReReadSamples( short *output, int channel, long samples, int stream ); |
66 | #else | 62 | #else |
67 | bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); | 63 | bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); |
68 | #endif | 64 | #endif |
69 | 65 | ||
70 | // If decoder doesn't support video then return 0 here | 66 | // If decoder doesn't support video then return 0 here |
71 | int videoStreams() { return 0; } | 67 | int videoStreams() { return 0; } |
72 | int videoWidth( int ) { return 0; } | 68 | int videoWidth( int ) { return 0; } |
73 | int videoHeight( int ) { return 0; } | 69 | int videoHeight( int ) { return 0; } |
74 | double videoFrameRate( int ) { return 0.0; } | 70 | double videoFrameRate( int ) { return 0.0; } |
75 | int videoFrames( int ) { return 0; } | 71 | int videoFrames( int ) { return 0; } |
76 | bool videoSetFrame( long, int ) { return FALSE; } | 72 | bool videoSetFrame( long, int ) { return FALSE; } |
77 | long videoGetFrame( int ) { return 0; } | 73 | long videoGetFrame( int ) { return 0; } |
78 | bool videoReadFrame( unsigned char **, int, int, int, int, ColorFormat, int ) { return FALSE; } | 74 | bool videoReadFrame( unsigned char **, int, int, int, int, ColorFormat, int ) { return FALSE; } |
79 | bool videoReadScaledFrame( unsigned char **, int, int, int, int, int, int, ColorFormat, int ) { return FALSE; } | 75 | bool videoReadScaledFrame( unsigned char **, int, int, int, int, int, int, ColorFormat, int ) { return FALSE; } |
80 | bool videoReadYUVFrame( char *, char *, char *, int, int, int, int, int ) { return FALSE; } | 76 | bool videoReadYUVFrame( char *, char *, char *, int, int, int, int, int ) { return FALSE; } |
81 | 77 | ||
diff --git a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.cpp b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.cpp index 1f7b85b..2923180 100644 --- a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.cpp | |||
@@ -1,47 +1,46 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "wavplugin.h" | 20 | #include "wavplugin.h" |
21 | #include "wavpluginimpl.h" | 21 | #include "wavpluginimpl.h" |
22 | 22 | ||
23 | |||
24 | WavPluginImpl::WavPluginImpl() | 23 | WavPluginImpl::WavPluginImpl() |
25 | : libmadplugin(0), ref(0) | 24 | : libmadplugin(0), ref(0) |
26 | { | 25 | { |
27 | } | 26 | } |
28 | 27 | ||
29 | 28 | ||
30 | WavPluginImpl::~WavPluginImpl() | 29 | WavPluginImpl::~WavPluginImpl() |
31 | { | 30 | { |
32 | if ( libmadplugin ) | 31 | if ( libmadplugin ) |
33 | delete libmadplugin; | 32 | delete libmadplugin; |
34 | } | 33 | } |
35 | 34 | ||
36 | 35 | ||
37 | MediaPlayerDecoder *WavPluginImpl::decoder() | 36 | MediaPlayerDecoder *WavPluginImpl::decoder() |
38 | { | 37 | { |
39 | if ( !libmadplugin ) | 38 | if ( !libmadplugin ) |
40 | libmadplugin = new WavPlugin; | 39 | libmadplugin = new WavPlugin; |
41 | return libmadplugin; | 40 | return libmadplugin; |
42 | } | 41 | } |
43 | 42 | ||
44 | 43 | ||
45 | MediaPlayerEncoder *WavPluginImpl::encoder() | 44 | MediaPlayerEncoder *WavPluginImpl::encoder() |
46 | { | 45 | { |
47 | return NULL; | 46 | return NULL; |
diff --git a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h index ee32f54..71f5f20 100644 --- a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h +++ b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h | |||
@@ -1,48 +1,47 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef WAV_PLUGIN_IMPL_H | 20 | #ifndef WAV_PLUGIN_IMPL_H |
21 | #define WAV_PLUGIN_IMPL_H | 21 | #define WAV_PLUGIN_IMPL_H |
22 | 22 | ||
23 | 23 | #include <qpe/mediaplayerplugininterface.h> | |
24 | #include "../mediaplayerplugininterface.h" | ||
25 | 24 | ||
26 | 25 | ||
27 | class WavPlugin; | 26 | class WavPlugin; |
28 | 27 | ||
29 | 28 | ||
30 | class WavPluginImpl : public MediaPlayerPluginInterface | 29 | class WavPluginImpl : public MediaPlayerPluginInterface |
31 | { | 30 | { |
32 | public: | 31 | public: |
33 | WavPluginImpl(); | 32 | WavPluginImpl(); |
34 | virtual ~WavPluginImpl(); | 33 | virtual ~WavPluginImpl(); |
35 | 34 | ||
36 | #ifndef QT_NO_COMPONENT | 35 | #ifndef QT_NO_COMPONENT |
37 | 36 | ||
38 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | 37 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); |
39 | Q_REFCOUNT | 38 | Q_REFCOUNT |
40 | 39 | ||
41 | #endif | 40 | #endif |
42 | 41 | ||
43 | virtual MediaPlayerDecoder *decoder(); | 42 | virtual MediaPlayerDecoder *decoder(); |
44 | virtual MediaPlayerEncoder *encoder(); | 43 | virtual MediaPlayerEncoder *encoder(); |
45 | 44 | ||
46 | private: | 45 | private: |
47 | WavPlugin *libmadplugin; | 46 | WavPlugin *libmadplugin; |
48 | ulong ref; | 47 | ulong ref; |