Skip to content

Commit

Permalink
1.1: clean
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Sep 3, 2022
1 parent 42bd6bd commit 4285060
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 49 deletions.
48 changes: 14 additions & 34 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ void MainWindow::on_openfiletoolButton_clicked()

void MainWindow::on_savefiletoolButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("Save Raw Codec2 File"), "", tr("Raw Codec2 File (*.c2);;Raw Codec2 File (*.raw);;All files (*.*)")) + "-" + ui->bitratecomboBox->currentText();
QString fileName = QFileDialog::getSaveFileName(this,tr("Save Raw Codec2 File"), "", tr("Raw Codec2 File (*.c2 *.c2*);;Raw Codec2 File (*.raw *.raw*);;All files (*.*)")) + "-" + ui->bitratecomboBox->currentText();
ui->savefilelineEdit->setText(fileName);
}

//encode on the fly and output to file using the class called "Sink" to do the work
void MainWindow::on_recButton_clicked()
int MainWindow::select_mode()
{
on_stopButton_clicked();
if(m_audioInput)m_audioInput->deleteLater();
if(m_sink)m_sink->deleteLater();

int mode=0;
if (ui->bitratecomboBox->currentText()=="3200")
mode = CODEC2_MODE_3200;
Expand All @@ -80,6 +75,17 @@ void MainWindow::on_recButton_clicked()
{
qDebug()<<"invalid bit rate";
}
return mode;
}

//encode on the fly and output to file using the class called "Sink" to do the work
void MainWindow::on_recButton_clicked()
{
on_stopButton_clicked();
if(m_audioInput)m_audioInput->deleteLater();
if(m_sink)m_sink->deleteLater();

int mode = select_mode();

int natural=1;
if(ui->encodingcomboBox->currentText()=="Natural") natural=1;
Expand All @@ -104,7 +110,6 @@ void MainWindow::on_recButton_clicked()
if(!m_sink->laststatusmsg.isEmpty())ui->statusBar->showMessage("Rec: "+m_sink->laststatusmsg);

if(m_sink->failed)on_stopButton_clicked();

}

//decode on the fly and output to soundcard using the class called "Source" to do the work
Expand All @@ -114,29 +119,7 @@ void MainWindow::on_playButton_clicked()
if(m_audioOutput)m_audioOutput->deleteLater();
if(m_source)m_source->deleteLater();

int mode=0;
if (ui->bitratecomboBox->currentText()=="3200")
mode = CODEC2_MODE_3200;
else if (ui->bitratecomboBox->currentText()=="2400")
mode = CODEC2_MODE_2400;
else if (ui->bitratecomboBox->currentText()=="1600")
mode = CODEC2_MODE_1600;
else if (ui->bitratecomboBox->currentText()=="1400")
mode = CODEC2_MODE_1400;
else if (ui->bitratecomboBox->currentText()=="1300")
mode = CODEC2_MODE_1300;
else if (ui->bitratecomboBox->currentText()=="1200")
mode = CODEC2_MODE_1200;
else if (ui->bitratecomboBox->currentText()=="700C")
mode = CODEC2_MODE_700C;
else if (ui->bitratecomboBox->currentText()=="450")
mode = CODEC2_MODE_450;
else if (ui->bitratecomboBox->currentText()=="450PWB")
mode = CODEC2_MODE_450PWB;
else
{
qDebug()<<"invalid bit rate";
}
int mode = select_mode();

int natural=1;
if(ui->encodingcomboBox->currentText()=="Natural") natural=1;
Expand All @@ -161,7 +144,6 @@ void MainWindow::on_playButton_clicked()
if(!m_source->laststatusmsg.isEmpty())ui->statusBar->showMessage("Play: "+m_source->laststatusmsg);

if(m_source->failed)on_stopButton_clicked();

}

void MainWindow::on_stopButton_clicked()
Expand Down Expand Up @@ -199,5 +181,3 @@ void MainWindow::on_action_About_triggered()
"<p>The compressed audio files are saved without any header information so will require you to"
" remember the settings that they were recorded at.</p>Jonti 2015" );
}


4 changes: 2 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private slots:

void on_stopButton_clicked();

int select_mode();

void on_recButton_clicked();

void max_mic_volume(int percentage);
Expand All @@ -49,8 +51,6 @@ private slots:
Source *m_source;
Sink *m_sink;



QAudioFormat m_format;
QAudioOutput *m_audioOutput;
QAudioInput *m_audioInput;
Expand Down
8 changes: 0 additions & 8 deletions src/sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Sink::Sink(QString filename, int codec2_mode, int natural, bool save_uncompresse
}
else writeWavHeader();//make space
}


}

Sink::~Sink()
Expand All @@ -84,7 +82,6 @@ void Sink::stop()
file_pcm->close();
}


qint64 Sink::readData(char *data, qint64 len)
{
Q_UNUSED(data);
Expand Down Expand Up @@ -142,10 +139,8 @@ qint64 Sink::writeData(const char *data, qint64 len)
}

return len;

}


//just so the wav file has a header
void Sink::writeWavHeader()
{
Expand Down Expand Up @@ -174,6 +169,3 @@ void Sink::writeWavHeader()

Q_ASSERT(pos() == 44); // Must be 44 for WAV PCM
}



5 changes: 0 additions & 5 deletions src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ Source::Source(QString filename,int codec2_mode, int natural, QObject *parent)

//fin = fopen(filename.toLocal8Bit().data(),"rb");
// fout = fopen("c:/testme.raw","wb");



}


Source::~Source()
{
if(codec2)codec2_destroy(codec2);
Expand Down Expand Up @@ -116,4 +112,3 @@ qint64 Source::writeData(const char *data, qint64 len)

return 0;
}

0 comments on commit 4285060

Please sign in to comment.