PortAudio is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

portaudio

Commit 1097

User picture
  • Author: rossb
  • 2006-08-26 01:27 (over 7 years ago)

added guide to source code doxygen page with groups of pages

Files Affected

 
10961097
24
- Implementation status is documented here:
24
- Implementation status is documented here:
25
http://www.portaudio.com/docs/proposals/status.html
25
http://www.portaudio.com/docs/proposals/status.html
26
 
26
 
 
 
27
- @ref srcguide
 
 
28
 
27
- The @ref License
29
- The @ref License
28
 
30
 
29
 
31
 
Show contents
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Allocation Group implementation.
43
 @brief Allocation Group implementation.
42
*/
44
*/
43
 
45
 
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Allocation Group prototypes. An Allocation Group makes it easy to
45
 @brief Allocation Group prototypes. An Allocation Group makes it easy to
44
 allocate multiple blocks of memory and free them all simultanously.
46
 allocate multiple blocks of memory and free them all simultanously.
45
 
47
 
10961097
37
 */
37
 */
38
 
38
 
39
/** @file
39
/** @file
 
 
40
 @ingroup common_src
 
 
41
 
40
 @brief Conversion functions implementations.
42
 @brief Conversion functions implementations.
41
 
43
 
42
 If the C9x function lrintf() is available, define PA_USE_C99_LRINTF to use it
44
 If the C9x function lrintf() is available, define PA_USE_C99_LRINTF to use it
10961097
39
 */
39
 */
40
 
40
 
41
/** @file
41
/** @file
 
 
42
 @ingroup common_src
 
 
43
 
42
 @brief Conversion functions used to convert buffers of samples from one
44
 @brief Conversion functions used to convert buffers of samples from one
43
 format to another.
45
 format to another.
44
*/
46
*/
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Functions to assist in measuring the CPU utilization of a callback
43
 @brief Functions to assist in measuring the CPU utilization of a callback
42
 stream. Used to implement the Pa_GetStreamCpuLoad() function.
44
 stream. Used to implement the Pa_GetStreamCpuLoad() function.
43
 
45
 
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Functions to assist in measuring the CPU utilization of a callback
45
 @brief Functions to assist in measuring the CPU utilization of a callback
44
 stream. Used to implement the Pa_GetStreamCpuLoad() function.
46
 stream. Used to implement the Pa_GetStreamCpuLoad() function.
45
*/
47
*/
10961097
37
 */
37
 */
38
 
38
 
39
/** @file
39
/** @file
 
 
40
 @ingroup common_src
 
 
41
 
40
 @brief Functions for generating dither noise
42
 @brief Functions for generating dither noise
41
*/
43
*/
42
 
44
 
10961097
39
 */
39
 */
40
 
40
 
41
/** @file
41
/** @file
 
 
42
 @ingroup common_src
 
 
43
 
42
 @brief Functions for generating dither noise
44
 @brief Functions for generating dither noise
43
*/
45
*/
44
 
46
 
10961097
39
 */
39
 */
40
 
40
 
41
/** @file
41
/** @file
 
 
42
 @ingroup common_src
 
 
43
 
42
 @brief Configure endianness symbols for the target processor.
44
 @brief Configure endianness symbols for the target processor.
43
 
45
 
44
 Arrange for either the PA_LITTLE_ENDIAN or PA_BIG_ENDIAN preprocessor symbols
46
 Arrange for either the PA_LITTLE_ENDIAN or PA_BIG_ENDIAN preprocessor symbols
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Implements public PortAudio API, checks some errors, forwards to
43
 @brief Implements public PortAudio API, checks some errors, forwards to
42
 host API implementations.
44
 host API implementations.
43
 
45
 
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Interface used by pa_front to virtualize functions which operate on
45
 @brief Interface used by pa_front to virtualize functions which operate on
44
 host APIs.
46
 host APIs.
45
*/
47
*/
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Buffer Processor implementation.
43
 @brief Buffer Processor implementation.
42
 
44
 
43
 The code in this file is not optimised yet - although it's not clear that
45
 The code in this file is not optimised yet - although it's not clear that
10961097
39
 */
39
 */
40
 
40
 
41
/** @file
41
/** @file
 
 
42
 @ingroup common_src
 
 
43
 
42
 @brief Buffer Processor prototypes. A Buffer Processor performs buffer length
44
 @brief Buffer Processor prototypes. A Buffer Processor performs buffer length
43
 adaption, coordinates sample format conversion, and interleaves/deinterleaves
45
 adaption, coordinates sample format conversion, and interleaves/deinterleaves
44
 channels.
46
 channels.
10961097
39
 */
39
 */
40
 
40
 
41
/** @file
41
/** @file
 
 
42
 @ingroup common_src
 
 
43
 
42
 @brief Skeleton implementation of support for a host API.
44
 @brief Skeleton implementation of support for a host API.
43
 
45
 
44
 @note This file is provided as a starting point for implementing support for
46
 @note This file is provided as a starting point for implementing support for
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Interface used by pa_front to virtualize functions which operate on
43
 @brief Interface used by pa_front to virtualize functions which operate on
42
 streams.
44
 streams.
43
*/
45
*/
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Interface used by pa_front to virtualize functions which operate on
45
 @brief Interface used by pa_front to virtualize functions which operate on
44
 streams.
46
 streams.
45
*/
47
*/
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup common_src
 
 
42
 
41
 @brief Event trace mechanism for debugging.
43
 @brief Event trace mechanism for debugging.
42
*/
44
*/
43
 
45
 
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Event trace mechanism for debugging.
45
 @brief Event trace mechanism for debugging.
44
 
46
 
45
 Allows data to be written to the buffer at interrupt time and dumped later.
47
 Allows data to be written to the buffer at interrupt time and dumped later.
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
 @brief Definition of 16 and 32 bit integer types (PaInt16, PaInt32 etc)
45
 @brief Definition of 16 and 32 bit integer types (PaInt16, PaInt32 etc)
44
 
46
 
45
 SIZEOF_SHORT, SIZEOF_INT and SIZEOF_LONG are set by the configure script
47
 SIZEOF_SHORT, SIZEOF_INT and SIZEOF_LONG are set by the configure script
10961097
40
 */
40
 */
41
 
41
 
42
/** @file
42
/** @file
 
 
43
 @ingroup common_src
 
 
44
 
43
    @brief Prototypes for utility functions used by PortAudio implementations.
45
    @brief Prototypes for utility functions used by PortAudio implementations.
44
 
46
 
45
    @todo Document and adhere to the alignment guarantees provided by
47
    @todo Document and adhere to the alignment guarantees provided by
10961097
41
 * license above.
41
 * license above.
42
 */
42
 */
43
 
43
 
 
 
44
/**
 
 
45
 @file
 
 
46
 @ingroup hostapi_src
 
 
47
*/
 
 
48
 
44
#define ALSA_PCM_NEW_HW_PARAMS_API
49
#define ALSA_PCM_NEW_HW_PARAMS_API
45
#define ALSA_PCM_NEW_SW_PARAMS_API
50
#define ALSA_PCM_NEW_SW_PARAMS_API
46
#include <alsa/asoundlib.h>
51
#include <alsa/asoundlib.h>
10961097
46
 */
