@@ -1,62 +1,62 | |||||
1 | #include "widget.h" |
|
1 | #include "widget.h" | |
2 | #include <QAudioDeviceInfo> |
|
2 | #include <QAudioDeviceInfo> | |
3 | #include <QAudioInput> |
|
3 | #include <QAudioInput> | |
4 | #include <QChartView> |
|
4 | #include <QChartView> | |
5 | #include <QLineSeries> |
|
5 | #include <QLineSeries> | |
6 | #include <QChart> |
|
6 | #include <QChart> | |
7 | #include <QVBoxLayout> |
|
7 | #include <QVBoxLayout> | |
8 | #include <QValueAxis> |
|
8 | #include <QValueAxis> | |
9 | #include "xyseriesiodevice.h" |
|
9 | #include "xyseriesiodevice.h" | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
11 | QTCOMMERCIALCHART_USE_NAMESPACE | |
12 |
|
12 | |||
13 | Widget::Widget(QWidget *parent) |
|
13 | Widget::Widget(QWidget *parent) | |
14 | : QWidget(parent), |
|
14 | : QWidget(parent), | |
15 | m_device(0), |
|
15 | m_device(0), | |
16 | m_chart(0), |
|
16 | m_chart(0), | |
17 | m_series(0), |
|
17 | m_series(0), | |
18 | m_audioInput(0) |
|
18 | m_audioInput(0) | |
19 | { |
|
19 | { | |
20 | m_chart = new QChart; |
|
20 | m_chart = new QChart; | |
21 | QChartView *chartView = new QChartView(m_chart); |
|
21 | QChartView *chartView = new QChartView(m_chart); | |
22 | chartView->setMinimumSize(800, 600); |
|
22 | chartView->setMinimumSize(800, 600); | |
23 | m_series = new QLineSeries; |
|
23 | m_series = new QLineSeries; | |
24 | m_chart->addSeries(m_series); |
|
24 | m_chart->addSeries(m_series); | |
25 | QValueAxis *axisX = new QValueAxis; |
|
25 | QValueAxis *axisX = new QValueAxis; | |
26 | axisX->setRange(0, 2000); |
|
26 | axisX->setRange(0, 2000); | |
27 | axisX->setLabelFormat("%g"); |
|
27 | axisX->setLabelFormat("%g"); | |
28 | axisX->setTitle("Samples"); |
|
28 | axisX->setTitle("Samples"); | |
29 | QValueAxis *axisY = new QValueAxis; |
|
29 | QValueAxis *axisY = new QValueAxis; | |
30 | axisY->setRange(-1, 1); |
|
30 | axisY->setRange(-1, 1); | |
31 | axisY->setTitle("Audio level"); |
|
31 | axisY->setTitle("Audio level"); | |
32 | m_chart->setAxisX(axisX, m_series); |
|
32 | m_chart->setAxisX(axisX, m_series); | |
33 | m_chart->setAxisY(axisY, m_series); |
|
33 | m_chart->setAxisY(axisY, m_series); | |
34 | m_chart->legend()->hide(); |
|
34 | m_chart->legend()->hide(); | |
35 | m_chart->setTitle("Data from the microphone"); |
|
35 | m_chart->setTitle("Data from the microphone"); | |
36 |
|
36 | |||
37 | QVBoxLayout *mainLayout = new QVBoxLayout; |
|
37 | QVBoxLayout *mainLayout = new QVBoxLayout; | |
38 | mainLayout->addWidget(chartView); |
|
38 | mainLayout->addWidget(chartView); | |
39 | setLayout(mainLayout); |
|
39 | setLayout(mainLayout); | |
40 |
|
40 | |||
41 | QAudioFormat formatAudio; |
|
41 | QAudioFormat formatAudio; | |
42 |
formatAudio.set |
|
42 | formatAudio.setSampleRate(8000); | |
43 |
formatAudio.setChannel |
|
43 | formatAudio.setChannelCount(1); | |
44 | formatAudio.setSampleSize(8); |
|
44 | formatAudio.setSampleSize(8); | |
45 | formatAudio.setCodec("audio/pcm"); |
|
45 | formatAudio.setCodec("audio/pcm"); | |
46 | formatAudio.setByteOrder(QAudioFormat::LittleEndian); |
|
46 | formatAudio.setByteOrder(QAudioFormat::LittleEndian); | |
47 | formatAudio.setSampleType(QAudioFormat::UnSignedInt); |
|
47 | formatAudio.setSampleType(QAudioFormat::UnSignedInt); | |
48 |
|
48 | |||
49 | QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice(); |
|
49 | QAudioDeviceInfo inputDevices = QAudioDeviceInfo::defaultInputDevice(); | |
50 | m_audioInput = new QAudioInput(inputDevices,formatAudio, this); |
|
50 | m_audioInput = new QAudioInput(inputDevices,formatAudio, this); | |
51 |
|
51 | |||
52 | m_device = new XYSeriesIODevice(m_series, this); |
|
52 | m_device = new XYSeriesIODevice(m_series, this); | |
53 | m_device->open(QIODevice::WriteOnly); |
|
53 | m_device->open(QIODevice::WriteOnly); | |
54 |
|
54 | |||
55 | m_audioInput->start(m_device); |
|
55 | m_audioInput->start(m_device); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | Widget::~Widget() |
|
58 | Widget::~Widget() | |
59 | { |
|
59 | { | |
60 | m_audioInput->stop(); |
|
60 | m_audioInput->stop(); | |
61 | m_device->close(); |
|
61 | m_device->close(); | |
62 | } |
|
62 | } |
@@ -1,55 +1,55 | |||||
1 | #include "widget.h" |
|
1 | #include "widget.h" | |
2 | #include <QPushButton> |
|
2 | #include <QPushButton> | |
3 | #include <QDir> |
|
3 | #include <QDir> | |
4 | #include <QGridLayout> |
|
4 | #include <QGridLayout> | |
5 | #include <QApplication> |
|
5 | #include <QApplication> | |
6 | #include <QProcess> |
|
6 | #include <QProcess> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | Widget::Widget(QWidget *parent) |
|
9 | Widget::Widget(QWidget *parent) | |
10 | : QWidget(parent), |
|
10 | : QWidget(parent), | |
11 | m_demoApp(0) |
|
11 | m_demoApp(0) | |
12 | { |
|
12 | { | |
13 | // Create a list of executables |
|
13 | // Create a list of executables | |
14 | QList<QFileInfo> appList; |
|
14 | QList<QFileInfo> appList; | |
15 | m_appFolder = QDir(QApplication::applicationDirPath()); |
|
15 | m_appFolder = QDir(QApplication::applicationDirPath()); | |
16 |
#ifdef Q_ |
|
16 | #ifdef Q_OS_MAC | |
17 | // The executable is inside an application bundle (a folder) on OSX |
|
17 | // The executable is inside an application bundle (a folder) on OSX | |
18 | m_appFolder.cdUp(); |
|
18 | m_appFolder.cdUp(); | |
19 | m_appFolder.cdUp(); |
|
19 | m_appFolder.cdUp(); | |
20 | m_appFolder.cdUp(); |
|
20 | m_appFolder.cdUp(); | |
21 | appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot); |
|
21 | appList = m_appFolder.entryInfoList(QStringList("*.app"), QDir::Executable | QDir::Dirs | QDir::NoDotAndDotDot); | |
22 |
#elif defined(Q_ |
|
22 | #elif defined(Q_OS_WIN) | |
23 | appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); |
|
23 | appList = m_appFolder.entryInfoList(QStringList("*.exe"), QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); | |
24 | #else |
|
24 | #else | |
25 | appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); |
|
25 | appList = m_appFolder.entryInfoList(QDir::Executable | QDir::Files | QDir::NoDotAndDotDot); | |
26 | #endif |
|
26 | #endif | |
27 | for (int k = appList.count() - 1; k >= 0; k--) { |
|
27 | for (int k = appList.count() - 1; k >= 0; k--) { | |
28 | QString name = appList[k].fileName(); |
|
28 | QString name = appList[k].fileName(); | |
29 | if (name.startsWith("tst_") || name.startsWith("demoLauncher")) |
|
29 | if (name.startsWith("tst_") || name.startsWith("demoLauncher")) | |
30 | appList.removeAt(k); |
|
30 | appList.removeAt(k); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | // Create push buttons for starting the executables |
|
33 | // Create push buttons for starting the executables | |
34 | QGridLayout* demosLayout = new QGridLayout; |
|
34 | QGridLayout* demosLayout = new QGridLayout; | |
35 | for( int i = 0; i < appList.count(); i++) { |
|
35 | for( int i = 0; i < appList.count(); i++) { | |
36 | QPushButton *button = new QPushButton(appList[i].fileName()); |
|
36 | QPushButton *button = new QPushButton(appList[i].fileName()); | |
37 | connect(button, SIGNAL(clicked()), this, SLOT (runApp())); |
|
37 | connect(button, SIGNAL(clicked()), this, SLOT (runApp())); | |
38 | demosLayout->addWidget(button, i%10, i/10); |
|
38 | demosLayout->addWidget(button, i%10, i/10); | |
39 | } |
|
39 | } | |
40 | setLayout(demosLayout); |
|
40 | setLayout(demosLayout); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | Widget::~Widget() |
|
43 | Widget::~Widget() | |
44 | { |
|
44 | { | |
45 | if (m_demoApp) |
|
45 | if (m_demoApp) | |
46 | m_demoApp->close(); |
|
46 | m_demoApp->close(); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void Widget::runApp() |
|
49 | void Widget::runApp() | |
50 | { |
|
50 | { | |
51 | QString name = qobject_cast<QPushButton *>(sender())->text(); |
|
51 | QString name = qobject_cast<QPushButton *>(sender())->text(); | |
52 | QString program = m_appFolder.absolutePath() + QDir::separator() + name; |
|
52 | QString program = m_appFolder.absolutePath() + QDir::separator() + name; | |
53 | m_demoApp = new QProcess(this); |
|
53 | m_demoApp = new QProcess(this); | |
54 | m_demoApp->start(program); |
|
54 | m_demoApp->start(program); | |
55 | } |
|
55 | } |
General Comments 0
You need to be logged in to leave comments.
Login now