author | llornkcor <llornkcor> | 2002-02-25 04:59:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-25 04:59:47 (UTC) |
commit | d948361c1b475fab4660b28fbf5ec21fd34d923f (patch) (unidiff) | |
tree | 89bc57d755e37b27c396499c58369d595158b530 /core | |
parent | f180c1a5e8fc889ff1fb390d5cc94cdbc5085046 (diff) | |
download | opie-d948361c1b475fab4660b28fbf5ec21fd34d923f.zip opie-d948361c1b475fab4660b28fbf5ec21fd34d923f.tar.gz opie-d948361c1b475fab4660b28fbf5ec21fd34d923f.tar.bz2 |
fixed
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 216 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.h | 5 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavpluginimpl.h | 2 |
3 files changed, 36 insertions, 187 deletions
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 0be667f..7ac63c0 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -19,2 +19,4 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | ||
21 | |||
20 | #include <stdio.h> | 22 | #include <stdio.h> |
@@ -48,3 +50,3 @@ struct ChunkData { | |||
48 | 50 | ||
49 | const int sound_buffer_size = 4096; | 51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? |
50 | 52 | ||
@@ -62,6 +64,2 @@ public: | |||
62 | int samples; | 64 | int samples; |
63 | int freq; | ||
64 | int chan; | ||
65 | int sampleRate; | ||
66 | int resolution; | ||
67 | 65 | ||
@@ -77,4 +75,4 @@ public: | |||
77 | { | 75 | { |
78 | qDebug("add"); | ||
79 | done = 0; | 76 | done = 0; |
77 | qApp->processEvents(); | ||
80 | 78 | ||
@@ -91,3 +89,3 @@ public: | |||
91 | } | 89 | } |
92 | samples_due += 44100; | 90 | samples_due += chunkdata.samplesPerSec; |
93 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | 91 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { |
@@ -101,3 +99,2 @@ public: | |||
101 | } | 99 | } |
102 | |||
103 | return TRUE; | 100 | return TRUE; |
@@ -106,3 +103,2 @@ public: | |||
106 | bool initialise() { | 103 | bool initialise() { |
107 | qDebug("initialize"); | ||
108 | if ( input == 0 ) | 104 | if ( input == 0 ) |
@@ -143,8 +139,3 @@ public: | |||
143 | } | 139 | } |
144 | } | 140 | } else { |
145 | |||
146 | |||
147 | |||
148 | |||
149 | else { | ||
150 | // ignored chunk | 141 | // ignored chunk |
@@ -155,3 +146,3 @@ public: | |||
155 | } // while | 146 | } // while |
156 | 147 | qDebug("bits %d", chunkdata.wBitsPerSample); | |
157 | return TRUE; | 148 | return TRUE; |
@@ -182,3 +173,3 @@ public: | |||
182 | } | 173 | } |
183 | if ( resolution == 8 ) { | 174 | if ( chunkdata.wBitsPerSample == 8 ) { |
184 | l = (data[out++] - 128) * 128; | 175 | l = (data[out++] - 128) * 128; |
@@ -188,6 +179,6 @@ public: | |||
188 | } | 179 | } |
189 | if ( chan == 1 ) { | 180 | if ( chunkdata.channels == 1 ) { |
190 | r = l; | 181 | r = l; |
191 | } else { | 182 | } else { |
192 | if ( resolution == 8 ) { | 183 | if ( chunkdata.wBitsPerSample == 8 ) { |
193 | r = (data[out++] - 128) * 128; | 184 | r = (data[out++] - 128) * 128; |
@@ -201,150 +192,2 @@ public: | |||
201 | 192 | ||
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 | } | ||
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 | ////////////////////////////////////////////////// | ||
350 | }; | 193 | }; |
@@ -365,3 +208,3 @@ WavPlugin::~WavPlugin() { | |||
365 | bool WavPlugin::isFileSupported( const QString& path ) { | 208 | bool WavPlugin::isFileSupported( const QString& path ) { |
366 | debugMsg( "WavPlugin::isFileSupported" ); | 209 | // qDebug( "WavPlugin::isFileSupported" ); |
367 | 210 | ||
@@ -384,3 +227,3 @@ bool WavPlugin::isFileSupported( const QString& path ) { | |||
384 | bool WavPlugin::open( const QString& path ) { | 227 | bool WavPlugin::open( const QString& path ) { |
385 | qDebug( "WavPlugin::open" ); | 228 | // qDebug( "WavPlugin::open" ); |
386 | 229 | ||
@@ -398,3 +241,2 @@ bool WavPlugin::open( const QString& path ) { | |||
398 | 241 | ||
399 | // d->getWavSettings( d->input.handle()); | ||
400 | d->initialise(); | 242 | d->initialise(); |
@@ -406,3 +248,3 @@ bool WavPlugin::open( const QString& path ) { | |||
406 | bool WavPlugin::close() { | 248 | bool WavPlugin::close() { |
407 | qDebug( "WavPlugin::close" ); | 249 | // qDebug( "WavPlugin::close" ); |
408 | 250 | ||
@@ -416,3 +258,3 @@ bool WavPlugin::close() { | |||
416 | bool WavPlugin::isOpen() { | 258 | bool WavPlugin::isOpen() { |
417 | qDebug( "WavPlugin::isOpen" ); | 259 | // qDebug( "WavPlugin::isOpen" ); |
418 | return ( d->input != 0 ); | 260 | return ( d->input != 0 ); |
@@ -422,3 +264,3 @@ bool WavPlugin::isOpen() { | |||
422 | int WavPlugin::audioStreams() { | 264 | int WavPlugin::audioStreams() { |
423 | qDebug( "WavPlugin::audioStreams" ); | 265 | // qDebug( "WavPlugin::audioStreams" ); |
424 | return 1; | 266 | return 1; |
@@ -428,4 +270,4 @@ int WavPlugin::audioStreams() { | |||
428 | int WavPlugin::audioChannels( int ) { | 270 | int WavPlugin::audioChannels( int ) { |
429 | debugMsg( "WavPlugin::audioChannels" ); | 271 | // qDebug( "WavPlugin::audioChannels" ); |
430 | return d->chan; | 272 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples |
431 | } | 273 | } |
@@ -434,4 +276,4 @@ int WavPlugin::audioChannels( int ) { | |||
434 | int WavPlugin::audioFrequency( int ) { | 276 | int WavPlugin::audioFrequency( int ) { |
435 | qDebug( "WavPlugin::audioFrequency" ); | 277 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); |
436 | return d->freq; | 278 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 |
437 | } | 279 | } |
@@ -440,6 +282,5 @@ int WavPlugin::audioFrequency( int ) { | |||
440 | int WavPlugin::audioSamples( int ) { | 282 | int WavPlugin::audioSamples( int ) { |
441 | qDebug( "WavPlugin::audioSamples" ); | 283 | // qDebug( "WavPlugin::audioSamples" ); |
442 | return d->samples; | 284 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, |
443 | // return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, | 285 | // Therefore if source is mono we will double the number of samples |
444 | // // Therefore if source is mono we will double the number of samples | ||
445 | } | 286 | } |
@@ -448,3 +289,3 @@ int WavPlugin::audioSamples( int ) { | |||
448 | bool WavPlugin::audioSetSample( long, int ) { | 289 | bool WavPlugin::audioSetSample( long, int ) { |
449 | qDebug( "WavPlugin::audioSetSample" ); | 290 | // qDebug( "WavPlugin::audioSetSample" ); |
450 | return FALSE; | 291 | return FALSE; |
@@ -454,3 +295,3 @@ bool WavPlugin::audioSetSample( long, int ) { | |||
454 | long WavPlugin::audioGetSample( int ) { | 295 | long WavPlugin::audioGetSample( int ) { |
455 | qDebug( "WavPlugin::audioGetSample" ); | 296 | // qDebug( "WavPlugin::audioGetSample" ); |
456 | return 0; | 297 | return 0; |
@@ -484,3 +325,3 @@ bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& sampl | |||
484 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { | 325 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { |
485 | qDebug( "WavPlugin::audioReadSamples" ); | 326 | // qDebug( "WavPlugin::audioReadSamples" ); |
486 | return d->add( output, samples, samplesMade, channels != 1 ); | 327 | return d->add( output, samples, samplesMade, channels != 1 ); |
@@ -489,3 +330,3 @@ bool WavPlugin::audioReadSamples( short *output, int channels, long samples, lon | |||
489 | double WavPlugin::getTime() { | 330 | double WavPlugin::getTime() { |
490 | qDebug( "WavPlugin::getTime" ); | 331 | // qDebug( "WavPlugin::getTime" ); |
491 | return 0.0; | 332 | return 0.0; |
@@ -493,2 +334,7 @@ double WavPlugin::getTime() { | |||
493 | 334 | ||
335 | int WavPlugin::audioBitsPerSample( int ) { | ||
336 | // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); | ||
337 | return d->chunkdata.wBitsPerSample; // | ||
338 | } | ||
339 | |||
494 | 340 | ||
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.h b/core/multimedia/opieplayer/wavplugin/wavplugin.h index 19d1a8e..6ae6e06 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.h +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.h | |||
@@ -19,2 +19,4 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | ||
21 | |||
20 | #ifndef WAV_PLUGIN_H | 22 | #ifndef WAV_PLUGIN_H |
@@ -24,3 +26,3 @@ | |||
24 | #include <qapplication.h> | 26 | #include <qapplication.h> |
25 | #include <qpe/mediaplayerplugininterface.h> | 27 | #include "../mediaplayerplugininterface.h" |
26 | 28 | ||
@@ -53,2 +55,3 @@ public: | |||
53 | int audioFrequency( int stream ); | 55 | int audioFrequency( int stream ); |
56 | int audioBitsPerSample( int stream ); | ||
54 | int audioSamples( int stream ); | 57 | int audioSamples( int stream ); |
diff --git a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h index 71f5f20..10f9305 100644 --- a/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h +++ b/core/multimedia/opieplayer/wavplugin/wavpluginimpl.h | |||
@@ -22,3 +22,3 @@ | |||
22 | 22 | ||
23 | #include <qpe/mediaplayerplugininterface.h> | 23 | #include "../mediaplayerplugininterface.h" |
24 | 24 | ||