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