PortAudio 2.0
paqa.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include "portaudio.h"
#include "qa_tools.h"
#include "paqa_tools.h"
#include "audio_analyzer.h"
#include "test_audio_analyzer.h"

Data Structures

struct  TestParameters_s
 
struct  LoopbackContext_s
 
struct  UserOptions_s
 

Macros

#define MAX_NUM_GENERATORS   (8)
 
#define MAX_NUM_RECORDINGS   (8)
 
#define MAX_BACKGROUND_NOISE_RMS   (0.0004)
 
#define LOOPBACK_DETECTION_DURATION_SECONDS   (0.8)
 
#define DEFAULT_FRAMES_PER_BUFFER   (0)
 
#define PAQA_WAIT_STREAM_MSEC   (100)
 
#define PAQA_TEST_DURATION   (1.2)
 
#define PAQA_FLAG_TWO_STREAMS   (1<<0)
 
#define PAQA_FLAG_USE_BLOCKING_IO   (1<<1)
 
#define BIG_BUFFER_SIZE   (sizeof(float) * 2 * 2 * 1024)
 
#define MAX_CONVERSION_SAMPLES   (2 * 32 * 1024)
 
#define CONVERSION_BUFFER_SIZE   (sizeof(float) * 2 * MAX_CONVERSION_SAMPLES)
 

Typedefs

typedef struct TestParameters_s TestParameters
 
typedef struct LoopbackContext_s LoopbackContext
 
typedef struct UserOptions_s UserOptions
 

Functions

int PaQa_RunLoopbackFullDuplex (LoopbackContext *loopbackContext)
 
int PaQa_WaitForStream (LoopbackContext *loopbackContext)
 
int PaQa_RunLoopbackHalfDuplex (LoopbackContext *loopbackContext)
 
int PaQa_RunInputOnly (LoopbackContext *loopbackContext)
 
int PaQa_RunLoopbackHalfDuplexBlockingIO (LoopbackContext *loopbackContext)
 
int PaQa_RunLoopbackFullDuplexBlockingIO (LoopbackContext *loopbackContext)
 
int PaQa_RunLoopback (LoopbackContext *loopbackContext)
 
int PaQa_CheckForClippedLoopback (LoopbackContext *loopbackContextPtr)
 
int PaQa_MeasureBackgroundNoise (LoopbackContext *loopbackContextPtr, double *rmsPtr)
 
int PaQa_CheckForLoopBack (UserOptions *userOptions, PaDeviceIndex inputDevice, PaDeviceIndex outputDevice)
 
int TestSampleFormatConversion (void)
 
void usage (const char *name)
 
int main (int argc, char **argv)
 

Variables

int g_testsPassed = 0
 
int g_testsFailed = 0
 
const char * s_FlagOnNames []
 
const char * s_FlagOffNames []
 

Macro Definition Documentation

◆ BIG_BUFFER_SIZE

#define BIG_BUFFER_SIZE   (sizeof(float) * 2 * 2 * 1024)

◆ CONVERSION_BUFFER_SIZE

#define CONVERSION_BUFFER_SIZE   (sizeof(float) * 2 * MAX_CONVERSION_SAMPLES)

◆ DEFAULT_FRAMES_PER_BUFFER

#define DEFAULT_FRAMES_PER_BUFFER   (0)

◆ LOOPBACK_DETECTION_DURATION_SECONDS

#define LOOPBACK_DETECTION_DURATION_SECONDS   (0.8)

Referenced by PaQa_CheckForLoopBack().

◆ MAX_BACKGROUND_NOISE_RMS

#define MAX_BACKGROUND_NOISE_RMS   (0.0004)

Referenced by PaQa_CheckForLoopBack().

◆ MAX_CONVERSION_SAMPLES

#define MAX_CONVERSION_SAMPLES   (2 * 32 * 1024)

◆ MAX_NUM_GENERATORS

#define MAX_NUM_GENERATORS   (8)

◆ MAX_NUM_RECORDINGS

#define MAX_NUM_RECORDINGS   (8)

◆ PAQA_FLAG_TWO_STREAMS

#define PAQA_FLAG_TWO_STREAMS   (1<<0)

◆ PAQA_FLAG_USE_BLOCKING_IO

#define PAQA_FLAG_USE_BLOCKING_IO   (1<<1)

Referenced by PaQa_RunLoopback().

◆ PAQA_TEST_DURATION

#define PAQA_TEST_DURATION   (1.2)

Referenced by PaQa_WaitForStream().

◆ PAQA_WAIT_STREAM_MSEC

#define PAQA_WAIT_STREAM_MSEC   (100)