46
 */
47
 
47
 
48
/** @file
48
/** @file
 
 
49
 @ingroup hostapi_src
49
 @brief Host API implementation supporting AudioScience cards 
50
 @brief Host API implementation supporting AudioScience cards 
50
        via the Linux HPI interface.
51
        via the Linux HPI interface.
51
 
52
 
10961097
71
*/
71
*/
72
 
72
 
73
/** @file
73
/** @file
 
 
74
    @ingroup hostapi_src
74
 
75
 
75
    Note that specific support for paInputUnderflow, paOutputOverflow and
76
    Note that specific support for paInputUnderflow, paOutputOverflow and
76
    paNeverDropInput is not necessary or possible with this driver due to the
77
    paNeverDropInput is not necessary or possible with this driver due to the
10961097
53
 
53
 
54
/**
54
/**
55
 @file pa_mac_core
55
 @file pa_mac_core
 
 
56
 @ingroup hostapi_src
56
 @author Bjorn Roche
57
 @author Bjorn Roche
57
 @brief AUHAL implementation of PortAudio
58
 @brief AUHAL implementation of PortAudio
58
*/
59
*/
10961097
51
 * license above.
51
 * license above.
52
 */
52
 */
53
 
53
 
54
/* This file contains the implementation
54
/**
55
 * required for blocking I/O. It is separated from pa_mac_core.c simply to ease
55
 @file
56
 * development. */
56
 @ingroup hostaip_src
57
 
57
 
 
 
58
 This file contains the implementation
 
 
59
 required for blocking I/O. It is separated from pa_mac_core.c simply to ease
 
 
60
 development.
 
 
61
*/
 
 
62
 
58
#include "pa_mac_core_blocking.h"
63
#include "pa_mac_core_blocking.h"
59
#include "pa_mac_core_internal.h"
64
#include "pa_mac_core_internal.h"
60
#include <assert.h>
65
#include <assert.h>
10961097
51
 * license above.
51
 * license above.
52
 */
52
 */
53
 
53
 
 
 
54
/**
 
 
55
 @file
 
 
56
 @ingroup hostaip_src
 
 
57
*/
 
 
58
 
54
#ifndef PA_MAC_CORE_BLOCKING_H_
59
#ifndef PA_MAC_CORE_BLOCKING_H_
55
#define PA_MAC_CORE_BLOCKING_H_
60
#define PA_MAC_CORE_BLOCKING_H_
56
 
61
 
10961097
53
 
53
 
54
/**
54
/**
55
 @file pa_mac_core
55
 @file pa_mac_core
 
 
56
 @ingroup hostapi_src
56
 @author Bjorn Roche
57
 @author Bjorn Roche
57
 @brief AUHAL implementation of PortAudio
58
 @brief AUHAL implementation of PortAudio
58
*/
59
*/
10961097
51
 * license above.
51
 * license above.
52
 */
52
 */
53
 
53
 
 
 
54
/**
 
 
55
 @file
 
 
56
 @ingroup hostapi_src
 
 
57
*/
 
 
58
 
54
#include "pa_mac_core_utilities.h"
59
#include "pa_mac_core_utilities.h"
55
 
60
 
56
PaError PaMacCore_SetUnixError( int err, int line )
61
PaError PaMacCore_SetUnixError( int err, int line )
10961097
51
 * license above.
51
 * license above.
52
 */
52
 */
53
 
53
 
 
 
54
/**
 
 
55
 @file
 
 
56
 @ingroup hostapi_src
 
 
57
*/
54
 
58
 
55
#ifndef PA_MAC_CORE_UTILITIES_H__
59
#ifndef PA_MAC_CORE_UTILITIES_H__
56
#define PA_MAC_CORE_UTILITIES_H__
60
#define PA_MAC_CORE_UTILITIES_H__
10961097
44
 * license above.
44
 * license above.
45
 */
45
 */
46
 
46
 
 
 
47
/**
 
 
48
 @file
 
 
49
 @ingroup hostapi_src
 
 
50
*/
 
 
51
 
47
#include <stdio.h>
52
#include <stdio.h>
48
#include <stdlib.h>
53
#include <stdlib.h>
49
#include <math.h>
54
#include <math.h>
10961097
51
 * license above.
51
 * license above.
52
 */
52
 */
53
 
53
 
 
 
54
/**
 
 
55
 @file
 
 
56
 @ingroup hostapi_src
 
 
57
*/
 
 
58
 
54
#include <stdio.h>
59
#include <stdio.h>
55
#include <stdlib.h>
60
#include <stdlib.h>
56
#include <math.h>
61
#include <math.h>
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup hostaip_src
41
 
42
 
42
    @todo implement paInputOverflow callback status flag
43
    @todo implement paInputOverflow callback status flag
43
 
44
 
10961097
39
 * license above.
39
 * license above.
40
 */
40
 */
41
 
41
 
 
 
42
/**
 
 
43
 @file
 
 
44
 @ingroup hostaip_src
 
 
45
*/
 
 
46
 
42
#include "pa_win_ds_dynlink.h"
47
#include "pa_win_ds_dynlink.h"
43
 
48
 
44
PaWinDsDSoundEntryPoints paWinDsDSoundEntryPoints = { 0, 0, 0, 0, 0, 0, 0 };
49
PaWinDsDSoundEntryPoints paWinDsDSoundEntryPoints = { 0, 0, 0, 0, 0, 0, 0 };
10961097
39
 * license above.
39
 * license above.
40
 */
40
 */
41
 
41
 
 
 
42
/**
 
 
43
 @file
 
 
44
 @ingroup hostaip_src
 
 
45
*/
42
 
46
 
43
#ifndef INCLUDED_PA_DSOUND_DYNLINK_H
47
#ifndef INCLUDED_PA_DSOUND_DYNLINK_H
44
#define INCLUDED_PA_DSOUND_DYNLINK_H
48
#define INCLUDED_PA_DSOUND_DYNLINK_H
10961097
42
 * license above.
42
 * license above.
43
 */
43
 */
44
 
44
 
 
 
45
/**
 
 
46
 @file
 
 
47
 @ingroup hostaip_src
 
 
48
*/
 
 
49
 
45
#include <string.h>
50
#include <string.h>
46
#include <regex.h>
51
#include <regex.h>
47
#include <stdlib.h>
52
#include <stdlib.h>
10961097
42
 * license above.
42
 * license above.
43
 */
43
 */
44
 
44
 
 
 
45
/**
 
 
46
 @file
 
 
47
 @ingroup hostaip_src
 
 
48
*/
 
 
49
 
45
#include <stdio.h>
50
#include <stdio.h>
46
#include <string.h>
51
#include <string.h>
47
#include <math.h>
52
#include <math.h>
10961097
37
 */
37
 */
38
 
38
 
