Skip to content

Commit

Permalink
Modify VoiceRecorder to be able to properly abort a recording.
Browse files Browse the repository at this point in the history
Previously huge amounts of silence were written in one step.
For long multi-channel recordings a joining user might cause
hours of silence to be written to disk before the user regained
the ability to abort a recording.

Now the recorder will only write up to 1s of silence per iteration.
If more silence has to be written the corresponding RecordBuffer
is re-queued for a later iteration enabling a timely abort.

This channel also includes some small refactoring for increasing
the readability of the recorder and to remove some warnings.
  • Loading branch information
hacst committed Feb 13, 2014
1 parent a0aa1bc commit ed424af
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 206 deletions.
24 changes: 12 additions & 12 deletions src/mumble/AudioOutput.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ AudioOutput::AudioOutput()
, fSpeakerVolume(NULL) , fSpeakerVolume(NULL)
, bSpeakerPositional(NULL) , bSpeakerPositional(NULL)


, mixedSampleCount(0) , m_mixedSampleCount(0)
, mixingMutex() , m_mixingMutex()
, eSampleFormat(SampleFloat) , eSampleFormat(SampleFloat)


, bRunning(true) , bRunning(true)
Expand Down Expand Up @@ -364,17 +364,17 @@ void AudioOutput::initializeMixer(const unsigned int *chanmasks, bool forceheadp
} }


bool AudioOutput::mix(void *outbuff, unsigned int nsamp) { bool AudioOutput::mix(void *outbuff, unsigned int nsamp) {
QMutexLocker mixingMutexLocker(&mixingMutex); QMutexLocker mixingMutexLocker(&m_mixingMutex);


QList<AudioOutputUser *> qlMix; QList<AudioOutputUser *> qlMix;
QList<AudioOutputUser *> qlDel; QList<AudioOutputUser *> qlDel;


if (g.s.fVolume < 0.01f) { if (g.s.fVolume < 0.01f) {
mixedSampleCount += nsamp; m_mixedSampleCount += nsamp;
return false; return false;
} }


const float adjustFactor = std::pow(10, -18.f / 20); const float adjustFactor = std::pow(10.f , -18.f / 20);
const float mul = g.s.fVolume; const float mul = g.s.fVolume;
const unsigned int nchan = iChannels; const unsigned int nchan = iChannels;
ServerHandlerPtr sh = g.sh; ServerHandlerPtr sh = g.sh;
Expand Down Expand Up @@ -512,9 +512,9 @@ bool AudioOutput::mix(void *outbuff, unsigned int nsamp) {
recbuff[i] += pfBuffer[i] * volumeAdjustment; recbuff[i] += pfBuffer[i] * volumeAdjustment;
} }


if (!recorder->getMixDown()) { if (!recorder->isInMixDownMode()) {
if (aos) { if (aos) {
recorder->addBuffer(aos->p, recbuff, nsamp, mixedSampleCount); recorder->addBuffer(aos->p, recbuff, nsamp, m_mixedSampleCount);
} else { } else {
// this should be unreachable // this should be unreachable
Q_ASSERT(false); Q_ASSERT(false);
Expand Down Expand Up @@ -571,8 +571,8 @@ bool AudioOutput::mix(void *outbuff, unsigned int nsamp) {
} }
} }


if (recorder && recorder->getMixDown()) { if (recorder && recorder->isInMixDownMode()) {
recorder->addBuffer(NULL, recbuff, nsamp, mixedSampleCount); recorder->addBuffer(NULL, recbuff, nsamp, m_mixedSampleCount);
} }


// Clip // Clip
Expand All @@ -589,7 +589,7 @@ bool AudioOutput::mix(void *outbuff, unsigned int nsamp) {
foreach(AudioOutputUser *aop, qlDel) foreach(AudioOutputUser *aop, qlDel)
removeBuffer(aop); removeBuffer(aop);


mixedSampleCount += nsamp; m_mixedSampleCount += nsamp;


return (! qlMix.isEmpty()); return (! qlMix.isEmpty());
} }
Expand All @@ -603,6 +603,6 @@ unsigned int AudioOutput::getMixerFreq() const {
} }


quint64 AudioOutput::getMixedSampleCount() const { quint64 AudioOutput::getMixedSampleCount() const {
QMutexLocker mixingMutexLocker(&mixingMutex); QMutexLocker mixingMutexLocker(&m_mixingMutex);
return mixedSampleCount; return m_mixedSampleCount;
} }
4 changes: 2 additions & 2 deletions src/mumble/AudioOutput.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class AudioOutput : public QThread {
float *fSpeakerVolume; float *fSpeakerVolume;
bool *bSpeakerPositional; bool *bSpeakerPositional;
/// Total number of samples mixed by this thread /// Total number of samples mixed by this thread
quint64 mixedSampleCount; quint64 m_mixedSampleCount;
/// Locked while mixing to protect mixedSampleCount /// Locked while mixing to protect mixedSampleCount
mutable QMutex mixingMutex; mutable QMutex m_mixingMutex;
protected: protected:
enum { SampleShort, SampleFloat } eSampleFormat; enum { SampleShort, SampleFloat } eSampleFormat;
volatile bool bRunning; volatile bool bRunning;
Expand Down
Loading

0 comments on commit ed424af

Please sign in to comment.