MixHelpers: added isSilent()

A simple function for testing whether a given sample buffer is silent.
Maybe we have to adjust/lower the threshold.
This commit is contained in:
Tobias Doerffel
2014-02-06 22:55:41 +01:00
parent f01c90b6a5
commit be5e17c29c
2 changed files with 20 additions and 0 deletions

View File

@@ -30,6 +30,8 @@
namespace MixHelpers
{
bool isSilent( const sampleFrame* src, int frames );
/*! \brief Add samples from src to dst */
void add( sampleFrame* dst, const sampleFrame* src, int frames );

View File

@@ -22,6 +22,8 @@
*
*/
#include <math.h>
#include "MixHelpers.h"
@@ -51,6 +53,22 @@ static inline void run( sampleFrame* dst, const sample_t* srcLeft, const sample_
bool isSilent( const sampleFrame* src, int frames )
{
const float silenceThreshold = 0.0000001f;
for( int i = 0; i < frames; ++i )
{
if( fabsf( src[i][0] ) >= silenceThreshold || fabsf( src[i][1] ) >= silenceThreshold )
{
return false;
}
}
return true;
}
struct AddOp
{
void operator()( sampleFrame& dst, const sampleFrame& src ) const