39
/** @file
39
/** @file
 
 
40
 @ingroup hostaip_src
40
 @brief WASAPI implementation of support for a host API.
41
 @brief WASAPI implementation of support for a host API.
41
 
42
 
42
 @note This file is provided as a starting point for implementing support for
43
 @note This file is provided as a starting point for implementing support for
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup hostaip_src
41
 @brief Portaudio WDM-KS host API.
42
 @brief Portaudio WDM-KS host API.
42
 
43
 
43
 @note This is the implementation of the Portaudio host API using the
44
 @note This is the implementation of the Portaudio host API using the
10961097
62
*/
62
*/
63
 
63
 
64
/** @file
64
/** @file
65
 
65
    @ingroup hostaip_src
 
 
66
 
66
    @todo Fix buffer catch up code, can sometimes get stuck (perhaps fixed now,
67
    @todo Fix buffer catch up code, can sometimes get stuck (perhaps fixed now,
67
            needs to be reviewed and tested.)
68
            needs to be reviewed and tested.)
68
 
69
 
10961097
37
 */
37
 */
38
 
38
 
39
/** @file
39
/** @file
 
 
40
 @ingroup macosx_src
40
Mac OS host API initialization function table.
41
Mac OS host API initialization function table.
41
*/
42
*/
42
 
43
 
10961097
36
 * license above.
36
 * license above.
37
 */
37
 */
38
 
38
 
 
 
39
/** @file
 
 
40
 @ingroup unix_src
 
 
41
*/
39
 
42
 
40
#include "pa_hostapi.h"
43
#include "pa_hostapi.h"
41
 
44
 
10961097
37
 * license above.
37
 * license above.
38
 */
38
 */
39
 
39
 
 
 
40
/** @file
 
 
41
 @ingroup unix_src
 
 
42
*/
40
 
43
 
41
#include <pthread.h>
44
#include <pthread.h>
42
#include <unistd.h>
45
#include <unistd.h>
10961097
37
 * license above.
37
 * license above.
38
 */
38
 */
39
 
39
 
 
 
40
/** @file
 
 
41
 @ingroup unix_src
 
 
42
*/
 
 
43
 
40
#ifndef PA_UNIX_UTIL_H
44
#ifndef PA_UNIX_UTIL_H
41
#define PA_UNIX_UTIL_H
45
#define PA_UNIX_UTIL_H
42
 
46
 
10961097
37
 */
37
 */
38
 
38
 
39
/** @file
39
/** @file
 
 
40
 @ingroup win_src
 
 
41
 
40
    Win32 host API initialization function table.
42
    Win32 host API initialization function table.
41
 
43
 
42
    @todo Consider using PA_USE_WMME etc instead of PA_NO_WMME. This is what
44
    @todo Consider using PA_USE_WMME etc instead of PA_NO_WMME. This is what
10961097
38
 */
38
 */
39
 
39
 
40
/** @file
40
/** @file
 
 
41
 @ingroup win_src
 
 
42
 
41
 Win32 platform-specific support functions.
43
 Win32 platform-specific support functions.
42
 
44
 
43
    @todo Implement workaround for QueryPerformanceCounter() skipping forward
45
    @todo Implement workaround for QueryPerformanceCounter() skipping forward
10961097
33
 * license above.
33
 * license above.
34
 */
34
 */
35
 
35
 
 
 
36
/** @file
 
 
37
 @ingroup win_src
 
 
38
*/
 
 
39
 
36
#include "pa_x86_plain_converters.h"
40
#include "pa_x86_plain_converters.h"
37
 
41
 
38
#include "pa_converters.h"
42
#include "pa_converters.h"
10961097
33
 * license above.
33
 * license above.
34
 */
34
 */
35
 
35
 
 
 
36
/** @file
 
 
37
 @ingroup win_src
 
 
38
*/
 
 
39
 
36
#ifndef PA_X86_PLAIN_CONVERTERS_H
40
#ifndef PA_X86_PLAIN_CONVERTERS_H
37
#define PA_X86_PLAIN_CONVERTERS_H
41
#define PA_X86_PLAIN_CONVERTERS_H
38
 
42
 
