|
PortAudio 2.0
|
#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) |
| #define MAX_BUFFER_SIZE 2048 |
Referenced by PaQa_MeasureLatency().
| #define NUM_SAMPLES (200) |
Referenced by PaQa_SaveRecordingToWaveFile().
| #define PAQA_POP_THRESHOLD (0.04) |
Referenced by PaQa_DetectPop().
| 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 buffer, 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 ) |
References PaQaRecording_s::buffer, MATH_PI, MATH_TWO_PI, PaQaRecording_s::numFrames, and QA_ASSERT_TRUE.
Referenced by PaQa_CheckForLoopBack(), and PaQa_DetectPhaseError().
| int PaQa_DetectPhaseError | ( | PaQaRecording * | recording, |
| PaQaTestTone * | testTone, | ||
| PaQaAnalysisResult * | analysisResult ) |
References PaQaAnalysisResult_s::addedFramesPosition, PaQaAnalysisResult_s::droppedFramesPosition, PaQaTestTone_s::frequency, PaQaAnalysisResult_s::latency, MATH_TWO_PI, PaQaAnalysisResult_s::numAddedFrames, PaQaAnalysisResult_s::numDroppedFrames, PaQaRecording_s::numFrames, PaQa_ComputePhaseDifference(), PaQa_CorrelateSine(), and PaQaTestTone_s::sampleRate.
Referenced by PaQa_AnalyseRecording().
| int PaQa_DetectPop | ( | PaQaRecording * | recording, |
| PaQaTestTone * | testTone, | ||
| PaQaAnalysisResult * | analysisResult ) |
Apply notch filter and high pass filter then detect remaining energy.
References BiquadFilter_SetupHighPass(), BiquadFilter_SetupNotch(), PaQaRecording_s::buffer, PaQaTestTone_s::frequency, PaQaAnalysisResult_s::latency, PaQaRecording_s::numFrames, PaQa_FadeInRecording(), PaQa_FilterRecording(), PaQa_InitializeRecording(), PAQA_POP_THRESHOLD, PaQa_TerminateRecording(), PaQaAnalysisResult_s::popAmplitude, PaQaAnalysisResult_s::popPosition, QA_ASSERT_EQUALS, and PaQaRecording_s::sampleRate.
Referenced by PaQa_AnalyseRecording().
| void PaQa_EraseBuffer | ( | float * | buffer, |
| int | numFrames, | ||
| int | samplesPerFrame ) |
References buffer.
Referenced by PaQa_FillWithSine(), and PaQa_MeasureLatency().
| 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 buffer, PaQaRecording_s::buffer, PaQaRecording_s::numFrames, and QA_ASSERT_TRUE.
Referenced by PaQa_MeasureLatency().
| void PaQa_GenerateCrackDISABLED | ( | float * | buffer, |
| int | numSamples, | ||
| int | stride ) |
References buffer, and 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 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.
References buffer.
Referenced by PaQa_CompareAmplitudes().
| double PaQa_MeasureCrossingSlope | ( | float * | buffer, |
| int | numFrames ) |
Measure slope of the positive zero crossings.
References buffer.
Referenced by PaQa_MeasureSineAmplitudeBySlope().
| int PaQa_MeasureLatency | ( | PaQaRecording * | recording, |
| PaQaTestTone * | testTone, | ||
| PaQaAnalysisResult * | analysisResult ) |
References PaQaTestTone_s::amplitude, PaQaAnalysisResult_s::amplitudeRatio, buffer, PaQaTestTone_s::frequency, PaQaAnalysisResult_s::latency, MAX_BUFFER_SIZE, PaQa_CompareAmplitudes(), PaQa_EraseBuffer(), PaQa_FindFirstMatch(), PaQa_MixSine(), PaQa_SetupSineGenerator(), QA_ASSERT_TRUE, PaQaTestTone_s::sampleRate, PaQaTestTone_s::samplesPerFrame, and PaQaAnalysisResult_s::valid.
Referenced by PaQa_AnalyseRecording().
| double PaQa_MeasureRootMeanSquare | ( | float * | buffer, |
| int | numFrames ) |
References buffer.
Referenced by PaQa_MeasureBackgroundNoise().
| 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 ) |
References PaQaSineGenerator_s::amplitude, buffer, MATH_TWO_PI, PaQaSineGenerator_s::phase, and PaQaSineGenerator_s::phaseIncrement.
Referenced by PaQa_FillWithSine(), and PaQa_MeasureLatency().
| int PaQa_RecordFreeze | ( | PaQaRecording * | recording, |
| int | numFrames ) |
References PaQaRecording_s::buffer, PaQaRecording_s::maxFrames, and PaQaRecording_s::numFrames.
| int PaQa_SaveRecordingToWaveFile | ( | PaQaRecording * | recording, |
| const char * | filename ) |
Write recording to WAV file.
References Audio_WAV_CloseWriter(), Audio_WAV_OpenWriter(), Audio_WAV_WriteShorts(), buffer, PaQaRecording_s::buffer, NUM_SAMPLES, PaQaRecording_s::numFrames, and PaQaRecording_s::sampleRate.
| 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 ) |
| stride | is 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.