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
Showing
8 changed files
with
167 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,50 @@ | ||
#include "AudioVisualizer.h" | ||
|
||
AudioVisualizer::AudioVisualizer(QWidget* parent) | ||
: QOpenGLWidget(parent) | ||
{ | ||
memset(_samples, 0, 1024 * 2); | ||
setMinimumSize(512, 64); | ||
} | ||
|
||
void AudioVisualizer::initializeGL() | ||
{ | ||
|
||
} | ||
|
||
void AudioVisualizer::paintGL() | ||
{ | ||
float x; | ||
float sample; | ||
|
||
glClearColor(0.f, 0.f, 1.f, 1.f); | ||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||
|
||
glColor3f(1.f, 1.f, 0.f); | ||
glBegin(GL_LINE_STRIP); | ||
{ | ||
std::unique_lock lock(_mutex); | ||
|
||
for (int i = 0; i < 1024; ++i) | ||
{ | ||
x = ((float)i) / 512.f - 1.f; | ||
sample = ((float)_samples[i]) / 32768.f; | ||
glVertex2f(x, sample); | ||
} | ||
} | ||
glEnd(); | ||
} | ||
|
||
void AudioVisualizer::resizeGL(int w, int h) | ||
{ | ||
(void)w; | ||
(void)h; | ||
glViewport(-1, -1, 1, 1); | ||
} | ||
|
||
void AudioVisualizer::pushSamples(const int16_t* samples) | ||
{ | ||
std::unique_lock lock(_mutex); | ||
|
||
memcpy(_samples, samples, 2048); | ||
} |
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 @@ | ||
#ifndef AUDIO_VISUALIZER_H | ||
#define AUDIO_VISUALIZER_H | ||
|
||
#include <mutex> | ||
#include <cstdint> | ||
#include <QWidget> | ||
#include <QOpenGLWidget> | ||
|
||
class AudioVisualizer : public QOpenGLWidget | ||
{ | ||
Q_OBJECT; | ||
|
||
public: | ||
explicit AudioVisualizer(QWidget* parent = nullptr); | ||
|
||
virtual void initializeGL() override; | ||
virtual void paintGL() override; | ||
virtual void resizeGL(int w, int j) override; | ||
|
||
void pushSamples(const int16_t* samples); | ||
|
||
private: | ||
std::mutex _mutex; | ||
int16_t _samples[1024]; | ||
}; | ||
|
||
#endif |
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,24 @@ | ||
#include <QVboxLayout> | ||
#include "AudioVisualizerWindow.h" | ||
#include "AudioVisualizer.h" | ||
|
||
AudioVisualizerWindow::AudioVisualizerWindow(QWidget* parent) | ||
: QWidget(parent, Qt::Window) | ||
{ | ||
QVBoxLayout* layout; | ||
|
||
setWindowTitle("Audio Visualizer"); | ||
|
||
layout = new QVBoxLayout; | ||
|
||
_audioVisualizer = new AudioVisualizer; | ||
layout->addWidget(_audioVisualizer); | ||
|
||
setLayout(layout); | ||
} | ||
|
||
void AudioVisualizerWindow::refresh(const int16_t* samples) | ||
{ | ||
_audioVisualizer->pushSamples(samples); | ||
_audioVisualizer->update(); | ||
} |
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,25 @@ | ||
#ifndef AUDIO_VISUALIZER_WINDOW_H | ||
#define AUDIO_VISUALIZER_WINDOW_H | ||
|
||
#include <cstdint> | ||
#include <QWidget> | ||
|
||
#include <nin/nin.h> | ||
#include "HexView.h" | ||
|
||
class AudioVisualizer; | ||
class AudioVisualizerWindow : public QWidget | ||
{ | ||
Q_OBJECT; | ||
|
||
public: | ||
explicit AudioVisualizerWindow(QWidget* parent = nullptr); | ||
|
||
public slots: | ||
void refresh(const int16_t* samples); | ||
|
||
private: | ||
AudioVisualizer* _audioVisualizer; | ||
}; | ||
|
||
#endif |
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
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