10961097
1
/** @file pa_devs.c
1
/** @file pa_devs.c
 
 
2
    @ingroup test_src
2
    @brief List available devices, including device information.
3
    @brief List available devices, including device information.
3
    @author Phil Burk http://www.softsynth.com
4
    @author Phil Burk http://www.softsynth.com
4
 
5
 
10961097
1
/** @file pa_fuzz.c
1
/** @file pa_fuzz.c
2
    @brief Distort input like a fuzz boz.
2
    @ingroup test_src
 
 
3
    @brief Distort input like a fuzz box.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
5
/*
6
/*
10961097
1
/** @file pa_minlat.c
1
/** @file pa_minlat.c
 
 
2
    @ingroup test_src
2
    @brief Experiment with different numbers of buffers to determine the
3
    @brief Experiment with different numbers of buffers to determine the
3
    minimum latency for a computer.
4
    minimum latency for a computer.
4
    @author Phil Burk  http://www.softsynth.com
5
    @author Phil Burk  http://www.softsynth.com
10961097
1
/** @file paqa_devs.c
1
/** @file paqa_devs.c
 
 
2
    @ingroup test_src
2
    @brief Self Testing Quality Assurance app for PortAudio
3
    @brief Self Testing Quality Assurance app for PortAudio
3
     Try to open each device and run through all the
4
     Try to open each device and run through all the
4
     possible configurations.
5
     possible configurations.
10961097
1
/** @file paqa_errs.c
1
/** @file paqa_errs.c
 
 
2
    @ingroup test_src
2
    @brief Self Testing Quality Assurance app for PortAudio
3
    @brief Self Testing Quality Assurance app for PortAudio
3
    Do lots of bad things to test error reporting.
4
    Do lots of bad things to test error reporting.
4
    @author Phil Burk  http://www.softsynth.com
5
    @author Phil Burk  http://www.softsynth.com
10961097
1
/** @file patest1.c
1
/** @file patest1.c
 
 
2
    @ingroup test_src
2
    @brief Ring modulate the audio input with a sine wave for 20 seconds.
3
    @brief Ring modulate the audio input with a sine wave for 20 seconds.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
*/
5
*/
10961097
1
/** @file patest_buffer.c
1
/** @file patest_buffer.c
 
 
2
    @ingroup test_src
2
    @brief Test opening streams with different buffer sizes.
3
    @brief Test opening streams with different buffer sizes.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_callbackstop.c
1
/** @file patest_callbackstop.c
 
 
2
    @ingroup test_src
2
    @brief Test the paComplete callback result code.
3
    @brief Test the paComplete callback result code.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
*/
5
*/
10961097
1
/** @file patest_clip.c
1
/** @file patest_clip.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave for several seconds at an amplitude 
3
    @brief Play a sine wave for several seconds at an amplitude 
3
    that would require clipping.
4
    that would require clipping.
4
 
5
 
10961097
1
/** @file patest_dither.c
1
/** @file patest_dither.c
 
 
2
    @ingroup test_src
2
    @brief Attempt to hear difference between dithered and non-dithered signal.
3
    @brief Attempt to hear difference between dithered and non-dithered signal.
3
 
4
 
4
    This only has an effect if the native format is 16 bit.
5
    This only has an effect if the native format is 16 bit.
10961097
1
/** @file patest_hang.c
1
/** @file patest_hang.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine then hang audio callback to test watchdog.
3
    @brief Play a sine then hang audio callback to test watchdog.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Phil Burk <philburk@softsynth.com>
5
    @author Phil Burk <philburk@softsynth.com>
10961097
1
/** @file patest_in_overflow.c
1
/** @file patest_in_overflow.c
 
 
2
    @ingroup test_src
2
    @brief Count input overflows (using paInputOverflow flag) under 
3
    @brief Count input overflows (using paInputOverflow flag) under 
3
    overloaded and normal conditions.
4
    overloaded and normal conditions.
4
    This test uses the same method to overload the stream as does
5
    This test uses the same method to overload the stream as does
10961097
1
/** @file
1
/** @file
 
 
2
    @ingroup test_src
2
    @brief Hear the latency caused by big buffers.
3
    @brief Hear the latency caused by big buffers.
3
    Play a sine wave and change frequency based on letter input.
4
    Play a sine wave and change frequency based on letter input.
4
    @author Phil Burk <philburk@softsynth.com>, and Darren Gibbs
5
    @author Phil Burk <philburk@softsynth.com>, and Darren Gibbs
10961097
1
/** @file patest_leftright.c
1
/** @file patest_leftright.c
 
 
2
    @ingroup test_src
2
    @brief Play different tone sine waves that 
3
    @brief Play different tone sine waves that 
3
        alternate between left and right channel.
4
        alternate between left and right channel.
4
 
5
 
10961097
1
/** @file patest_longsine.c
1
/** @file patest_longsine.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave until ENTER hit.
3
    @brief Play a sine wave until ENTER hit.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_many.c
1
/** @file patest_many.c
 
 
2
    @ingroup test_src
2
    @brief Start and stop the PortAudio Driver multiple times.
3
    @brief Start and stop the PortAudio Driver multiple times.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_maxsines.c
1
/** @file patest_maxsines.c
 
 
2
    @ingroup test_src
2
    @brief How many sine waves can we calculate and play in less than 80% CPU Load.
3
    @brief How many sine waves can we calculate and play in less than 80% CPU Load.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Phil Burk <philburk@softsynth.com>
5
    @author Phil Burk <philburk@softsynth.com>
10961097
 
 
1
/** @file patest_mono.c
 
 
2
    @ingroup test_src
 
 
3
    @brief Play a monophonic sine wave using the Portable Audio api for several seconds.
 
 
4
    @author Phil Burk  http://www.softsynth.com
 
 
5
*/
1
/*
6
/*
2
 * $Id$
7
 * $Id$
3
 * patest_sine.c
 
 
4
 * Play a monophonic sine wave using the Portable Audio api for several seconds.
 
 
5
 *
8
 *
6
 * Authors:
9
 * Authors:
7
 *    Ross Bencina <rossb@audiomulch.com>
10
 *    Ross Bencina <rossb@audiomulch.com>
10961097
 
 
1
/** @file pa_test_mono_asio_channel_select.c
 
 
2
    @ingroup test_src
 
 
3
    @brief Play a monophonic sine wave on a specific ASIO channel.
 
 
4
    @author Ross Bencina <rossb@audiomulch.com>
 
 
5
    @author Phil Burk <philburk@softsynth.com>
 
 
6
*/
1
/*
7
/*
2
 * $Id$
8
 * $Id$
3
 * patest_sine.c
 
 
4
 * Play a monophonic sine wave using the Portable Audio api for several seconds.
 
 
5
 *
9
 *
6
 * Authors:
10
 * Authors:
7
 *    Ross Bencina <rossb@audiomulch.com>
11
 *    Ross Bencina <rossb@audiomulch.com>
10961097
1
/** @file patest_multi_sine.c
1
/** @file patest_multi_sine.c
 
 
2
    @ingroup test_src
2
    @brief Play a different sine wave on each channel.
3
    @brief Play a different sine wave on each channel.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_out_underflow.c
1
/** @file patest_out_underflow.c
 
 
2
    @ingroup test_src
2
    @brief Count output underflows (using paOutputUnderflow flag) 
3
    @brief Count output underflows (using paOutputUnderflow flag) 
3
    under overloaded and normal conditions.
4
    under overloaded and normal conditions.
4
    @author Ross Bencina <rossb@audiomulch.com>
5
    @author Ross Bencina <rossb@audiomulch.com>
10961097
1
/** @file patest_pink.c
1
/** @file patest_pink.c
 
 
2
    @ingroup test_src
2
    @brief Generate Pink Noise using Gardner method.
3
    @brief Generate Pink Noise using Gardner method.
3
 
4
 
4
    Optimization suggested by James McCartney uses a tree
5
    Optimization suggested by James McCartney uses a tree
10961097
1
/** @file patest_prime.c
1
/** @file patest_prime.c
 
 
2
    @ingroup test_src
2
    @brief Test stream priming mode.
3
    @brief Test stream priming mode.
3
    @author Ross Bencina http://www.audiomulch.com/~rossb
4
    @author Ross Bencina http://www.audiomulch.com/~rossb
4
*/
5
*/
10961097
1
/** @file patest_read_record.c
1
/** @file patest_read_record.c
 
 
2
    @ingroup test_src
2
    @brief Record input into an array; Save array to a file; Playback recorded
3
    @brief Record input into an array; Save array to a file; Playback recorded
3
    data. Implemented using the blocking API (Pa_ReadStream(), Pa_WriteStream() )
4
    data. Implemented using the blocking API (Pa_ReadStream(), Pa_WriteStream() )
4
    @author Phil Burk  http://www.softsynth.com
5
    @author Phil Burk  http://www.softsynth.com
10961097
1
/** @file patest_read_write_wire.c
1
/** @file patest_read_write_wire.c
2
    @brief Tests full duplex blocking I/O by passing input straight to output.
2
    @ingroup test_src
3
    @author Bjorn Roche. XO Audio LLC for Z-Systems Engineering.
3
    @brief Tests full duplex blocking I/O by passing input straight to output.
4
    @author based on code by: Phil Burk  http://www.softsynth.com
4
    @author Bjorn Roche. XO Audio LLC for Z-Systems Engineering.
5
    @author based on code by: Ross Bencina rossb@audiomulch.com
5
    @author based on code by: Phil Burk  http://www.softsynth.com
6
*/
6
    @author based on code by: Ross Bencina rossb@audiomulch.com
7
/*
7
*/
8
 * $Id: patest_read_record.c 757 2004-02-13 07:48:10Z rossbencina $
8
/*
9
 *
9
 * $Id: patest_read_record.c 757 2004-02-13 07:48:10Z rossbencina $
10
 * This program uses the PortAudio Portable Audio Library.
10
 *
11
 * For more information see: http://www.portaudio.com
11
 * This program uses the PortAudio Portable Audio Library.
12
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
12
 * For more information see: http://www.portaudio.com
13
 *
13
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
 
 
14
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining
15
 * Permission is hereby granted, free of charge, to any person obtaining
15
 * a copy of this software and associated documentation files
16
 * a copy of this software and associated documentation files
16
 * (the "Software"), to deal in the Software without restriction,
17
 * (the "Software"), to deal in the Software without restriction,
...
 
...
 
40
 * they can be incorporated into the canonical version. It is also 
41
 * they can be incorporated into the canonical version. It is also 
41
 * requested that these non-binding requests be included along with the 
42
 * requested that these non-binding requests be included along with the 
42
 * license above.
43
 * license above.
43
 */
