-
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.
implementing the soundwave functionality
- Loading branch information
Showing
5 changed files
with
94 additions
and
11 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
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,48 @@ | ||
#include "io_device.hpp" | ||
#include <qobject.h> | ||
#include <qtpreprocessorsupport.h> | ||
#include <qtypes.h> | ||
|
||
namespace sound { | ||
|
||
IODevice::IODevice(QObject* parent) : QIODevice(parent) {} | ||
|
||
qint64 IODevice::readData(char* data, qint64 maxSize) { | ||
Q_UNUSED(data); | ||
Q_UNUSED(maxSize); | ||
return -1; | ||
} | ||
|
||
qint64 IODevice::writeData(const char* data, qint64 maxSize) { | ||
static const int resolution = 4; | ||
|
||
if (m_buffer.isEmpty()) { | ||
m_buffer.reserve(sampleCount); | ||
|
||
for (int i = 0; i < sampleCount; ++i) { | ||
m_buffer.append(QPointF(i, 0)); | ||
} | ||
} | ||
|
||
int start = 0; | ||
|
||
const int availableSamples = int(maxSize) / resolution; | ||
|
||
if (availableSamples < sampleCount) { | ||
start = sampleCount - availableSamples; | ||
|
||
for (int s = 0; s < start; ++s) { | ||
m_buffer[s].setY(m_buffer.at(s + availableSamples).y()); | ||
} | ||
} | ||
|
||
for (int s = start; s < sampleCount; ++s, data += resolution) { | ||
m_buffer[s].setY(qreal(uchar(*data) - 128) / qreal(128)); | ||
} | ||
|
||
// m_series->replace(m_buffer); | ||
|
||
return (sampleCount - start) * resolution; | ||
} | ||
|
||
} // namespace sound |
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,27 @@ | ||
#pragma once | ||
|
||
#include <qobject.h> | ||
#include <qtmetamacros.h> | ||
#include <qtypes.h> | ||
#include <QIODevice> | ||
#include <QList> | ||
#include <QPointF> | ||
|
||
namespace sound { | ||
|
||
class IODevice : public QIODevice { | ||
Q_OBJECT | ||
public: | ||
explicit IODevice(QObject* parent = nullptr); | ||
|
||
static const int sampleCount = 2000; | ||
|
||
protected: | ||
qint64 readData(char* data, qint64 maxSize) override; | ||
qint64 writeData(const char* data, qint64 maxSize) override; | ||
|
||
private: | ||
QList<QPointF> m_buffer; | ||
}; | ||
|
||
} // namespace sound |
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
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