Typedef Documentation

◆ LoopbackContext

◆ TestParameters

Parameters that describe a single test run.

◆ UserOptions

typedef struct UserOptions_s UserOptions

Function Documentation

◆ main()

◆ PaQa_CheckForClippedLoopback()

◆ PaQa_CheckForLoopBack()

◆ PaQa_MeasureBackgroundNoise()

int PaQa_MeasureBackgroundNoise ( LoopbackContext * loopbackContextPtr,
double * rmsPtr )

◆ PaQa_RunInputOnly()

int PaQa_RunInputOnly ( LoopbackContext * loopbackContext)

Open one audio streams, just for input. Record background level. Then close the stream.

Returns
0 if OK or negative error.

References LoopbackContext_s::done, Pa_CloseStream(), Pa_OpenStream(), Pa_StartStream(), Pa_StopStream(), paClipOff, paNoError, PaQa_WaitForStream(), LoopbackContext_s::test, and test().

Referenced by PaQa_MeasureBackgroundNoise().

◆ PaQa_RunLoopback()

◆ PaQa_RunLoopbackFullDuplex()

int PaQa_RunLoopbackFullDuplex ( LoopbackContext * loopbackContext)

Open a full duplex audio stream. Generate sine waves on the output channels and record the input channels. Then close the stream.

Returns
0 if OK or negative error.

References LoopbackContext_s::done, Pa_CloseStream(), Pa_OpenStream(), Pa_Sleep(), Pa_StartStream(), Pa_StopStream(), paClipOff, paNoError, PAQA_WAIT_STREAM_MSEC, LoopbackContext_s::test, and test().

Referenced by PaQa_RunLoopback().

◆ PaQa_RunLoopbackFullDuplexBlockingIO()

int PaQa_RunLoopbackFullDuplexBlockingIO ( LoopbackContext * loopbackContext)

Open one audio stream with non-blocking IO. Generate sine waves on the output channels and record the input channels. Then close the stream.

Returns
0 if OK or negative error.

References Pa_CloseStream(), Pa_OpenStream(), Pa_StartStream(), Pa_StopStream(), paClipOff, paNoError, LoopbackContext_s::test, and test().

Referenced by PaQa_RunLoopback().

◆ PaQa_RunLoopbackHalfDuplex()

int PaQa_RunLoopbackHalfDuplex ( LoopbackContext * loopbackContext)

Open two audio streams, one for input and one for output. Generate sine waves on the output channels and record the input channels. Then close the stream.

Returns
0 if OK or negative error.

References LoopbackContext_s::done, Pa_CloseStream(), Pa_OpenStream(), Pa_StartStream(), Pa_StopStream(), paNoError, PaQa_WaitForStream(), LoopbackContext_s::test, and test().

Referenced by PaQa_RunLoopback().

◆ PaQa_RunLoopbackHalfDuplexBlockingIO()

int PaQa_RunLoopbackHalfDuplexBlockingIO ( LoopbackContext * loopbackContext)

Open two audio streams with non-blocking IO. Generate sine waves on the output channels and record the input channels. Then close the stream.

Returns
0 if OK or negative error.

References Pa_CloseStream(), Pa_OpenStream(), Pa_StartStream(), Pa_StopStream(), paClipOff, paNoError, LoopbackContext_s::test, and test().

Referenced by PaQa_RunLoopback().

◆ PaQa_WaitForStream()

int PaQa_WaitForStream ( LoopbackContext * loopbackContext)

Open two audio streams, one for input and one for output. Generate sine waves on the output channels and record the input channels. Then close the stream.

Returns
0 if OK or paTimedOut.

References LoopbackContext_s::done, Pa_Sleep(), PAQA_TEST_DURATION, PAQA_WAIT_STREAM_MSEC, and paTimedOut.

Referenced by PaQa_RunInputOnly(), and PaQa_RunLoopbackHalfDuplex().

◆ TestSampleFormatConversion()

int TestSampleFormatConversion ( void )

◆ usage()

void usage ( const char * name)

References usage().

Referenced by main(), and usage().

Variable Documentation

◆ g_testsFailed

int g_testsFailed = 0

Referenced by main().

◆ g_testsPassed

int g_testsPassed = 0

Accumulate counts for how many tests pass or fail.

Referenced by main().

◆ s_FlagOffNames

const char* s_FlagOffNames[]
Initial value:
=
{
"One Stream (Full Duplex)",
"Callback"
}

◆ s_FlagOnNames

const char* s_FlagOnNames[]
Initial value:
=
{
"Two Streams (Half Duplex)",
"Blocking Read/Write"
}