You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
#pragma once |
|
|
|
#include <QObject> |
|
#include <QString> |
|
#include <QTimer> |
|
#include <vector> |
|
#include <cstdint> |
|
|
|
struct ma_device; |
|
|
|
class AudioRecorder : public QObject { |
|
Q_OBJECT |
|
public: |
|
explicit AudioRecorder(QObject* parent = nullptr); |
|
~AudioRecorder() override; |
|
|
|
bool init(); |
|
void shutdown(); |
|
bool isInitialized() const { return m_initialized; } |
|
|
|
void setCaptureDeviceIndex(int index) { m_captureDeviceIndex = index; } |
|
int captureDeviceIndex() const { return m_captureDeviceIndex; } |
|
|
|
void startRecording(); |
|
void stopRecording(); |
|
bool isRecording() const { return m_recording; } |
|
|
|
float peakLevel() const; |
|
|
|
const std::vector<int16_t>& buffer() const { return m_pcmBuffer; } |
|
int durationMs() const; |
|
|
|
signals: |
|
void recordingStarted(); |
|
void recordingStopped(int durationMs); |
|
void durationChanged(int ms); |
|
|
|
private: |
|
ma_device* m_device = nullptr; |
|
bool m_initialized = false; |
|
bool m_recording = false; |
|
int m_sampleRate = 48000; |
|
int m_channels = 1; |
|
int m_captureDeviceIndex = -1; |
|
|
|
std::vector<int16_t> m_pcmBuffer; |
|
mutable float m_peakLevel = 0.0f; |
|
QTimer m_durationTimer; |
|
int m_elapsedMs = 0; |
|
|
|
friend void audioCaptureCallback(ma_device* pDevice, void* pOutput, const void* pInput, unsigned int frameCount); |
|
};
|
|
|