author | llornkcor <llornkcor> | 2005-03-12 01:54:52 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-03-12 01:54:52 (UTC) |
commit | 84af289057291a49a52a60b390bc5320c02b5a55 (patch) (unidiff) | |
tree | 523f2d36240efd4f500bfbc35996771bebd7360d | |
parent | 6b67c3b2685b2d3f1bc7a787216aa769d4ea257a (diff) | |
download | opie-84af289057291a49a52a60b390bc5320c02b5a55.zip opie-84af289057291a49a52a60b390bc5320c02b5a55.tar.gz opie-84af289057291a49a52a60b390bc5320c02b5a55.tar.bz2 |
fix irregularity with adpcm and bits
-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 16 | ||||
-rw-r--r-- | noncore/multimedia/opierec/opierec.pro | 1 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 123 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 62 |
4 files changed, 105 insertions, 97 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp index e7e0f4b..a76665e 100644 --- a/noncore/multimedia/opierec/device.cpp +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -45,64 +45,67 @@ | |||
45 | #define DSPSTRIN "/dev/dsp" | 45 | #define DSPSTRIN "/dev/dsp" |
46 | #define DSPSTRMIXERIN "/dev/mixer" | 46 | #define DSPSTRMIXERIN "/dev/mixer" |
47 | #define DSPSTRMIXEROUT "/dev/mixer" | 47 | #define DSPSTRMIXEROUT "/dev/mixer" |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | Device::Device( QObject * parent, bool record ) | 52 | Device::Device( QObject * parent, bool record ) |
53 | : QObject( parent) | 53 | : QObject( parent) |
54 | { | 54 | { |
55 | // dspstr = dsp; | 55 | // dspstr = dsp; |
56 | devForm = -1; | 56 | devForm = -1; |
57 | devCh = -1; | 57 | devCh = -1; |
58 | devRate = -1; | 58 | devRate = -1; |
59 | 59 | ||
60 | if( !record){ //playing | 60 | if( !record){ //playing |
61 | owarn << "setting up DSP for playing" << oendl; | 61 | owarn << "New Sound device DSP for playing" << oendl; |
62 | flags = O_WRONLY; | 62 | flags = O_RDWR; |
63 | // flags = O_WRONLY; | ||
63 | } else { //recording | 64 | } else { //recording |
64 | owarn << "setting up DSP for recording" << oendl; | 65 | owarn << "New Sound device DSP for recording" << oendl; |
65 | flags = O_RDWR; | 66 | flags = O_RDWR; |
66 | // flags = O_RDONLY; | 67 | // flags = O_RDONLY; |
67 | selectMicInput(); | 68 | selectMicInput(); |
68 | } | 69 | } |
69 | } | 70 | } |
70 | 71 | ||
71 | bool Device::openDsp() { | 72 | bool Device::openDsp() { |
73 | qWarning("Device::openDsp()"); | ||
72 | if( openDevice( flags) == -1) { | 74 | if( openDevice( flags) == -1) { |
73 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | 75 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); |
74 | return false; | 76 | return false; |
75 | } | 77 | } |
76 | return true; | 78 | return true; |
77 | } | 79 | } |
78 | 80 | ||
79 | int Device::openDevice( int flags) { | 81 | int Device::openDevice( int flags) { |
80 | owarn << "Opening"<< dspstr; | 82 | owarn << "Opening sound device:"<< DSPSTROUT << oendl; |
81 | 83 | ||
82 | if (( sd = ::open( DSPSTROUT, flags)) == -1) { | 84 | if (( sd = ::open( DSPSTROUT, O_RDWR)) == -1) { |
83 | perror("open(\"/dev/dsp\")"); | 85 | perror("open(\"/dev/dsp\")\n"); |
84 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | 86 | QString errorMsg="Could not open audio device\n /dev/dsp\n" |
85 | +(QString)strerror(errno); | 87 | +(QString)strerror(errno); |
86 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); | 88 | qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg ); |
87 | return -1; | 89 | return -1; |
88 | } | 90 | } |
89 | 91 | ||
90 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | 92 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ |
91 | perror("ioctl RESET"); | 93 | perror("ioctl RESET"); |
92 | } | 94 | } |
95 | qWarning("opened!"); | ||
93 | return sd; | 96 | return sd; |
94 | } | 97 | } |
95 | 98 | ||
96 | int Device::getInVolume() { | 99 | int Device::getInVolume() { |
97 | unsigned int volume = 0; | 100 | unsigned int volume = 0; |
98 | Config cfg("qpe"); | 101 | Config cfg("qpe"); |
99 | cfg.setGroup("Volume"); | 102 | cfg.setGroup("Volume"); |
100 | 103 | ||
101 | return cfg.readNumEntry("Mic"); | 104 | return cfg.readNumEntry("Mic"); |
102 | } | 105 | } |
103 | 106 | ||
104 | int Device::getOutVolume( ) { | 107 | int Device::getOutVolume( ) { |
105 | unsigned int volume; | 108 | unsigned int volume; |
106 | Config cfg("qpe"); | 109 | Config cfg("qpe"); |
107 | cfg.setGroup("Volume"); | 110 | cfg.setGroup("Volume"); |
108 | 111 | ||
@@ -137,32 +140,33 @@ bool Device::selectMicInput() { | |||
137 | if ( md <= 0) { | 140 | if ( md <= 0) { |
138 | QString err; | 141 | QString err; |
139 | err.sprintf("open %s", DSPSTRMIXEROUT); | 142 | err.sprintf("open %s", DSPSTRMIXEROUT); |
140 | perror(err.latin1()); | 143 | perror(err.latin1()); |
141 | } else { | 144 | } else { |
142 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 145 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
143 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 146 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
144 | ::close(md); | 147 | ::close(md); |
145 | return false; | 148 | return false; |
146 | } | 149 | } |
147 | ::close(md); | 150 | ::close(md); |
148 | 151 | ||
149 | return true; | 152 | return true; |
150 | } | 153 | } |
151 | 154 | ||
152 | bool Device::closeDevice( bool) { | 155 | bool Device::closeDevice( bool) { |
156 | if(sd) | ||
153 | ::close( sd); //close sound device | 157 | ::close( sd); //close sound device |
154 | return true; | 158 | return true; |
155 | } | 159 | } |
156 | 160 | ||
157 | bool Device::setDeviceFormat( int form) { | 161 | bool Device::setDeviceFormat( int form) { |
158 | qDebug( "set device res %d: %d ",form, sd ); | 162 | qDebug( "set device res %d: %d ",form, sd ); |
159 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | 163 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format |
160 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 164 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
161 | return false; | 165 | return false; |
162 | } | 166 | } |
163 | devRes=form; | 167 | devRes=form; |
164 | return true; | 168 | return true; |
165 | } | 169 | } |
166 | 170 | ||
167 | bool Device::setDeviceChannels( int ch) { | 171 | bool Device::setDeviceChannels( int ch) { |
168 | qDebug( "set channels %d: %d",ch ,sd); | 172 | qDebug( "set channels %d: %d",ch ,sd); |
diff --git a/noncore/multimedia/opierec/opierec.pro b/noncore/multimedia/opierec/opierec.pro index 6a5838a..6008bf7 100644 --- a/noncore/multimedia/opierec/opierec.pro +++ b/noncore/multimedia/opierec/opierec.pro | |||
@@ -18,21 +18,22 @@ INTERFACES = | |||
18 | contains(CONFIG, pdaudio) { | 18 | contains(CONFIG, pdaudio) { |
19 | # LIBS += -L/opt/buildroot-opie/output/staging/target/lib -lqpe -lpthread -ljpeg -lpng -lz | 19 | # LIBS += -L/opt/buildroot-opie/output/staging/target/lib -lqpe -lpthread -ljpeg -lpng -lz |
20 | LIBS += -L$(QPEDIR)/lib -lqpe -lpthread -ljpeg -lpng -lz -lopiecore2 | 20 | LIBS += -L$(QPEDIR)/lib -lqpe -lpthread -ljpeg -lpng -lz -lopiecore2 |
21 | INCLUDEPATH += $(QPEDIR)/include | 21 | INCLUDEPATH += $(QPEDIR)/include |
22 | DEPENDPATH += $(QPEDIR)/include | 22 | DEPENDPATH += $(QPEDIR)/include |
23 | DEFINES += PDAUDIO | 23 | DEFINES += PDAUDIO |
24 | DEFINES += THREADED | 24 | DEFINES += THREADED |
25 | TARGET = qperec | 25 | TARGET = qperec |
26 | 26 | ||
27 | # DESTDIR=$(QPEDIR)/bin | 27 | # DESTDIR=$(QPEDIR)/bin |
28 | } | 28 | } |
29 | 29 | ||
30 | !contains(CONFIG, pdaudio) { | 30 | !contains(CONFIG, pdaudio) { |
31 | INCLUDEPATH += $(OPIEDIR)/include | 31 | INCLUDEPATH += $(OPIEDIR)/include |
32 | DEPENDPATH += $(OPIEDIR)/include | 32 | DEPENDPATH += $(OPIEDIR)/include |
33 | LIBS += -lqpe -lopiecore2 -lpthread | 33 | LIBS += -lqpe -lopiecore2 -lpthread |
34 | DEFINES += THREADED | ||
34 | TARGET = opierec | 35 | TARGET = opierec |
35 | include( $(OPIEDIR)/include.pro ) | 36 | include( $(OPIEDIR)/include.pro ) |
36 | } | 37 | } |
37 | 38 | ||
38 | 39 | ||
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index e827083..9b761aa 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -104,83 +104,83 @@ void quickRec() | |||
104 | void QtRec::quickRec() | 104 | void QtRec::quickRec() |
105 | #endif | 105 | #endif |
106 | { | 106 | { |
107 | 107 | ||
108 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; | 108 | odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; |
109 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate | 109 | odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate |
110 | << ", channels " << filePara.channels << oendl; | 110 | << ", channels " << filePara.channels << oendl; |
111 | 111 | ||
112 | int total = 0; // Total number of bytes read in so far. | 112 | int total = 0; // Total number of bytes read in so far. |
113 | int bytesWritten, number; | 113 | int bytesWritten, number; |
114 | 114 | ||
115 | bytesWritten = 0; | 115 | bytesWritten = 0; |
116 | number = 0; | 116 | number = 0; |
117 | QString num; | 117 | QString num; |
118 | int level = 0; | 118 | int level = 0; |
119 | int threshold = 0; | 119 | int threshold = 0; |
120 | int bits = filePara.resolution; | 120 | int bits = filePara.resolution; |
121 | odebug << "bits " << bits << "" << oendl; | 121 | odebug << "bits " << bits << "" << oendl; |
122 | 122 | ||
123 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | 123 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) |
124 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; | 124 | odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; |
125 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; | 125 | odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; |
126 | odebug << "" << filePara.sd << "" << oendl; | 126 | odebug << "" << filePara.sd << "" << oendl; |
127 | level = 7; | 127 | level = 7; |
128 | threshold = 0; | 128 | threshold = 0; |
129 | 129 | ||
130 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { | 130 | if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { |
131 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; | 131 | odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; |
132 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 132 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
133 | char abuf[ BUFSIZE/2 ]; | 133 | char abuf[ BUFSIZE/2 ]; |
134 | short sbuf[ BUFSIZE ]; | 134 | short sbuf[ BUFSIZE ]; |
135 | short sbuf2[ BUFSIZE ]; | 135 | short sbuf2[ BUFSIZE ]; |
136 | memset( abuf, 0, BUFSIZE/2); | 136 | memset( abuf, 0, BUFSIZE/2); |
137 | memset( sbuf, 0, BUFSIZE); | 137 | memset( sbuf, 0, BUFSIZE); |
138 | memset( sbuf2, 0, BUFSIZE); | 138 | memset( sbuf2, 0, BUFSIZE); |
139 | 139 | ||
140 | for(;;) { | 140 | for(;;) { |
141 | if ( stopped) { | 141 | if ( stopped) { |
142 | odebug << "quickRec:: stopped" << oendl; | 142 | odebug << "quickRec:: stopped" << oendl; |
143 | break; | 143 | break; |
144 | } | 144 | } |
145 | 145 | ||
146 | // number=::read( filePara.sd, sbuf, BUFSIZE); | 146 | // number=::read( filePara.sd, sbuf, BUFSIZE); |
147 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); | 147 | number = soundDevice->devRead( filePara.sd, sbuf, BUFSIZE); |
148 | 148 | ||
149 | if(number <= 0) { | 149 | if(number <= 0) { |
150 | perror("recording error "); | 150 | perror("recording error "); |
151 | odebug << "" << filePara.fileName << " " << number << "" << oendl; | 151 | odebug << "" << filePara.fileName << " " << number << "" << oendl; |
152 | stopped = true; | 152 | stopped = true; |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | //if(stereo == 2) { | 155 | //if(stereo == 2) { |
156 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 156 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
157 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 157 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
158 | 158 | ||
159 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | 159 | bytesWritten = ::write( filePara.fd , abuf, number/4); |
160 | 160 | ||
161 | waveform->newSamples( sbuf, number ); | 161 | waveform->newSamples( sbuf, number ); |
162 | 162 | ||
163 | total += bytesWritten; | 163 | total += bytesWritten; |
164 | filePara.numberSamples = total; | 164 | filePara.numberSamples = total; |
165 | timeSlider->setValue( total); | 165 | timeSlider->setValue( total); |
166 | 166 | ||
167 | printf("%d, bytes %d,total %d\r", number, bytesWritten, total); | 167 | printf("%d, bytes %d,total %d\r", number, bytesWritten, total); |
168 | fflush(stdout); | 168 | fflush(stdout); |
169 | 169 | ||
170 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2/ filePara.channels; | 170 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2;/// filePara.channels; |
171 | 171 | ||
172 | qApp->processEvents(); | 172 | qApp->processEvents(); |
173 | if( total >= filePara.samplesToRecord) { | 173 | if( total >= filePara.samplesToRecord) { |
174 | stopped = true; | 174 | stopped = true; |
175 | break; | 175 | break; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | } else { | 178 | } else { |
179 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 179 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
180 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; | 180 | odebug << "start recording WAVE_FORMAT_PCM" << oendl; |
181 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 181 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
182 | memset( inbuffer, 0, BUFSIZE); | 182 | memset( inbuffer, 0, BUFSIZE); |
183 | memset( outbuffer, 0, BUFSIZE); | 183 | memset( outbuffer, 0, BUFSIZE); |
184 | 184 | ||
185 | for(;;) { | 185 | for(;;) { |
186 | if ( stopped) { | 186 | if ( stopped) { |
@@ -201,34 +201,34 @@ void quickRec() | |||
201 | 201 | ||
202 | bytesWritten = ::write( filePara.fd , inbuffer, number); | 202 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
203 | waveform->newSamples( inbuffer, number ); | 203 | waveform->newSamples( inbuffer, number ); |
204 | 204 | ||
205 | if( bytesWritten < 0) { | 205 | if( bytesWritten < 0) { |
206 | perror("File writing error "); | 206 | perror("File writing error "); |
207 | stopped = true; | 207 | stopped = true; |
208 | return; | 208 | return; |
209 | } | 209 | } |
210 | 210 | ||
211 | total += bytesWritten; | 211 | total += bytesWritten; |
212 | 212 | ||
213 | filePara.numberSamples = total; | 213 | filePara.numberSamples = total; |
214 | 214 | ||
215 | if( filePara.SecondsToRecord != 0) | 215 | if( filePara.SecondsToRecord != 0) |
216 | timeSlider->setValue( total); | 216 | timeSlider->setValue( total); |
217 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); | 217 | printf("%d, bytes %d,total %d\r",number, bytesWritten , total); |
218 | fflush(stdout); | 218 | fflush(stdout); |
219 | 219 | ||
220 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate | 220 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate |
221 | / (float)2/filePara.channels; | 221 | / (float)2/filePara.channels; |
222 | qApp->processEvents(); | 222 | qApp->processEvents(); |
223 | 223 | ||
224 | if( total >= filePara.samplesToRecord) { | 224 | if( total >= filePara.samplesToRecord) { |
225 | stopped = true; | 225 | stopped = true; |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } //end main loop | 229 | } //end main loop |
230 | 230 | ||
231 | } else { | 231 | } else { |
232 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | 232 | // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; |
233 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; | 233 | unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; |
234 | memset( unsigned_inbuffer, 0, BUFSIZE); | 234 | memset( unsigned_inbuffer, 0, BUFSIZE); |
@@ -288,34 +288,36 @@ void playIt() | |||
288 | memset( abuf, 0, BUFSIZE / 2); | 288 | memset( abuf, 0, BUFSIZE / 2); |
289 | memset( sbuf, 0, BUFSIZE); | 289 | memset( sbuf, 0, BUFSIZE); |
290 | memset( sbuf2, 0, BUFSIZE * 2); | 290 | memset( sbuf2, 0, BUFSIZE * 2); |
291 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | 291 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> |
292 | for(;;) { // play loop | 292 | for(;;) { // play loop |
293 | if ( stopped) { | 293 | if ( stopped) { |
294 | break; | 294 | break; |
295 | return; | 295 | return; |
296 | }// stop if playing was set to false | 296 | }// stop if playing was set to false |
297 | 297 | ||
298 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); | 298 | number = ::read( filePara.fd, abuf, BUFSIZE / 2); |
299 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); | 299 | adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); |
300 | 300 | ||
301 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 301 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
302 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | 302 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; |
303 | // } | 303 | // } |
304 | bytesWritten = write ( filePara.sd, sbuf, number * 4); | 304 | bytesWritten = write ( soundDevice->sd , sbuf, number * 4); |
305 | waveform->newSamples( (const short *)sbuf, number *4); | 305 | |
306 | waveform->newSamples( sbuf, number ); | ||
307 | |||
306 | // if(filePara.channels==1) | 308 | // if(filePara.channels==1) |
307 | // total += bytesWritten/2; //mono | 309 | // total += bytesWritten/2; //mono |
308 | // else | 310 | // else |
309 | total += bytesWritten; | 311 | total += bytesWritten; |
310 | filePara.numberSamples = total/4; | 312 | filePara.numberSamples = total/4; |
311 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | 313 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; |
312 | 314 | ||
313 | timeSlider->setValue( total/4); | 315 | timeSlider->setValue( total/4); |
314 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 316 | // timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
315 | // if(filePara.numberOfRecordedSeconds>1) | 317 | // if(filePara.numberOfRecordedSeconds>1) |
316 | // timeLabel->setText( timeString+ tr(" seconds")); | 318 | // timeLabel->setText( timeString+ tr(" seconds")); |
317 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | 319 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); |
318 | // fflush(stdout); | 320 | // fflush(stdout); |
319 | 321 | ||
320 | qApp->processEvents(); | 322 | qApp->processEvents(); |
321 | 323 | ||
@@ -329,33 +331,33 @@ void playIt() | |||
329 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | 331 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> |
330 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; | 332 | short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; |
331 | memset( inbuffer, 0, BUFSIZE); | 333 | memset( inbuffer, 0, BUFSIZE); |
332 | memset( outbuffer, 0, BUFSIZE); | 334 | memset( outbuffer, 0, BUFSIZE); |
333 | 335 | ||
334 | for(;;) { // play loop | 336 | for(;;) { // play loop |
335 | if ( stopped) { | 337 | if ( stopped) { |
336 | break; | 338 | break; |
337 | return; | 339 | return; |
338 | } | 340 | } |
339 | // stop if playing was set to false | 341 | // stop if playing was set to false |
340 | number = ::read( filePara.fd, inbuffer, BUFSIZE); | 342 | number = ::read( filePara.fd, inbuffer, BUFSIZE); |
341 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | 343 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel |
342 | // // for (int i=0;i< number ; i++) { //2*i is left channel | 344 | // // for (int i=0;i< number ; i++) { //2*i is left channel |
343 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; | 345 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; |
344 | // } | 346 | // } |
345 | bytesWritten = ::write( filePara.sd, inbuffer, number); | 347 | bytesWritten = ::write( soundDevice->sd, inbuffer, number); |
346 | waveform->newSamples( inbuffer, number); | 348 | waveform->newSamples( inbuffer, number); |
347 | //-------------->>>> out to device | 349 | //-------------->>>> out to device |
348 | // total+=bytesWritten; | 350 | // total+=bytesWritten; |
349 | // if(filePara.channels==1) | 351 | // if(filePara.channels==1) |
350 | // total += bytesWritten/2; //mono | 352 | // total += bytesWritten/2; //mono |
351 | // else | 353 | // else |
352 | total += bytesWritten; | 354 | total += bytesWritten; |
353 | timeSlider->setValue( total); | 355 | timeSlider->setValue( total); |
354 | 356 | ||
355 | filePara.numberSamples = total; | 357 | filePara.numberSamples = total; |
356 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; | 358 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; |
357 | 359 | ||
358 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | 360 | // timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); |
359 | // timeLabel->setText( timeString + tr(" seconds")); | 361 | // timeLabel->setText( timeString + tr(" seconds")); |
360 | 362 | ||
361 | qApp->processEvents(); | 363 | qApp->processEvents(); |
@@ -419,33 +421,33 @@ QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) | |||
419 | 421 | ||
420 | // open sound device to get volumes | 422 | // open sound device to get volumes |
421 | Config hwcfg("OpieRec"); | 423 | Config hwcfg("OpieRec"); |
422 | hwcfg.setGroup("Hardware"); | 424 | hwcfg.setGroup("Hardware"); |
423 | 425 | ||
424 | 426 | ||
425 | soundDevice = new Device( this, false); //open play | 427 | soundDevice = new Device( this, false); //open play |
426 | 428 | ||
427 | getInVol(); | 429 | getInVol(); |
428 | getOutVol(); | 430 | getOutVol(); |
429 | 431 | ||
430 | soundDevice->closeDevice( true); | 432 | soundDevice->closeDevice( true); |
431 | soundDevice->sd = -1; | 433 | soundDevice->sd = -1; |
432 | soundDevice = 0; | 434 | soundDevice = 0; |
433 | wavFile = 0; | 435 | wavFile = 0; |
434 | // if( soundDevice) delete soundDevice; | 436 | // if( soundDevice) delete soundDevice; |
435 | QTimer::singleShot(100,this, SLOT(initIconView())); | 437 | QTimer::singleShot(100,this, SLOT(initIconView())); |
436 | 438 | ||
437 | if( autoMute) | 439 | if( autoMute) |
438 | doMute( true); | 440 | doMute( true); |
439 | // ListView1->setFocus(); | 441 | // ListView1->setFocus(); |
440 | playing = false; | 442 | playing = false; |
441 | } | 443 | } |
442 | 444 | ||
443 | QtRec::~QtRec() { | 445 | QtRec::~QtRec() { |
444 | // if( soundDevice) delete soundDevice; | 446 | // if( soundDevice) delete soundDevice; |
445 | 447 | ||
446 | } | 448 | } |
447 | 449 | ||
448 | void QtRec::cleanUp() { | 450 | void QtRec::cleanUp() { |
449 | 451 | ||
450 | if( !stopped) { | 452 | if( !stopped) { |
451 | stopped = true; | 453 | stopped = true; |
@@ -775,34 +777,34 @@ void QtRec::initConfig() { | |||
775 | 777 | ||
776 | filePara.resolution = i; | 778 | filePara.resolution = i; |
777 | 779 | ||
778 | i = cfg.readNumEntry("sizeLimit", 5 ); | 780 | i = cfg.readNumEntry("sizeLimit", 5 ); |
779 | QString temp; | 781 | QString temp; |
780 | sizeLimitCombo->setCurrentItem((i/5)); | 782 | sizeLimitCombo->setCurrentItem((i/5)); |
781 | 783 | ||
782 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); | 784 | stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); |
783 | if( stereoCheckBox->isChecked()) { | 785 | if( stereoCheckBox->isChecked()) { |
784 | filePara.channels = 2; | 786 | filePara.channels = 2; |
785 | } else { | 787 | } else { |
786 | filePara.channels = 1; | 788 | filePara.channels = 1; |
787 | } | 789 | } |
788 | 790 | ||
789 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); | 791 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); |
790 | if( compressionCheckBox->isChecked()) { | 792 | if( compressionCheckBox->isChecked()) { |
793 | bitRateComboBox->setCurrentItem(1); | ||
791 | bitRateComboBox->setEnabled(false); | 794 | bitRateComboBox->setEnabled(false); |
792 | bitRateComboBox->setCurrentItem(0); | ||
793 | filePara.resolution=16; | 795 | filePara.resolution=16; |
794 | } | 796 | } |
795 | 797 | ||
796 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); | 798 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); |
797 | if( autoMuteCheckBox->isChecked()) | 799 | if( autoMuteCheckBox->isChecked()) |
798 | slotAutoMute(true); | 800 | slotAutoMute(true); |
799 | else | 801 | else |
800 | slotAutoMute(false); | 802 | slotAutoMute(false); |
801 | 803 | ||
802 | Config cofg( "qpe"); | 804 | Config cofg( "qpe"); |
803 | cofg.setGroup( "Volume"); | 805 | cofg.setGroup( "Volume"); |
804 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); | 806 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); |
805 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); | 807 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); |
806 | } | 808 | } |
807 | 809 | ||
808 | void QtRec::stop() { | 810 | void QtRec::stop() { |
@@ -1035,33 +1037,33 @@ bool QtRec::setupAudio( bool b) { | |||
1035 | // odebug << "WAVE_FORMAT_PCM" << oendl; | 1037 | // odebug << "WAVE_FORMAT_PCM" << oendl; |
1036 | } else { | 1038 | } else { |
1037 | filePara.format = WAVE_FORMAT_DVI_ADPCM; | 1039 | filePara.format = WAVE_FORMAT_DVI_ADPCM; |
1038 | sampleformat = AFMT_S16_LE; | 1040 | sampleformat = AFMT_S16_LE; |
1039 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; | 1041 | // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; |
1040 | } | 1042 | } |
1041 | #endif | 1043 | #endif |
1042 | 1044 | ||
1043 | stereo = filePara.channels; | 1045 | stereo = filePara.channels; |
1044 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; | 1046 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; |
1045 | flags= O_RDWR; | 1047 | flags= O_RDWR; |
1046 | // flags= O_RDONLY; | 1048 | // flags= O_RDONLY; |
1047 | recording = true; | 1049 | recording = true; |
1048 | } | 1050 | } |
1049 | 1051 | ||
1050 | // if(soundDevice) delete soundDevice; | 1052 | // if(soundDevice) delete soundDevice; |
1051 | odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; | 1053 | owarn << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; |
1052 | // owarn << "change waveform settings" << oendl; | 1054 | // owarn << "change waveform settings" << oendl; |
1053 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); | 1055 | waveform->changeSettings( filePara.sampleRate, filePara.channels ); |
1054 | 1056 | ||
1055 | soundDevice = new Device( this, b); //open rec | 1057 | soundDevice = new Device( this, b); //open rec |
1056 | // soundDevice->openDsp(); | 1058 | // soundDevice->openDsp(); |
1057 | soundDevice->reset(); | 1059 | soundDevice->reset(); |
1058 | 1060 | ||
1059 | odebug << "device has been made " << soundDevice->sd << "" << oendl; | 1061 | odebug << "device has been made " << soundDevice->sd << "" << oendl; |
1060 | 1062 | ||
1061 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> | 1063 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> |
1062 | soundDevice->setDeviceFormat( sampleformat); | 1064 | soundDevice->setDeviceFormat( sampleformat); |
1063 | soundDevice->setDeviceChannels( filePara.channels); | 1065 | soundDevice->setDeviceChannels( filePara.channels); |
1064 | soundDevice->setDeviceRate( filePara.sampleRate); | 1066 | soundDevice->setDeviceRate( filePara.sampleRate); |
1065 | soundDevice->getDeviceFragSize(); | 1067 | soundDevice->getDeviceFragSize(); |
1066 | #ifdef QT_QWS_EBX | 1068 | #ifdef QT_QWS_EBX |
1067 | int frag = FRAGSIZE; | 1069 | int frag = FRAGSIZE; |
@@ -1217,64 +1219,64 @@ void QtRec::itClick(QListViewItem *item) { | |||
1217 | currentFile = item->text(0); | 1219 | currentFile = item->text(0); |
1218 | setCaption("OpieRecord "+currentFile); | 1220 | setCaption("OpieRecord "+currentFile); |
1219 | } | 1221 | } |
1220 | 1222 | ||
1221 | void QtRec::deleteSound() { | 1223 | void QtRec::deleteSound() { |
1222 | Config cfg("OpieRec"); | 1224 | Config cfg("OpieRec"); |
1223 | cfg.setGroup("Sounds"); | 1225 | cfg.setGroup("Sounds"); |
1224 | if( ListView1->currentItem() == NULL) | 1226 | if( ListView1->currentItem() == NULL) |
1225 | return; | 1227 | return; |
1226 | // #ifndef DEV_VERSION | 1228 | // #ifndef DEV_VERSION |
1227 | // switch ( QMessageBox::warning(this,tr("Delete"), | 1229 | // switch ( QMessageBox::warning(this,tr("Delete"), |
1228 | // tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), | 1230 | // tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), |
1229 | // tr("Yes"),tr("No"),0,1,1) ) { | 1231 | // tr("Yes"),tr("No"),0,1,1) ) { |
1230 | // case 0: | 1232 | // case 0: |
1231 | // #endif | 1233 | // #endif |
1232 | // { | 1234 | // { |
1233 | QString file = ListView1->currentItem()->text(0); | 1235 | QString file = ListView1->currentItem()->text(0); |
1234 | QString fileName; | 1236 | QString fileName; |
1235 | fileName = cfg.readEntry( file, ""); | 1237 | fileName = cfg.readEntry( file, ""); |
1236 | QFile f( fileName); | 1238 | QFile f( fileName); |
1237 | if( f.exists()) | 1239 | if( f.exists()) |
1238 | if( !f.remove()) | 1240 | if( !f.remove()) |
1239 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); | 1241 | QMessageBox::message( tr("Error"), tr("Could not remove file.")); |
1240 | 1242 | ||
1241 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1243 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1242 | bool found = false; | 1244 | bool found = false; |
1243 | for(int i=0;i<nFiles+1;i++) { | 1245 | for(int i=0;i<nFiles+1;i++) { |
1244 | 1246 | ||
1245 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { | 1247 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { |
1246 | found = true; | 1248 | found = true; |
1247 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1249 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1248 | } | 1250 | } |
1249 | if(found) | 1251 | if(found) |
1250 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | 1252 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); |
1251 | } | 1253 | } |
1252 | 1254 | ||
1253 | cfg.removeEntry( cfg.readEntry( file)); | 1255 | cfg.removeEntry( cfg.readEntry( file)); |
1254 | cfg.removeEntry( file); | 1256 | cfg.removeEntry( file); |
1255 | cfg.writeEntry( "NumberofFiles", nFiles-1); | 1257 | cfg.writeEntry( "NumberofFiles", nFiles-1); |
1256 | cfg.write(); | 1258 | cfg.write(); |
1257 | 1259 | ||
1258 | ListView1->takeItem( ListView1->currentItem() ); | 1260 | ListView1->takeItem( ListView1->currentItem() ); |
1259 | delete ListView1->currentItem(); | 1261 | delete ListView1->currentItem(); |
1260 | 1262 | ||
1261 | ListView1->clear(); | 1263 | ListView1->clear(); |
1262 | ListView1->setSelected( ListView1->firstChild(), true); | 1264 | ListView1->setSelected( ListView1->firstChild(), true); |
1263 | initIconView(); | 1265 | initIconView(); |
1264 | update(); | 1266 | update(); |
1265 | setCaption( tr( "OpieRecord " )); | 1267 | setCaption( tr( "OpieRecord " )); |
1266 | } | 1268 | } |
1267 | 1269 | ||
1268 | void QtRec::keyPressEvent( QKeyEvent *e) { | 1270 | void QtRec::keyPressEvent( QKeyEvent *e) { |
1269 | 1271 | ||
1270 | switch ( e->key() ) { | 1272 | switch ( e->key() ) { |
1271 | // case Key_F1: | 1273 | // case Key_F1: |
1272 | // if(stopped && !recording) | 1274 | // if(stopped && !recording) |
1273 | // newSound(); | 1275 | // newSound(); |
1274 | // else | 1276 | // else |
1275 | // stop(); | 1277 | // stop(); |
1276 | // break; | 1278 | // break; |
1277 | // case Key_F2: { | 1279 | // case Key_F2: { |
1278 | // if( !e->isAutoRepeat()) | 1280 | // if( !e->isAutoRepeat()) |
1279 | // rewindPressed(); | 1281 | // rewindPressed(); |
1280 | // } | 1282 | // } |
@@ -1396,53 +1398,53 @@ void QtRec::endRecording() { | |||
1396 | doMute( true); | 1398 | doMute( true); |
1397 | 1399 | ||
1398 | soundDevice->closeDevice( true); | 1400 | soundDevice->closeDevice( true); |
1399 | 1401 | ||
1400 | if( wavFile->track.isOpen()) { | 1402 | if( wavFile->track.isOpen()) { |
1401 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); | 1403 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); |
1402 | // soundDevice->sd=-1; | 1404 | // soundDevice->sd=-1; |
1403 | filePara.numberSamples = 0; | 1405 | filePara.numberSamples = 0; |
1404 | // filePara.sd=-1; | 1406 | // filePara.sd=-1; |
1405 | wavFile->closeFile(); | 1407 | wavFile->closeFile(); |
1406 | filePara.fd=0; | 1408 | filePara.fd=0; |
1407 | 1409 | ||
1408 | if( wavFile->isTempFile()) { | 1410 | if( wavFile->isTempFile()) { |
1409 | // move tmp file to regular file | 1411 | // move tmp file to regular file |
1410 | QString cmd; | 1412 | QString cmd; |
1411 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); | 1413 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); |
1412 | odebug << "moving tmp file to "+currentFileName << oendl; | 1414 | odebug << "moving tmp file to "+currentFileName << oendl; |
1413 | system( cmd.latin1()); | 1415 | system( cmd.latin1()); |
1414 | } | 1416 | } |
1415 | 1417 | ||
1416 | odebug << "Just moved " + wavFile->currentFileName << oendl; | 1418 | odebug << "Just moved " + wavFile->currentFileName << oendl; |
1417 | Config cfg("OpieRec"); | 1419 | Config cfg("OpieRec"); |
1418 | cfg.setGroup("Sounds"); | 1420 | cfg.setGroup("Sounds"); |
1419 | 1421 | ||
1420 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | 1422 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); |
1421 | 1423 | ||
1422 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); | 1424 | currentFile = QFileInfo( wavFile->currentFileName).fileName(); |
1423 | currentFile = currentFile.left( currentFile.length() - 4); | 1425 | currentFile = currentFile.left( currentFile.length() - 4); |
1424 | 1426 | ||
1425 | cfg.writeEntry( "NumberofFiles", nFiles + 1); | 1427 | cfg.writeEntry( "NumberofFiles", nFiles + 1); |
1426 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); | 1428 | cfg.writeEntry( QString::number( nFiles + 1), currentFile); |
1427 | cfg.writeEntry( currentFile, wavFile->currentFileName); | 1429 | cfg.writeEntry( currentFile, wavFile->currentFileName); |
1428 | 1430 | ||
1429 | QString time; | 1431 | QString time; |
1430 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); | 1432 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); |
1431 | cfg.writeEntry( wavFile->currentFileName, time ); | 1433 | cfg.writeEntry( wavFile->currentFileName, time ); |
1432 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; | 1434 | odebug << "writing config numberOfRecordedSeconds "+time << oendl; |
1433 | 1435 | ||
1434 | cfg.write(); | 1436 | cfg.write(); |
1435 | odebug << "finished recording" << oendl; | 1437 | odebug << "finished recording" << oendl; |
1436 | // timeLabel->setText(""); | 1438 | // timeLabel->setText(""); |
1437 | } | 1439 | } |
1438 | 1440 | ||
1439 | // if(soundDevice) delete soundDevice; | 1441 | // if(soundDevice) delete soundDevice; |
1440 | 1442 | ||
1441 | timeSlider->setValue(0); | 1443 | timeSlider->setValue(0); |
1442 | initIconView(); | 1444 | initIconView(); |
1443 | selectItemByName( currentFile); | 1445 | selectItemByName( currentFile); |
1444 | setCaption( tr( "OpieRecord " )); | 1446 | setCaption( tr( "OpieRecord " )); |
1445 | 1447 | ||
1446 | } | 1448 | } |
1447 | 1449 | ||
1448 | void QtRec::endPlaying() { | 1450 | void QtRec::endPlaying() { |
@@ -1470,36 +1472,36 @@ void QtRec::endPlaying() { | |||
1470 | filePara.numberSamples = 0; | 1472 | filePara.numberSamples = 0; |
1471 | filePara.sd = -1; | 1473 | filePara.sd = -1; |
1472 | // wavFile->closeFile(); | 1474 | // wavFile->closeFile(); |
1473 | filePara.fd = 0; | 1475 | filePara.fd = 0; |
1474 | // if(wavFile) delete wavFile; //this crashes | 1476 | // if(wavFile) delete wavFile; //this crashes |
1475 | 1477 | ||
1476 | odebug << "track closed" << oendl; | 1478 | odebug << "track closed" << oendl; |
1477 | killTimers(); | 1479 | killTimers(); |
1478 | // owarn << "reset slider" << oendl; | 1480 | // owarn << "reset slider" << oendl; |
1479 | timeSlider->setValue(0); | 1481 | timeSlider->setValue(0); |
1480 | 1482 | ||
1481 | // if(soundDevice) delete soundDevice; | 1483 | // if(soundDevice) delete soundDevice; |
1482 | 1484 | ||
1483 | } | 1485 | } |
1484 | 1486 | ||
1485 | bool QtRec::openPlayFile() { | 1487 | bool QtRec::openPlayFile() { |
1486 | 1488 | qWarning("opening file"); | |
1487 | qApp->processEvents(); | 1489 | qApp->processEvents(); |
1488 | if( currentFile.isEmpty()) { | 1490 | if( currentFile.isEmpty()) { |
1489 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); | 1491 | QMessageBox::message(tr("Opierec"),tr("Please select file to play")); |
1490 | endPlaying(); | 1492 | endPlaying(); |
1491 | return false; | 1493 | return false; |
1492 | } | 1494 | } |
1493 | QString currentFileName; | 1495 | QString currentFileName; |
1494 | Config cfg("OpieRec"); | 1496 | Config cfg("OpieRec"); |
1495 | cfg.setGroup("Sounds"); | 1497 | cfg.setGroup("Sounds"); |
1496 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); | 1498 | int nFiles = cfg.readNumEntry( "NumberofFiles", 0); |
1497 | for(int i=0;i<nFiles+1;i++) { //look for file | 1499 | for(int i=0;i<nFiles+1;i++) { //look for file |
1498 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { | 1500 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { |
1499 | currentFileName = cfg.readEntry( currentFile, "" ); | 1501 | currentFileName = cfg.readEntry( currentFile, "" ); |
1500 | odebug << "opening for play: " + currentFileName << oendl; | 1502 | odebug << "opening for play: " + currentFileName << oendl; |
1501 | } | 1503 | } |
1502 | } | 1504 | } |
1503 | wavFile = new WavFile(this, | 1505 | wavFile = new WavFile(this, |
1504 | currentFileName, | 1506 | currentFileName, |
1505 | false); | 1507 | false); |
@@ -1713,34 +1715,35 @@ void QtRec::doMicMuting(bool b) { | |||
1713 | Config cfg( "qpe" ); | 1715 | Config cfg( "qpe" ); |
1714 | cfg. setGroup( "Volume" ); | 1716 | cfg. setGroup( "Volume" ); |
1715 | cfg.writeEntry( "MicMute",b); | 1717 | cfg.writeEntry( "MicMute",b); |
1716 | cfg.write(); | 1718 | cfg.write(); |
1717 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; | 1719 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; |
1718 | } | 1720 | } |
1719 | 1721 | ||
1720 | void QtRec::compressionSelected(bool b) { | 1722 | void QtRec::compressionSelected(bool b) { |
1721 | Config cfg("OpieRec"); | 1723 | Config cfg("OpieRec"); |
1722 | cfg.setGroup("Settings"); | 1724 | cfg.setGroup("Settings"); |
1723 | cfg.writeEntry("wavCompression", b); | 1725 | cfg.writeEntry("wavCompression", b); |
1724 | cfg.writeEntry("bitrate", 16); | 1726 | cfg.writeEntry("bitrate", 16); |
1725 | filePara.resolution = 16; | 1727 | filePara.resolution = 16; |
1726 | cfg.write(); | 1728 | cfg.write(); |
1727 | 1729 | ||
1728 | if(b) { | 1730 | if(b) { |
1729 | bitRateComboBox->setEnabled( false); | 1731 | qWarning("set adpcm"); |
1730 | bitRateComboBox->setCurrentItem( 1); | 1732 | bitRateComboBox->setCurrentItem( 1); |
1733 | bitRateComboBox->setEnabled( false); | ||
1731 | filePara.resolution = 16; | 1734 | filePara.resolution = 16; |
1732 | } else{ | 1735 | } else{ |
1733 | bitRateComboBox->setEnabled( true); | 1736 | bitRateComboBox->setEnabled( true); |
1734 | } | 1737 | } |
1735 | } | 1738 | } |
1736 | 1739 | ||
1737 | long QtRec::checkDiskSpace(const QString &path) { | 1740 | long QtRec::checkDiskSpace(const QString &path) { |
1738 | 1741 | ||
1739 | struct statfs fs; | 1742 | struct statfs fs; |
1740 | 1743 | ||
1741 | if ( !statfs( path.latin1(), &fs ) ) { | 1744 | if ( !statfs( path.latin1(), &fs ) ) { |
1742 | 1745 | ||
1743 | int blkSize = fs.f_bsize; | 1746 | int blkSize = fs.f_bsize; |
1744 | int availBlks = fs.f_bavail; | 1747 | int availBlks = fs.f_bavail; |
1745 | 1748 | ||
1746 | long mult = blkSize / 1024; | 1749 | long mult = blkSize / 1024; |
@@ -1788,101 +1791,101 @@ void QtRec::timerEvent( QTimerEvent * ) { | |||
1788 | 1791 | ||
1789 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { | 1792 | if( recording && filePara.SecondsToRecord < secCount && filePara.SecondsToRecord != 0) { |
1790 | stop(); | 1793 | stop(); |
1791 | } | 1794 | } |
1792 | 1795 | ||
1793 | odebug << "" << secCount << "" << oendl; | 1796 | odebug << "" << secCount << "" << oendl; |
1794 | QString timeString; | 1797 | QString timeString; |
1795 | 1798 | ||
1796 | timeString.sprintf("%d", secCount); | 1799 | timeString.sprintf("%d", secCount); |
1797 | // timeLabel->setText( timeString + " seconds"); | 1800 | // timeLabel->setText( timeString + " seconds"); |
1798 | 1801 | ||
1799 | secCount++; | 1802 | secCount++; |
1800 | } | 1803 | } |
1801 | 1804 | ||
1802 | void QtRec::changeTimeSlider(int index) { | 1805 | void QtRec::changeTimeSlider(int index) { |
1803 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; | 1806 | if( ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; |
1804 | odebug << "Slider moved to " << index << "" << oendl; | 1807 | odebug << "Slider moved to " << index << "" << oendl; |
1805 | paused = true; | 1808 | paused = true; |
1806 | stopped = true; | 1809 | stopped = true; |
1807 | 1810 | ||
1808 | sliderPos=index; | 1811 | sliderPos=index; |
1809 | 1812 | ||
1810 | QString timeString; | 1813 | QString timeString; |
1811 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1814 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1812 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1815 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1813 | secCount = (int)filePara.numberOfRecordedSeconds; | 1816 | secCount = (int)filePara.numberOfRecordedSeconds; |
1814 | // timeLabel->setText( timeString + tr(" seconds")); | 1817 | // timeLabel->setText( timeString + tr(" seconds")); |
1815 | } | 1818 | } |
1816 | 1819 | ||
1817 | void QtRec::timeSliderPressed() { | 1820 | void QtRec::timeSliderPressed() { |
1818 | if( ListView1->currentItem() == 0) return; | 1821 | if( ListView1->currentItem() == 0) return; |
1819 | odebug << "slider pressed" << oendl; | 1822 | odebug << "slider pressed" << oendl; |
1820 | paused = true; | 1823 | paused = true; |
1821 | stopped = true; | 1824 | stopped = true; |
1822 | } | 1825 | } |
1823 | 1826 | ||
1824 | void QtRec::timeSliderReleased() { | 1827 | void QtRec::timeSliderReleased() { |
1825 | if( ListView1->currentItem() == 0) return; | 1828 | if( ListView1->currentItem() == 0) return; |
1826 | sliderPos = timeSlider->value(); | 1829 | sliderPos = timeSlider->value(); |
1827 | 1830 | ||
1828 | odebug << "slider released " << sliderPos << "" << oendl; | 1831 | odebug << "slider released " << sliderPos << "" << oendl; |
1829 | stopped = false; | 1832 | stopped = false; |
1830 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1833 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1831 | total = newPos*4; | 1834 | total = newPos*4; |
1832 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; | 1835 | filePara.numberOfRecordedSeconds = (float)sliderPos / (float)filePara.sampleRate * (float)2; |
1833 | 1836 | ||
1834 | doPlay(); | 1837 | doPlay(); |
1835 | } | 1838 | } |
1836 | 1839 | ||
1837 | void QtRec::rewindPressed() { | 1840 | void QtRec::rewindPressed() { |
1838 | if( ListView1->currentItem() == 0) return; | 1841 | if( ListView1->currentItem() == 0) return; |
1839 | if( !wavFile->track.isOpen()) { | 1842 | if( !wavFile->track.isOpen()) { |
1840 | if( !openPlayFile() ) | 1843 | if( !openPlayFile() ) |
1841 | return; | 1844 | return; |
1842 | else | 1845 | else |
1843 | if( !setupAudio( false)) | 1846 | if( !setupAudio( false)) |
1844 | return; | 1847 | return; |
1845 | } else { | 1848 | } else { |
1846 | killTimers(); | 1849 | killTimers(); |
1847 | paused = true; | 1850 | paused = true; |
1848 | stopped = true; | 1851 | stopped = true; |
1849 | rewindTimer->start( 50, false); | 1852 | rewindTimer->start( 50, false); |
1850 | } | 1853 | } |
1851 | } | 1854 | } |
1852 | 1855 | ||
1853 | void QtRec::rewindTimerTimeout() { | 1856 | void QtRec::rewindTimerTimeout() { |
1854 | int sliderValue = timeSlider->value(); | 1857 | int sliderValue = timeSlider->value(); |
1855 | sliderValue = sliderValue - ( filePara.numberSamples / 100); | 1858 | sliderValue = sliderValue - ( filePara.numberSamples / 100); |
1856 | // if(toBeginningButton->isDown()) | 1859 | // if(toBeginningButton->isDown()) |
1857 | timeSlider->setValue( sliderValue ) ; | 1860 | timeSlider->setValue( sliderValue ) ; |
1858 | odebug << "" << sliderValue << "" << oendl; | 1861 | odebug << "" << sliderValue << "" << oendl; |
1859 | QString timeString; | 1862 | QString timeString; |
1860 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; | 1863 | filePara.numberOfRecordedSeconds = (float)sliderValue / (float)filePara.sampleRate * (float)2; |
1861 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | 1864 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); |
1862 | // timeLabel->setText( timeString+ tr(" seconds")); | 1865 | // timeLabel->setText( timeString+ tr(" seconds")); |
1863 | } | 1866 | } |
1864 | 1867 | ||
1865 | void QtRec::rewindReleased() { | 1868 | void QtRec::rewindReleased() { |
1866 | rewindTimer->stop(); | 1869 | rewindTimer->stop(); |
1867 | if( wavFile->track.isOpen()) { | 1870 | if( wavFile->track.isOpen()) { |
1868 | sliderPos=timeSlider->value(); | 1871 | sliderPos=timeSlider->value(); |
1869 | stopped = false; | 1872 | stopped = false; |
1870 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | 1873 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); |
1871 | total = newPos * 4; | 1874 | total = newPos * 4; |
1872 | odebug << "rewind released " << total << "" << oendl; | 1875 | odebug << "rewind released " << total << "" << oendl; |
1873 | startTimer( 1000); | 1876 | startTimer( 1000); |
1874 | doPlay(); | 1877 | doPlay(); |
1875 | } | 1878 | } |
1876 | } | 1879 | } |
1877 | 1880 | ||
1878 | void QtRec::FastforwardPressed() { | 1881 | void QtRec::FastforwardPressed() { |
1879 | if( ListView1->currentItem() == 0) return; | 1882 | if( ListView1->currentItem() == 0) return; |
1880 | if( !wavFile->track.isOpen()) | 1883 | if( !wavFile->track.isOpen()) |
1881 | if( !openPlayFile() ) | 1884 | if( !openPlayFile() ) |
1882 | return; | 1885 | return; |
1883 | else | 1886 | else |
1884 | if( !setupAudio( false)) | 1887 | if( !setupAudio( false)) |
1885 | return; | 1888 | return; |
1886 | killTimers(); | 1889 | killTimers(); |
1887 | 1890 | ||
1888 | paused = true; | 1891 | paused = true; |
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 80453e1..b53c416 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp | |||
@@ -14,33 +14,33 @@ using namespace Opie::Core; | |||
14 | /* STD */ | 14 | /* STD */ |
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include <sys/time.h> | 16 | #include <sys/time.h> |
17 | #include <sys/types.h> | 17 | #include <sys/types.h> |
18 | #include <sys/vfs.h> | 18 | #include <sys/vfs.h> |
19 | #include <fcntl.h> | 19 | #include <fcntl.h> |
20 | #include <math.h> | 20 | #include <math.h> |
21 | #include <mntent.h> | 21 | #include <mntent.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | 25 | ||
26 | WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, | 26 | WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, |
27 | int channels, int resolution, int format ) | 27 | int channels, int resolution, int format ) |
28 | : QObject( parent) | 28 | : QObject( parent) |
29 | { | 29 | { |
30 | //odebug << "new wave file" << oendl; | 30 | owarn << "new wave file: " << fileName << oendl; |
31 | bool b = makeNwFile; | 31 | bool b = makeNwFile; |
32 | wavSampleRate=sampleRate; | 32 | wavSampleRate=sampleRate; |
33 | wavFormat=format; | 33 | wavFormat=format; |
34 | wavChannels=channels; | 34 | wavChannels=channels; |
35 | wavResolution=resolution; | 35 | wavResolution=resolution; |
36 | useTmpFile=false; | 36 | useTmpFile=false; |
37 | if( b) { | 37 | if( b) { |
38 | newFile(); | 38 | newFile(); |
39 | } else { | 39 | } else { |
40 | openFile(fileName); | 40 | openFile(fileName); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | bool WavFile::newFile() { | 44 | bool WavFile::newFile() { |
45 | 45 | ||
46 | // odebug << "Set up new file" << oendl; | 46 | // odebug << "Set up new file" << oendl; |
@@ -96,163 +96,163 @@ bool WavFile::newFile() { | |||
96 | setWavHeader( track.handle() , &hdr); | 96 | setWavHeader( track.handle() , &hdr); |
97 | } | 97 | } |
98 | return true; | 98 | return true; |
99 | } | 99 | } |
100 | 100 | ||
101 | WavFile::~WavFile() { | 101 | WavFile::~WavFile() { |
102 | 102 | ||
103 | closeFile(); | 103 | closeFile(); |
104 | } | 104 | } |
105 | 105 | ||
106 | void WavFile::closeFile() { | 106 | void WavFile::closeFile() { |
107 | if(track.isOpen()) | 107 | if(track.isOpen()) |
108 | track.close(); | 108 | track.close(); |
109 | } | 109 | } |
110 | 110 | ||
111 | int WavFile::openFile(const QString ¤tFileName) { | 111 | int WavFile::openFile(const QString ¤tFileName) { |
112 | // odebug << "open play file "+currentFileName << oendl; | 112 | qWarning("open play file "+currentFileName);; |
113 | closeFile(); | 113 | closeFile(); |
114 | 114 | ||
115 | track.setName(currentFileName); | 115 | track.setName(currentFileName); |
116 | 116 | ||
117 | if(!track.open(IO_ReadOnly)) { | 117 | if(!track.open(IO_ReadOnly)) { |
118 | QString errorMsg=(QString)strerror(errno); | 118 | QString errorMsg=(QString)strerror(errno); |
119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; | 119 | odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; |
120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | 120 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); |
121 | return -1; | 121 | return -1; |
122 | } else { | 122 | } else { |
123 | parseWavHeader( track.handle()); | 123 | parseWavHeader( track.handle()); |
124 | } | 124 | } |
125 | return track.handle(); | 125 | return track.handle(); |
126 | } | 126 | } |
127 | 127 | ||
128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | 128 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { |
129 | 129 | ||
130 | strncpy((*hdr).riffID, "RIFF", 4); // RIFF | 130 | strncpy((*hdr).riffID, "RIFF", 4); // RIFF |
131 | strncpy((*hdr).wavID, "WAVE", 4); //WAVE | 131 | strncpy((*hdr).wavID, "WAVE", 4); //WAVE |
132 | strncpy((*hdr).fmtID, "fmt ", 4); // fmt | 132 | strncpy((*hdr).fmtID, "fmt ", 4); // fmt |
133 | (*hdr).fmtLen = 16; // format length = 16 | 133 | (*hdr).fmtLen = 16; // format length = 16 |
134 | 134 | ||
135 | if( wavFormat == WAVE_FORMAT_PCM) { | 135 | if( wavFormat == WAVE_FORMAT_PCM) { |
136 | (*hdr).fmtTag = 1; // PCM | 136 | (*hdr).fmtTag = 1; // PCM |
137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; | 137 | // odebug << "set header WAVE_FORMAT_PCM" << oendl; |
138 | } | 138 | } |
139 | else { | 139 | else { |
140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM | 140 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM |
141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; | 141 | // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; |
142 | } | 142 | } |
143 | 143 | ||
144 | // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels | 144 | // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels |
145 | (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels | 145 | (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels |
146 | 146 | ||
147 | (*hdr).sampleRate = wavSampleRate; //samples per second | 147 | (*hdr).sampleRate = wavSampleRate; //samples per second |
148 | (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second | 148 | (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second |
149 | (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align | 149 | (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align |
150 | (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 | 150 | (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 |
151 | 151 | ||
152 | strncpy((*hdr).dataID, "data", 4); | 152 | strncpy((*hdr).dataID, "data", 4); |
153 | 153 | ||
154 | write( fd,hdr, sizeof(*hdr)); | 154 | write( fd,hdr, sizeof(*hdr)); |
155 | odebug << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; | 155 | owarn << "writing header: bitrate " << wavResolution << ", samplerate " << wavSampleRate << ", channels " << wavChannels << oendl; |
156 | return true; | 156 | return true; |
157 | } | 157 | } |
158 | 158 | ||
159 | bool WavFile::adjustHeaders(int fd, int total) { | 159 | bool WavFile::adjustHeaders(int fd, int total) { |
160 | lseek(fd, 4, SEEK_SET); | 160 | lseek(fd, 4, SEEK_SET); |
161 | int i = total + 36; | 161 | int i = total + 36; |
162 | write( fd, &i, sizeof(i)); | 162 | write( fd, &i, sizeof(i)); |
163 | lseek( fd, 40, SEEK_SET); | 163 | lseek( fd, 40, SEEK_SET); |
164 | write( fd, &total, sizeof(total)); | 164 | write( fd, &total, sizeof(total)); |
165 | odebug << "adjusting header " << total << "" << oendl; | 165 | owarn << "adjusting header " << total << "" << oendl; |
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | int WavFile::parseWavHeader(int fd) { | 169 | int WavFile::parseWavHeader(int fd) { |
170 | odebug << "Parsing wav header" << oendl; | 170 | owarn << "Parsing wav header" << oendl; |
171 | char string[4]; | 171 | char string[4]; |
172 | int found; | 172 | int found; |
173 | short fmt; | 173 | short fmt; |
174 | unsigned short ch, bitrate; | 174 | unsigned short ch, bitrate; |
175 | unsigned long samplerrate, longdata; | 175 | unsigned long samplerrate, longdata; |
176 | 176 | ||
177 | if (read(fd, string, 4) < 4) { | 177 | if (read(fd, string, 4) < 4) { |
178 | odebug << " Could not read from sound file." << oendl; | 178 | owarn << " Could not read from sound file." << oendl; |
179 | return -1; | 179 | return -1; |
180 | } | 180 | } |
181 | if (strncmp(string, "RIFF", 4)) { | 181 | if (strncmp(string, "RIFF", 4)) { |
182 | odebug << " not a valid WAV file." << oendl; | 182 | owarn << " not a valid WAV file." << oendl; |
183 | return -1; | 183 | return -1; |
184 | } | 184 | } |
185 | lseek(fd, 4, SEEK_CUR); | 185 | lseek(fd, 4, SEEK_CUR); |
186 | if (read(fd, string, 4) < 4) { | 186 | if (read(fd, string, 4) < 4) { |
187 | odebug << "Could not read from sound file." << oendl; | 187 | owarn << "Could not read from sound file." << oendl; |
188 | return -1; | 188 | return -1; |
189 | } | 189 | } |
190 | if (strncmp(string, "WAVE", 4)) { | 190 | if (strncmp(string, "WAVE", 4)) { |
191 | odebug << "not a valid WAV file." << oendl; | 191 | owarn << "not a valid WAV file." << oendl; |
192 | return -1; | 192 | return -1; |
193 | } | 193 | } |
194 | found = 0; | 194 | found = 0; |
195 | 195 | ||
196 | while (!found) { | 196 | while (!found) { |
197 | if (read(fd, string, 4) < 4) { | 197 | if (read(fd, string, 4) < 4) { |
198 | odebug << "Could not read from sound file." << oendl; | 198 | owarn << "Could not read from sound file." << oendl; |
199 | return -1; | 199 | return -1; |
200 | } | 200 | } |
201 | if (strncmp(string, "fmt ", 4)) { | 201 | if (strncmp(string, "fmt ", 4)) { |
202 | if (read(fd, &longdata, 4) < 4) { | 202 | if (read(fd, &longdata, 4) < 4) { |
203 | odebug << "Could not read from sound file." << oendl; | 203 | owarn << "Could not read from sound file." << oendl; |
204 | return -1; | 204 | return -1; |
205 | } | 205 | } |
206 | lseek(fd, longdata, SEEK_CUR); | 206 | lseek(fd, longdata, SEEK_CUR); |
207 | } else { | 207 | } else { |
208 | lseek(fd, 4, SEEK_CUR); | 208 | lseek(fd, 4, SEEK_CUR); |
209 | if (read(fd, &fmt, 2) < 2) { | 209 | if (read(fd, &fmt, 2) < 2) { |
210 | odebug << "Could not read format chunk." << oendl; | 210 | owarn << "Could not read format chunk." << oendl; |
211 | return -1; | 211 | return -1; |
212 | } | 212 | } |
213 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { | 213 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { |
214 | odebug << "Wave file contains unknown format. Unable to continue." << oendl; | 214 | owarn << "Wave file contains unknown format. Unable to continue." << oendl; |
215 | return -1; | 215 | return -1; |
216 | } | 216 | } |
217 | wavFormat = fmt; | 217 | wavFormat = fmt; |
218 | // compressionFormat=fmt; | 218 | // compressionFormat=fmt; |
219 | odebug << "compressionFormat is " << fmt << "" << oendl; | 219 | owarn << "compressionFormat is " << fmt << "" << oendl; |
220 | if (read(fd, &ch, 2) < 2) { | 220 | if (read(fd, &ch, 2) < 2) { |
221 | odebug << "Could not read format chunk." << oendl; | 221 | owarn << "Could not read format chunk." << oendl; |
222 | return -1; | 222 | return -1; |
223 | } else { | 223 | } else { |
224 | wavChannels = ch; | 224 | wavChannels = ch; |
225 | odebug << "File has " << ch << " channels" << oendl; | 225 | owarn << "File has " << ch << " channels" << oendl; |
226 | } | 226 | } |
227 | if (read(fd, &samplerrate, 4) < 4) { | 227 | if (read(fd, &samplerrate, 4) < 4) { |
228 | odebug << "Could not read from format chunk." << oendl; | 228 | owarn << "Could not read from format chunk." << oendl; |
229 | return -1; | 229 | return -1; |
230 | } else { | 230 | } else { |
231 | wavSampleRate = samplerrate; | 231 | wavSampleRate = samplerrate; |
232 | // sampleRate = samplerrate; | 232 | // sampleRate = samplerrate; |
233 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; | 233 | owarn << "File has samplerate of " << (int) samplerrate << "" << oendl; |
234 | } | 234 | } |
235 | lseek(fd, 6, SEEK_CUR); | 235 | lseek(fd, 6, SEEK_CUR); |
236 | if (read(fd, &bitrate, 2) < 2) { | 236 | if (read(fd, &bitrate, 2) < 2) { |
237 | odebug << "Could not read format chunk." << oendl; | 237 | owarn << "Could not read format chunk." << oendl; |
238 | return -1; | 238 | return -1; |
239 | } else { | 239 | } else { |
240 | wavResolution=bitrate; | 240 | wavResolution=bitrate; |
241 | // resolution = bitrate; | 241 | // resolution = bitrate; |
242 | odebug << "File has bitrate of " << bitrate << "" << oendl; | 242 | owarn << "File has bitrate of " << bitrate << "" << oendl; |
243 | } | 243 | } |
244 | found++; | 244 | found++; |
245 | } | 245 | } |
246 | } | 246 | } |
247 | found = 0; | 247 | found = 0; |
248 | while (!found) { | 248 | while (!found) { |
249 | if (read(fd, string, 4) < 4) { | 249 | if (read(fd, string, 4) < 4) { |
250 | odebug << "Could not read from sound file." << oendl; | 250 | odebug << "Could not read from sound file." << oendl; |
251 | return -1; | 251 | return -1; |
252 | } | 252 | } |
253 | 253 | ||
254 | if (strncmp(string, "data", 4)) { | 254 | if (strncmp(string, "data", 4)) { |
255 | if (read(fd, &longdata, 4)<4) { | 255 | if (read(fd, &longdata, 4)<4) { |
256 | odebug << "Could not read from sound file." << oendl; | 256 | odebug << "Could not read from sound file." << oendl; |
257 | return -1; | 257 | return -1; |
258 | } | 258 | } |