Diffstat (limited to 'noncore/multimedia/opierec/qtrec.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 103 |
1 files changed, 78 insertions, 25 deletions
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index aeab26d..bc6abcc 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -56,6 +56,16 @@ extern "C" { | |||
56 | #include <sys/wait.h> | 56 | #include <sys/wait.h> |
57 | #include <sys/signal.h> | 57 | #include <sys/signal.h> |
58 | 58 | ||
59 | |||
60 | #ifdef PDAUDIO //ALSA | ||
61 | #include <alsa/asoundlib.h> | ||
62 | static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; | ||
63 | static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; | ||
64 | #else //OSS | ||
65 | static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; | ||
66 | static int deviceBitRates[] = { 8, 16, -1 }; | ||
67 | #endif | ||
68 | |||
59 | #if defined(QT_QWS_SL5XXX) | 69 | #if defined(QT_QWS_SL5XXX) |
60 | ///#if defined(QT_QWS_EBX) | 70 | ///#if defined(QT_QWS_EBX) |
61 | 71 | ||
@@ -108,9 +118,9 @@ Device *soundDevice; | |||
108 | 118 | ||
109 | // threaded recording | 119 | // threaded recording |
110 | //fuckin fulgy here | 120 | //fuckin fulgy here |
111 | void quickRec() | 121 | //void quickRec() |
112 | { | 122 | //{ |
113 | //void QtRec::quickRec() { | 123 | void QtRec::quickRec() { |
114 | 124 | ||
115 | qDebug("%d", | 125 | qDebug("%d", |
116 | filePara.numberSamples/filePara.sampleRate * filePara.channels); | 126 | filePara.numberSamples/filePara.sampleRate * filePara.channels); |
@@ -163,7 +173,9 @@ void quickRec() | |||
163 | //if(stereo == 2) { | 173 | //if(stereo == 2) { |
164 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | 174 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); |
165 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | 175 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); |
166 | bytesWritten = soundDevice->devWrite( filePara.fd , (short *)abuf, number/4); | 176 | |
177 | bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); | ||
178 | |||
167 | waveform->newSamples( (const short *)abuf, bytesWritten ); | 179 | waveform->newSamples( (const short *)abuf, bytesWritten ); |
168 | 180 | ||
169 | total += bytesWritten; | 181 | total += bytesWritten; |
@@ -203,7 +215,7 @@ void quickRec() | |||
203 | return; | 215 | return; |
204 | } | 216 | } |
205 | 217 | ||
206 | bytesWritten = soundDevice->devWrite( filePara.fd , inbuffer, number); | 218 | bytesWritten = ::write( filePara.fd , inbuffer, number); |
207 | 219 | ||
208 | if( bytesWritten < 0) { | 220 | if( bytesWritten < 0) { |
209 | perror("File writing error "); | 221 | perror("File writing error "); |
@@ -270,8 +282,9 @@ void quickRec() | |||
270 | } | 282 | } |
271 | } /// END quickRec() | 283 | } /// END quickRec() |
272 | 284 | ||
285 | void QtRec::playIt() | ||
273 | 286 | ||
274 | void playIt() | 287 | //void playIt() |
275 | { | 288 | { |
276 | int bytesWritten, number; | 289 | int bytesWritten, number; |
277 | int total = 0; // Total number of bytes read in so far. | 290 | int total = 0; // Total number of bytes read in so far. |
@@ -569,15 +582,13 @@ void QtRec::init() { | |||
569 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); | 582 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); |
570 | sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) ); | 583 | sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) ); |
571 | //#ifndef QT_QWS_EBX | 584 | //#ifndef QT_QWS_EBX |
572 | sampleRateComboBox->insertItem( tr( "44100")); | 585 | QString s; |
573 | sampleRateComboBox->insertItem( tr( "32000")); | 586 | int z = 0; |
574 | //#endif | 587 | while( deviceSampleRates[z] != -1) { |
575 | sampleRateComboBox->insertItem( tr( "22050")); | 588 | sampleRateComboBox->insertItem( s.setNum( deviceSampleRates[z], 10)); |
576 | //#ifndef QT_QWS_VERCEL_IDR | 589 | z++; |
577 | sampleRateComboBox->insertItem( tr( "16000")); | 590 | } |
578 | sampleRateComboBox->insertItem( tr( "11025")); | 591 | |
579 | sampleRateComboBox->insertItem( tr( "8000")); | ||
580 | //#endif | ||
581 | 592 | ||
582 | glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0); | 593 | glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0); |
583 | 594 | ||
@@ -609,8 +620,13 @@ void QtRec::init() { | |||
609 | bitGroup->setFixedSize( 65, 50); | 620 | bitGroup->setFixedSize( 65, 50); |
610 | 621 | ||
611 | bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" ); | 622 | bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" ); |
612 | bitRateComboBox->insertItem( tr( "16" ) ); | 623 | |
613 | bitRateComboBox->insertItem( tr( "8" ) ); | 624 | z = 0; |
625 | while( deviceBitRates[z] != -1) { | ||
626 | bitRateComboBox->insertItem( s.setNum( deviceBitRates[z], 10) ); | ||
627 | z++; | ||
628 | } | ||
629 | |||
614 | bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); | 630 | bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); |
615 | 631 | ||
616 | glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1); | 632 | glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1); |
@@ -845,9 +861,14 @@ void QtRec::initConfig() { | |||
845 | 861 | ||
846 | i = cfg.readNumEntry("bitrate",16); | 862 | i = cfg.readNumEntry("bitrate",16); |
847 | if(i == 16) | 863 | if(i == 16) |
848 | bitRateComboBox->setCurrentItem( 0); | ||
849 | else | ||
850 | bitRateComboBox->setCurrentItem( 1); | 864 | bitRateComboBox->setCurrentItem( 1); |
865 | elseif(i == 24) | ||
866 | bitRateComboBox->setCurrentItem( 2); | ||
867 | elseif(i == 32) | ||
868 | bitRateComboBox->setCurrentItem( 3); | ||
869 | else | ||
870 | bitRateComboBox->setCurrentItem( 0); | ||
871 | |||
851 | filePara.resolution = i; | 872 | filePara.resolution = i; |
852 | 873 | ||
853 | i = cfg.readNumEntry("sizeLimit", 5 ); | 874 | i = cfg.readNumEntry("sizeLimit", 5 ); |
@@ -990,13 +1011,13 @@ bool QtRec::rec() { //record | |||
990 | // qDebug("Start recording thread"); | 1011 | // qDebug("Start recording thread"); |
991 | stopped = false; | 1012 | stopped = false; |
992 | 1013 | ||
993 | pthread_t thread1; | 1014 | // pthread_t thread1; |
994 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); | 1015 | // pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); |
995 | toBeginningButton->setEnabled( false); | 1016 | toBeginningButton->setEnabled( false); |
996 | toEndButton->setEnabled( false); | 1017 | toEndButton->setEnabled( false); |
997 | 1018 | ||
998 | startTimer(1000); | 1019 | startTimer(1000); |
999 | // quickRec(); | 1020 | quickRec(); |
1000 | } | 1021 | } |
1001 | } //end setUpFile | 1022 | } //end setUpFile |
1002 | } //end setupAudio | 1023 | } //end setupAudio |
@@ -1053,6 +1074,22 @@ bool QtRec::setupAudio( bool b) { | |||
1053 | 1074 | ||
1054 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 | 1075 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 |
1055 | 1076 | ||
1077 | #ifdef PDAUDIO //ALSA | ||
1078 | if( !b) { // we want to play | ||
1079 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | ||
1080 | sampleformat = SND_PCM_FORMAT_S16; | ||
1081 | filePara.resolution = 16; | ||
1082 | } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { | ||
1083 | sampleformat = SND_PCM_FORMAT_S24; | ||
1084 | filePara.resolution = 24; | ||
1085 | } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { | ||
1086 | sampleformat = SND_PCM_FORMAT_S32; | ||
1087 | filePara.resolution = 32; | ||
1088 | } else { | ||
1089 | sampleformat = SND_PCM_FORMAT_U8; | ||
1090 | filePara.resolution = 8; | ||
1091 | } | ||
1092 | #else | ||
1056 | if( !b) { | 1093 | if( !b) { |
1057 | // we want to play | 1094 | // we want to play |
1058 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | 1095 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { |
@@ -1062,6 +1099,7 @@ bool QtRec::setupAudio( bool b) { | |||
1062 | sampleformat = AFMT_U8; | 1099 | sampleformat = AFMT_U8; |
1063 | filePara.resolution = 8; | 1100 | filePara.resolution = 8; |
1064 | } | 1101 | } |
1102 | #endif | ||
1065 | 1103 | ||
1066 | stereo = filePara.channels; | 1104 | stereo = filePara.channels; |
1067 | flags = O_WRONLY; | 1105 | flags = O_WRONLY; |
@@ -1070,6 +1108,17 @@ bool QtRec::setupAudio( bool b) { | |||
1070 | recording = false; | 1108 | recording = false; |
1071 | } else { // we want to record | 1109 | } else { // we want to record |
1072 | 1110 | ||
1111 | #ifdef PDAUDIO //ALSA | ||
1112 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | ||
1113 | sampleformat = SND_PCM_FORMAT_S16; | ||
1114 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") | ||
1115 | sampleformat = SND_PCM_FORMAT_S24; | ||
1116 | else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") | ||
1117 | sampleformat = SND_PCM_FORMAT_S32; | ||
1118 | else | ||
1119 | sampleformat = SND_PCM_FORMAT_U8; | ||
1120 | |||
1121 | #else | ||
1073 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | 1122 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") |
1074 | sampleformat = AFMT_S16_LE; | 1123 | sampleformat = AFMT_S16_LE; |
1075 | else | 1124 | else |
@@ -1083,6 +1132,7 @@ bool QtRec::setupAudio( bool b) { | |||
1083 | sampleformat = AFMT_S16_LE; | 1132 | sampleformat = AFMT_S16_LE; |
1084 | // qDebug("WAVE_FORMAT_DVI_ADPCM"); | 1133 | // qDebug("WAVE_FORMAT_DVI_ADPCM"); |
1085 | } | 1134 | } |
1135 | #endif | ||
1086 | 1136 | ||
1087 | stereo = filePara.channels; | 1137 | stereo = filePara.channels; |
1088 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; | 1138 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; |
@@ -1183,11 +1233,12 @@ bool QtRec::doPlay() { | |||
1183 | #endif | 1233 | #endif |
1184 | 1234 | ||
1185 | startTimer( 1000); | 1235 | startTimer( 1000); |
1186 | pthread_t thread2; | 1236 | // pthread_t thread2; |
1187 | pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); | 1237 | // pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); |
1188 | 1238 | ||
1189 | toBeginningButton->setEnabled( false); | 1239 | toBeginningButton->setEnabled( false); |
1190 | toEndButton->setEnabled( false); | 1240 | toEndButton->setEnabled( false); |
1241 | playIt(); | ||
1191 | 1242 | ||
1192 | return true; | 1243 | return true; |
1193 | } | 1244 | } |
@@ -1197,7 +1248,9 @@ void QtRec::changebitrateCombo(int i) { | |||
1197 | Config cfg("OpieRec"); | 1248 | Config cfg("OpieRec"); |
1198 | cfg.setGroup("Settings"); | 1249 | cfg.setGroup("Settings"); |
1199 | int bits = 0; | 1250 | int bits = 0; |
1200 | if( i == 0) { bits = 16; } | 1251 | if( i == 1) { bits = 16; } |
1252 | else if( i == 2) { bits = 24; } | ||
1253 | else if( i == 3) { bits = 32; } | ||
1201 | else { bits=8; } | 1254 | else { bits=8; } |
1202 | cfg.writeEntry("bitrate", bits); | 1255 | cfg.writeEntry("bitrate", bits); |
1203 | filePara.resolution = bits; | 1256 | filePara.resolution = bits; |