summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/qtrec.cpp
Side-by-side diff
Diffstat (limited to 'noncore/multimedia/opierec/qtrec.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/qtrec.cpp121
1 files changed, 87 insertions, 34 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
@@ -11,312 +11,325 @@
#include "waveform.h"
#include "device.h"
#include <pthread.h>
extern "C" {
#include "adpcm.h"
}
#include <sys/soundcard.h>
#include <qpe/config.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qpe/storage.h>
#include <qcheckbox.h>
#include <qcombobox.h>
//#include <qdatetime.h>
#include <qdir.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlistview.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qslider.h>
#include <qtabwidget.h>
#include <qtimer.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/signal.h>
+
+#ifdef PDAUDIO //ALSA
+#include <alsa/asoundlib.h>
+static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 };
+static int deviceBitRates[] = { 8, 16, 24, 32, -1 };
+#else //OSS
+static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 };
+static int deviceBitRates[] = { 8, 16, -1 };
+#endif
+
#if defined(QT_QWS_SL5XXX)
///#if defined(QT_QWS_EBX)
#define DSPSTROUT "/dev/dsp"
#define DSPSTRIN "/dev/dsp1"
#define DSPSTRMIXEROUT "/dev/mixer"
#define DSPSTRMIXERIN "/dev/mixer1"
#else
#define DSPSTROUT "/dev/dsp"
#define DSPSTRIN "/dev/dsp"
#define DSPSTRMIXERIN "/dev/mixer"
#define DSPSTRMIXEROUT "/dev/mixer"
#endif
//#define ZAURUS 0
struct adpcm_state encoder_state;
struct adpcm_state decoder_state;
typedef struct {
int sampleRate;
/* int fragSize; */
/* int blockSize; */
int resolution; //bitrate
int channels; //number of channels
int fd; //file descriptor
int sd; //sound device descriptor
int numberSamples; //total number of samples
int SecondsToRecord; // number of seconds that should be recorded
float numberOfRecordedSeconds; //total number of samples recorded
int samplesToRecord; //number of samples to be recorded
int inVol; //input volume
int outVol; //output volume
int format; //wavfile format PCM.. ADPCM
const char *fileName; //name of fiel to be played/recorded
} fileParameters;
fileParameters filePara;
bool monitoring, recording, playing;
bool stopped;
QLabel *timeLabel;
QSlider *timeSlider;
int sd;
Waveform* waveform;
Device *soundDevice;
// threaded recording
//fuckin fulgy here
-void quickRec()
-{
-//void QtRec::quickRec() {
+//void quickRec()
+//{
+void QtRec::quickRec() {
qDebug("%d",
filePara.numberSamples/filePara.sampleRate * filePara.channels);
qDebug("samples %d, rate %d, channels %d",
filePara.numberSamples, filePara.sampleRate, filePara.channels);
int total = 0; // Total number of bytes read in so far.
int bytesWritten, number;
bytesWritten = 0;
number = 0;
QString num;
int level = 0;
int threshold = 0;
// int bits = filePara.resolution;
// qDebug("bits %d", bits);
if( filePara.resolution == 16 ) { //AFMT_S16_LE)
// qDebug("AFMT_S16_LE size %d", filePara.SecondsToRecord);
// qDebug("samples to record %d", filePara.samplesToRecord);
// qDebug("%d", filePara.sd);
level = 7;
threshold = 0;
if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
// qDebug("start recording WAVE_FORMAT_DVI_ADPCM");
// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
char abuf[ BUFSIZE/2 ];
short sbuf[ BUFSIZE ];
short sbuf2[ BUFSIZE ];
memset( abuf, 0, BUFSIZE/2);
memset( sbuf, 0, BUFSIZE);
memset( sbuf2, 0, BUFSIZE);
for(;;) {
if ( stopped) {
qDebug("quickRec:: stopped");
break;
}
// number=::read( filePara.sd, sbuf, BUFSIZE);
number = soundDevice ->devRead( filePara.sd, sbuf, BUFSIZE);
if(number <= 0) {
perror("recording error ");
qDebug( "%s %d", filePara.fileName, number);
stopped = true;
return;
}
//if(stereo == 2) {
// adpcm_coder( sbuf2, abuf, number/2, &encoder_state);
adpcm_coder( sbuf, abuf, number/2, &encoder_state);
- bytesWritten = soundDevice->devWrite( filePara.fd , (short *)abuf, number/4);
- waveform->newSamples( (const short *)abuf, bytesWritten );
+
+ bytesWritten = ::write( filePara.fd , (short *)abuf, number/4);
+
+ waveform->newSamples( (const short *)abuf, bytesWritten );
total += bytesWritten;
filePara.numberSamples = total;
timeSlider->setValue( total);
filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2 / filePara.channels;
qApp->processEvents();
if( total >= filePara.samplesToRecord) {
stopped = true;
break;
}
}
} else {
// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>>
qDebug("start recording WAVE_FORMAT_PCM");
short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ];
memset( inbuffer, 0, BUFSIZE);
memset( outbuffer, 0, BUFSIZE);
for(;;) {
if ( stopped) {
qDebug("quickRec:: stopped");
stopped = true;
break; // stop if playing was set to false
return;
}
- number = soundDevice ->devRead( filePara.sd, (short *)inbuffer, BUFSIZE);
+ number = soundDevice->devRead( filePara.sd, (short *)inbuffer, BUFSIZE);
waveform->newSamples( inbuffer, number );
if( number <= 0) {
perror( "recording error ");
qDebug( filePara.fileName);
stopped = true;
return;
}
- bytesWritten = soundDevice->devWrite( filePara.fd , inbuffer, number);
+ bytesWritten = ::write( filePara.fd , inbuffer, number);
if( bytesWritten < 0) {
perror("File writing error ");
stopped = true;
return;
}
total += bytesWritten;
filePara.numberSamples = total;
if( filePara.SecondsToRecord != 0)
timeSlider->setValue( total);
// printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total);
// fflush(stdout);
filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2/filePara.channels;
qApp->processEvents();
if( total >= filePara.samplesToRecord) {
stopped = true;
break;
}
}
} //end main loop
} else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8;
unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ];
memset( unsigned_inbuffer, 0, BUFSIZE);
memset( unsigned_outbuffer, 0, BUFSIZE);
for(;;) {
if ( stopped) {
qDebug("quickRec:: stopped");
break; // stop if playing was set to false
}
number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE);
bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number);
if(bytesWritten < 0) {
stopped = true;
QMessageBox::message("Note","There was a problem\nwriting to the file");
perror("File writing error ");
return;
}
total += bytesWritten;
filePara.numberSamples = total;
// printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total);
// fflush(stdout);
if( filePara.SecondsToRecord !=0)
timeSlider->setValue( total);
filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate;
qApp->processEvents();
if( total >= filePara.samplesToRecord) {
stopped = true;
break;
}
} //end main loop
}
} /// END quickRec()
+void QtRec::playIt()
-void playIt()
+//void playIt()
{
int bytesWritten, number;
int total = 0; // Total number of bytes read in so far.
if( filePara.resolution == 16 ) { //AFMT_S16_LE) {
if( filePara.format == WAVE_FORMAT_DVI_ADPCM) {
char abuf[ BUFSIZE / 2 ];
short sbuf[ BUFSIZE ];
short sbuf2[ BUFSIZE * 2 ];
memset( abuf, 0, BUFSIZE / 2);
memset( sbuf, 0, BUFSIZE);
memset( sbuf2, 0, BUFSIZE * 2);
// <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>>
for(;;) { // play loop
if ( stopped) {
break;
return;
}// stop if playing was set to false
number = ::read( filePara.fd, abuf, BUFSIZE / 2);
adpcm_decoder( abuf, sbuf, number * 2, &decoder_state);
// for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel
// sbuf2[i+1]=sbuf2[i]=sbuf[i];
// }
bytesWritten = write ( filePara.sd, sbuf, number * 4);
waveform->newSamples( (const short *)sbuf, number );
// if(filePara.channels==1)
// total += bytesWritten/2; //mono
// else
total += bytesWritten;
filePara.numberSamples = total/4;
filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2;
timeSlider->setValue( total/4);
// timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds);
// if(filePara.numberOfRecordedSeconds>1)
// timeLabel->setText( timeString+ tr(" seconds"));
printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4);
fflush(stdout);
qApp->processEvents();
if( /*total >= filePara.numberSamples || */ bytesWritten == 0) {
// if( total >= filePara.numberSamples ){//|| secCount > filePara.numberOfRecordedSeconds ) {
stopped = true;
break;
}
}
@@ -524,139 +537,142 @@ void QtRec::init() {
rewindTimer = new QTimer( this );
connect( rewindTimer, SIGNAL( timeout() ),
this, SLOT( rewindTimerTimeout() ) );
forwardTimer = new QTimer( this );
connect( forwardTimer, SIGNAL( timeout() ),
this, SLOT( forwardTimerTimeout() ) );
deleteSoundButton = new QPushButton( tab, "deleteSoundButton" );
layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8);
deleteSoundButton->setText( tr( "Delete" ) );
ListView1 = new QListView( tab, "IconView1" );
layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8);
ListView1->addColumn( tr( "Name" ) );
ListView1->setColumnWidth( 0, 140);
ListView1->setSorting( 1, false);
ListView1->addColumn( tr( "Time" ) ); //in seconds
ListView1->setColumnWidth( 1, 50);
ListView1->addColumn( tr("Location") );
ListView1->setColumnWidth( 2, 50);
ListView1->addColumn( tr("Date") );
ListView1->setColumnWidth( 3, 63);
ListView1->setColumnWidthMode( 0, QListView::Manual);
ListView1->setColumnAlignment( 1, QListView::AlignCenter);
ListView1->setColumnAlignment( 2, QListView::AlignRight);
ListView1->setColumnAlignment( 3, QListView::AlignLeft);
ListView1->setAllColumnsShowFocus( true );
QPEApplication::setStylusOperation( ListView1->viewport(), QPEApplication::RightOnHold);
TabWidget->insertTab( tab, tr( "Files" ) );
///**********<<<<<<<<<<<<>>>>>>>>>>>>***************
tab_3 = new QWidget( TabWidget, "tab_3" );
QGridLayout *glayout3 = new QGridLayout( tab_3 );
glayout3->setSpacing( 2);
glayout3->setMargin( 2);
////////////////////////////////////
sampleGroup = new QGroupBox( tab_3, "samplegroup" );
sampleGroup->setTitle( tr( "Sample Rate" ) );
sampleGroup->setFixedSize( 95,50);
sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" );
sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) );
//#ifndef QT_QWS_EBX
- sampleRateComboBox->insertItem( tr( "44100"));
- sampleRateComboBox->insertItem( tr( "32000"));
-//#endif
- sampleRateComboBox->insertItem( tr( "22050"));
- //#ifndef QT_QWS_VERCEL_IDR
- sampleRateComboBox->insertItem( tr( "16000"));
- sampleRateComboBox->insertItem( tr( "11025"));
- sampleRateComboBox->insertItem( tr( "8000"));
- //#endif
+ QString s;
+ int z = 0;
+ while( deviceSampleRates[z] != -1) {
+ sampleRateComboBox->insertItem( s.setNum( deviceSampleRates[z], 10));
+ z++;
+ }
+
glayout3->addMultiCellWidget( sampleGroup, 0, 0, 0, 0);
sizeGroup= new QGroupBox( tab_3, "sizeGroup" );
sizeGroup->setTitle( tr( "Limit Size" ) );
sizeGroup->setFixedSize( 80, 50);
sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" );
sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) );
sizeLimitCombo->insertItem(tr("Unlimited"));
for(int i=1;i<13; i++) {
sizeLimitCombo->insertItem( QString::number( i * 5));
}
glayout3->addMultiCellWidget( sizeGroup, 0, 0, 1, 1);
dirGroup = new QGroupBox( tab_3, "dirGroup" );
dirGroup->setTitle( tr( "File Directory" ) );
dirGroup->setFixedSize( 130, 50);
directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" );
directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) );
glayout3->addMultiCellWidget( dirGroup, 1, 1, 0, 0);
bitGroup = new QGroupBox( tab_3, "bitGroup" );
bitGroup->setTitle( tr( "Bit Depth" ) );
bitGroup->setFixedSize( 65, 50);
bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" );
- bitRateComboBox->insertItem( tr( "16" ) );
- bitRateComboBox->insertItem( tr( "8" ) );
- bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) );
+
+ z = 0;
+ while( deviceBitRates[z] != -1) {
+ bitRateComboBox->insertItem( s.setNum( deviceBitRates[z], 10) );
+ z++;
+ }
+
+ bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) );
glayout3->addMultiCellWidget( bitGroup, 1, 1, 1, 1);
compressionCheckBox = new QCheckBox ( tr("Wave Compression (smaller files)"), tab_3 );
autoMuteCheckBox = new QCheckBox ( tr("Auto Mute"), tab_3 );
stereoCheckBox = new QCheckBox ( tr("Stereo Channels"), tab_3 );
glayout3->addMultiCellWidget( compressionCheckBox, 2, 2, 0, 3);
glayout3->addMultiCellWidget( autoMuteCheckBox, 3, 3, 0, 0);
glayout3->addMultiCellWidget( stereoCheckBox, 3, 3, 1, 1);
QWidget *d = QApplication::desktop();
int width = d->width();
int height = d->height();
if( width < height) {
tab_5 = new QWidget( TabWidget, "tab_5" );
QHBoxLayout *Layout19a;
Layout19a = new QHBoxLayout( tab_5);
Layout19a->setSpacing( 2 );
Layout19a->setMargin( 0 );
Layout15 = new QVBoxLayout( this);
Layout15->setSpacing( 2 );
Layout15->setMargin( 0 );
Layout15b = new QVBoxLayout( this);
Layout15b->setSpacing( 2 );
Layout15b->setMargin( 0 );
TextLabel2 = new QLabel( tab_5, "InputLabel" );
TextLabel2->setText( tr( "In"));
TextLabel2->setFixedWidth( 35);
Layout15->addWidget( TextLabel2 );
TextLabel3 = new QLabel( tab_5, "OutputLabel" );
TextLabel3->setText( tr( "Out" ) );
Layout15b->addWidget( TextLabel3 );
InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_5, (const char *) "InputSlider" );
InputSlider->setTickmarks( QSlider::Both);
Layout15->addWidget( InputSlider);
OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_5,(const char *) "OutputSlider" );
OutputSlider->setTickmarks( QSlider::Both);
@@ -799,100 +815,105 @@ void QtRec::initConnections() {
this, SLOT( changebitrateCombo(int)) );
connect( directoryComboBox, SIGNAL(activated( int)),
this, SLOT( changeDirCombo(int)) );
connect( sizeLimitCombo, SIGNAL(activated( int)),
this, SLOT( changeSizeLimitCombo(int)) );
connect( stereoCheckBox, SIGNAL(toggled( bool)),
this, SLOT( changeStereoCheck(bool)) );
connect( outMuteCheckBox, SIGNAL(toggled( bool)),
this, SLOT( doVolMuting(bool)) );
connect( inMuteCheckBox , SIGNAL(toggled( bool)),
this, SLOT( doMicMuting(bool)) );
connect( ListView1,SIGNAL(doubleClicked( QListViewItem*)),
this,SLOT( itClick(QListViewItem*)));
connect( ListView1, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this,SLOT( listPressed(int, QListViewItem *, const QPoint&, int)) );
connect( timeSlider, SIGNAL( sliderMoved( int)),
this, SLOT( changeTimeSlider(int) ));
connect( timeSlider, SIGNAL( sliderPressed( )),
this, SLOT( timeSliderPressed() ));
connect( timeSlider, SIGNAL( sliderReleased( )),
this, SLOT( timeSliderReleased() ));
connect( compressionCheckBox, SIGNAL( toggled(bool)),
this, SLOT( compressionSelected(bool)));
connect( autoMuteCheckBox, SIGNAL( toggled(bool)),
this, SLOT( slotAutoMute(bool)));
}
void QtRec::initConfig() {
int index, fred, i;
Config cfg("OpieRec");
cfg.setGroup("Settings");
index = cfg.readNumEntry("samplerate",22050);
bool ok;
for(int ws=0;ws<sampleRateComboBox->count();ws++) {
fred = sampleRateComboBox->text(ws).toInt(&ok, 10);
if( index == fred) {
filePara.sampleRate = fred;
sampleRateComboBox->setCurrentItem(ws);
}
}
i = cfg.readNumEntry("bitrate",16);
- if(i == 16)
- bitRateComboBox->setCurrentItem( 0);
- else
- bitRateComboBox->setCurrentItem( 1);
+ if(i == 16)
+ bitRateComboBox->setCurrentItem( 1);
+ else if(i == 24)
+ bitRateComboBox->setCurrentItem( 2);
+ else if(i == 32)
+ bitRateComboBox->setCurrentItem( 3);
+ else
+ bitRateComboBox->setCurrentItem( 0);
+
filePara.resolution = i;
i = cfg.readNumEntry("sizeLimit", 5 );
QString temp;
sizeLimitCombo->setCurrentItem((i/5));
stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1));
if( stereoCheckBox->isChecked()) {
filePara.channels = 2;
} else {
filePara.channels = 1;
}
compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1));
if( compressionCheckBox->isChecked()) {
bitRateComboBox->setEnabled(false);
bitRateComboBox->setCurrentItem(0);
filePara.resolution=16;
}
autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0));
if( autoMuteCheckBox->isChecked())
slotAutoMute(true);
else
slotAutoMute(false);
Config cofg( "qpe");
cofg.setGroup( "Volume");
outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0));
inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0));
}
void QtRec::stop() {
qWarning("STOP");
setRecordButton(false);
if( !recording)
endPlaying();
else
endRecording();
timeSlider->setValue(0);
}
void QtRec::doPlayBtn() {
if(!stopped) {
playLabel2->setText(tr("Play"));
stop();
@@ -945,190 +966,219 @@ bool QtRec::rec() { //record
//filePara.sampleRate = cfg.readNumEntry("samplerate", 22050);
// qDebug("sample rate is %d", filePara.sampleRate);
filePara.SecondsToRecord = getCurrentSizeLimit();
// qDebug("size limit %d sec", filePara.SecondsToRecord);
int diskSize = checkDiskSpace( (const QString &) wavFile->trackName());
if( filePara.SecondsToRecord == 0) {
fileSize = diskSize;
} else if( filePara.format == WAVE_FORMAT_PCM) {
// qDebug("WAVE_FORMAT_PCM");
fileSize = (filePara.SecondsToRecord ) * filePara.channels
* filePara.sampleRate * ( filePara.resolution / 8) + 1000;
} else {
// qDebug("WAVE_FORMAT_DVI_ADPCM");
fileSize = ((filePara.SecondsToRecord) * filePara.channels
* filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250;
}
filePara.samplesToRecord = fileSize;
qDebug("filesize should be %d, bits %d, rate %d",
filePara.samplesToRecord, filePara.resolution, filePara.sampleRate);
if( paused) {
paused = false;
}
// else {
qDebug("Setting timeslider %d", filePara.samplesToRecord);
// if(fileSize != 0)
timeSlider->setRange(0, filePara.samplesToRecord);
// }
if( diskSize < fileSize/1024) {
QMessageBox::warning(this,
tr("Low Disk Space"),
tr("You are running low of\nrecording space\n"
"or a card isn't being recognized"));
stopped = true; //we need to be stopped
stop();
} else {
QString msg;
msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution);
#ifdef DEV_VERSION
setCaption( msg);
#endif
filePara.fileName=currentFile.latin1();
// qDebug("Start recording thread");
stopped = false;
- pthread_t thread1;
- pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/);
+// pthread_t thread1;
+// pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/);
toBeginningButton->setEnabled( false);
toEndButton->setEnabled( false);
startTimer(1000);
-// quickRec();
+ quickRec();
}
} //end setUpFile
} //end setupAudio
return true;
}
/*
This happens when a tab is selected*/
void QtRec::thisTab(QWidget* widg) {
if(widg != NULL) {
int index = TabWidget->currentPageIndex();
if(index == 0) { //file page
}
if(index == 1) { //control page
fillDirectoryCombo();
// soundDevice->getOutVol();
// soundDevice->getInVol();
}
if( index==2) { //help page
}
qApp->processEvents();
update();
}
}
void QtRec::getOutVol( ) {
filePara.outVol = soundDevice->getOutVolume();
// qDebug("out vol %d", filePara.outVol);
OutputSlider->setValue( -filePara.outVol);
}
void QtRec::getInVol() {
filePara.inVol = soundDevice->getInVolume();
// qDebug("in vol %d", filePara.inVol);
InputSlider->setValue( -filePara.inVol);
}
void QtRec::changedOutVolume() {
soundDevice->changedOutVolume( -OutputSlider->value());
}
void QtRec::changedInVolume( ) {
soundDevice->changedInVolume( -InputSlider->value());
}
bool QtRec::setupAudio( bool b) {
bool ok;
int sampleformat, stereo, flags;
char * dspString, *mixerString;
filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16
+#ifdef PDAUDIO //ALSA
+ if( !b) { // we want to play
+ if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) {
+ sampleformat = SND_PCM_FORMAT_S16;
+ filePara.resolution = 16;
+ } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) {
+ sampleformat = SND_PCM_FORMAT_S24;
+ filePara.resolution = 24;
+ } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) {
+ sampleformat = SND_PCM_FORMAT_S32;
+ filePara.resolution = 32;
+ } else {
+ sampleformat = SND_PCM_FORMAT_U8;
+ filePara.resolution = 8;
+ }
+#else
if( !b) {
// we want to play
if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) {
sampleformat = AFMT_S16_LE;
filePara.resolution = 16;
} else {
sampleformat = AFMT_U8;
filePara.resolution = 8;
}
-
+#endif
+
stereo = filePara.channels;
flags = O_WRONLY;
dspString = DSPSTROUT;
mixerString = DSPSTRMIXEROUT;
recording = false;
} else { // we want to record
- if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
+#ifdef PDAUDIO //ALSA
+ if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
+ sampleformat = SND_PCM_FORMAT_S16;
+ else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24")
+ sampleformat = SND_PCM_FORMAT_S24;
+ else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32")
+ sampleformat = SND_PCM_FORMAT_S32;
+ else
+ sampleformat = SND_PCM_FORMAT_U8;
+
+#else
+ if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16")
sampleformat = AFMT_S16_LE;
else
sampleformat = AFMT_U8;
if( !compressionCheckBox->isChecked()) {
filePara.format = WAVE_FORMAT_PCM;
// qDebug("WAVE_FORMAT_PCM");
} else {
filePara.format = WAVE_FORMAT_DVI_ADPCM;
sampleformat = AFMT_S16_LE;
// qDebug("WAVE_FORMAT_DVI_ADPCM");
}
-
+#endif
+
stereo = filePara.channels;
// filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100;
flags= O_RDWR;
// flags= O_RDONLY;
dspString = DSPSTRIN;
mixerString = DSPSTRMIXEROUT;
recording = true;
}
// if(soundDevice) delete soundDevice;
qDebug("<<<<<<<<<<<<<<<<<<<open dsp %d %d %d", filePara.sampleRate, filePara.channels, sampleformat);
qWarning("change waveform settings");
waveform->changeSettings( filePara.sampleRate, filePara.channels );
soundDevice = new Device( this, dspString, mixerString, b);
// soundDevice->openDsp();
soundDevice->reset();
qDebug("device has been made %d", soundDevice->sd);
////////////////// <<<<<<<<<<<<>>>>>>>>>>>>
soundDevice->setDeviceFormat( sampleformat);
soundDevice->setDeviceChannels( filePara.channels);
soundDevice->setDeviceRate( filePara.sampleRate);
soundDevice->getDeviceFragSize();
#ifdef QT_QWS_EBX
int frag = FRAGSIZE;
soundDevice->setFragSize( frag);
soundDevice->getDeviceFragSize();
#endif
/////////////////
filePara.sd = soundDevice->sd;
if ( filePara.sd == -1) {
monitoring = false;
stopped = true;
update();
setCaption( tr( "OpieRecord " )+ QString::number(VERSION) );
return false;
}
if(autoMute)
doMute(false);
return true;
}
@@ -1138,112 +1188,115 @@ bool QtRec::setUpFile() { //setup file for recording
wavFile = new WavFile( this, (const QString &)"",
true,
filePara.sampleRate,
filePara.channels,
filePara.resolution,
filePara.format);
filePara.fd = wavFile->wavHandle();
if(filePara.fd == -1) {
return false;
} else {
// filePara.channels=1;
}
return true;
}
/// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>>
bool QtRec::doPlay() {
if( !paused) {
total = 0;
filePara.numberOfRecordedSeconds = 0;
} else {
paused = false;
secCount = (int)filePara.numberOfRecordedSeconds;
}
playing = true;
stopped = false;
recording = false;
QString num;
qDebug( "Play number of samples %d", filePara.numberSamples);
// timeSlider->setRange( 0, filePara.numberSamples);
timeString.sprintf("%d", filePara.numberOfRecordedSeconds);
timeLabel->setText( timeString+ tr(" seconds"));
QString msg;
msg.sprintf("%d, %d, %d",
filePara.sampleRate,
filePara.channels,
filePara.resolution);
#ifdef DEV_VERSION
setCaption( msg);
#endif
startTimer( 1000);
- pthread_t thread2;
- pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/);
+// pthread_t thread2;
+// pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/);
toBeginningButton->setEnabled( false);
toEndButton->setEnabled( false);
+ playIt();
return true;
}
void QtRec::changebitrateCombo(int i) {
Config cfg("OpieRec");
cfg.setGroup("Settings");
int bits = 0;
- if( i == 0) { bits = 16; }
- else { bits=8; }
+ if( i == 1) { bits = 16; }
+ else if( i == 2) { bits = 24; }
+ else if( i == 3) { bits = 32; }
+ else { bits=8; }
cfg.writeEntry("bitrate", bits);
filePara.resolution = bits;
cfg.write();
}
void QtRec::changesamplerateCombo(int i) {
Config cfg("OpieRec");
cfg.setGroup("Settings");
int rate=0;
bool ok;
rate = sampleRateComboBox->text(i).toInt(&ok, 10);
cfg.writeEntry( "samplerate",rate);
filePara.sampleRate=rate;
qDebug( "Change sample rate %d", rate);
cfg.write();
}
void QtRec::changeDirCombo(int index) {
Config cfg("OpieRec");
cfg.setGroup("Settings");
QString sName = directoryComboBox->text(index);
StorageInfo storageInfo;
const QList<FileSystem> &fs = storageInfo.fileSystems();
QListIterator<FileSystem> it ( fs );
QString storage;
for( ; it.current(); ++it ){
if( sName == (*it)->name()+" "+ (*it)->path() ||
(*it)->name() == sName ) {
const QString path = (*it)->path();
recDir = path;
cfg.writeEntry("directory", recDir);
qDebug("new rec dir "+recDir);
}
}
cfg.write();
}
void QtRec::changeSizeLimitCombo(int) {
Config cfg("OpieRec");
cfg.setGroup("Settings");
cfg.writeEntry("sizeLimit", getCurrentSizeLimit() );
cfg.write();
}
void QtRec::newSound() {