44
 */
44
 
45
 
45
#include <stdio.h>
46
#include <stdio.h>
46
#include <stdlib.h>
47
#include <stdlib.h>
47
#include "portaudio.h"
48
#include "portaudio.h"
48
 
49
 
49
/* #define SAMPLE_RATE  (17932) // Test failure to open with this value. */
50
/* #define SAMPLE_RATE  (17932) // Test failure to open with this value. */
50
#define SAMPLE_RATE  (44100)
51
#define SAMPLE_RATE  (44100)
51
#define FRAMES_PER_BUFFER (1024)
52
#define FRAMES_PER_BUFFER (1024)
52
#define NUM_CHANNELS    (2)
53
#define NUM_CHANNELS    (2)
53
/* #define DITHER_FLAG     (paDitherOff)  */
54
/* #define DITHER_FLAG     (paDitherOff)  */
54
#define DITHER_FLAG     (0) /**/
55
#define DITHER_FLAG     (0) /**/
55
 
56
 
56
/* Select sample format. */
57
/* Select sample format. */
57
#if 1
58
#if 1
58
#define PA_SAMPLE_TYPE  paFloat32
59
#define PA_SAMPLE_TYPE  paFloat32
59
typedef float SAMPLE;
60
typedef float SAMPLE;
60
#define SAMPLE_SILENCE  (0.0f)
61
#define SAMPLE_SILENCE  (0.0f)
61
#define PRINTF_S_FORMAT "%.8f"
62
#define PRINTF_S_FORMAT "%.8f"
62
#elif 1
63
#elif 1
63
#define PA_SAMPLE_TYPE  paInt16
64
#define PA_SAMPLE_TYPE  paInt16
64
typedef short SAMPLE;
65
typedef short SAMPLE;
65
#define SAMPLE_SILENCE  (0)
66
#define SAMPLE_SILENCE  (0)
66
#define PRINTF_S_FORMAT "%d"
67
#define PRINTF_S_FORMAT "%d"
67
#elif 0
68
#elif 0
68
#define PA_SAMPLE_TYPE  paInt8
69
#define PA_SAMPLE_TYPE  paInt8
69
typedef char SAMPLE;
70
typedef char SAMPLE;
70
#define SAMPLE_SILENCE  (0)
71
#define SAMPLE_SILENCE  (0)
71
#define PRINTF_S_FORMAT "%d"
72
#define PRINTF_S_FORMAT "%d"
72
#else
73
#else
73
#define PA_SAMPLE_TYPE  paUInt8
74
#define PA_SAMPLE_TYPE  paUInt8
74
typedef unsigned char SAMPLE;
75
typedef unsigned char SAMPLE;
75
#define SAMPLE_SILENCE  (128)
76
#define SAMPLE_SILENCE  (128)
76
#define PRINTF_S_FORMAT "%d"
77
#define PRINTF_S_FORMAT "%d"
77
#endif
78
#endif
78
 
79
 
79
 
80
 
80
/*******************************************************************/
81
/*******************************************************************/
81
int main(void);
82
int main(void);
82
int main(void)
83
int main(void)
83
{
84
{
84
    PaStreamParameters inputParameters, outputParameters;
85
    PaStreamParameters inputParameters, outputParameters;
85
    PaStream *stream = NULL;
86
    PaStream *stream = NULL;
86
    PaError err;
87
    PaError err;
87
    SAMPLE *sampleBlock;
88
    SAMPLE *sampleBlock;
88
    int i;
89
    int i;
89
    int numBytes;
90
    int numBytes;
90
 
91
 
91
 
92
 
92
    printf("patest_read_write_wire.c\n"); fflush(stdout);
93
    printf("patest_read_write_wire.c\n"); fflush(stdout);
93
 
94
 
94
    numBytes = FRAMES_PER_BUFFER * NUM_CHANNELS * sizeof(SAMPLE);
95
    numBytes = FRAMES_PER_BUFFER * NUM_CHANNELS * sizeof(SAMPLE);
95
    sampleBlock = (SAMPLE *) malloc( numBytes );
96
    sampleBlock = (SAMPLE *) malloc( numBytes );
96
    if( sampleBlock == NULL )
97
    if( sampleBlock == NULL )
97
    {
98
    {
98
        printf("Could not allocate record array.\n");
99
        printf("Could not allocate record array.\n");
99
        exit(1);
100
        exit(1);
100
    }
101
    }
101
    for( i=0; i<FRAMES_PER_BUFFER*NUM_CHANNELS; i++ )
102
    for( i=0; i<FRAMES_PER_BUFFER*NUM_CHANNELS; i++ )
102
        sampleBlock[i] = (SAMPLE_SILENCE);
103
        sampleBlock[i] = (SAMPLE_SILENCE);
103
 
104
 
104
    err = Pa_Initialize();
105
    err = Pa_Initialize();
105
    if( err != paNoError ) goto error;
106
    if( err != paNoError ) goto error;
106
 
107
 
107
    inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */
108
    inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */
108
    printf( "Input device # %d.\n", inputParameters.device );
109
    printf( "Input device # %d.\n", inputParameters.device );
109
    printf( "Input LL: %g s\n", Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency );
110
    printf( "Input LL: %g s\n", Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency );
110
    printf( "Input HL: %g s\n", Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency );
111
    printf( "Input HL: %g s\n", Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency );
111
    inputParameters.channelCount = NUM_CHANNELS;
112
    inputParameters.channelCount = NUM_CHANNELS;
112
    inputParameters.sampleFormat = PA_SAMPLE_TYPE;
113
    inputParameters.sampleFormat = PA_SAMPLE_TYPE;
113
    inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
114
    inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultHighInputLatency ;
114
    inputParameters.hostApiSpecificStreamInfo = NULL;
115
    inputParameters.hostApiSpecificStreamInfo = NULL;
115
 
116
 
116
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
117
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
117
    printf( "Output device # %d.\n", outputParameters.device );
118
    printf( "Output device # %d.\n", outputParameters.device );
118
    printf( "Output LL: %g s\n", Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency );
119
    printf( "Output LL: %g s\n", Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency );
119
    printf( "Output HL: %g s\n", Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency );
120
    printf( "Output HL: %g s\n", Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency );
120
    outputParameters.channelCount = NUM_CHANNELS;
121
    outputParameters.channelCount = NUM_CHANNELS;
121
    outputParameters.sampleFormat = PA_SAMPLE_TYPE;
122
    outputParameters.sampleFormat = PA_SAMPLE_TYPE;
122
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency;
123
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency;
123
    outputParameters.hostApiSpecificStreamInfo = NULL;
124
    outputParameters.hostApiSpecificStreamInfo = NULL;
124
 
125
 
125
    /* -- setup -- */
126
    /* -- setup -- */
126
 
127
 
127
   err = Pa_OpenStream(
128
   err = Pa_OpenStream(
128
              &stream,
129
              &stream,
129
              &inputParameters,
130
              &inputParameters,
130
              &outputParameters,
131
              &outputParameters,
131
              SAMPLE_RATE,
132
              SAMPLE_RATE,
132
              FRAMES_PER_BUFFER,
133
              FRAMES_PER_BUFFER,
133
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
134
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
134
              NULL, /* no callback, use blocking API */
135
              NULL, /* no callback, use blocking API */
135
              NULL ); /* no callback, so no callback userData */
136
              NULL ); /* no callback, so no callback userData */
136
    if( err != paNoError ) goto error;
137
    if( err != paNoError ) goto error;
137
 
138
 
138
    err = Pa_StartStream( stream );
139
    err = Pa_StartStream( stream );
139
    if( err != paNoError ) goto error;
140
    if( err != paNoError ) goto error;
140
    printf("Wire on. Will run one minute.\n"); fflush(stdout);
141
    printf("Wire on. Will run one minute.\n"); fflush(stdout);
141
 
142
 
142
    for( i=0; i<(60*SAMPLE_RATE)/FRAMES_PER_BUFFER; ++i )
143
    for( i=0; i<(60*SAMPLE_RATE)/FRAMES_PER_BUFFER; ++i )
143
    {
144
    {
144
       err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER );
145
       err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER );
145
       if( err ) goto xrun;
146
       if( err ) goto xrun;
146
       err = Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
147
       err = Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
147
       if( err ) goto xrun;
148
       if( err ) goto xrun;
148
    }
149
    }
