# HG changeset patch # User Chris Cannam # Date 1484156797 0 # Node ID 298d864113f076e270f9f9804a950206ec4acfc0 # Parent 1a8a8980f39a8e735c90837a4c2260248aafe7f1 Fix flickery level meters diff -r 1a8a8980f39a -r 298d864113f0 audio/AudioCallbackPlaySource.cpp --- a/audio/AudioCallbackPlaySource.cpp Thu Jan 05 13:04:30 2017 +0000 +++ b/audio/AudioCallbackPlaySource.cpp Wed Jan 11 17:46:37 2017 +0000 @@ -72,6 +72,7 @@ m_ringBufferSize(DEFAULT_RING_BUFFER_SIZE), m_outputLeft(0.0), m_outputRight(0.0), + m_levelsSet(false), m_auditioningPlugin(0), m_auditioningPluginBypassed(false), m_playStartFrame(0), @@ -967,6 +968,7 @@ { if (left > m_outputLeft) m_outputLeft = left; if (right > m_outputRight) m_outputRight = right; + m_levelsSet = true; } bool @@ -974,9 +976,11 @@ { left = m_outputLeft; right = m_outputRight; + bool valid = m_levelsSet; m_outputLeft = 0.f; m_outputRight = 0.f; - return true; + m_levelsSet = false; + return valid; } void diff -r 1a8a8980f39a -r 298d864113f0 audio/AudioCallbackPlaySource.h --- a/audio/AudioCallbackPlaySource.h Thu Jan 05 13:04:30 2017 +0000 +++ b/audio/AudioCallbackPlaySource.h Wed Jan 11 17:46:37 2017 +0000 @@ -188,8 +188,15 @@ virtual void setOutputLevels(float left, float right) override; /** - * Return the current (or thereabouts) output levels in the range - * 0.0 -> 1.0, for metering purposes. + * Return the current output levels in the range 0.0 -> 1.0, for + * metering purposes. The values returned are the peak values + * since the last time this function was called (after which they + * are reset to zero until setOutputLevels is called again by the + * driver). + * + * Return true if the values have been set since this function was + * last called (i.e. if they are meaningful). Return false if they + * have not been set (in which case both will be zero). */ virtual bool getOutputLevels(float &left, float &right) override; @@ -360,6 +367,7 @@ int m_ringBufferSize; float m_outputLeft; float m_outputRight; + bool m_levelsSet; RealTimePluginInstance *m_auditioningPlugin; bool m_auditioningPluginBypassed; Scavenger m_pluginScavenger; diff -r 1a8a8980f39a -r 298d864113f0 audio/AudioCallbackRecordTarget.cpp --- a/audio/AudioCallbackRecordTarget.cpp Thu Jan 05 13:04:30 2017 +0000 +++ b/audio/AudioCallbackRecordTarget.cpp Wed Jan 11 17:46:37 2017 +0000 @@ -34,7 +34,8 @@ m_buffers(0), m_bufferCount(0), m_inputLeft(0.f), - m_inputRight(0.f) + m_inputRight(0.f), + m_levelsSet(false) { m_viewManager->setAudioRecordTarget(this); @@ -193,6 +194,7 @@ { if (left > m_inputLeft) m_inputLeft = left; if (right > m_inputRight) m_inputRight = right; + m_levelsSet = true; } bool @@ -202,7 +204,7 @@ right = m_inputRight; m_inputLeft = 0.f; m_inputRight = 0.f; - return true; + return m_levelsSet; } void diff -r 1a8a8980f39a -r 298d864113f0 audio/AudioCallbackRecordTarget.h --- a/audio/AudioCallbackRecordTarget.h Thu Jan 05 13:04:30 2017 +0000 +++ b/audio/AudioCallbackRecordTarget.h Wed Jan 11 17:46:37 2017 +0000 @@ -63,7 +63,18 @@ virtual bool isRecording() const override { return m_recording; } virtual sv_frame_t getRecordDuration() const override { return m_frameCount; } - virtual bool getInputLevels(float &left, float &right) override; + /** + * Return the current input levels in the range 0.0 -> 1.0, for + * metering purposes. The values returned are the peak values + * since the last time this function was called (after which they + * are reset to zero until setInputLevels is called again by the + * driver). + * + * Return true if the values have been set since this function was + * last called (i.e. if they are meaningful). Return false if they + * have not been set (in which case both will be zero). + */ + virtual bool getInputLevels(float &left, float &right) override; WritableWaveFileModel *startRecording(); // caller takes ownership of model void stopRecording(); @@ -91,6 +102,7 @@ int m_bufferCount; float m_inputLeft; float m_inputRight; + bool m_levelsSet; void recreateBuffers(); };