PortAudio  2.0
Macros | Functions
audio_analyzer.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "qa_tools.h"
#include "audio_analyzer.h"
#include "write_wav.h"

Macros

#define PAQA_POP_THRESHOLD   (0.04)
 
#define NUM_SAMPLES   (200)
 
#define MAX_BUFFER_SIZE   2048
 

Functions

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

Macro Definition Documentation

#define MAX_BUFFER_SIZE   2048

Referenced by PaQa_MeasureLatency().

#define NUM_SAMPLES   (200)
#define PAQA_POP_THRESHOLD   (0.04)

Referenced by PaQa_DetectPop().

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  numFrames,
double *  phasePtr 
)
int PaQa_DetectPhaseError ( PaQaRecording recording,
PaQaTestTone testTone,
PaQaAnalysisResult analysisResult 
)
int PaQa_DetectPop ( PaQaRecording recording,
PaQaTestTone testTone,
PaQaAnalysisResult analysisResult 
)
void PaQa_EraseBuffer ( float *  buffer,
int  numFrames,
int  samplesPerFrame 
)
void PaQa_FadeInRecording ( PaQaRecording recording,
int  startFrame,
int  count 
)

References PaQaRecording_s::buffer, and MATH_PI.

Referenced by PaQa_DetectPop().

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_GenerateCrackDISABLED ( float *  buffer,
int  numSamples,
int  stride 
)

References MATH_TWO_PI.

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

int PaQa_MeasureLatency ( PaQaRecording recording,
PaQaTestTone testTone,
PaQaAnalysisResult analysisResult 
)
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  numFrames 
)
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.