summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/wavplugin
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/wavplugin') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/wavplugin/Makefile.in4
-rw-r--r--core/multimedia/opieplayer/wavplugin/wavplugin.cpp261
-rw-r--r--core/multimedia/opieplayer/wavplugin/wavplugin.h24
3 files changed, 154 insertions, 135 deletions
diff --git a/core/multimedia/opieplayer/wavplugin/Makefile.in b/core/multimedia/opieplayer/wavplugin/Makefile.in
index bcbe7f2..a46b925 100644
--- a/core/multimedia/opieplayer/wavplugin/Makefile.in
+++ b/core/multimedia/opieplayer/wavplugin/Makefile.in
@@ -102,3 +102,4 @@ REQUIRES=
102wavplugin.o: wavplugin.cpp \ 102wavplugin.o: wavplugin.cpp \
103 wavplugin.h 103 wavplugin.h \
104 ../mediaplayerplugininterface.h
104 105
@@ -106,2 +107,3 @@ wavpluginimpl.o: wavpluginimpl.cpp \
106 wavplugin.h \ 107 wavplugin.h \
108 ../mediaplayerplugininterface.h \
107 wavpluginimpl.h 109 wavpluginimpl.h
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp
index a6bd974..7f63b3b 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>
@@ -28,3 +30,3 @@
28 30
29 //#define debugMsg(a) qDebug(a) 31//#define debugMsg(a) qDebug(a)
30#define debugMsg(a) 32#define debugMsg(a)
@@ -49,3 +51,3 @@ struct ChunkData {
49 51
50const int sound_buffer_size = 4096; 52const int sound_buffer_size = 512; // 4096; // you got to be kidding right?
51 53
@@ -65,6 +67,6 @@ public:
65 WavPluginData() { 67 WavPluginData() {
66 max = out = sound_buffer_size; 68 max = out = sound_buffer_size;
67 wavedata_remaining = 0; 69 wavedata_remaining = 0;
68 samples_due = 0; 70 samples_due = 0;
69 samples = -1; 71 samples = -1;
70 } 72 }
@@ -74,8 +76,9 @@ public:
74 { 76 {
75 done = 0; 77 done = 0;
78 qApp->processEvents();
76 79
77 if ( input == 0 ) { 80 if ( input == 0 ) {
78 qDebug("no input"); 81 qDebug("no input");
79 return FALSE; 82 return FALSE;
80 } 83 }
81 84
@@ -84,16 +87,15 @@ public:
84 if ( getSample(l, r) == FALSE ) { 87 if ( getSample(l, r) == FALSE ) {
85 qDebug("didn't get sample"); 88 qDebug("didn't get sample");
86 return FALSE; 89 return FALSE;
87 } 90 }
88 samples_due += 44100; 91 samples_due += chunkdata.samplesPerSec;
89 while ( count && (samples_due > chunkdata.samplesPerSec) ) { 92 while ( count && (samples_due > chunkdata.samplesPerSec) ) {
90 *output++ = l; 93 *output++ = l;
91 if ( stereo ) 94 if ( stereo )
92 *output++ = r; 95 *output++ = r;
93 samples_due -= chunkdata.samplesPerSec; 96 samples_due -= chunkdata.samplesPerSec;
94 count--; 97 count--;
95 done++; 98 done++;
96 } 99 }
97 } 100 }
98
99 return TRUE; 101 return TRUE;
@@ -102,47 +104,47 @@ public:
102 bool initialise() { 104 bool initialise() {
103 if ( input == 0 ) 105 if ( input == 0 )
104 return FALSE; 106 return FALSE;
105 107
106 wavedata_remaining = -1; 108 wavedata_remaining = -1;
107 109
108 while ( wavedata_remaining == -1 ) { 110 while ( wavedata_remaining == -1 ) {
109 // Keep reading chunks... 111 // Keep reading chunks...
110 const int n = sizeof(chunk) - sizeof(chunk.data); 112 const int n = sizeof(chunk) - sizeof(chunk.data);
111 int t = input->readBlock( (char*)&chunk, n ); 113 int t = input->readBlock( (char*)&chunk, n );
112 if ( t != n ) { 114 if ( t != n ) {
113 if ( t == -1 ) 115 if ( t == -1 )
114 return FALSE; 116 return FALSE;
115 return TRUE; 117 return TRUE;
116 } 118 }
117 if ( qstrncmp(chunk.id,"data",4) == 0 ) { 119 if ( qstrncmp(chunk.id,"data",4) == 0 ) {
118 samples = wavedata_remaining = chunk.size; 120 samples = wavedata_remaining = chunk.size;
119 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { 121 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
120 char d[4]; 122 char d[4];
121 if ( input->readBlock(d,4) != 4 ) { 123 if ( input->readBlock(d,4) != 4 ) {
122 return FALSE; 124 return FALSE;
123 } 125 }
124 if ( qstrncmp(d,"WAVE",4) != 0 ) { 126 if ( qstrncmp(d,"WAVE",4) != 0 ) {
125 // skip 127 // skip
126 if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { 128 if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) {
127 return FALSE; 129 return FALSE;
128 } 130 }
129 } 131 }
130 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { 132 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) {
131 if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { 133 if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) {
132 return FALSE; 134 return FALSE;
133 } 135 }
134#define WAVE_FORMAT_PCM 1 136#define WAVE_FORMAT_PCM 1
135 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { 137 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) {
136 qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); 138 qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag);
137 return FALSE; 139 return FALSE;
138 } 140 }
139 } else { 141 } else {
140 // ignored chunk 142 // ignored chunk
141 if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { 143 if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) {
142 return FALSE; 144 return FALSE;
143 } 145 }
144 } 146 }
145 } // while 147 } // while
146 148 qDebug("bits %d", chunkdata.wBitsPerSample);
147 return TRUE; 149 return TRUE;
148 } 150 }
@@ -153,38 +155,38 @@ public:
153 { 155 {
154 l = r = 0; 156 l = r = 0;
155 157
156 if ( input == 0 ) 158 if ( input == 0 )
157 return FALSE; 159 return FALSE;
158 160
159 if ( (wavedata_remaining < 0) || !max ) 161 if ( (wavedata_remaining < 0) || !max )
160 return FALSE; 162 return FALSE;
161 163
162 if ( out >= max ) { 164 if ( out >= max ) {
163 max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); 165 max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) );
164 166
165 wavedata_remaining -= max; 167 wavedata_remaining -= max;
166 168
167 out = 0; 169 out = 0;
168 if ( max <= 0 ) { 170 if ( max <= 0 ) {
169 max = 0; 171 max = 0;
170 return TRUE; 172 return TRUE;
171 } 173 }
172 } 174 }
173 if ( chunkdata.wBitsPerSample == 8 ) { 175 if ( chunkdata.wBitsPerSample == 8 ) {
174 l = (data[out++] - 128) * 128; 176 l = (data[out++] - 128) * 128;
175 } else { 177 } else {
176 l = ((short*)data)[out/2]; 178 l = ((short*)data)[out/2];
177 out += 2; 179 out += 2;
178 } 180 }
179 if ( chunkdata.channels == 1 ) { 181 if ( chunkdata.channels == 1 ) {
180 r = l; 182 r = l;
181 } else { 183 } else {
182 if ( chunkdata.wBitsPerSample == 8 ) { 184 if ( chunkdata.wBitsPerSample == 8 ) {
183 r = (data[out++] - 128) * 128; 185 r = (data[out++] - 128) * 128;
184 } else { 186 } else {
185 r = ((short*)data)[out/2]; 187 r = ((short*)data)[out/2];
186 out += 2; 188 out += 2;
187 } 189 }
188 } 190 }
189 return TRUE; 191 return TRUE;
190 } // getSample 192 } // getSample
@@ -207,3 +209,3 @@ WavPlugin::~WavPlugin() {
207bool WavPlugin::isFileSupported( const QString& path ) { 209bool WavPlugin::isFileSupported( const QString& path ) {
208 debugMsg( "WavPlugin::isFileSupported" ); 210// qDebug( "WavPlugin::isFileSupported" );
209 211
@@ -213,8 +215,8 @@ bool WavPlugin::isFileSupported( const QString& path ) {
213 if ( ext ) { 215 if ( ext ) {
214 if ( strncasecmp(ext, ".raw", 4) == 0 ) 216 if ( strncasecmp(ext, ".raw", 4) == 0 )
215 return TRUE; 217 return TRUE;
216 if ( strncasecmp(ext, ".wav", 4) == 0 ) 218 if ( strncasecmp(ext, ".wav", 4) == 0 )
217 return TRUE; 219 return TRUE;
218 if ( strncasecmp(ext, ".wave", 4) == 0 ) 220 if ( strncasecmp(ext, ".wave", 4) == 0 )
219 return TRUE; 221 return TRUE;
220 } 222 }
@@ -226,3 +228,3 @@ bool WavPlugin::isFileSupported( const QString& path ) {
226bool WavPlugin::open( const QString& path ) { 228bool WavPlugin::open( const QString& path ) {
227 debugMsg( "WavPlugin::open" ); 229// qDebug( "WavPlugin::open" );
228 230
@@ -234,6 +236,6 @@ bool WavPlugin::open( const QString& path ) {
234 if ( d->input->open(IO_ReadOnly) == FALSE ) { 236 if ( d->input->open(IO_ReadOnly) == FALSE ) {
235 qDebug("couldn't open file"); 237 qDebug("couldn't open file");
236 delete d->input; 238 delete d->input;
237 d->input = 0; 239 d->input = 0;
238 return FALSE; 240 return FALSE;
239 } 241 }
@@ -247,3 +249,3 @@ bool WavPlugin::open( const QString& path ) {
247bool WavPlugin::close() { 249bool WavPlugin::close() {
248 debugMsg( "WavPlugin::close" ); 250// qDebug( "WavPlugin::close" );
249 251
@@ -257,3 +259,3 @@ bool WavPlugin::close() {
257bool WavPlugin::isOpen() { 259bool WavPlugin::isOpen() {
258 debugMsg( "WavPlugin::isOpen" ); 260// qDebug( "WavPlugin::isOpen" );
259 return ( d->input != 0 ); 261 return ( d->input != 0 );
@@ -263,3 +265,3 @@ bool WavPlugin::isOpen() {
263int WavPlugin::audioStreams() { 265int WavPlugin::audioStreams() {
264 debugMsg( "WavPlugin::audioStreams" ); 266// qDebug( "WavPlugin::audioStreams" );
265 return 1; 267 return 1;
@@ -269,4 +271,4 @@ int WavPlugin::audioStreams() {
269int WavPlugin::audioChannels( int ) { 271int WavPlugin::audioChannels( int ) {
270 debugMsg( "WavPlugin::audioChannels" ); 272// qDebug( "WavPlugin::audioChannels" );
271 return 2; // ### Always scale audio to stereo samples 273 return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples
272} 274}
@@ -275,4 +277,4 @@ int WavPlugin::audioChannels( int ) {
275int WavPlugin::audioFrequency( int ) { 277int WavPlugin::audioFrequency( int ) {
276 debugMsg( "WavPlugin::audioFrequency" ); 278// qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec );
277 return 44100; // ### Always scale to frequency of 44100 279 return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100
278} 280}
@@ -281,5 +283,5 @@ int WavPlugin::audioFrequency( int ) {
281int WavPlugin::audioSamples( int ) { 283int WavPlugin::audioSamples( int ) {
282 debugMsg( "WavPlugin::audioSamples" ); 284// qDebug( "WavPlugin::audioSamples" );
283 return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, 285 return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo,
284 // Therefore if source is mono we will double the number of samples 286 // Therefore if source is mono we will double the number of samples
285} 287}
@@ -288,3 +290,3 @@ int WavPlugin::audioSamples( int ) {
288bool WavPlugin::audioSetSample( long, int ) { 290bool WavPlugin::audioSetSample( long, int ) {
289 debugMsg( "WavPlugin::audioSetSample" ); 291// qDebug( "WavPlugin::audioSetSample" );
290 return FALSE; 292 return FALSE;
@@ -294,3 +296,3 @@ bool WavPlugin::audioSetSample( long, int ) {
294long WavPlugin::audioGetSample( int ) { 296long WavPlugin::audioGetSample( int ) {
295 debugMsg( "WavPlugin::audioGetSample" ); 297// qDebug( "WavPlugin::audioGetSample" );
296 return 0; 298 return 0;
@@ -324,3 +326,3 @@ bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& sampl
324bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { 326bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) {
325 debugMsg( "WavPlugin::audioReadSamples" ); 327// qDebug( "WavPlugin::audioReadSamples" );
326 return d->add( output, samples, samplesMade, channels != 1 ); 328 return d->add( output, samples, samplesMade, channels != 1 );
@@ -329,3 +331,3 @@ bool WavPlugin::audioReadSamples( short *output, int channels, long samples, lon
329double WavPlugin::getTime() { 331double WavPlugin::getTime() {
330 debugMsg( "WavPlugin::getTime" ); 332// qDebug( "WavPlugin::getTime" );
331 return 0.0; 333 return 0.0;
@@ -333,2 +335,7 @@ double WavPlugin::getTime() {
333 335
336int WavPlugin::audioBitsPerSample( int ) {
337// qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample );
338 return d->chunkdata.wBitsPerSample; //
339}
340
334 341
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.h b/core/multimedia/opieplayer/wavplugin/wavplugin.h
index 64635ca..6afd67e 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
@@ -25,3 +27,6 @@
25#include <qapplication.h> 27#include <qapplication.h>
26#include "mediaplayerplugininterface.h" 28#include "../mediaplayerplugininterface.h"
29
30
31// #define OLD_MEDIAPLAYER_API
27 32
@@ -45,4 +50,3 @@ public:
45 bool isOpen(); 50 bool isOpen();
46 //const QString &fileInfo() { return strInfo = qApp->translate( "MediaPlayer", "No Information Available", "media plugin text" ); } 51 const QString &fileInfo() { return strInfo = ""; }
47 const QString &fileInfo() { return strInfo = QString(""); }
48 52
@@ -52,2 +56,3 @@ public:
52 int audioFrequency( int stream ); 56 int audioFrequency( int stream );
57 int audioBitsPerSample( int stream );
53 int audioSamples( int stream ); 58 int audioSamples( int stream );
@@ -55,7 +60,10 @@ public:
55 long audioGetSample( int stream ); 60 long audioGetSample( int stream );
56 //bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); 61#ifdef OLD_MEDIAPLAYER_API
57 //bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); 62 bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream );
63 bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream );
64 bool audioReadSamples( short *output, int channel, long samples, int stream );
65 bool audioReReadSamples( short *output, int channel, long samples, int stream );
66#else
58 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); 67 bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream );
59 //bool audioReadSamples( short *output, int channel, long samples, int stream ); 68#endif
60 //bool audioReReadSamples( short *output, int channel, long samples, int stream );
61 69
@@ -89,2 +97,4 @@ public:
89 97
98 long getPlayTime() { return -1; }
99
90private: 100private: