author | llornkcor <llornkcor> | 2002-02-15 02:40:16 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-15 02:40:16 (UTC) |
commit | b429144b79049fcc25dfff5a9a38415451399e58 (patch) (unidiff) | |
tree | e6a6bf929667e3c5a521145809b2615bb4b0c6e9 | |
parent | e5ac946b3ced52f4aba73dfc64398bb3d8245734 (diff) | |
download | opie-b429144b79049fcc25dfff5a9a38415451399e58.zip opie-b429144b79049fcc25dfff5a9a38415451399e58.tar.gz opie-b429144b79049fcc25dfff5a9a38415451399e58.tar.bz2 |
forgot length in header
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 25ee476..bba55a3 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -246,121 +246,122 @@ int VMemo::openDSP() | |||
246 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 246 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
247 | if (cfg.readNumEntry("SixteenBit", 1)==1) | 247 | if (cfg.readNumEntry("SixteenBit", 1)==1) |
248 | { | 248 | { |
249 | format = AFMT_S16_LE; | 249 | format = AFMT_S16_LE; |
250 | resolution = 16; | 250 | resolution = 16; |
251 | } | 251 | } |
252 | else | 252 | else |
253 | { | 253 | { |
254 | format = AFMT_U8; | 254 | format = AFMT_U8; |
255 | resolution = 8; | 255 | resolution = 8; |
256 | } | 256 | } |
257 | 257 | ||
258 | if(systemZaurus) | 258 | if(systemZaurus) |
259 | { | 259 | { |
260 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 260 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
261 | channels=1; //zaurus has one input channel | 261 | channels=1; //zaurus has one input channel |
262 | } | 262 | } |
263 | else | 263 | else |
264 | dsp = open("/dev/dsp", O_RDWR); | 264 | dsp = open("/dev/dsp", O_RDWR); |
265 | 265 | ||
266 | if(dsp == -1) | 266 | if(dsp == -1) |
267 | { | 267 | { |
268 | perror("open(\"/dev/dsp\")"); | 268 | perror("open(\"/dev/dsp\")"); |
269 | return -1; | 269 | return -1; |
270 | } | 270 | } |
271 | 271 | ||
272 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) | 272 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
273 | { | 273 | { |
274 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 274 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
275 | return -1; | 275 | return -1; |
276 | } | 276 | } |
277 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) | 277 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
278 | { | 278 | { |
279 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 279 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
280 | return -1; | 280 | return -1; |
281 | } | 281 | } |
282 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) | 282 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
283 | { | 283 | { |
284 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 284 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
285 | return -1; | 285 | return -1; |
286 | } | 286 | } |
287 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) | 287 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
288 | { | 288 | { |
289 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 289 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
290 | return -1; | 290 | return -1; |
291 | } | 291 | } |
292 | 292 | ||
293 | return 1; | 293 | return 1; |
294 | } | 294 | } |
295 | 295 | ||
296 | int VMemo::openWAV(const char *filename) | 296 | int VMemo::openWAV(const char *filename) |
297 | { | 297 | { |
298 | qDebug("Creating %s ",filename); | 298 | qDebug("Creating %s ",filename); |
299 | track.setName(filename); | 299 | track.setName(filename); |
300 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 300 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
301 | { | 301 | { |
302 | qDebug("Could not open file"); | 302 | qDebug("Could not open file"); |
303 | return -1; | 303 | return -1; |
304 | } | 304 | } |
305 | wav=track.handle(); | 305 | wav=track.handle(); |
306 | 306 | ||
307 | WaveHeader wh; | 307 | WaveHeader wh; |
308 | 308 | ||
309 | wh.main_chunk = RIFF;// RIFF | 309 | wh.main_chunk = RIFF;// RIFF |
310 | wh.length=0; /* filelen */ | ||
310 | wh.chunk_type = WAVE;//WAVE | 311 | wh.chunk_type = WAVE;//WAVE |
311 | wh.sub_chunk = FMT;// fmt | 312 | wh.sub_chunk = FMT;// fmt |
312 | wh.sc_len = 16;// format length = 16 | 313 | wh.sc_len = 16;// format length = 16 |
313 | wh.format = PCM_CODE;// PCM | 314 | wh.format = PCM_CODE;// PCM |
314 | wh.modus = channels;// channels | 315 | wh.modus = channels;// channels |
315 | wh.sample_fq = speed;//samplerate | 316 | wh.sample_fq = speed;//samplerate |
316 | wh.byte_p_sec = speed * channels * resolution/8;// av bytes per second | 317 | wh.byte_p_sec = speed * channels * resolution/8;// av bytes per second |
317 | wh.byte_p_spl = channels * (resolution / 8); //block align | 318 | wh.byte_p_spl = channels * (resolution / 8); //block align |
318 | wh.bit_p_spl = resolution;//bits per sample 8, or 16 | 319 | wh.bit_p_spl = resolution;//bits per sample 8, or 16 |
319 | wh.data_chunk = DATA; | 320 | wh.data_chunk = DATA; |
320 | wh.data_length= 0; // <--- | 321 | wh.data_length= 0; // <--- |
321 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 322 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
322 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 323 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
323 | write (wav, &wh, sizeof(WaveHeader)); | 324 | write (wav, &wh, sizeof(WaveHeader)); |
324 | 325 | ||
325 | return 1; | 326 | return 1; |
326 | } | 327 | } |
327 | 328 | ||
328 | void VMemo::record(void) | 329 | void VMemo::record(void) |
329 | { | 330 | { |
330 | int length=0, result, value; | 331 | int length=0, result, value; |
331 | char sound[8192]; | 332 | char sound[8192]; |
332 | 333 | ||
333 | qWarning("VMemo::record()"); | 334 | qWarning("VMemo::record()"); |
334 | 335 | ||
335 | while(recording) | 336 | while(recording) |
336 | { | 337 | { |
337 | result = read(dsp, sound, 512); // 8192 | 338 | result = read(dsp, sound, 512); // 8192 |
338 | qApp->processEvents(); | 339 | qApp->processEvents(); |
339 | write(wav, sound, result); | 340 | write(wav, sound, result); |
340 | qApp->processEvents(); | 341 | qApp->processEvents(); |
341 | length += result; | 342 | length += result; |
342 | qApp->processEvents(); | 343 | qApp->processEvents(); |
343 | // printf("%d\r",length); | 344 | // printf("%d\r",length); |
344 | // fflush(stdout); | 345 | // fflush(stdout); |
345 | } | 346 | } |
346 | 347 | ||
347 | qWarning("VMemo::record() -> Done recording"); | 348 | qWarning("VMemo::record() -> Done recording"); |
348 | qWarning("VMemo::record() -> Closing dsp"); | 349 | qWarning("VMemo::record() -> Closing dsp"); |
349 | 350 | ||
350 | value = length+36; | 351 | value = length+36; |
351 | lseek(wav, 4, SEEK_SET); | 352 | lseek(wav, 4, SEEK_SET); |
352 | write(wav, &value, 4); | 353 | write(wav, &value, 4); |
353 | lseek(wav, 40, SEEK_SET); | 354 | lseek(wav, 40, SEEK_SET); |
354 | write(wav, &length, 4); | 355 | write(wav, &length, 4); |
355 | // qDebug("File length %d, samplecount %d", value, length); | 356 | // qDebug("File length %d, samplecount %d", value, length); |
356 | track.close(); | 357 | track.close(); |
357 | 358 | ||
358 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while | 359 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)// ); //tell driver to stop for a while |
359 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 360 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
360 | ::close(dsp); | 361 | ::close(dsp); |
361 | 362 | ||
362 | qWarning("VMemo::record() -> playing done recording sound"); | 363 | qWarning("VMemo::record() -> playing done recording sound"); |
363 | QSound::play(Resource::findSound("vmemoe")); | 364 | QSound::play(Resource::findSound("vmemoe")); |
364 | qWarning("VMemo::record() -> terminating"); | 365 | qWarning("VMemo::record() -> terminating"); |
365 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | 366 | QMessageBox::information(0, "VMemo", "Recording Done", 1); |
366 | } | 367 | } |