forked from jontio/jc2rec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 92d507a
Showing
15 changed files
with
1,178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# This file is used to ignore files which are generated | ||
# ---------------------------------------------------------------------------- | ||
|
||
*~ | ||
*.autosave | ||
*.a | ||
*.core | ||
*.moc | ||
*.o | ||
*.obj | ||
*.orig | ||
*.rej | ||
*.so | ||
*.so.* | ||
*_pch.h.cpp | ||
*_resource.rc | ||
*.qm | ||
.#* | ||
*.*# | ||
core | ||
!core/ | ||
tags | ||
.DS_Store | ||
.directory | ||
*.debug | ||
Makefile* | ||
*.prl | ||
*.app | ||
moc_*.cpp | ||
ui_*.h | ||
qrc_*.cpp | ||
Thumbs.db | ||
*.res | ||
*.rc | ||
/.qmake.cache | ||
/.qmake.stash | ||
|
||
# qtcreator generated files | ||
*.pro.user* | ||
|
||
# xemacs temporary files | ||
*.flc | ||
|
||
# Vim temporary files | ||
.*.swp | ||
|
||
# Visual Studio generated files | ||
*.ib_pdb_index | ||
*.idb | ||
*.ilk | ||
*.pdb | ||
*.sln | ||
*.suo | ||
*.vcproj | ||
*vcproj.*.*.user | ||
*.ncb | ||
*.sdf | ||
*.opensdf | ||
*.vcxproj | ||
*vcxproj.* | ||
|
||
# MinGW generated files | ||
*.Debug | ||
*.Release | ||
|
||
# Python byte code | ||
*.pyc | ||
|
||
# Binaries | ||
# -------- | ||
*.dll | ||
*.exe | ||
|
||
# other | ||
test_output/* | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#------------------------------------------------- | ||
# | ||
# Project created by QtCreator 2015-05-23T17:32:54 | ||
# | ||
#------------------------------------------------- | ||
|
||
QT += multimedia core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
TARGET = JC2Rec | ||
TEMPLATE = app | ||
|
||
|
||
INCLUDEPATH += ../codec2/src | ||
INCLUDEPATH += ../codec2/build/codec2 | ||
|
||
|
||
SOURCES += main.cpp\ | ||
mainwindow.cpp \ | ||
source.cpp \ | ||
sink.cpp | ||
|
||
HEADERS += mainwindow.h \ | ||
../codec2/src/codec2.h \ | ||
source.h \ | ||
sink.h | ||
|
||
FORMS += mainwindow.ui | ||
|
||
win32 { | ||
LIBS += -L../codec2/build/src \ | ||
-lcodec2 | ||
} | ||
|
||
RESOURCES += \ | ||
icon.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Jonti Olds | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# JC2Rec is a GUI in Qt for recording speech using Codec2. | ||
|
||
This is a simple speech recording application that uses Codec2 and Qt. For more information see https://jontio.zapto.org/hda1/jc2rec.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/icons"> | ||
<file>icon.png</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "mainwindow.h" | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
|
||
#include <QFileDialog> | ||
#include <QDebug> | ||
#include <QMessageBox> | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow), | ||
m_source(NULL), | ||
m_sink(NULL), | ||
m_audioOutput(NULL), | ||
m_audioInput(NULL) | ||
|
||
{ | ||
ui->setupUi(this); | ||
|
||
//select default devices and set the format | ||
m_device_out=QAudioDeviceInfo::defaultOutputDevice(); | ||
m_device_in=QAudioDeviceInfo::defaultInputDevice(); | ||
m_format.setSampleRate(8000); | ||
m_format.setChannelCount(1); | ||
m_format.setSampleSize(16); | ||
m_format.setCodec("audio/pcm"); | ||
m_format.setByteOrder(QAudioFormat::LittleEndian); | ||
m_format.setSampleType(QAudioFormat::SignedInt); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void MainWindow::max_mic_volume(int percentage) | ||
{ | ||
ui->progressBar->setValue(percentage); | ||
} | ||
|
||
void MainWindow::played_file_percentage(int percentage) | ||
{ | ||
ui->progressBar->setValue(percentage); | ||
} | ||
|
||
void MainWindow::on_openfiletoolButton_clicked() | ||
{ | ||
QString fileName = QFileDialog::getOpenFileName(this,tr("Open Raw Codec2 File"), "", tr("Raw Codec2 Files (*.c2 *.raw);;All files (*.*)")); | ||
ui->playfilelineEdit->setText(fileName); | ||
} | ||
|
||
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->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() | ||
{ | ||
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; | ||
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 natural=1; | ||
if(ui->encodingcomboBox->currentText()=="Natural") natural=1; | ||
if(ui->encodingcomboBox->currentText()=="Gray") natural=0; | ||
|
||
//setup | ||
m_device_in=QAudioDeviceInfo::defaultInputDevice(); | ||
m_sink = new Sink(ui->savefilelineEdit->text(),mode,natural,ui->saveorgpcmcheckBox->isChecked(), this); | ||
m_audioInput = new QAudioInput(m_device_in, m_format, this); | ||
m_audioInput->setBufferSize(8000);//1 second buffer | ||
connect(m_sink, SIGNAL(signal_volume(int)),this, SLOT(max_mic_volume(int))); | ||
connect(m_sink, SIGNAL(ChannelFailed()),this,SLOT(on_stopButton_clicked()),Qt::QueuedConnection); | ||
ui->progressBar->setFormat("Volume"); | ||
ui->recButton->setEnabled(false); | ||
ui->playButton->setEnabled(false); | ||
|
||
//start | ||
m_sink->start(); | ||
m_audioInput->start(m_sink); | ||
|
||
ui->statusBar->clearMessage(); | ||
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 | ||
void MainWindow::on_playButton_clicked() | ||
{ | ||
on_stopButton_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 natural=1; | ||
if(ui->encodingcomboBox->currentText()=="Natural") natural=1; | ||
if(ui->encodingcomboBox->currentText()=="Gray") natural=0; | ||
|
||
//setup | ||
m_device_out=QAudioDeviceInfo::defaultOutputDevice(); | ||
m_source = new Source(ui->playfilelineEdit->text(),mode,natural, this); | ||
m_audioOutput = new QAudioOutput(m_device_out, m_format, this); | ||
m_audioOutput->setBufferSize(8000);//1 second buffer | ||
connect(m_source, SIGNAL(percentage_played(int)),this, SLOT(max_mic_volume(int))); | ||
connect(m_source, SIGNAL(readChannelFinished()),this,SLOT(on_stopButton_clicked()),Qt::QueuedConnection);//seems to need to be placed in the message queue on windows else calling close will crash | ||
ui->progressBar->setFormat("Progress"); | ||
ui->recButton->setEnabled(false); | ||
ui->playButton->setEnabled(false); | ||
|
||
//start | ||
m_source->start(); | ||
m_audioOutput->start(m_source); | ||
|
||
ui->statusBar->clearMessage(); | ||
if(!m_source->laststatusmsg.isEmpty())ui->statusBar->showMessage("Play: "+m_source->laststatusmsg); | ||
|
||
if(m_source->failed)on_stopButton_clicked(); | ||
|
||
} | ||
|
||
void MainWindow::on_stopButton_clicked() | ||
{ | ||
if(m_audioOutput)m_audioOutput->stop(); | ||
if(m_source)m_source->stop(); | ||
if(m_audioInput)m_audioInput->stop(); | ||
if(m_sink)m_sink->stop(); | ||
max_mic_volume(0); | ||
ui->progressBar->setFormat(" Volume/Progress"); | ||
ui->recButton->setEnabled(true); | ||
ui->playButton->setEnabled(true); | ||
//ui->statusBar->clearMessage(); | ||
} | ||
|
||
void MainWindow::error_slot_msg(QString msg) | ||
{ | ||
ui->statusBar->showMessage(msg); | ||
} | ||
|
||
void MainWindow::on_actionAbout_Qt_triggered() | ||
{ | ||
QApplication::aboutQt(); | ||
} | ||
|
||
void MainWindow::on_action_About_triggered() | ||
{ | ||
QMessageBox::about(this,"JC2Rec","" | ||
"<H1>A speech recorder using Codec2</H1>" | ||
"<p>This is a simple program to record and play using the Codec2 codec.</p>" | ||
"<p>Codec2 is an audio codec designed for speech that highly compresses speech." | ||
" For information about the codec see <a href=\"http://www.rowetel.com/blog/?page_id=452\">http://www.rowetel.com/blog/?page_id=452</a></p>" | ||
"<p>For this application see <a href=\"http://jontio.zapto.org/hda1/jc2rec.html\">http://jontio.zapto.org/hda1/jc2rec.html</a>." | ||
" In addition to this GUI being useful, it is hoped that the source code of it will be useful for others to implement digital communication software.</p>" | ||
"<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" ); | ||
} | ||
|
||
|
Oops, something went wrong.