summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec
authorllornkcor <llornkcor>2004-04-25 20:38:04 (UTC)
committer llornkcor <llornkcor>2004-04-25 20:38:04 (UTC)
commit0e3e74030b2a38cfc754d253ab098a1126f382ef (patch) (unidiff)
tree9eb7544e6c29431cddbcfbc5bfe907d08227dbb2 /noncore/multimedia/opierec
parentae76c412a340a0808ed6ece5e4a8fbc04baa4ff3 (diff)
downloadopie-0e3e74030b2a38cfc754d253ab098a1126f382ef.zip
opie-0e3e74030b2a38cfc754d253ab098a1126f382ef.tar.gz
opie-0e3e74030b2a38cfc754d253ab098a1126f382ef.tar.bz2
hook things up
Diffstat (limited to 'noncore/multimedia/opierec') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opierec/qtrec.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp
index 2187d5a..6eb6524 100644
--- a/noncore/multimedia/opierec/qtrec.cpp
+++ b/noncore/multimedia/opierec/qtrec.cpp
@@ -166,108 +166,111 @@ void quickRec()
166 if(number <= 0) { 166 if(number <= 0) {
167 perror("recording error "); 167 perror("recording error ");
168 odebug << "" << filePara.fileName << " " << number << "" << oendl; 168 odebug << "" << filePara.fileName << " " << number << "" << oendl;
169 stopped = true; 169 stopped = true;
170 return; 170 return;
171 } 171 }
172 //if(stereo == 2) { 172 //if(stereo == 2) {
173// adpcm_coder( sbuf2, abuf, number/2, &encoder_state); 173// adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
174 adpcm_coder( sbuf, abuf, number/2, &encoder_state); 174 adpcm_coder( sbuf, abuf, number/2, &encoder_state);
175 175
176 bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); 176 bytesWritten = ::write( filePara.fd , (short *)abuf, number/4);
177 177
178 waveform->newSamples( (const short *)abuf, bytesWritten ); 178 waveform->newSamples( sbuf, number );
179 179
180 total += bytesWritten; 180 total += bytesWritten;
181 filePara.numberSamples = total; 181 filePara.numberSamples = total;
182 timeSlider->setValue( total); 182 timeSlider->setValue( total);
183 183
184 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2 / filePara.channels; 184 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2
185 / filePara.channels;
185 186
186 qApp->processEvents(); 187 qApp->processEvents();
187 if( total >= filePara.samplesToRecord) { 188 if( total >= filePara.samplesToRecord) {
188 stopped = true; 189 stopped = true;
189 break; 190 break;
190 } 191 }
191 } 192 }
192 } else { 193 } else {
193 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> 194 // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
194 odebug << "start recording WAVE_FORMAT_PCM" << oendl; 195 odebug << "start recording WAVE_FORMAT_PCM" << oendl;
195 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; 196 short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
196 memset( inbuffer, 0, BUFSIZE); 197 memset( inbuffer, 0, BUFSIZE);
197 memset( outbuffer, 0, BUFSIZE); 198 memset( outbuffer, 0, BUFSIZE);
198 199
199 for(;;) { 200 for(;;) {
200 if ( stopped) { 201 if ( stopped) {
201 odebug << "quickRec:: stopped" << oendl; 202 odebug << "quickRec:: stopped" << oendl;
202 stopped = true; 203 stopped = true;
203 break; // stop if playing was set to false 204 break; // stop if playing was set to false
204 return; 205 return;
205 } 206 }
206 207
207 number = soundDevice->devRead( filePara.sd, (short *)inbuffer, BUFSIZE); 208 number = soundDevice->devRead( filePara.sd, (short *)inbuffer, BUFSIZE);
208 waveform->newSamples( inbuffer, number );
209 209
210 if( number <= 0) { 210 if( number <= 0) {
211 perror( "recording error "); 211 perror( "recording error ");
212 odebug << filePara.fileName << oendl; 212 odebug << filePara.fileName << oendl;
213 stopped = true; 213 stopped = true;
214 return; 214 return;
215 } 215 }
216 216
217 bytesWritten = ::write( filePara.fd , inbuffer, number); 217 bytesWritten = ::write( filePara.fd , inbuffer, number);
218 waveform->newSamples( inbuffer, number );
218 219
219 if( bytesWritten < 0) { 220 if( bytesWritten < 0) {
220 perror("File writing error "); 221 perror("File writing error ");
221 stopped = true; 222 stopped = true;
222 return; 223 return;
223 } 224 }
224 225
225 total += bytesWritten; 226 total += bytesWritten;
226 227
227 filePara.numberSamples = total; 228 filePara.numberSamples = total;
228 229
229 if( filePara.SecondsToRecord != 0) 230 if( filePara.SecondsToRecord != 0)
230 timeSlider->setValue( total); 231 timeSlider->setValue( total);
231// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total); 232// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total);
232// fflush(stdout); 233// fflush(stdout);
233 234
234 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2/filePara.channels; 235 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate
236 / (float)2/filePara.channels;
235 qApp->processEvents(); 237 qApp->processEvents();
236 238
237 if( total >= filePara.samplesToRecord) { 239 if( total >= filePara.samplesToRecord) {
238 stopped = true; 240 stopped = true;
239 break; 241 break;
240 } 242 }
241 } 243 }
242 } //end main loop 244 } //end main loop
243 245
244 } else { 246 } else {
245// <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; 247// <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8;
246 unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; 248 unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ];
247 memset( unsigned_inbuffer, 0, BUFSIZE); 249 memset( unsigned_inbuffer, 0, BUFSIZE);
248 memset( unsigned_outbuffer, 0, BUFSIZE); 250 memset( unsigned_outbuffer, 0, BUFSIZE);
249 251
250 for(;;) { 252 for(;;) {
251 if ( stopped) { 253 if ( stopped) {
252 odebug << "quickRec:: stopped" << oendl; 254 odebug << "quickRec:: stopped" << oendl;
253 break; // stop if playing was set to false 255 break; // stop if playing was set to false
254 } 256 }
255 257
256 number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE); 258 number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE);
257 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); 259 bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
260 waveform->newSamples( (const short *) unsigned_inbuffer, number );
258 261
259 if(bytesWritten < 0) { 262 if(bytesWritten < 0) {
260 stopped = true; 263 stopped = true;
261 QMessageBox::message("Note","There was a problem\nwriting to the file"); 264 QMessageBox::message("Note","<p>There was a problem writing to the file</p>");
262 perror("File writing error "); 265 perror("File writing error ");
263 return; 266 return;
264 } 267 }
265 268
266 total += bytesWritten; 269 total += bytesWritten;
267 filePara.numberSamples = total; 270 filePara.numberSamples = total;
268 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); 271 // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total);
269 // fflush(stdout); 272 // fflush(stdout);
270 if( filePara.SecondsToRecord !=0) 273 if( filePara.SecondsToRecord !=0)
271 timeSlider->setValue( total); 274 timeSlider->setValue( total);
272 275
273 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; 276 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
@@ -304,25 +307,25 @@ void playIt()
304 if ( stopped) { 307 if ( stopped) {
305 break; 308 break;
306 return; 309 return;
307 }// stop if playing was set to false 310 }// stop if playing was set to false
308 311
309 number = ::read( filePara.fd, abuf, BUFSIZE / 2); 312 number = ::read( filePara.fd, abuf, BUFSIZE / 2);
310 adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); 313 adpcm_decoder( abuf, sbuf, number * 2, &decoder_state);
311 314
312// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel 315// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
313// sbuf2[i+1]=sbuf2[i]=sbuf[i]; 316// sbuf2[i+1]=sbuf2[i]=sbuf[i];
314// } 317// }
315 bytesWritten = write ( filePara.sd, sbuf, number * 4); 318 bytesWritten = write ( filePara.sd, sbuf, number * 4);
316 waveform->newSamples( (const short *)sbuf, number ); 319 waveform->newSamples( (const short *)sbuf, number *4);
317 // if(filePara.channels==1) 320 // if(filePara.channels==1)
318 // total += bytesWritten/2; //mono 321 // total += bytesWritten/2; //mono
319 // else 322 // else
320 total += bytesWritten; 323 total += bytesWritten;
321 filePara.numberSamples = total/4; 324 filePara.numberSamples = total/4;
322 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; 325 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2;
323 326
324 timeSlider->setValue( total/4); 327 timeSlider->setValue( total/4);
325// timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); 328// timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
326// if(filePara.numberOfRecordedSeconds>1) 329// if(filePara.numberOfRecordedSeconds>1)
327// timeLabel->setText( timeString+ tr(" seconds")); 330// timeLabel->setText( timeString+ tr(" seconds"));
328 // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); 331 // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4);
@@ -345,50 +348,50 @@ void playIt()
345 for(;;) { // play loop 348 for(;;) { // play loop
346 if ( stopped) { 349 if ( stopped) {
347 break; 350 break;
348 return; 351 return;
349 } 352 }
350// stop if playing was set to false 353// stop if playing was set to false
351 number = ::read( filePara.fd, inbuffer, BUFSIZE); 354 number = ::read( filePara.fd, inbuffer, BUFSIZE);
352// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel 355// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
353// // for (int i=0;i< number ; i++) { //2*i is left channel 356// // for (int i=0;i< number ; i++) { //2*i is left channel
354// outbuffer[i+1]= outbuffer[i]=inbuffer[i]; 357// outbuffer[i+1]= outbuffer[i]=inbuffer[i];
355// } 358// }
356 bytesWritten = ::write( filePara.sd, inbuffer, number); 359 bytesWritten = ::write( filePara.sd, inbuffer, number);
357 waveform->newSamples( inbuffer, bytesWritten ); 360 waveform->newSamples( inbuffer, number);
358 //-------------->>>> out to device 361 //-------------->>>> out to device
359 // total+=bytesWritten; 362 // total+=bytesWritten;
360 // if(filePara.channels==1) 363 // if(filePara.channels==1)
361 // total += bytesWritten/2; //mono 364 // total += bytesWritten/2; //mono
362 // else 365 // else
363 total += bytesWritten; 366 total += bytesWritten;
364 timeSlider->setValue( total); 367 timeSlider->setValue( total);
365 368
366 filePara.numberSamples = total; 369 filePara.numberSamples = total;
367 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; 370 filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2;
368 371
369// timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); 372// timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds);
370// timeLabel->setText( timeString + tr(" seconds")); 373// timeLabel->setText( timeString + tr(" seconds"));
371 374
372 qApp->processEvents(); 375 qApp->processEvents();
373 376
374 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) { 377 if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
375 owarn << "Jane! Stop this crazy thing!" << oendl; 378 owarn << "Jane! Stop this crazy thing!" << oendl;
376 stopped = true; 379 stopped = true;
377// playing = false; 380// playing = false;
378 break; 381 break;
379 } 382 }
380 } 383 }
381 printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); 384// printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total);
382 fflush(stdout); 385// fflush(stdout);
383 } //end loop 386 } //end loop
384 } else { 387 } else {
385/////////////////////////////// format = AFMT_U8; 388/////////////////////////////// format = AFMT_U8;
386 unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE]; 389 unsigned char unsigned_inbuffer[ BUFSIZE ]; //, unsigned_outbuffer[BUFSIZE];
387 memset( unsigned_inbuffer, 0, BUFSIZE); 390 memset( unsigned_inbuffer, 0, BUFSIZE);
388 for(;;) { 391 for(;;) {
389// main loop 392// main loop
390 if (stopped) { 393 if (stopped) {
391 break; // stop if playing was set to false 394 break; // stop if playing was set to false
392 return; 395 return;
393 } 396 }
394 number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE); 397 number = ::read( filePara.fd, unsigned_inbuffer, BUFSIZE);
@@ -441,51 +444,52 @@ QtRec::QtRec( QWidget* parent, const char* name, WFlags fl )
441// soundDevice->setDeviceFormat(AFMT_S16_LE); 444// soundDevice->setDeviceFormat(AFMT_S16_LE);
442// soundDevice->setDeviceChannels(1); 445// soundDevice->setDeviceChannels(1);
443// soundDevice->setDeviceRate( 22050); 446// soundDevice->setDeviceRate( 22050);
444 447
445 getInVol(); 448 getInVol();
446 getOutVol(); 449 getOutVol();
447 450
448 soundDevice->closeDevice( true); 451 soundDevice->closeDevice( true);
449 soundDevice->sd = -1; 452 soundDevice->sd = -1;
450 soundDevice = 0; 453 soundDevice = 0;
451 wavFile = 0; 454 wavFile = 0;
452 455
453 if( soundDevice) delete soundDevice; 456 // if( soundDevice) delete soundDevice;
454 457
455 initIconView(); 458 initIconView();
456 459
457 if( autoMute) 460 if( autoMute)
458 doMute( true); 461 doMute( true);
459 ListView1->setFocus(); 462 ListView1->setFocus();
460 playing = false; 463 playing = false;
461} 464}
462 465
463QtRec::~QtRec() { 466QtRec::~QtRec() {
467// if( soundDevice) delete soundDevice;
464 468
465} 469}
466 470
467void QtRec::cleanUp() { 471void QtRec::cleanUp() {
468 472
469 if( !stopped) { 473 if( !stopped) {
470 stopped = true; 474 stopped = true;
471 endRecording(); 475 endRecording();
472 } 476 }
473 477
474 ListView1->clear(); 478 ListView1->clear();
475 479
476 if( autoMute) 480 if( autoMute)
477 doMute(false); 481 doMute(false);
478 482
479 if( wavFile) delete wavFile; 483 // if( wavFile) delete wavFile;
480// if(soundDevice) delete soundDevice; 484// if(soundDevice) delete soundDevice;
481} 485}
482 486
483void QtRec::init() { 487void QtRec::init() {
484 488
485 needsStereoOut = false; 489 needsStereoOut = false;
486 QPixmap image3( ( const char** ) image3_data ); 490 QPixmap image3( ( const char** ) image3_data );
487 QPixmap image4( ( const char** ) image4_data ); 491 QPixmap image4( ( const char** ) image4_data );
488 QPixmap image6( ( const char** ) image6_data ); 492 QPixmap image6( ( const char** ) image6_data );
489 493
490 stopped = true; 494 stopped = true;
491 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) ); 495 setCaption( tr( "OpieRecord " ) + QString::number(VERSION) );
@@ -1492,25 +1496,25 @@ void QtRec::endRecording() {
1492 cfg.writeEntry( currentFile, wavFile->currentFileName); 1496 cfg.writeEntry( currentFile, wavFile->currentFileName);
1493 1497
1494 QString time; 1498 QString time;
1495 time.sprintf("%.2f", filePara.numberOfRecordedSeconds); 1499 time.sprintf("%.2f", filePara.numberOfRecordedSeconds);
1496 cfg.writeEntry( wavFile->currentFileName, time ); 1500 cfg.writeEntry( wavFile->currentFileName, time );
1497// odebug << "writing config numberOfRecordedSeconds "+time << oendl; 1501// odebug << "writing config numberOfRecordedSeconds "+time << oendl;
1498 1502
1499 cfg.write(); 1503 cfg.write();
1500 odebug << "finished recording" << oendl; 1504 odebug << "finished recording" << oendl;
1501 timeLabel->setText(""); 1505 timeLabel->setText("");
1502 } 1506 }
1503 1507
1504 if(soundDevice) delete soundDevice; 1508 // if(soundDevice) delete soundDevice;
1505 1509
1506 timeSlider->setValue(0); 1510 timeSlider->setValue(0);
1507 initIconView(); 1511 initIconView();
1508 selectItemByName( currentFile); 1512 selectItemByName( currentFile);
1509} 1513}
1510 1514
1511void QtRec::endPlaying() { 1515void QtRec::endPlaying() {
1512 monitoring = false; 1516 monitoring = false;
1513 recording = false; 1517 recording = false;
1514 playing = false; 1518 playing = false;
1515 stopped = true; 1519 stopped = true;
1516 waveform->reset(); 1520 waveform->reset();
@@ -1532,25 +1536,25 @@ void QtRec::endPlaying() {
1532 total = 0; 1536 total = 0;
1533 filePara.numberSamples = 0; 1537 filePara.numberSamples = 0;
1534 filePara.sd = -1; 1538 filePara.sd = -1;
1535// wavFile->closeFile(); 1539// wavFile->closeFile();
1536 filePara.fd = 0; 1540 filePara.fd = 0;
1537// if(wavFile) delete wavFile; //this crashes 1541// if(wavFile) delete wavFile; //this crashes
1538 1542
1539// odebug << "track closed" << oendl; 1543// odebug << "track closed" << oendl;
1540 killTimers(); 1544 killTimers();
1541 owarn << "reset slider" << oendl; 1545 owarn << "reset slider" << oendl;
1542 timeSlider->setValue(0); 1546 timeSlider->setValue(0);
1543 1547
1544 if(soundDevice) delete soundDevice; 1548 // if(soundDevice) delete soundDevice;
1545 1549
1546} 1550}
1547 1551
1548bool QtRec::openPlayFile() { 1552bool QtRec::openPlayFile() {
1549 1553
1550 qApp->processEvents(); 1554 qApp->processEvents();
1551 if( currentFile.isEmpty()) { 1555 if( currentFile.isEmpty()) {
1552 QMessageBox::message(tr("Opierec"),tr("Please select file to play")); 1556 QMessageBox::message(tr("Opierec"),tr("Please select file to play"));
1553 endPlaying(); 1557 endPlaying();
1554 return false; 1558 return false;
1555 } 1559 }
1556 QString currentFileName; 1560 QString currentFileName;
@@ -1781,25 +1785,25 @@ void QtRec::doMicMuting(bool b) {
1781} 1785}
1782 1786
1783void QtRec::compressionSelected(bool b) { 1787void QtRec::compressionSelected(bool b) {
1784 Config cfg("OpieRec"); 1788 Config cfg("OpieRec");
1785 cfg.setGroup("Settings"); 1789 cfg.setGroup("Settings");
1786 cfg.writeEntry("wavCompression", b); 1790 cfg.writeEntry("wavCompression", b);
1787 cfg.writeEntry("bitrate", 16); 1791 cfg.writeEntry("bitrate", 16);
1788 filePara.resolution = 16; 1792 filePara.resolution = 16;
1789 cfg.write(); 1793 cfg.write();
1790 1794
1791 if(b) { 1795 if(b) {
1792 bitRateComboBox->setEnabled( false); 1796 bitRateComboBox->setEnabled( false);
1793 bitRateComboBox->setCurrentItem( 0); 1797 bitRateComboBox->setCurrentItem( 1);
1794 filePara.resolution = 16; 1798 filePara.resolution = 16;
1795 } else{ 1799 } else{
1796 bitRateComboBox->setEnabled( true); 1800 bitRateComboBox->setEnabled( true);
1797 } 1801 }
1798} 1802}
1799 1803
1800long QtRec::checkDiskSpace(const QString &path) { 1804long QtRec::checkDiskSpace(const QString &path) {
1801 1805
1802 struct statfs fs; 1806 struct statfs fs;
1803 1807
1804 if ( !statfs( path.latin1(), &fs ) ) { 1808 if ( !statfs( path.latin1(), &fs ) ) {
1805 1809