PortAudio  2.0
audio_analyzer.h
Go to the documentation of this file.
1 
2 /*
3  * PortAudio Portable Real-Time Audio Library
4  * Latest Version at: http://www.portaudio.com
5  *
6  * Copyright (c) 1999-2010 Phil Burk and Ross Bencina
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files
10  * (the "Software"), to deal in the Software without restriction,
11  * including without limitation the rights to use, copy, modify, merge,
12  * publish, distribute, sublicense, and/or sell copies of the Software,
13  * and to permit persons to whom the Software is furnished to do so,
14  * subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 /*
29  * The text above constitutes the entire PortAudio license; however,
30  * the PortAudio community also makes the following non-binding requests:
31  *
32  * Any person wishing to distribute modifications to the Software is
33  * requested to send the modifications to the original developer so that
34  * they can be incorporated into the canonical version. It is also
35  * requested that these non-binding requests be included along with the
36  * license above.
37  */
38 
39 #ifndef _AUDIO_ANALYZER_H
40 #define _AUDIO_ANALYZER_H
41 
42 #include "biquad_filter.h"
43 
44 #define MATH_PI (3.141592653589793238462643)
45 #define MATH_TWO_PI (2.0 * MATH_PI)
46 
47 typedef struct PaQaSineGenerator_s
48 {
49  double phase;
51  double frequency;
52  double amplitude;
54 
56 typedef struct PaQaRecording_s
57 {
59  int maxFrames;
60  float *buffer;
62  int numFrames;
65 
66 typedef struct PaQaTestTone_s
67 {
70  double sampleRate;
71  double frequency;
72  double amplitude;
73 } PaQaTestTone;
74 
75 typedef struct PaQaAnalysisResult_s
76 {
77  int valid;
79  double latency;
81  double popAmplitude;
82  double popPosition;
88 
89 
90 /*================================================================*/
91 /*================= General DSP Tools ============================*/
92 /*================================================================*/
97 double PaQa_GetNthFrequency( double baseFrequency, int index );
98 
99 void PaQa_EraseBuffer( float *buffer, int numFrames, int samplesPerFrame );
100 
101 void PaQa_MixSine( PaQaSineGenerator *generator, float *buffer, int numSamples, int stride );
102 
103 void PaQa_WriteSine( float *buffer, int numSamples, int stride,
104  double frequency, double amplitude );
105 
109 void PaQa_GenerateCrack( float *buffer, int numSamples, int stride );
110 
111 double PaQa_ComputePhaseDifference( double phase1, double phase2 );
112 
116 double PaQa_MeasureArea( float *buffer, int numFrames, int stride );
117 
121 double PaQa_MeasureCrossingSlope( float *buffer, int numFrames );
122 
123 
127 void PaQa_SetupSineGenerator( PaQaSineGenerator *generator, double frequency, double amplitude, double frameRate );
128 
129 /*================================================================*/
130 /*================= Recordings ===================================*/
131 /*================================================================*/
135  int PaQa_InitializeRecording( PaQaRecording *recording, int maxSamples, int sampleRate );
136 
140  void PaQa_TerminateRecording( PaQaRecording *recording );
141 
145 void PaQa_FilterRecording( PaQaRecording *input, PaQaRecording *output, BiquadFilter *filter );
146 
147 
148 int PaQa_SaveRecordingToWaveFile( PaQaRecording *recording, const char *filename );
149 
153 int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numSamples, int stride );
154 
156 int PaQa_WriteSilence( PaQaRecording *recording, int numSamples );
157 
158 int PaQa_RecordFreeze( PaQaRecording *recording, int numSamples );
159 
160 double PaQa_CorrelateSine( PaQaRecording *recording, double frequency, double frameRate,
161  int startFrame, int numSamples, double *phasePtr );
162 
163 double PaQa_FindFirstMatch( PaQaRecording *recording, float *buffer, int numSamples, double tolerance );
164 
170  double frequency, double frameRate,
171  int startFrame, int numFrames );
172 
173 double PaQa_MeasureRootMeanSquare( float *buffer, int numFrames );
174 
179 double PaQa_CompareAmplitudes( PaQaRecording *recording, int startAt, float *buffer, int numSamples );
180 
185 int PaQa_AnalyseRecording( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult );
186 
187 #endif /* _AUDIO_ANALYZER_H */
void PaQa_WriteSine(float *buffer, int numSamples, int stride, double frequency, double amplitude)
int PaQa_SaveRecordingToWaveFile(PaQaRecording *recording, const char *filename)
Definition: audio_analyzer.c:206
int PaQa_AnalyseRecording(PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult)
Definition: audio_analyzer.c:685
double frequency
Definition: audio_analyzer.h:51
struct PaQaTestTone_s PaQaTestTone
void PaQa_FilterRecording(PaQaRecording *input, PaQaRecording *output, BiquadFilter *filter)
Definition: audio_analyzer.c:340
double droppedFramesPosition
Definition: audio_analyzer.h:84
int PaQa_WriteRecording(PaQaRecording *recording, float *buffer, int numFrames, int stride)
Definition: audio_analyzer.c:138
void PaQa_SetupSineGenerator(PaQaSineGenerator *generator, double frequency, double amplitude, double frameRate)
Definition: audio_analyzer.c:69
double PaQa_CorrelateSine(PaQaRecording *recording, double frequency, double frameRate, int startFrame, int numFrames, double *phasePtr)
Definition: audio_analyzer.c:299
double amplitude
Definition: audio_analyzer.h:52
void PaQa_GenerateCrack(float *buffer, int numSamples, int stride)
int maxFrames
Definition: audio_analyzer.h:59
Definition: audio_analyzer.h:66
struct PaQaAnalysisResult_s PaQaAnalysisResult
int PaQa_WriteSilence(PaQaRecording *recording, int numFrames)
Definition: audio_analyzer.c:160
double numDroppedFrames
Definition: audio_analyzer.h:83
int PaQa_RecordFreeze(PaQaRecording *recording, int numFrames)
Definition: audio_analyzer.c:181
struct PaQaRecording_s PaQaRecording
int startDelay
Definition: audio_analyzer.h:69
double PaQa_ComputePhaseDifference(double phase1, double phase2)
Definition: audio_analyzer.c:463
struct PaQaSineGenerator_s PaQaSineGenerator
double phaseIncrement
Definition: audio_analyzer.h:50
double latency
Definition: audio_analyzer.h:79
double PaQa_MeasureSineAmplitudeBySlope(PaQaRecording *recording, double frequency, double frameRate, int startFrame, int numFrames)
Definition: audio_analyzer.c:287
double addedFramesPosition
Definition: audio_analyzer.h:86
double PaQa_MeasureCrossingSlope(float *buffer, int numFrames)
Definition: audio_analyzer.c:251
Definition: audio_analyzer.h:75
void PaQa_EraseBuffer(float *buffer, int numFrames, int samplesPerFrame)
Definition: audio_analyzer.c:58
Definition: audio_analyzer.h:47
Definition: audio_analyzer.h:56
Definition: biquad_filter.h:14
double amplitudeRatio
Definition: audio_analyzer.h:80
int sampleRate
Definition: audio_analyzer.h:63
double popAmplitude
Definition: audio_analyzer.h:81
double PaQa_GetNthFrequency(double baseFrequency, int index)
Definition: audio_analyzer.c:51
double frequency
Definition: audio_analyzer.h:71
void PaQa_MixSine(PaQaSineGenerator *generator, float *buffer, int numSamples, int stride)
Definition: audio_analyzer.c:78
void PaQa_TerminateRecording(PaQaRecording *recording)
Definition: audio_analyzer.c:127
double popPosition
Definition: audio_analyzer.h:82
float * buffer
Definition: audio_analyzer.h:60
int PaQa_InitializeRecording(PaQaRecording *recording, int maxFrames, int frameRate)
Definition: audio_analyzer.c:114
double sampleRate
Definition: audio_analyzer.h:70
char buffer[NUM_BYTES]
Definition: recplay.c:26
int valid
Definition: audio_analyzer.h:77
double PaQa_MeasureRootMeanSquare(float *buffer, int numFrames)
Definition: audio_analyzer.c:428
double amplitude
Definition: audio_analyzer.h:72
double PaQa_CompareAmplitudes(PaQaRecording *recording, int startAt, float *buffer, int numFrames)
Definition: audio_analyzer.c:447
double PaQa_MeasureArea(float *buffer, int numFrames, int stride)
Definition: audio_analyzer.c:414
int numFrames
Definition: audio_analyzer.h:62
double phase
Definition: audio_analyzer.h:49
double numAddedFrames
Definition: audio_analyzer.h:85
double PaQa_FindFirstMatch(PaQaRecording *recording, float *buffer, int numFrames, double threshold)
Definition: audio_analyzer.c:352
int samplesPerFrame
Definition: audio_analyzer.h:68