PortAudio 2.0
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

◆ MATH_PI

#define MATH_PI   (3.141592653589793238462643)

◆ MATH_TWO_PI

Typedef Documentation

◆ PaQaAnalysisResult

◆ PaQaRecording

Container for a monophonic audio sample in memory.

◆ PaQaSineGenerator

◆ PaQaTestTone

typedef struct PaQaTestTone_s PaQaTestTone

Function Documentation

◆ PaQa_AnalyseRecording()

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.

◆ PaQa_CompareAmplitudes()

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 buffer, PaQaRecording_s::buffer, PaQaRecording_s::numFrames, PaQa_MeasureArea(), and QA_ASSERT_TRUE.

Referenced by PaQa_MeasureLatency().

◆ PaQa_ComputePhaseDifference()

double PaQa_ComputePhaseDifference ( double phase1,
double phase2 )

References MATH_PI, and MATH_TWO_PI.

Referenced by PaQa_DetectPhaseError().

◆ PaQa_CorrelateSine()

double PaQa_CorrelateSine ( PaQaRecording * recording,
double frequency,
double frameRate,
int startFrame,
int numSamples,
double * phasePtr )

◆ PaQa_EraseBuffer()

void PaQa_EraseBuffer ( float * buffer,
int numFrames,
int samplesPerFrame )

References buffer.

Referenced by PaQa_FillWithSine(), and PaQa_MeasureLatency().

◆ PaQa_FilterRecording()

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().

◆ PaQa_FindFirstMatch()

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 buffer, PaQaRecording_s::buffer, PaQaRecording_s::numFrames, and QA_ASSERT_TRUE.

Referenced by PaQa_MeasureLatency().

◆ PaQa_GenerateCrack()

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.

◆ PaQa_GetNthFrequency()

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.

◆ PaQa_InitializeRecording()

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().

◆ PaQa_MeasureArea()

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

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

References buffer.

Referenced by PaQa_CompareAmplitudes().

◆ PaQa_MeasureCrossingSlope()

double PaQa_MeasureCrossingSlope ( float * buffer,
int numFrames )

Measure slope of the positive zero crossings.

References buffer.

Referenced by PaQa_MeasureSineAmplitudeBySlope().

◆ PaQa_MeasureRootMeanSquare()

double PaQa_MeasureRootMeanSquare ( float * buffer,
int numFrames )

References buffer.

Referenced by PaQa_MeasureBackgroundNoise().

◆ PaQa_MeasureSineAmplitudeBySlope()

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().

◆ PaQa_MixSine()

void PaQa_MixSine ( PaQaSineGenerator * generator,
float * buffer,
int numSamples,
int stride )

◆ PaQa_RecordFreeze()

int PaQa_RecordFreeze ( PaQaRecording * recording,
int numSamples )

◆ PaQa_SaveRecordingToWaveFile()

int PaQa_SaveRecordingToWaveFile ( PaQaRecording * recording,
const char * filename )

◆ PaQa_SetupSineGenerator()

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().

◆ PaQa_TerminateRecording()

void PaQa_TerminateRecording ( PaQaRecording * recording)

Free memory allocated by PaQa_InitializeRecording.

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

Referenced by PaQa_DetectPop().

◆ PaQa_WriteRecording()

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().

◆ PaQa_WriteSilence()

int PaQa_WriteSilence ( PaQaRecording * recording,
int numSamples )

Write zeros into a recording.

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

◆ PaQa_WriteSine()

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