PortAudio  2.0
Data Structures | Macros | Typedefs | Functions
audio_analyzer.h File Reference
#include "biquad_filter.h"

Go to the source code of this file.

Data Structures

struct  PaQaSineGenerator_s
 
struct  PaQaRecording_s
 
struct  PaQaTestTone_s
 
struct  PaQaAnalysisResult_s
 

Macros

#define MATH_PI   (3.141592653589793238462643)
 
#define MATH_TWO_PI   (2.0 * MATH_PI)
 

Typedefs

typedef struct PaQaSineGenerator_s PaQaSineGenerator
 
typedef struct PaQaRecording_s PaQaRecording
 
typedef struct PaQaTestTone_s PaQaTestTone
 
typedef struct PaQaAnalysisResult_s PaQaAnalysisResult
 

Functions

double PaQa_GetNthFrequency (double baseFrequency, int index)
 
void PaQa_EraseBuffer (float *buffer, int numFrames, int samplesPerFrame)
 
void PaQa_MixSine (PaQaSineGenerator *generator, float *buffer, int numSamples, int stride)
 
void PaQa_WriteSine (float *buffer, int numSamples, int stride, double frequency, double amplitude)
 
void PaQa_GenerateCrack (float *buffer, int numSamples, int stride)
 
double PaQa_ComputePhaseDifference (double phase1, double phase2)
 
double PaQa_MeasureArea (float *buffer, int numFrames, int stride)
 
double PaQa_MeasureCrossingSlope (float *buffer, int numFrames)
 
void PaQa_SetupSineGenerator (PaQaSineGenerator *generator, double frequency, double amplitude, double frameRate)
 
int PaQa_InitializeRecording (PaQaRecording *recording, int maxSamples, int sampleRate)
 
void PaQa_TerminateRecording (PaQaRecording *recording)
 
void PaQa_FilterRecording (PaQaRecording *input, PaQaRecording *output, BiquadFilter *filter)
 
int PaQa_SaveRecordingToWaveFile (PaQaRecording *recording, const char *filename)
 
int PaQa_WriteRecording (PaQaRecording *recording, float *buffer, int numSamples, int stride)
 
int PaQa_WriteSilence (PaQaRecording *recording, int numSamples)
 
int PaQa_RecordFreeze (PaQaRecording *recording, int numSamples)
 
double PaQa_CorrelateSine (PaQaRecording *recording, double frequency, double frameRate, int startFrame, int numSamples, double *phasePtr)
 
double PaQa_FindFirstMatch (PaQaRecording *recording, float *buffer, int numSamples, double tolerance)
 
double PaQa_MeasureSineAmplitudeBySlope (PaQaRecording *recording, double frequency, double frameRate, int startFrame, int numFrames)
 
double PaQa_MeasureRootMeanSquare (float *buffer, int numFrames)
 
double PaQa_CompareAmplitudes (PaQaRecording *recording, int startAt, float *buffer, int numSamples)
 
int PaQa_AnalyseRecording (PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult)
 

Macro Definition Documentation

#define MATH_PI   (3.141592653589793238462643)
#define MATH_TWO_PI   (2.0 * MATH_PI)

Typedef Documentation

Container for a monophonic audio sample in memory.

typedef struct PaQaTestTone_s PaQaTestTone

Function Documentation

int PaQa_AnalyseRecording ( PaQaRecording recording,
PaQaTestTone testTone,
PaQaAnalysisResult analysisResult 
)

Analyse a recording of a sine wave. Measure latency and look for dropped frames, etc.

References PaQaAnalysisResult_s::amplitudeRatio, PaQaAnalysisResult_s::latency, PaQa_DetectPhaseError(), PaQa_DetectPop(), PaQa_MeasureLatency(), QA_ASSERT_EQUALS, and PaQaAnalysisResult_s::valid.

double PaQa_CompareAmplitudes ( PaQaRecording recording,
int  startAt,
float *  buffer,
int  numSamples 
)

Compare the amplitudes of these two signals. Return ratio of recorded signal over buffer signal.

References PaQaRecording_s::buffer, PaQaRecording_s::numFrames, PaQa_MeasureArea(), and QA_ASSERT_TRUE.

Referenced by PaQa_MeasureLatency().

double PaQa_ComputePhaseDifference ( double  phase1,
double  phase2 
)

References MATH_PI, and MATH_TWO_PI.

Referenced by PaQa_DetectPhaseError().

