author | bipolar <bipolar> | 2002-03-03 17:13:17 (UTC) |
---|---|---|
committer | bipolar <bipolar> | 2002-03-03 17:13:17 (UTC) |
commit | a99347380a9006ec81a9dba2340d6aaab690a86e (patch) (unidiff) | |
tree | 73fdc2eff476fba2113172ed881dd64a4031def6 /core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |
parent | 0e245156b28b70be5cd98a58a9256fe5e2739562 (diff) | |
download | opie-a99347380a9006ec81a9dba2340d6aaab690a86e.zip opie-a99347380a9006ec81a9dba2340d6aaab690a86e.tar.gz opie-a99347380a9006ec81a9dba2340d6aaab690a86e.tar.bz2 |
commited by ljp (llornkcor) reverted to qpe's interface for compatibility. Added playlist features:
save, remove, and have different ones. Uncommented code for background image and added opielogo.
Diffstat (limited to 'core/multimedia/opieplayer/wavplugin/wavplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 7ac63c0..4a0da16 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -25,114 +25,116 @@ | |||
25 | #include <errno.h> | 25 | #include <errno.h> |
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include "wavplugin.h" | 28 | #include "wavplugin.h" |
29 | 29 | ||
30 | //#define debugMsg(a) qDebug(a) | 30 | //#define debugMsg(a) qDebug(a) |
31 | #define debugMsg(a) | 31 | #define debugMsg(a) |
32 | 32 | ||
33 | 33 | ||
34 | struct RiffChunk { | 34 | struct RiffChunk { |
35 | char id[4]; | 35 | char id[4]; |
36 | Q_UINT32 size; | 36 | Q_UINT32 size; |
37 | char data[4]; | 37 | char data[4]; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | 40 | ||
41 | struct ChunkData { | 41 | struct ChunkData { |
42 | Q_INT16 formatTag; | 42 | Q_INT16 formatTag; |
43 | Q_INT16 channels; | 43 | Q_INT16 channels; |
44 | Q_INT32 samplesPerSec; | 44 | Q_INT32 samplesPerSec; |
45 | Q_INT32 avgBytesPerSec; | 45 | Q_INT32 avgBytesPerSec; |
46 | Q_INT16 blockAlign; | 46 | Q_INT16 blockAlign; |
47 | Q_INT16 wBitsPerSample; | 47 | Q_INT16 wBitsPerSample; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | 50 | ||
51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? | 51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? |
52 | 52 | ||
53 | 53 | ||
54 | class WavPluginData { | 54 | class WavPluginData { |
55 | public: | 55 | public: |
56 | QFile *input; | 56 | QFile *input; |
57 | 57 | ||
58 | int wavedata_remaining; | 58 | int wavedata_remaining; |
59 | ChunkData chunkdata; | 59 | ChunkData chunkdata; |
60 | RiffChunk chunk; | 60 | RiffChunk chunk; |
61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data | 61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data |
62 | int out,max; | 62 | int out,max; |
63 | int samples_due; | 63 | int samples_due; |
64 | int samples; | 64 | int samples; |
65 | 65 | ||
66 | WavPluginData() { | 66 | WavPluginData() { |
67 | max = out = sound_buffer_size; | 67 | max = out = sound_buffer_size; |
68 | wavedata_remaining = 0; | 68 | wavedata_remaining = 0; |
69 | samples_due = 0; | 69 | samples_due = 0; |
70 | samples = -1; | 70 | samples = -1; |
71 | } | 71 | } |
72 | 72 | ||
73 | // expands out samples to the frequency of 44kHz | 73 | // expands out samples to the frequency of 44kHz //not any more |
74 | bool add( short *output, long count, long& done, bool stereo ) | 74 | bool add( short *output, long count, long& done, bool stereo ) |
75 | { | 75 | { |
76 | done = 0; | 76 | done = 0; |
77 | qApp->processEvents(); | 77 | qApp->processEvents(); |
78 | 78 | ||
79 | if ( input == 0 ) { | 79 | if ( input == 0 ) { |
80 | qDebug("no input"); | 80 | qDebug("no input"); |
81 | return FALSE; | 81 | return FALSE; |
82 | } | 82 | } |
83 | 83 | ||
84 | while ( count ) { | 84 | while ( count ) { |
85 | int l,r; | 85 | int l,r; |
86 | if ( getSample(l, r) == FALSE ) { | 86 | if ( getSample(l, r) == FALSE ) { |
87 | qDebug("didn't get sample"); | 87 | qDebug("didn't get sample"); |
88 | return FALSE; | 88 | return FALSE; |
89 | } | 89 | } |
90 | samples_due += chunkdata.samplesPerSec; | 90 | samples_due += chunkdata.samplesPerSec; |
91 | printf("samples due %d\r", samples_due); | ||
92 | fflush(stdout); | ||
91 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | 93 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { |
92 | *output++ = l; | 94 | *output++ = l; |
93 | if ( stereo ) | 95 | if ( stereo ) |
94 | *output++ = r; | 96 | *output++ = r; |
95 | samples_due -= chunkdata.samplesPerSec; | 97 | samples_due -= chunkdata.samplesPerSec; |
96 | count--; | 98 | count--; |
97 | done++; | 99 | done++; |
98 | } | 100 | } |
99 | } | 101 | } |
100 | return TRUE; | 102 | return TRUE; |
101 | } | 103 | } |
102 | 104 | ||
103 | bool initialise() { | 105 | bool initialise() { |
104 | if ( input == 0 ) | 106 | if ( input == 0 ) |
105 | return FALSE; | 107 | return FALSE; |
106 | 108 | ||
107 | wavedata_remaining = -1; | 109 | wavedata_remaining = -1; |
108 | 110 | ||
109 | while ( wavedata_remaining == -1 ) { | 111 | while ( wavedata_remaining == -1 ) { |
110 | // Keep reading chunks... | 112 | // Keep reading chunks... |
111 | const int n = sizeof(chunk) - sizeof(chunk.data); | 113 | const int n = sizeof(chunk) - sizeof(chunk.data); |
112 | int t = input->readBlock( (char*)&chunk, n ); | 114 | int t = input->readBlock( (char*)&chunk, n ); |
113 | if ( t != n ) { | 115 | if ( t != n ) { |
114 | if ( t == -1 ) | 116 | if ( t == -1 ) |
115 | return FALSE; | 117 | return FALSE; |
116 | return TRUE; | 118 | return TRUE; |
117 | } | 119 | } |
118 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | 120 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { |
119 | samples = wavedata_remaining = chunk.size; | 121 | samples = wavedata_remaining = chunk.size; |
120 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | 122 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { |
121 | char d[4]; | 123 | char d[4]; |
122 | if ( input->readBlock(d,4) != 4 ) { | 124 | if ( input->readBlock(d,4) != 4 ) { |
123 | return FALSE; | 125 | return FALSE; |
124 | } | 126 | } |
125 | if ( qstrncmp(d,"WAVE",4) != 0 ) { | 127 | if ( qstrncmp(d,"WAVE",4) != 0 ) { |
126 | // skip | 128 | // skip |
127 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { | 129 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { |
128 | return FALSE; | 130 | return FALSE; |
129 | } | 131 | } |
130 | } | 132 | } |
131 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { | 133 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { |
132 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { | 134 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { |
133 | return FALSE; | 135 | return FALSE; |
134 | } | 136 | } |
135 | #define WAVE_FORMAT_PCM 1 | 137 | #define WAVE_FORMAT_PCM 1 |
136 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | 138 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { |
137 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | 139 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); |
138 | return FALSE; | 140 | return FALSE; |
@@ -283,58 +285,58 @@ int WavPlugin::audioSamples( int ) { | |||
283 | // qDebug( "WavPlugin::audioSamples" ); | 285 | // qDebug( "WavPlugin::audioSamples" ); |
284 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, | 286 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, |
285 | // Therefore if source is mono we will double the number of samples | 287 | // Therefore if source is mono we will double the number of samples |
286 | } | 288 | } |
287 | 289 | ||
288 | 290 | ||
289 | bool WavPlugin::audioSetSample( long, int ) { | 291 | bool WavPlugin::audioSetSample( long, int ) { |
290 | // qDebug( "WavPlugin::audioSetSample" ); | 292 | // qDebug( "WavPlugin::audioSetSample" ); |
291 | return FALSE; | 293 | return FALSE; |
292 | } | 294 | } |
293 | 295 | ||
294 | 296 | ||
295 | long WavPlugin::audioGetSample( int ) { | 297 | long WavPlugin::audioGetSample( int ) { |
296 | // qDebug( "WavPlugin::audioGetSample" ); | 298 | // qDebug( "WavPlugin::audioGetSample" ); |
297 | return 0; | 299 | return 0; |
298 | } | 300 | } |
299 | 301 | ||
300 | /* | 302 | /* |
301 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { | 303 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { |
302 | debugMsg( "WavPlugin::audioReadSamples" ); | 304 | debugMsg( "WavPlugin::audioReadSamples" ); |
303 | return FALSE; | 305 | return FALSE; |
304 | } | 306 | } |
305 | 307 | ||
306 | 308 | ||
307 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { | 309 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { |
308 | debugMsg( "WavPlugin::audioReReadSamples" ); | 310 | debugMsg( "WavPlugin::audioReReadSamples" ); |
309 | return FALSE; | 311 | return FALSE; |
310 | } | 312 | } |
311 | 313 | ||
312 | 314 | ||
313 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { | 315 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { |
314 | debugMsg( "WavPlugin::audioReadMonoSamples" ); | 316 | debugMsg( "WavPlugin::audioReadMonoSamples" ); |
315 | return !d->add( output, samples, samplesMade, FALSE ); | 317 | return !d->add( output, samples, samplesMade, FALSE ); |
316 | } | 318 | } |
317 | 319 | ||
318 | 320 | ||
319 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { | 321 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { |
320 | debugMsg( "WavPlugin::audioReadStereoSamples" ); | 322 | debugMsg( "WavPlugin::audioReadStereoSamples" ); |
321 | return !d->add( output, samples, samplesMade, TRUE ); | 323 | return !d->add( output, samples, samplesMade, TRUE ); |
322 | } | 324 | } |
323 | */ | 325 | */ |
324 | 326 | ||
325 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { | 327 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { |
326 | // qDebug( "WavPlugin::audioReadSamples" ); | 328 | // qDebug( "WavPlugin::audioReadSamples" ); |
327 | return d->add( output, samples, samplesMade, channels != 1 ); | 329 | return d->add( output, samples, samplesMade, channels != 1 ); |
328 | } | 330 | } |
329 | 331 | ||
330 | double WavPlugin::getTime() { | 332 | double WavPlugin::getTime() { |
331 | // qDebug( "WavPlugin::getTime" ); | 333 | // qDebug( "WavPlugin::getTime" ); //this is a stupid hack here!! |
332 | return 0.0; | 334 | return d->chunkdata.wBitsPerSample; /*0.0*/; |
333 | } | 335 | } |
334 | 336 | ||
335 | int WavPlugin::audioBitsPerSample( int ) { | 337 | // int WavPlugin::audioBitsPerSample( int ) { |
336 | // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); | 338 | // // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); |
337 | return d->chunkdata.wBitsPerSample; // | 339 | // return d->chunkdata.wBitsPerSample; // |
338 | } | 340 | // } |
339 | 341 | ||
340 | 342 | ||