149
    err = Pa_StopStream( stream );
150
    err = Pa_StopStream( stream );
150
    if( err != paNoError ) goto error;
151
    if( err != paNoError ) goto error;
151
 
152
 
152
    for( i=0; i<FRAMES_PER_BUFFER*NUM_CHANNELS; i++ )
153
    for( i=0; i<FRAMES_PER_BUFFER*NUM_CHANNELS; i++ )
153
        sampleBlock[i] = (SAMPLE_SILENCE);
154
        sampleBlock[i] = (SAMPLE_SILENCE);
154
 
155
 
155
    err = Pa_StartStream( stream );
156
    err = Pa_StartStream( stream );
156
    if( err != paNoError ) goto error;
157
    if( err != paNoError ) goto error;
157
    printf("Wire on. Interrupt to stop.\n"); fflush(stdout);
158
    printf("Wire on. Interrupt to stop.\n"); fflush(stdout);
158
 
159
 
159
    while( 1 )
160
    while( 1 )
160
    {
161
    {
161
       err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER );
162
       err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER );
162
       if( err ) goto xrun;
163
       if( err ) goto xrun;
163
       err = Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
164
       err = Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
164
       if( err ) goto xrun;
165
       if( err ) goto xrun;
165
    }
166
    }
166
    err = Pa_StopStream( stream );
167
    err = Pa_StopStream( stream );
167
    if( err != paNoError ) goto error;
168
    if( err != paNoError ) goto error;
168
 
169
 
169
    Pa_CloseStream( stream );
170
    Pa_CloseStream( stream );
170
 
171
 
171
    free( sampleBlock );
172
    free( sampleBlock );
172
 
173
 
173
    Pa_Terminate();
174
    Pa_Terminate();
174
    return 0;
175
    return 0;
175
 
176
 
176
xrun:
177
xrun:
177
    if( stream ) {
178
    if( stream ) {
178
       Pa_AbortStream( stream );
179
       Pa_AbortStream( stream );
179
       Pa_CloseStream( stream );
180
       Pa_CloseStream( stream );
180
    }
181
    }
181
    free( sampleBlock );
182
    free( sampleBlock );
182
    Pa_Terminate();
183
    Pa_Terminate();
183
    if( err & paInputOverflow )
184
    if( err & paInputOverflow )
184
       fprintf( stderr, "Input Overflow.\n" );
185
       fprintf( stderr, "Input Overflow.\n" );
185
    if( err & paOutputUnderflow )
186
    if( err & paOutputUnderflow )
186
       fprintf( stderr, "Output Underflow.\n" );
187
       fprintf( stderr, "Output Underflow.\n" );
187
    return -2;
188
    return -2;
188
 
189
 
189
error:
190
error:
190
    if( stream ) {
191
    if( stream ) {
191
       Pa_AbortStream( stream );
192
       Pa_AbortStream( stream );
192
       Pa_CloseStream( stream );
193
       Pa_CloseStream( stream );
193
    }
194
    }
194
    free( sampleBlock );
195
    free( sampleBlock );
195
    Pa_Terminate();
196
    Pa_Terminate();
196
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
197
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
197
    fprintf( stderr, "Error number: %d\n", err );
198
    fprintf( stderr, "Error number: %d\n", err );
198
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
199
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
199
    return -1;
200
    return -1;
200
}
201
}
201
 
202
 
