Skip to content

Commit

Permalink
attempt to fix opus crash
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp96 committed Sep 18, 2023
1 parent f786093 commit 55101ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CSoundInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CSoundInput::CSoundInput(int _bitRate) : encoder(new COpusEncoder(SAMPLE_RATE, A

CSoundInput::~CSoundInput()
{
std::unique_lock lock{ inputMutex };
delete encoder;
delete opusBuffer;
rnnoise_destroy(denoiser);
Expand Down Expand Up @@ -203,6 +204,7 @@ void CSoundInput::SetNoiseSuppressionEnabled(const bool enabled)
BOOL CSoundInput::OnSoundFrame(HRECORD handle, const void* buffer, DWORD length, void* user)
{
const auto self = static_cast<CSoundInput*>(user);
std::unique_lock lock{ self->inputMutex };

for (int i = 0; i < length; i += (FRAME_SIZE_SAMPLES * sizeof(short)))
{
Expand Down
3 changes: 3 additions & 0 deletions src/CSoundInput.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <bass.h>
#include <rnnoise.h>
#include <mutex>

#include "alt-voice.h"
#include "ISoundInput.h"
Expand Down Expand Up @@ -36,6 +37,8 @@ class CSoundInput : public ISoundInput
bool recording = false;
bool deviceLost = false;
bool isDefault = true;

std::mutex inputMutex;
public:
CSoundInput(int _bitRate);
~CSoundInput() override;
Expand Down

0 comments on commit 55101ef

Please sign in to comment.