Diffstat (limited to 'noncore/multimedia/opierec/wavFile.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 7e9b50f..fc0130c 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp | |||
@@ -131,50 +131,51 @@ bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | |||
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 | qDebug("writing header: bitrate%d, samplerate %d, channels %d", | 155 | odebug << "writing header: bitrate " << wavResolution |
156 | wavResolution, wavSampleRate, wavChannels); | 156 | << ", samplerate " << wavSampleRate |
157 | << ", channels " << wavChannels << oendl; | ||
157 | return true; | 158 | return true; |
158 | } | 159 | } |
159 | 160 | ||
160 | bool WavFile::adjustHeaders(int fd, int total) { | 161 | bool WavFile::adjustHeaders(int fd, int total) { |
161 | lseek(fd, 4, SEEK_SET); | 162 | lseek(fd, 4, SEEK_SET); |
162 | int i = total + 36; | 163 | int i = total + 36; |
163 | write( fd, &i, sizeof(i)); | 164 | write( fd, &i, sizeof(i)); |
164 | lseek( fd, 40, SEEK_SET); | 165 | lseek( fd, 40, SEEK_SET); |
165 | write( fd, &total, sizeof(total)); | 166 | write( fd, &total, sizeof(total)); |
166 | odebug << "adjusting header " << total << "" << oendl; | 167 | odebug << "adjusting header " << total << "" << oendl; |
167 | return true; | 168 | return true; |
168 | } | 169 | } |
169 | 170 | ||
170 | int WavFile::parseWavHeader(int fd) { | 171 | int WavFile::parseWavHeader(int fd) { |
171 | odebug << "Parsing wav header" << oendl; | 172 | odebug << "Parsing wav header" << oendl; |
172 | char string[4]; | 173 | char string[4]; |
173 | int found; | 174 | int found; |
174 | short fmt; | 175 | short fmt; |
175 | unsigned short ch, bitrate; | 176 | unsigned short ch, bitrate; |
176 | unsigned long samplerrate, longdata; | 177 | unsigned long samplerrate, longdata; |
177 | 178 | ||
178 | if (read(fd, string, 4) < 4) { | 179 | if (read(fd, string, 4) < 4) { |
179 | odebug << " Could not read from sound file.\n" << oendl; | 180 | odebug << " Could not read from sound file.\n" << oendl; |
180 | return -1; | 181 | return -1; |
@@ -191,50 +192,49 @@ int WavFile::parseWavHeader(int fd) { | |||
191 | if (strncmp(string, "WAVE", 4)) { | 192 | if (strncmp(string, "WAVE", 4)) { |
192 | odebug << "not a valid WAV file.\n" << oendl; | 193 | odebug << "not a valid WAV file.\n" << oendl; |
193 | return -1; | 194 | return -1; |
194 | } | 195 | } |
195 | found = 0; | 196 | found = 0; |
196 | 197 | ||
197 | while (!found) { | 198 | while (!found) { |
198 | if (read(fd, string, 4) < 4) { | 199 | if (read(fd, string, 4) < 4) { |
199 | odebug << "Could not read from sound file.\n" << oendl; | 200 | odebug << "Could not read from sound file.\n" << oendl; |
200 | return -1; | 201 | return -1; |
201 | } | 202 | } |
202 | if (strncmp(string, "fmt ", 4)) { | 203 | if (strncmp(string, "fmt ", 4)) { |
203 | if (read(fd, &longdata, 4) < 4) { | 204 | if (read(fd, &longdata, 4) < 4) { |
204 | odebug << "Could not read from sound file.\n" << oendl; | 205 | odebug << "Could not read from sound file.\n" << oendl; |
205 | return -1; | 206 | return -1; |
206 | } | 207 | } |
207 | lseek(fd, longdata, SEEK_CUR); | 208 | lseek(fd, longdata, SEEK_CUR); |
208 | } else { | 209 | } else { |
209 | lseek(fd, 4, SEEK_CUR); | 210 | lseek(fd, 4, SEEK_CUR); |
210 | if (read(fd, &fmt, 2) < 2) { | 211 | if (read(fd, &fmt, 2) < 2) { |
211 | odebug << "Could not read format chunk.\n" << oendl; | 212 | odebug << "Could not read format chunk.\n" << oendl; |
212 | return -1; | 213 | return -1; |
213 | } | 214 | } |
214 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { | 215 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { |
215 | qDebug("Wave file contains unknown format." | 216 | odebug << "Wave file contains unknown format. Unable to continue.\n" << oendl; |
216 | " Unable to continue.\n"); | ||
217 | return -1; | 217 | return -1; |
218 | } | 218 | } |
219 | wavFormat = fmt; | 219 | wavFormat = fmt; |
220 | // compressionFormat=fmt; | 220 | // compressionFormat=fmt; |
221 | odebug << "compressionFormat is " << fmt << "" << oendl; | 221 | odebug << "compressionFormat is " << fmt << "" << oendl; |
222 | if (read(fd, &ch, 2) < 2) { | 222 | if (read(fd, &ch, 2) < 2) { |
223 | odebug << "Could not read format chunk.\n" << oendl; | 223 | odebug << "Could not read format chunk.\n" << oendl; |
224 | return -1; | 224 | return -1; |
225 | } else { | 225 | } else { |
226 | wavChannels = ch; | 226 | wavChannels = ch; |
227 | odebug << "File has " << ch << " channels" << oendl; | 227 | odebug << "File has " << ch << " channels" << oendl; |
228 | } | 228 | } |
229 | if (read(fd, &samplerrate, 4) < 4) { | 229 | if (read(fd, &samplerrate, 4) < 4) { |
230 | odebug << "Could not read from format chunk.\n" << oendl; | 230 | odebug << "Could not read from format chunk.\n" << oendl; |
231 | return -1; | 231 | return -1; |
232 | } else { | 232 | } else { |
233 | wavSampleRate = samplerrate; | 233 | wavSampleRate = samplerrate; |
234 | // sampleRate = samplerrate; | 234 | // sampleRate = samplerrate; |
235 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; | 235 | odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; |
236 | } | 236 | } |
237 | lseek(fd, 6, SEEK_CUR); | 237 | lseek(fd, 6, SEEK_CUR); |
238 | if (read(fd, &bitrate, 2) < 2) { | 238 | if (read(fd, &bitrate, 2) < 2) { |
239 | odebug << "Could not read format chunk.\n" << oendl; | 239 | odebug << "Could not read format chunk.\n" << oendl; |
240 | return -1; | 240 | return -1; |
@@ -245,50 +245,52 @@ int WavFile::parseWavHeader(int fd) { | |||
245 | } | 245 | } |
246 | found++; | 246 | found++; |
247 | } | 247 | } |
248 | } | 248 | } |
249 | found = 0; | 249 | found = 0; |
250 | while (!found) { | 250 | while (!found) { |
251 | if (read(fd, string, 4) < 4) { | 251 | if (read(fd, string, 4) < 4) { |
252 | odebug << "Could not read from sound file.\n" << oendl; | 252 | odebug << "Could not read from sound file.\n" << oendl; |
253 | return -1; | 253 | return -1; |
254 | } | 254 | } |
255 | 255 | ||
256 | if (strncmp(string, "data", 4)) { | 256 | if (strncmp(string, "data", 4)) { |
257 | if (read(fd, &longdata, 4)<4) { | 257 | if (read(fd, &longdata, 4)<4) { |
258 | odebug << "Could not read from sound file.\n" << oendl; | 258 | odebug << "Could not read from sound file.\n" << oendl; |
259 | return -1; | 259 | return -1; |
260 | } | 260 | } |
261 | 261 | ||
262 | lseek(fd, longdata, SEEK_CUR); | 262 | lseek(fd, longdata, SEEK_CUR); |
263 | } else { | 263 | } else { |
264 | if (read(fd, &longdata, 4) < 4) { | 264 | if (read(fd, &longdata, 4) < 4) { |
265 | odebug << "Could not read from sound file.\n" << oendl; | 265 | odebug << "Could not read from sound file.\n" << oendl; |
266 | return -1; | 266 | return -1; |
267 | } else { | 267 | } else { |
268 | wavNumberSamples = longdata; | 268 | wavNumberSamples = longdata; |
269 | qDebug("file has length of %d \nlasting %d seconds", (int)longdata, | 269 | odebug << "file hase length of " << (int)longdata << "\n" |
270 | (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) ); | 270 | << "lasting " |
271 | << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) | ||
272 | << " seconds" << oendl; | ||
271 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); | 273 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); |
272 | 274 | ||
273 | return longdata; | 275 | return longdata; |
274 | } | 276 | } |
275 | } | 277 | } |
276 | } | 278 | } |
277 | 279 | ||
278 | lseek(fd, 0, SEEK_SET); | 280 | lseek(fd, 0, SEEK_SET); |
279 | 281 | ||
280 | return 0; | 282 | return 0; |
281 | } | 283 | } |
282 | 284 | ||
283 | QString WavFile::trackName() { | 285 | QString WavFile::trackName() { |
284 | return track.name(); | 286 | return track.name(); |
285 | } | 287 | } |
286 | 288 | ||
287 | int WavFile::wavHandle(){ | 289 | int WavFile::wavHandle(){ |
288 | return track.handle(); | 290 | return track.handle(); |
289 | } | 291 | } |
290 | 292 | ||
291 | int WavFile::getFormat() { | 293 | int WavFile::getFormat() { |
292 | return wavFormat; | 294 | return wavFormat; |
293 | } | 295 | } |
294 | 296 | ||