10961097
1
/** @file patest_record.c
1
/** @file patest_record.c
 
 
2
    @ingroup test_src
2
    @brief Record input into an array; Save array to a file; Playback recorded data.
3
    @brief Record input into an array; Save array to a file; Playback recorded data.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_ringmix.c
1
/** @file patest_ringmix.c
 
 
2
    @ingroup test_src
2
    @brief Ring modulate inputs to left output, mix inputs to right output.
3
    @brief Ring modulate inputs to left output, mix inputs to right output.
3
*/
4
*/
4
/*
5
/*
10961097
1
/** @file patest_saw.c
1
/** @file patest_saw.c
 
 
2
    @ingroup test_src
2
    @brief Play a simple (aliasing) sawtooth wave.
3
    @brief Play a simple (aliasing) sawtooth wave.
3
    @author Phil Burk  http://www.softsynth.com
4
    @author Phil Burk  http://www.softsynth.com
4
*/
5
*/
10961097
1
/** @file patest_sine.c
1
/** @file patest_sine.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave for several seconds.
3
    @brief Play a sine wave for several seconds.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Phil Burk <philburk@softsynth.com>
5
    @author Phil Burk <philburk@softsynth.com>
10961097
1
/** @file patest_sine8.c
1
/** @file patest_sine8.c
 
 
2
    @ingroup test_src
2
    @brief Test 8 bit data: play a sine wave for several seconds.
3
    @brief Test 8 bit data: play a sine wave for several seconds.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
*/
5
*/
10961097
1
/** @file patest_sine_formats.c
1
/** @file patest_sine_formats.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave for several seconds. Test various data formats.
3
    @brief Play a sine wave for several seconds. Test various data formats.
3
    @author Phil Burk
4
    @author Phil Burk
4
*/
5
*/
10961097
1
/** @file patest_sine_time.c
1
/** @file patest_sine_time.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave for several seconds, pausing in the middle.
3
    @brief Play a sine wave for several seconds, pausing in the middle.
3
    Uses the Pa_GetStreamTime() call.
4
    Uses the Pa_GetStreamTime() call.
4
    @author Ross Bencina <rossb@audiomulch.com>
5
    @author Ross Bencina <rossb@audiomulch.com>
10961097
1
/** @file patest_start_stop.c
1
/** @file patest_start_stop.c
2
    @brief Play a sine wave for several seconds
2
    @ingroup test_src
3
        - start and stop the stream multiple times.
3
    @brief Play a sine wave for several seconds. Start and stop the stream multiple times.
4
 
4
 
5
    @author Ross Bencina <rossb@audiomulch.com>
5
    @author Ross Bencina <rossb@audiomulch.com>
6
    @author Phil Burk <philburk@softsynth.com>
6
    @author Phil Burk <philburk@softsynth.com>
10961097
1
/** @file patest_stop.c
1
/** @file patest_stop.c
 
 
2
    @ingroup test_src
2
    @brief Test different ways of stopping audio.
3
    @brief Test different ways of stopping audio.
3
 
4
 
4
    Test the three ways of stopping audio:
5
    Test the three ways of stopping audio:
10961097
1
/** @file patest_stop_playout.c
1
/** @file patest_stop_playout.c
 
 
2
    @ingroup test_src
2
    @brief Test whether all queued samples are played when Pa_StopStream()
3
    @brief Test whether all queued samples are played when Pa_StopStream()
3
            is used with a callback or read/write stream, or when the callback
4
            is used with a callback or read/write stream, or when the callback
4
            returns paComplete.
5
            returns paComplete.
10961097
1
/** @file patest_sync.c
1
/** @file patest_sync.c
 
 
2
    @ingroup test_src
2
    @brief Test time stamping and synchronization of audio and video.
3
    @brief Test time stamping and synchronization of audio and video.
3
 
4
 
4
    A high latency is used so we can hear the difference in time.
5
    A high latency is used so we can hear the difference in time.
10961097
1
/** @file patest_timing.c
1
/** @file patest_timing.c
2
    @brief Play a sine wave for several seconds, and spits out a ton of timing info while it's at it. Based on patet_sine.c
2
    @ingroup test_src
3
   @author Bjorn Roche
3
    @brief Play a sine wave for several seconds, and spits out a ton of timing info while it's at it. Based on patet_sine.c
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Bjorn Roche
5
    @author Phil Burk <philburk@softsynth.com>
5
    @author Ross Bencina <rossb@audiomulch.com>
6
*/
6
    @author Phil Burk <philburk@softsynth.com>
7
/*
7
*/
8
 * $Id: patest_sine.c 578 2003-09-02 04:17:38Z rossbencina $
8
/*
9
 *
9
 * $Id: patest_sine.c 578 2003-09-02 04:17:38Z rossbencina $
10
 * This program uses the PortAudio Portable Audio Library.
10
 *
11
 * For more information see: http://www.portaudio.com/
11
 * This program uses the PortAudio Portable Audio Library.
12
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
12
 * For more information see: http://www.portaudio.com/
13
 *
13
 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
 
 
14
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining
15
 * Permission is hereby granted, free of charge, to any person obtaining
15
 * a copy of this software and associated documentation files
16
 * a copy of this software and associated documentation files
16
 * (the "Software"), to deal in the Software without restriction,
17
 * (the "Software"), to deal in the Software without restriction,
...
 
...
 
40
 * they can be incorporated into the canonical version. It is also 
41
 * they can be incorporated into the canonical version. It is also 
41
 * requested that these non-binding requests be included along with the 
42
 * requested that these non-binding requests be included along with the 
42
 * license above.
43
 * license above.
43
 */
44
 */
44
 
45
 
45
#include <stdio.h>
46
#include <stdio.h>
46
#include <math.h>
47
#include <math.h>
47
#include "portaudio.h"
48
#include "portaudio.h"
48
 
49
 
49
#define NUM_SECONDS   (5)
50
#define NUM_SECONDS   (5)
50
#define SAMPLE_RATE   (44100)
51
#define SAMPLE_RATE   (44100)
51
#define FRAMES_PER_BUFFER  (64)
52
#define FRAMES_PER_BUFFER  (64)
52
 
53
 
53
#ifndef M_PI
54
#ifndef M_PI
54
#define M_PI  (3.14159265)
55
#define M_PI  (3.14159265)
55
#endif
56
#endif
56
 
57
 
57
#define TABLE_SIZE   (200)
58
#define TABLE_SIZE   (200)
58
typedef struct
59
typedef struct
59
{
60
{
60
    PaStream *stream;
61
    PaStream *stream;
61
    PaTime start;
62
    PaTime start;
62
    float sine[TABLE_SIZE];
63
    float sine[TABLE_SIZE];
63
    int left_phase;
64
    int left_phase;
64
    int right_phase;
65
    int right_phase;
65
}
66
}
66
paTestData;
67
paTestData;
67
 
68
 
68
/* This routine will be called by the PortAudio engine when audio is needed.
69
/* This routine will be called by the PortAudio engine when audio is needed.
69
** It may called at interrupt level on some machines so don't do anything
70
** It may called at interrupt level on some machines so don't do anything
70
** that could mess up the system like calling malloc() or free().
71
** that could mess up the system like calling malloc() or free().
71
*/
72
*/
72
static int patestCallback( const void *inputBuffer, void *outputBuffer,
73
static int patestCallback( const void *inputBuffer, void *outputBuffer,
73
                            unsigned long framesPerBuffer,
74
                            unsigned long framesPerBuffer,
74
                            const PaStreamCallbackTimeInfo* timeInfo,
75
                            const PaStreamCallbackTimeInfo* timeInfo,
75
                            PaStreamCallbackFlags statusFlags,
76
                            PaStreamCallbackFlags statusFlags,
76
                            void *userData )
77
                            void *userData )
77
{
78
{
78
    paTestData *data = (paTestData*)userData;
79
    paTestData *data = (paTestData*)userData;
79
    float *out = (float*)outputBuffer;
80
    float *out = (float*)outputBuffer;
80
    unsigned long i;
81
    unsigned long i;
81
 
82
 
82
    (void) timeInfo; /* Prevent unused variable warnings. */
83
    (void) timeInfo; /* Prevent unused variable warnings. */
83
    (void) statusFlags;
84
    (void) statusFlags;
84
    (void) inputBuffer;
85
    (void) inputBuffer;
85
 
86
 
86
    printf( "Timing info given to callback: Adc: %g, Current: %g, Dac: %g\n",
87
    printf( "Timing info given to callback: Adc: %g, Current: %g, Dac: %g\n",
87
            timeInfo->inputBufferAdcTime,
88
            timeInfo->inputBufferAdcTime,
88
            timeInfo->currentTime,
89
            timeInfo->currentTime,
89
            timeInfo->outputBufferDacTime );
90
            timeInfo->outputBufferDacTime );
90
 
91
 
91
    printf( "getStreamTime() returns: %g\n", Pa_GetStreamTime(data->stream)-data->start );
92
    printf( "getStreamTime() returns: %g\n", Pa_GetStreamTime(data->stream)-data->start );
92
 
93
 
93
    for( i=0; i<framesPerBuffer; i++ )
94
    for( i=0; i<framesPerBuffer; i++ )
94
    {
95
    {
95
        *out++ = data->sine[data->left_phase];  /* left */
96
        *out++ = data->sine[data->left_phase];  /* left */
96
        *out++ = data->sine[data->right_phase];  /* right */
97
        *out++ = data->sine[data->right_phase];  /* right */
97
        data->left_phase += 1;
98
        data->left_phase += 1;
98
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
99
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
99
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
100
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
100
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
101
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
101
    }
102
    }
102
 
103
 
103
    return paContinue;
104
    return paContinue;
104
}
105
}
105
 
