mirror of
https://github.com/lubosz/overte.git
synced 2025-04-12 10:02:25 +02:00
move save logic to audioclient
This commit is contained in:
parent
20d6615417
commit
8abe8b9879
4 changed files with 27 additions and 21 deletions
|
@ -58,19 +58,9 @@ Audio::Audio() : _devices(_contextIsHMD) {
|
|||
enableNoiseReduction(enableNoiseReductionSetting.get());
|
||||
}
|
||||
|
||||
void Audio::onOutputBufferReceived(const QByteArray outputBuffer) {
|
||||
_audioFileWav.addRawAudioChunk((char*)outputBuffer.data(), outputBuffer.size());
|
||||
}
|
||||
|
||||
bool Audio::startRecording(const QString& filepath) {
|
||||
auto client = DependencyManager::get<AudioClient>().data();
|
||||
if (!_audioFileWav.create(client->getOutputFormat(), filepath)) {
|
||||
qDebug() << "Error creating audio file: "+filepath;
|
||||
return false;
|
||||
}
|
||||
connect(client, &AudioClient::outputBufferReceived, this, &Audio::onOutputBufferReceived);
|
||||
client->setRecording(true);
|
||||
return true;
|
||||
return client->startRecording(filepath);
|
||||
}
|
||||
|
||||
bool Audio::getRecording() {
|
||||
|
@ -80,12 +70,7 @@ bool Audio::getRecording() {
|
|||
|
||||
void Audio::stopRecording() {
|
||||
auto client = DependencyManager::get<AudioClient>().data();
|
||||
disconnect(client, &AudioClient::outputBufferReceived, this, 0);
|
||||
|
||||
if (client->getRecording()) {
|
||||
client->setRecording(false);
|
||||
_audioFileWav.close();
|
||||
}
|
||||
client->stopRecording();
|
||||
}
|
||||
|
||||
void Audio::setMuted(bool isMuted) {
|
||||
|
|
|
@ -76,7 +76,6 @@ private slots:
|
|||
void onNoiseReductionChanged();
|
||||
void onInputVolumeChanged(float volume);
|
||||
void onInputLoudnessChanged(float loudness);
|
||||
void onOutputBufferReceived(const QByteArray outputBuffer);
|
||||
|
||||
protected:
|
||||
// Audio must live on a separate thread from AudioClient to avoid deadlocks
|
||||
|
@ -91,7 +90,6 @@ private:
|
|||
bool _contextIsHMD { false };
|
||||
AudioDevices* getDevices() { return &_devices; }
|
||||
AudioDevices _devices;
|
||||
AudioFileWav _audioFileWav;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -79,6 +79,7 @@ Setting::Handle<int> staticJitterBufferFrames("staticJitterBufferFrames",
|
|||
using Mutex = std::mutex;
|
||||
using Lock = std::unique_lock<Mutex>;
|
||||
Mutex _deviceMutex;
|
||||
Mutex _recordMutex;
|
||||
|
||||
// thread-safe
|
||||
QList<QAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
|
||||
|
@ -1910,8 +1911,8 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
|||
|
||||
// send output buffer for recording
|
||||
if (_audio->_isRecording) {
|
||||
QByteArray outputBuffer(reinterpret_cast<char*>(scratchBuffer), bytesWritten);
|
||||
emit _audio->outputBufferReceived(outputBuffer);
|
||||
Lock lock(_recordMutex);
|
||||
_audio->_audioFileWav.addRawAudioChunk(reinterpret_cast<char*>(scratchBuffer), bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1926,6 +1927,22 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
|||
return bytesWritten;
|
||||
}
|
||||
|
||||
bool AudioClient::startRecording(const QString& filepath) {
|
||||
if (!_audioFileWav.create(_outputFormat, filepath)) {
|
||||
qDebug() << "Error creating audio file: " + filepath;
|
||||
return false;
|
||||
}
|
||||
_isRecording = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioClient::stopRecording() {
|
||||
if (_isRecording) {
|
||||
_isRecording = false;
|
||||
_audioFileWav.close();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioClient::loadSettings() {
|
||||
_receivedAudioStream.setDynamicJitterBufferEnabled(dynamicJitterBufferEnabled.get());
|
||||
_receivedAudioStream.setStaticJitterBufferFrames(staticJitterBufferFrames.get());
|
||||
|
|
|
@ -161,6 +161,10 @@ public:
|
|||
void setRecording(bool isRecording) { _isRecording = isRecording; };
|
||||
bool getRecording() { return _isRecording; };
|
||||
|
||||
bool startRecording(const QString& filename);
|
||||
void stopRecording();
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
static QString getWinDeviceName(wchar_t* guid);
|
||||
#endif
|
||||
|
@ -402,6 +406,8 @@ private:
|
|||
QList<QAudioDeviceInfo> _inputDevices;
|
||||
QList<QAudioDeviceInfo> _outputDevices;
|
||||
|
||||
AudioFileWav _audioFileWav;
|
||||
|
||||
bool _hasReceivedFirstPacket { false };
|
||||
|
||||
QVector<AudioInjectorPointer> _activeLocalAudioInjectors;
|
||||
|
|
Loading…
Reference in a new issue