double PaQa_CorrelateSine ( PaQaRecording recording,
double  frequency,
double  frameRate,
int  startFrame,
int  numSamples,
double *  phasePtr 
)
void PaQa_EraseBuffer ( float *  buffer,
int  numFrames,
int  samplesPerFrame 
)
void PaQa_FilterRecording ( PaQaRecording input,
PaQaRecording output,
BiquadFilter filter 
)

Apply a biquad filter to the audio from the input recording and write it to the output recording.

References BiquadFilter_Filter(), PaQaRecording_s::buffer, PaQaRecording_s::maxFrames, and PaQaRecording_s::numFrames.

Referenced by PaQa_DetectPop().

double PaQa_FindFirstMatch ( PaQaRecording recording,
float *  buffer,
int  numFrames,
double  threshold 
)

Scan until we get a correlation of a single that goes over the tolerance level, peaks then drops to half the peak. Look for inverse correlation as well.

References PaQaRecording_s::buffer, PaQaRecording_s::numFrames, and QA_ASSERT_TRUE.

Referenced by PaQa_MeasureLatency().

void PaQa_GenerateCrack ( float *  buffer,
int  numSamples,
int  stride 
)

Generate a signal with a sharp edge in the middle that can be recognized despite some phase shift.

double PaQa_GetNthFrequency ( double  baseFrequency,
int  index 
)

Calculate Nth frequency of a series for use in testing multiple channels. Series should avoid harmonic overlap between channels.

int PaQa_InitializeRecording ( PaQaRecording recording,
int  maxSamples,
int  sampleRate 
)

Allocate memory for containing a mono audio signal. Set up recording for writing.

References PaQaRecording_s::buffer, PaQaRecording_s::maxFrames, PaQaRecording_s::numFrames, QA_ASSERT_TRUE, and PaQaRecording_s::sampleRate.

Referenced by PaQa_DetectPop().

double PaQa_MeasureArea ( float *  buffer,
int  numFrames,
int  stride 
)

Measure the area under the curve by summing absolute value of each value.

Referenced by PaQa_CompareAmplitudes().

double PaQa_MeasureCrossingSlope ( float *  buffer,
int  numFrames 
)

Measure slope of the positive zero crossings.

Referenced by PaQa_MeasureSineAmplitudeBySlope().

double PaQa_MeasureRootMeanSquare ( float *  buffer,
int  numFrames 
)
double PaQa_MeasureSineAmplitudeBySlope ( PaQaRecording recording,
double  frequency,
double  frameRate,
int  startFrame,
int  numFrames 
)

Estimate the original amplitude of a clipped sine wave by measuring its average slope at the zero crossings.

References buffer, PaQaRecording_s::buffer, MATH_TWO_PI, and PaQa_MeasureCrossingSlope().

Referenced by PaQa_CheckForClippedLoopback().

void PaQa_MixSine ( PaQaSineGenerator generator,
float *  buffer,
int  numSamples,
int  stride 
)
int PaQa_RecordFreeze ( PaQaRecording recording,
int  numSamples 
)
int PaQa_SaveRecordingToWaveFile ( PaQaRecording recording,
const char *  filename 
)
void PaQa_SetupSineGenerator ( PaQaSineGenerator generator,
double  frequency,
double  amplitude,
double  frameRate 
)

Prepare an oscillator that can generate a sine tone for testing.

References PaQaSineGenerator_s::amplitude, PaQaSineGenerator_s::frequency, MATH_PI, PaQaSineGenerator_s::phase, and PaQaSineGenerator_s::phaseIncrement.

Referenced by PaQa_FillWithSine(), and PaQa_MeasureLatency().

void PaQa_TerminateRecording ( PaQaRecording recording)

Free memory allocated by PaQa_InitializeRecording.

References PaQaRecording_s::buffer, and PaQaRecording_s::maxFrames.

Referenced by PaQa_DetectPop().

int PaQa_WriteRecording ( PaQaRecording recording,
float *  buffer,
int  numSamples,
int  stride 
)
Parameters
strideis the spacing of samples to skip in the input buffer. To use every samples pass 1. To use every other sample pass 2.

References buffer, PaQaRecording_s::buffer, PaQaRecording_s::maxFrames, and PaQaRecording_s::numFrames.

Referenced by PaQa_FillWithSine().

int PaQa_WriteSilence ( PaQaRecording recording,
int  numSamples 
)

Write zeros into a recording.

References PaQaRecording_s::buffer, PaQaRecording_s::maxFrames, and PaQaRecording_s::numFrames.

void PaQa_WriteSine ( float *  buffer,
int  numSamples,
int  stride,
double  frequency,
double  amplitude 
)