106
 
106
/*******************************************************************/
107
/*******************************************************************/
107
int main(void);
108
int main(void);
108
int main(void)
109
int main(void)
109
{
110
{
110
    PaStreamParameters outputParameters;
111
    PaStreamParameters outputParameters;
111
    PaStream *stream;
112
    PaStream *stream;
112
    PaError err;
113
    PaError err;
113
    paTestData data;
114
    paTestData data;
114
    int i;
115
    int i;
115
 
116
 
116
 
117
 
117
    printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
118
    printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
118
 
119
 
119
    /* initialise sinusoidal wavetable */
120
    /* initialise sinusoidal wavetable */
120
    for( i=0; i<TABLE_SIZE; i++ )
121
    for( i=0; i<TABLE_SIZE; i++ )
121
    {
122
    {
122
        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
123
        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
123
    }
124
    }
124
    data.left_phase = data.right_phase = 0;
125
    data.left_phase = data.right_phase = 0;
125
 
126
 
126
    err = Pa_Initialize();
127
    err = Pa_Initialize();
127
    if( err != paNoError ) goto error;
128
    if( err != paNoError ) goto error;
128
 
129
 
129
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
130
    outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
130
    outputParameters.channelCount = 2;       /* stereo output */
131
    outputParameters.channelCount = 2;       /* stereo output */
131
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
132
    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
132
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
133
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
133
    outputParameters.hostApiSpecificStreamInfo = NULL;
134
    outputParameters.hostApiSpecificStreamInfo = NULL;
134
 
135
 
135
    err = Pa_OpenStream(
136
    err = Pa_OpenStream(
136
              &stream,
137
              &stream,
137
              NULL, /* no input */
138
              NULL, /* no input */
138
              &outputParameters,
139
              &outputParameters,
139
              SAMPLE_RATE,
140
              SAMPLE_RATE,
140
              FRAMES_PER_BUFFER,
141
              FRAMES_PER_BUFFER,
141
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
142
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
142
              patestCallback,
143
              patestCallback,
143
              &data );
144
              &data );
144
    data.stream = stream;
145
    data.stream = stream;
145
    data.start = Pa_GetStreamTime(stream);
146
    data.start = Pa_GetStreamTime(stream);
146
    if( err != paNoError ) goto error;
147
    if( err != paNoError ) goto error;
147
 
148
 
148
    err = Pa_StartStream( stream );
149
    err = Pa_StartStream( stream );
149
    data.start = Pa_GetStreamTime(stream);
150
    data.start = Pa_GetStreamTime(stream);
150
    if( err != paNoError ) goto error;
151
    if( err != paNoError ) goto error;
151
 
152
 
152
    printf("Play for %d seconds.\n", NUM_SECONDS );
153
    printf("Play for %d seconds.\n", NUM_SECONDS );
153
    Pa_Sleep( NUM_SECONDS * 1000 );
154
    Pa_Sleep( NUM_SECONDS * 1000 );
154
 
155
 
155
    err = Pa_StopStream( stream );
156
    err = Pa_StopStream( stream );
156
    if( err != paNoError ) goto error;
157
    if( err != paNoError ) goto error;
157
 
158
 
158
    err = Pa_CloseStream( stream );
159
    err = Pa_CloseStream( stream );
159
    if( err != paNoError ) goto error;
160
    if( err != paNoError ) goto error;
160
 
161
 
161
    Pa_Terminate();
162
    Pa_Terminate();
162
    printf("Test finished.\n");
163
    printf("Test finished.\n");
163
    printf("The tone should have been heard for about 5 seconds and all the timing info above should report that about 5 seconds elapsed (except Adc, which
is undefined since there was no input device opened).\n");
164
    printf("The tone should have been heard for about 5 seconds and all the timing info above should report that about 5 seconds elapsed (except Adc, which
is undefined since there was no input device opened).\n");
164
 
165
 
165
    return err;
166
    return err;
166
error:
167
error:
167
    Pa_Terminate();
168
    Pa_Terminate();
168
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
169
    fprintf( stderr, "An error occured while using the portaudio stream\n" );
169
    fprintf( stderr, "Error number: %d\n", err );
170
    fprintf( stderr, "Error number: %d\n", err );
170
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
171
    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
171
    return err;
172
    return err;
172
}
173
}
10961097
1
/** @file patest_toomanysines.c
1
/** @file patest_toomanysines.c
 
 
2
    @ingroup test_src
2
    @brief Play more sine waves than we can handle in real time as a stress test.
3
    @brief Play more sine waves than we can handle in real time as a stress test.
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Phil Burk <philburk@softsynth.com>
5
    @author Phil Burk <philburk@softsynth.com>
10961097
 
 
1
/** @file patest_two_rates.c
 
 
2
    @ingroup test_src
 
 
3
    @brief Play two streams at different rates to make sure they don't interfere.
 
 
4
    @author Phil Burk <philburk@softsynth.com>
 
 
5
*/
1
/*
6
/*
2
 * $Id$
7
 * $Id$
3
 * patest_two_rates.c
 
 
4
 * Play two streams at different rates to make sure they don't interfere.
 
 
5
 *
8
 *
6
 * Author: Phil Burk  http://www.softsynth.com
9
 * Author: Phil Burk  http://www.softsynth.com
7
 *
10
 *
10961097
1
/** @file patest_underflow.c
1
/** @file patest_underflow.c
 
 
2
    @ingroup test_src
2
    @brief Simulate an output buffer underflow condition.
3
    @brief Simulate an output buffer underflow condition.
3
    Tests whether the stream can be stopped when underflowing buffers.
4
    Tests whether the stream can be stopped when underflowing buffers.
4
    @author Ross Bencina <rossb@audiomulch.com>
5
    @author Ross Bencina <rossb@audiomulch.com>
10961097
1
/** @file patest_wire.c
1
/** @file patest_wire.c
 
 
2
    @ingroup test_src
2
    @brief Pass input directly to output.
3
    @brief Pass input directly to output.
3
 
4
 
4
    Note that some HW devices, for example many ISA audio cards
5
    Note that some HW devices, for example many ISA audio cards
10961097
1
/** @file patest_write_sine.c
1
/** @file patest_write_sine.c
 
 
2
    @ingroup test_src
2
    @brief Play a sine wave for several seconds using the blocking API (Pa_WriteStream())
3
    @brief Play a sine wave for several seconds using the blocking API (Pa_WriteStream())
3
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Ross Bencina <rossb@audiomulch.com>
4
    @author Phil Burk <philburk@softsynth.com>
5
    @author Phil Burk <philburk@softsynth.com>