Browse Source

Version 2.0

tags/2.0
Gary Scavone Stephen Sinclair 18 years ago
commit
72ee1e6be2
30 changed files with 8556 additions and 0 deletions
  1. +12
    -0
      README
  2. +4997
    -0
      RtAudio.cpp
  3. +430
    -0
      RtAudio.h
  4. +155
    -0
      doc/Doxyfile
  5. BIN
      doc/ccrma.gif
  6. +9
    -0
      doc/footer.html
  7. +9
    -0
      doc/header.html
  8. +628
    -0
      doc/tutorial.txt
  9. +125
    -0
      rtaudio.dsw
  10. +0
    -0
      tests/Debug/.placeholder
  11. +58
    -0
      tests/Makefile
  12. +0
    -0
      tests/Release/.placeholder
  13. +100
    -0
      tests/call_inout.cpp
  14. +110
    -0
      tests/call_inout.dsp
  15. +128
    -0
      tests/call_saw.cpp
  16. +110
    -0
      tests/call_saw.dsp
  17. +166
    -0
      tests/call_twostreams.cpp
  18. +110
    -0
      tests/call_twostreams.dsp
  19. +109
    -0
      tests/in_out.cpp
  20. +110
    -0
      tests/in_out.dsp
  21. +66
    -0
      tests/info.cpp
  22. +110
    -0
      tests/info.dsp
  23. +128
    -0
      tests/play_raw.cpp
  24. +110
    -0
      tests/play_raw.dsp
  25. +128
    -0
      tests/play_saw.cpp
  26. +110
    -0
      tests/play_saw.dsp
  27. +114
    -0
      tests/record_raw.cpp
  28. +110
    -0
      tests/record_raw.dsp
  29. +204
    -0
      tests/twostreams.cpp
  30. +110
    -0
      tests/twostreams.dsp

+ 12
- 0
README View File

@@ -0,0 +1,12 @@

This is the parent directory of the RtAudio distribution. Here is a quick description of what is contained here:

RtAudio.h - class header
RtAudio.cpp - class source
rtaudio.dsw - Visual C++ 6.0 workspace file

Directories:

tests - various test programs and Visual C++ 6.0 project files
doc - complete documentation in a variety of formats (see doc/html/index.html)


+ 4997
- 0
RtAudio.cpp
File diff suppressed because it is too large
View File


+ 430
- 0
RtAudio.h View File

@@ -0,0 +1,430 @@
/******************************************/
/*
RtAudio - realtime sound I/O C++ class
Version 2.0 by Gary P. Scavone, 2001-2002.
*/
/******************************************/

#if !defined(__RtAudio_h)
#define __RtAudio_h

#include <map>

#if defined(__LINUX_ALSA_)
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <unistd.h>

typedef snd_pcm_t *AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;

#elif defined(__LINUX_OSS_)
#include <pthread.h>
#include <unistd.h>

typedef int AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;

#elif defined(__WINDOWS_DS_)
#include <windows.h>
#include <process.h>

// The following struct is used to hold the extra variables
// specific to the DirectSound implementation.
typedef struct {
void * object;
void * buffer;
UINT bufferPointer;
} AUDIO_HANDLE;

typedef LPGUID DEVICE_ID;
typedef unsigned long THREAD_HANDLE;
typedef CRITICAL_SECTION MUTEX;

#elif defined(__IRIX_AL_)
#include <dmedia/audio.h>
#include <pthread.h>
#include <unistd.h>

typedef ALport AUDIO_HANDLE;
typedef int DEVICE_ID;
typedef pthread_t THREAD_HANDLE;
typedef pthread_mutex_t MUTEX;

#endif


// *************************************************** //
//
// RtAudioError class declaration.
//
// *************************************************** //

class RtAudioError
{
public:
enum TYPE {
WARNING,
DEBUG_WARNING,
UNSPECIFIED,
NO_DEVICES_FOUND,
INVALID_DEVICE,
INVALID_STREAM,
MEMORY_ERROR,
INVALID_PARAMETER,
DRIVER_ERROR,
SYSTEM_ERROR,
THREAD_ERROR
};

protected:
char error_message[256];
TYPE type;

public:
//! The constructor.
RtAudioError(const char *p, TYPE tipe = RtAudioError::UNSPECIFIED);

//! The destructor.
virtual ~RtAudioError(void);

//! Prints "thrown" error message to stdout.
virtual void printMessage(void);

//! Returns the "thrown" error message TYPE.
virtual const TYPE& getType(void) { return type; }

//! Returns the "thrown" error message string.
virtual const char *getMessage(void) { return error_message; }
};


// *************************************************** //
//
// RtAudio class declaration.
//
// *************************************************** //

class RtAudio
{
public:

// Support for signed integers and floats. Audio data fed to/from
// the tickStream() routine is assumed to ALWAYS be in host
// byte order. The internal routines will automatically take care of
// any necessary byte-swapping between the host format and the
// soundcard. Thus, endian-ness is not a concern in the following
// format definitions.
typedef unsigned long RTAUDIO_FORMAT;
static const RTAUDIO_FORMAT RTAUDIO_SINT8;
static const RTAUDIO_FORMAT RTAUDIO_SINT16;
static const RTAUDIO_FORMAT RTAUDIO_SINT24; /*!< Upper 3 bytes of 32-bit integer. */
static const RTAUDIO_FORMAT RTAUDIO_SINT32;
static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; /*!< Normalized between plus/minus 1.0. */
static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; /*!< Normalized between plus/minus 1.0. */

//static const int MAX_SAMPLE_RATES = 14;
enum { MAX_SAMPLE_RATES = 14 };

typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);

typedef struct {
char name[128];
DEVICE_ID id[2]; /*!< No value reported by getDeviceInfo(). */
bool probed; /*!< true if the device capabilities were successfully probed. */
int maxOutputChannels;
int maxInputChannels;
int maxDuplexChannels;
int minOutputChannels;
int minInputChannels;
int minDuplexChannels;
bool hasDuplexSupport; /*!< true if device supports duplex mode. */
int nSampleRates; /*!< Number of discrete rates or -1 if range supported. */
int sampleRates[MAX_SAMPLE_RATES]; /*!< Supported rates or (min, max) if range. */
RTAUDIO_FORMAT nativeFormats; /*!< Bit mask of supported data formats. */
} RTAUDIO_DEVICE;

//! The default constructor.
/*!
Probes the system to make sure at least one audio
input/output device is available and determines
the api-specific identifier for each device found.
An RtAudioError error can be thrown if no devices are
found or if a memory allocation error occurs.
*/
RtAudio();

//! A constructor which can be used to open a stream during instantiation.
/*!
The specified output and/or input device identifiers correspond
to those enumerated via the getDeviceInfo() method. If device =
0, the default or first available devices meeting the given
parameters is selected. If an output or input channel value is
zero, the corresponding device value is ignored. When a stream is
successfully opened, its identifier is returned via the "streamID"
pointer. An RtAudioError can be thrown if no devices are found
for the given parameters, if a memory allocation error occurs, or
if a driver error occurs. \sa openStream()
*/
RtAudio(int *streamID,
int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);

//! The destructor.
/*!
Stops and closes any open streams and devices and deallocates
buffer and structure memory.
*/
~RtAudio();

//! A public method for opening a stream with the specified parameters.
/*!
If successful, the opened stream ID is returned. Otherwise, an
RtAudioError is thrown.

\param outputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param outputChannels: The desired number of output channels. If
equal to zero, the outputDevice identifier is ignored.
\param inputDevice: If equal to 0, the default or first device
found meeting the given parameters is opened. Otherwise, the
device number should correspond to one of those enumerated via
the getDeviceInfo() method.
\param inputChannels: The desired number of input channels. If
equal to zero, the inputDevice identifier is ignored.
\param format: An RTAUDIO_FORMAT specifying the desired sample data format.
\param sampleRate: The desired sample rate (sample frames per second).
\param *bufferSize: A pointer value indicating the desired internal buffer
size in sample frames. The actual value used by the device is
returned via the same pointer. A value of zero can be specified,
in which case the lowest allowable value is determined.
\param numberOfBuffers: A value which can be used to help control device
latency. More buffers typically result in more robust performance,
though at a cost of greater latency. A value of zero can be
specified, in which case the lowest allowable value is used.
*/
int openStream(int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RTAUDIO_FORMAT format, int sampleRate,
int *bufferSize, int numberOfBuffers);

//! A public method which sets a user-defined callback function for a given stream.
/*!
This method assigns a callback function to a specific,
previously opened stream for non-blocking stream functionality. A
separate process is initiated, though the user function is called
only when the stream is "running" (between calls to the
startStream() and stopStream() methods, respectively). The
callback process remains active for the duration of the stream and
is automatically shutdown when the stream is closed (via the
closeStream() method or by object destruction). The callback
process can also be shutdown and the user function de-referenced
through an explicit call to the cancelStreamCallback() method.
Note that a single stream can use only blocking or callback
functionality at the same time, though it is possible to alternate
modes on the same stream through the use of the
setStreamCallback() and cancelStreamCallback() methods (the
blocking tickStream() method can be used before a callback is set
and/or after a callback is cancelled). An RtAudioError will be
thrown for an invalid device argument.
*/
void setStreamCallback(int streamID, RTAUDIO_CALLBACK callback, void *userData);

//! A public method which cancels a callback process and function for a given stream.
/*!
This method shuts down a callback process and de-references the
user function for a specific stream. Callback functionality can
subsequently be restarted on the stream via the
setStreamCallback() method. An RtAudioError will be thrown for an
invalid device argument.
*/
void cancelStreamCallback(int streamID);

//! A public method which returns the number of audio devices found.
int getDeviceCount(void);

//! Fill a user-supplied RTAUDIO_DEVICE structure for a specified device.
/*!
Any device between 0 and getDeviceCount()-1 is valid. If a
device is busy or otherwise unavailable, the structure member
"probed" has a value of "false". The system default input and
output devices are referenced by device identifier = 0. On
systems which allow dynamic default device settings, the default
devices are not identified by name (specific device enumerations
are assigned device identifiers > 0). An RtAudioError will be
thrown for an invalid device argument.
*/
void getDeviceInfo(int device, RTAUDIO_DEVICE *info);

//! A public method which returns a pointer to the buffer for an open stream.
/*!
The user should fill and/or read the buffer data in interleaved format
and then call the tickStream() method. An RtAudioError will be
thrown for an invalid stream identifier.
*/
char * const getStreamBuffer(int streamID);

//! Public method used to trigger processing of input/output data for a stream.
/*!
This method blocks until all buffer data is read/written. An
RtAudioError will be thrown for an invalid stream identifier or if
a driver error occurs.
*/
void tickStream(int streamID);

//! Public method which closes a stream and frees any associated buffers.
/*!
If an invalid stream identifier is specified, this method
issues a warning and returns (an RtAudioError is not thrown).
*/
void closeStream(int streamID);

//! Public method which starts a stream.
/*!
An RtAudioError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void startStream(int streamID);

//! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
/*!
An RtAudioError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void stopStream(int streamID);

//! Stop a stream, discarding any samples remaining in the input/output queue.
/*!
An RtAudioError will be thrown for an invalid stream identifier
or if a driver error occurs.
*/
void abortStream(int streamID);

//! Queries a stream to determine whether a call to the tickStream() method will block.
/*!
A return value of 0 indicates that the stream will NOT block. A positive
return value indicates the number of sample frames that cannot yet be
processed without blocking.
*/
int streamWillBlock(int streamID);

protected:

private:

static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];

enum { FAILURE, SUCCESS };

enum STREAM_MODE {
PLAYBACK,
RECORD,
DUPLEX,
UNINITIALIZED = -75
};

enum STREAM_STATE {
STREAM_STOPPED,
STREAM_RUNNING
};

typedef struct {
int device[2]; // Playback and record, respectively.
STREAM_MODE mode; // PLAYBACK, RECORD, or DUPLEX.
AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.
STREAM_STATE state; // STOPPED or RUNNING
char *userBuffer;
char *deviceBuffer;
bool doConvertBuffer[2]; // Playback and record, respectively.
bool deInterleave[2]; // Playback and record, respectively.
bool doByteSwap[2]; // Playback and record, respectively.
int sampleRate;
int bufferSize;
int nBuffers;
int nUserChannels[2]; // Playback and record, respectively.
int nDeviceChannels[2]; // Playback and record channels, respectively.
RTAUDIO_FORMAT userFormat;
RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.
bool usingCallback;
THREAD_HANDLE thread;
MUTEX mutex;
RTAUDIO_CALLBACK callback;
void *userData;
} RTAUDIO_STREAM;

typedef signed short INT16;
typedef signed int INT32;
typedef float FLOAT32;
typedef double FLOAT64;

char message[256];
int nDevices;
RTAUDIO_DEVICE *devices;

std::map<int, void *> streams;

//! Private error method to allow global control over error handling.
void error(RtAudioError::TYPE type);

/*!
Private method to count the system audio devices, allocate the
RTAUDIO_DEVICE structures, and probe the device capabilities.
*/
void initialize(void);

//! Private method to clear an RTAUDIO_DEVICE structure.
void clearDeviceInfo(RTAUDIO_DEVICE *info);

/*!
Private method which attempts to fill an RTAUDIO_DEVICE
structure for a given device. If an error is encountered during
the probe, a "warning" message is reported and the value of
"probed" remains false (no exception is thrown). A successful
probe is indicated by probed = true.
*/
void probeDeviceInfo(RTAUDIO_DEVICE *info);

/*!
Private method which attempts to open a device with the given parameters.
If an error is encountered during the probe, a "warning" message is
reported and FAILURE is returned (no exception is thrown). A
successful probe is indicated by a return value of SUCCESS.
*/
bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
STREAM_MODE mode, int channels,
int sampleRate, RTAUDIO_FORMAT format,
int *bufferSize, int numberOfBuffers);

/*!
Private common method used to check validity of a user-passed
stream ID. When the ID is valid, this method returns a pointer to
an RTAUDIO_STREAM structure (in the form of a void pointer).
Otherwise, an "invalid identifier" exception is thrown.
*/
void *verifyStream(int streamID);

/*!
Private method used to perform format, channel number, and/or interleaving
conversions between the user and device buffers.
*/
void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);

//! Private method used to perform byte-swapping on buffers.
void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);

//! Private method which returns the number of bytes for a given format.
int formatBytes(RTAUDIO_FORMAT format);
};

// Uncomment the following definition to have extra information spewed to stderr.
//#define RTAUDIO_DEBUG

#endif

+ 155
- 0
doc/Doxyfile View File

@@ -0,0 +1,155 @@
# Doxyfile 1.2.6
#---------------------------------------------------------------------------
# General configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = RtAudio
PROJECT_NUMBER =
OUTPUT_DIRECTORY = .
OUTPUT_LANGUAGE = English
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
INTERNAL_DOCS = NO
CLASS_DIAGRAMS = YES
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
VERBATIM_HEADERS = YES
SHOW_INCLUDE_FILES = YES
JAVADOC_AUTOBRIEF = NO
INHERIT_DOCS = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = NO
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ENABLED_SECTIONS =
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
ALIASES =
MAX_INITIALIZER_LINES = 30
OPTIMIZE_OUTPUT_FOR_C = NO
SHOW_USED_FILES = YES
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = tutorial.txt ../RtAudio.h
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
IMAGE_PATH =
INPUT_FILTER =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_HEADER = header.html
HTML_FOOTER = footer.html
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = YES
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = YES
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = YES
MAN_OUTPUT = man
MAN_EXTENSION = .3
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
#---------------------------------------------------------------------------
# Configuration::addtions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
GRAPHICAL_HIERARCHY = YES
DOT_PATH =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::addtions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO
CGI_NAME = search.cgi
CGI_URL =
DOC_URL =
DOC_ABSPATH =
BIN_ABSPATH = /usr/local/bin/
EXT_DOC_PATHS =

BIN
doc/ccrma.gif View File

Before After
Width: 164  |  Height: 36  |  Size: 3.4KB

+ 9
- 0
doc/footer.html View File

@@ -0,0 +1,9 @@
<HR>
<table><tr><td><img src="../ccrma.gif">
<td>&copy;2001-2002 CCRMA, Stanford University. All Rights Reserved.<br>
Maintained by Gary P. Scavone, <a href="mailto:gary@ccrma.stanford.edu">gary@ccrma.stanford.edu</a><P>
</table>
</BODY>
</HTML>

+ 9
- 0
doc/header.html View File

@@ -0,0 +1,9 @@
<HTML>
<HEAD>
<TITLE>The RtAudio Tutorial</TITLE>
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<a class="qindex" href="index.html">Tutorial</a> &nbsp; <a class="qindex" href="annotated.html">Class/Enum List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </CENTER>
<HR>

+ 628
- 0
doc/tutorial.txt View File

@@ -0,0 +1,628 @@
/*! \mainpage The RtAudio Tutorial
<BODY BGCOLOR="white">
<CENTER>
\ref intro &nbsp;&nbsp; \ref download &nbsp;&nbsp; \ref start &nbsp;&nbsp; \ref error &nbsp;&nbsp; \ref probing &nbsp;&nbsp; \ref settings &nbsp;&nbsp; \ref playbackb &nbsp;&nbsp; \ref playbackc &nbsp;&nbsp; \ref recording &nbsp;&nbsp; \ref duplex &nbsp;&nbsp; \ref methods &nbsp;&nbsp; \ref compiling &nbsp;&nbsp; \ref osnotes &nbsp;&nbsp; \ref acknowledge
</CENTER>
\section intro Introduction
RtAudio is a C++ class which provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA and OSS), SGI, and Windows operating systems. RtAudio significantly simplifies the process of interacting with computer audio hardware. It was designed with the following goals:
<UL>
<LI>object oriented C++ design</LI>
<LI>simple, common API across all supported platforms</LI>
<LI>single independent header and source file for easy inclusion in programming projects (no libraries!)</LI>
<LI>blocking functionality</LI>
<LI>callback functionality</LI>
<LI>extensive audio device parameter control</LI>
<LI>audio device capability probing</LI>
<LI>automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping</LI>
<LI>control over multiple audio streams and devices with a single instance</LI>
</UL>
RtAudio incorporates the concept of audio streams, which represent audio output (playback) and/or input (recording). Available audio devices and their capabilities can be enumerated and then specified when opening a stream. Multiple streams can run at the same time and, when allowed by the underlying audio API, a single device can serve multiple streams.
The RtAudio API provides both blocking (synchronous) and callback (asynchronous) functionality. Callbacks are typically used in conjunction with graphical user interfaces (GUI). Blocking functionality is often necessary for explicit control of multiple input/output stream synchronization or when audio must be synchronized with other system events.
\section download Download
Latest Release (22 January 2002): <A href="release/rtaudio-2.0.tgz">Version 2.0 (111 kB tar/gzipped)</A>
\section start Getting Started
The first thing that must be done when using RtAudio is to create an instance of the class. The default constructor RtAudio::RtAudio() scans the underlying audio system to verify that at least one device is available. RtAudio often uses C++ exceptions to report errors, necessitating try/catch blocks around most member functions. The following code example demonstrates default object construction and destruction:
\code
#include "RtAudio.h"
int main()
{
RtAudio *audio;
// Default RtAudio constructor
try {
audio = new RtAudio();
}
catch (RtAudioError &error) {
// Handle the exception here
}
// Clean up
delete audio;
}
\endcode
Obviously, this example doesn't demonstrate any of the real functionality of RtAudio. However, all uses of RtAudio must begin with a constructor (either default or overloaded varieties) and must end with class destruction. Further, it is necessary that all class methods which can throw a C++ exception be called within a try/catch block.
\section error Error Handling
RtAudio uses a C++ exception handler called RtAudioError, which is declared and defined within the RtAudio class files. The RtAudioError class is quite simple but it does allow errors to be "caught" by RtAudioError::TYPE. Almost all RtAudio methods can "throw" an RtAudioError, most typically if an invalid stream identifier is supplied to a method or a driver error occurs. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a private RtAudio method, error(), which can be modified to globally control how these messages are handled and reported.
\section probing Probing Device Capabilities
A programmer may wish to query the available audio device capabilities before deciding which to use. The following example outlines how this can be done.
\code
// probe.cpp
#include <iostream.h>
#include "RtAudio.h"
int main()
{
RtAudio *audio;
// Default RtAudio constructor
try {
audio = new RtAudio();
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
// Determine the number of devices available
int devices = audio->getDeviceCount();
// Scan through devices for various capabilities
RtAudio::RTAUDIO_DEVICE info;
for (int i=0; i<devices; i++) {
try {
audio->getDeviceInfo(i, &info);
}
catch (RtAudioError &error) {
error.printMessage();
break;
}
// Print, for example, the maximum number of output channels for each device
cout << "device = " << i;
cout << ": maximum output channels = " << info.maxOutputChannels << endl;
}
// Clean up
delete audio;
return 0;
}
\endcode
The RTAUDIO_DEVICE structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device:
\code
typedef struct {
char name[128];
DEVICE_ID id[2]; // No value reported by getDeviceInfo().
bool probed; // true if the device probe was successful.
int maxOutputChannels;
int maxInputChannels;
int maxDuplexChannels;
int minOutputChannels;
int minInputChannels;
int minDuplexChannels;
bool hasDuplexSupport; // true if duplex supported
int nSampleRates; // Number of discrete rates, or -1 if range supported.
double sampleRates[MAX_SAMPLE_RATES]; // Supported sample rates, or {min, max} if range.
RTAUDIO_FORMAT nativeFormats;
} RTAUDIO_DEVICE;
\endcode
The following data formats are defined and fully supported by RtAudio:
\code
typedef unsigned long RTAUDIO_FORMAT;
static const RTAUDIO_FORMAT RTAUDIO_SINT8; // Signed 8-bit integer
static const RTAUDIO_FORMAT RTAUDIO_SINT16; // Signed 16-bit integer
static const RTAUDIO_FORMAT RTAUDIO_SINT24; // Signed 24-bit integer
static const RTAUDIO_FORMAT RTAUDIO_SINT32; // Signed 32-bit integer
static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; // 32-bit float
static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; // 64-bit double
\endcode
The <I>nativeFormats</I> member of the RtAudio::RTAUDIO_DEVICE structure is a bit mask of the above formats which are natively supported by the device. However, RtAudio will automatically provide format conversion if a particular format is not natively supported. When the <I>probed</I> member of the RTAUDIO_DEVICE structure is false, the remaining structure members are likely unknown and the device is probably unusable.
In general, the user need not be concerned with the minimum channel values reported in the RTAUDIO_DEVICE structure. While some audio devices may require a minimum channel value > 1, RtAudio will provide automatic channel number compensation when the number of channels set by the user is less than that required by the device. Channel compensation is <I>NOT</I> possible when the number of channels set by the user is greater than that supported by the device.
It should be noted that the capabilities reported by a device driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings.
\section settings Device Settings
The next step in using RtAudio is to open a stream with a particular set of device settings.
\code
#include "RtAudio.h"
int main()
{
int channels = 2;
int sample_rate = 44100;
int buffer_size = 256; // 256 sample frames
int n_buffers = 4; // number of internal buffers used by device
int device = 0; // 0 indicates the default or first available device
int stream; // our stream identifier
RtAudio *audio;
// Instantiate RtAudio and open a stream within a try/catch block
try {
audio = new RtAudio();
stream = audio->openStream(device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
sample_rate, &buffer_size, n_buffers);
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
// Clean up
delete audio;
return 0;
}
\endcode
The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. When successful, a stream identifier is returned. In this case, we attempt to open a playback stream on device 0 with two channels, 32-bit floating point data, a sample rate of 44100 Hz, a frame rate of 256 sample frames per read/write, and 4 internal device buffers. When device = 0, RtAudio first attempts to open the default audio device with the given parameters. If that attempt fails, an attempt is made to find a device or set of devices which will meet the given parameters. If all attempts are unsuccessful, an RtAudioError is thrown. When a non-zero device value is specified, an attempt is made to open that device only.
RtAudio provides four signed integer and two floating point data formats which can be specified using the RtAudio::RTAUDIO_FORMAT parameter values mentioned earlier. If the opened device does not natively support the given format, RtAudio will automatically perform the necessary data format conversion.
Buffer sizes in RtAudio are <I>ALWAYS</I> given in sample frame units. For example, if you open an output stream with 4 channels and set <I>bufferSize</I> to 512, you will have to write 2048 samples of data to the output buffer within your callback or between calls to RtAudio::tickStream(). In this case, a single sample frame of data contains 4 samples of data.
The <I>bufferSize</I> parameter specifies the desired number of sample frames which will be written to and/or read from a device per write/read operation. The <I>nBuffers</I> parameter is used in setting the underlying device buffer parameters. Both the <I>bufferSize</I> and <I>nBuffers</I> parameters can be used to control stream latency though there is no guarantee that the passed values will be those used by a device. In general, lower values for both parameters will produce less latency but perhaps less robust performance. Both parameters can be specified with values of zero, in which case the smallest allowable values will be used. The <I>bufferSize</I> parameter is passed as a pointer and the actual value used by the stream is set during the device setup procedure. <I>bufferSize</I> values should be a power of two. Optimal and allowable buffer values tend to vary between systems and devices. Check the \ref osnotes section for general guidelines.
As noted earlier, the device capabilities reported by a driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. Because of this, RtAudio does not attempt to query a device's capabilities or use previously reported values when opening a device. Instead, RtAudio simply attempts to set the given parameters on a specified device and then checks whether the setup is successful or not.
\section playbackb Playback (blocking functionality)
Once the device is open for playback, there are only a few final steps necessary for realtime audio output. We'll first provide an example (blocking functionality) and then discuss the details.
\code
// playback.cpp
#include "RtAudio.h"
int main()
{
int count;
int channels = 2;
int sample_rate = 44100;
int buffer_size = 256; // 256 sample frames
int n_buffers = 4; // number of internal buffers used by device
float *buffer;
int device = 0; // 0 indicates the default or first available device
int stream; // our stream identifier
RtAudio *audio;
// Open a stream during RtAudio instantiation
try {
audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
sample_rate, &buffer_size, n_buffers);
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
try {
// Get a pointer to the stream buffer
buffer = (float *) audio->getStreamBuffer(stream);
// Start the stream
audio->startStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
// An example loop which runs for about 40000 sample frames
count = 0;
while (count < 40000) {
// Generate your samples and fill the buffer with buffer_size sample frames of data
...
// Trigger the output of the data buffer
try {
audio->tickStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
count += buffer_size;
}
try {
// Stop and close the stream
audio->stopStream(stream);
audio->closeStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
}
cleanup:
delete audio;
return 0;
}
\endcode
The first thing to notice in this example is that we attempt to open a stream during class instantiation with an overloaded constructor. This constructor simply combines the functionality of the default constructor, used earlier, and the RtAudio::openStream() method. Again, we have specified a device value of 0, indicating that the default or first available device meeting the given parameters should be used. The integer identifier of the opened stream is returned via the <I>stream</I> pointer value. An attempt is made to open the stream with the specified <I>bufferSize</I> value. However, it is possible that the device will not accept this value, in which case the closest allowable size is used and returned via the pointer value. The constructor can fail if no available devices are found, or a memory allocation or device driver error occurs. Note that you should not call the RtAudio destructor if an exception is thrown during instantiation.
Because RtAudio can be used to simultaneously control more than a single stream, it is necessary that the stream identifier be provided to nearly all public methods. Assuming the constructor is successful, it is necessary to get a pointer to the buffer, provided by RtAudio, for use in feeding data to/from the opened stream. Note that the user should <I>NOT</I> attempt to deallocate the stream buffer memory ... memory management for the stream buffer will be automatically controlled by RtAudio. After starting the stream with RtAudio::startStream(), one simply fills that buffer, which is of length equal to the returned <I>bufferSize</I> value, with interleaved audio data (in the specified format) for playback. Finally, a call to the RtAudio::tickStream() routine triggers a blocking write call for the stream.
In general, one should call the RtAudio::stopStream() and RtAudio::closeStream() methods after finishing with a stream. However, both methods will implicitly be called during object destruction if necessary.
\section playbackc Playback (callback functionality)
The primary difference in using RtAudio with callback functionality involves the creation of a user-defined callback function. Here is an example which produces a sawtooth waveform for playback.
\code
#include <iostream.h>
#include "RtAudio.h"
// Two-channel sawtooth wave generator.
int sawtooth(char *buffer, int buffer_size, void *data)
{
int i, j;
double *my_buffer = (double *) buffer;
double *my_data = (double *) data;
// Write interleaved audio data.
for (i=0; i<buffer_size; i++) {
for (j=0; j<2; j++) {
*my_buffer++ = my_data[j];
my_data[j] += 0.005 * (j+1+(j*0.1));
if (my_data[j] >= 1.0) my_data[j] -= 2.0;
}
}
return 0;
}
int main()
{
int channels = 2;
int sample_rate = 44100;
int buffer_size = 256; // 256 sample frames
int n_buffers = 4; // number of internal buffers used by device
int device = 0; // 0 indicates the default or first available device
int stream; // our stream identifier
double data[2];
char input;
RtAudio *audio;
// Open a stream during RtAudio instantiation
try {
audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT64,
sample_rate, &buffer_size, n_buffers);
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
try {
// Set the stream callback function
audio->setStreamCallback(stream, &sawtooth, (void *)data);
// Start the stream
audio->startStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
cout << "\nPlaying ... press <enter> to quit.\n";
cin.get(input);
try {
// Stop and close the stream
audio->stopStream(stream);
audio->closeStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
}
cleanup:
delete audio;
return 0;
}
\endcode
After opening the device in exactly the same way as the previous example (except with a data format change), we must set our callback function for the stream using RtAudio::setStreamCallback(). This method will spawn a new process (or thread) which automatically calls the callback function when more data is needed. Note that the callback function is called only when the stream is "running" (between calls to the RtAudio::startStream() and RtAudio::stopStream() methods). The last argument to RtAudio::setStreamCallback() is a pointer to arbitrary data that you wish to access from within your callback function.
In this example, we stop the stream with an explicit call to RtAudio::stopStream(). When using callback functionality, it is also possible to stop a stream by returning a non-zero value from the callback function.
Once set with RtAudio::setStreamCallback, the callback process will continue to run for the life of the stream (until the stream is closed with RtAudio::closeStream() or the RtAudio instance is deleted). It is possible to disassociate a callback function and cancel its process for an open stream using the RtAudio::cancelStreamCallback() method. The stream can then be used with blocking functionality or a new callback can be associated with it.
\section recording Recording
Using RtAudio for audio input is almost identical to the way it is used for playback. Here's the blocking playback example rewritten for recording:
\code
// record.cpp
#include "RtAudio.h"
int main()
{
int count;
int channels = 2;
int sample_rate = 44100;
int buffer_size = 256; // 256 sample frames
int n_buffers = 4; // number of internal buffers used by device
float *buffer;
int device = 0; // 0 indicates the default or first available device
int stream; // our stream identifier
RtAudio *audio;
// Instantiate RtAudio and open a stream.
try {
audio = new RtAudio(&stream, 0, 0, device, channels,
RtAudio::RTAUDIO_FLOAT32, sample_rate, &buffer_size, n_buffers);
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
try {
// Get a pointer to the stream buffer
buffer = (float *) audio->getStreamBuffer(stream);
// Start the stream
audio->startStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
// An example loop which runs for about 40000 sample frames
count = 0;
while (count < 40000) {
// Read a buffer of data
try {
audio->tickStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
// Process the input samples (buffer_size sample frames) that were read
...
count += buffer_size;
}
try {
// Stop the stream
audio->stopStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
}
cleanup:
delete audio;
return 0;
}
\endcode
In this example, the stream was opened for recording with a non-zero <I>inputChannels</I> value. The only other difference between this example and that for playback involves the order of data processing in the loop, where it is necessary to first read a buffer of input data before manipulating it.
\section duplex Duplex Mode
Finally, it is easy to use RtAudio for simultaneous audio input/output, or duplex operation. In this example, we use a callback function and pass our recorded data directly through for playback.
\code
// duplex.cpp
#include <iostream.h>
#include "RtAudio.h"
// Pass-through function.
int pass(char *buffer, int buffer_size, void *)
{
// Surprise!! We do nothing to pass the data through.
return 0;
}
int main()
{
int channels = 2;
int sample_rate = 44100;
int buffer_size = 256; // 256 sample frames
int n_buffers = 4; // number of internal buffers used by device
int device = 0; // 0 indicates the default or first available device
int stream; // our stream identifier
double data[2];
char input;
RtAudio *audio;
// Open a stream during RtAudio instantiation
try {
audio = new RtAudio(&stream, device, channels, device, channels, RtAudio::RTAUDIO_FLOAT64,
sample_rate, &buffer_size, n_buffers);
}
catch (RtAudioError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
try {
// Set the stream callback function
audio->setStreamCallback(stream, &pass, NULL);
// Start the stream
audio->startStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
goto cleanup;
}
cout << "\nRunning duplex ... press <enter> to quit.\n";
cin.get(input);
try {
// Stop and close the stream
audio->stopStream(stream);
audio->closeStream(stream);
}
catch (RtAudioError &error) {
error.printMessage();
}
cleanup:
delete audio;
return 0;
}
\endcode
When an RtAudio stream is running in duplex mode (nonzero input <I>AND</I> output channels), the audio write (playback) operation always occurs before the audio read (record) operation. This sequence allows the use of a single buffer to store both output and input data.
As we see with this example, the write-read sequence of operations does not preclude the use of RtAudio in situations where input data is first processed and then output through a duplex stream. When the stream buffer is first allocated, it is initialized with zeros, which produces no audible result when output to the device. In this example, anything recorded by the audio stream input will be played out during the next round of audio processing.
Note that duplex operation can also be achieved by opening one output stream and one input stream using the same or different devices. However, there may be timing problems when attempting to use two different devices, due to possible device clock variations. This becomes even more difficult to achieve using two separate callback streams because it is not possible to explicitly control the calling order of the callback functions.
\section methods Summary of Methods
The following is short summary of public methods (not including constructors and the destructor) provided by RtAudio:
<UL>
<LI>RtAudio::openStream(): opens a stream with the specified parameters.</LI>
<LI>RtAudio::setStreamCallback(): sets a user-defined callback function for a given stream.</LI>
<LI>RtAudio::cancelStreamCallback(): cancels a callback process and function for a given stream.</LI>
<LI>RtAudio::getDeviceCount(): returns the number of audio devices available.</LI>
<LI>RtAudio::getDeviceInfo(): fills a user-supplied RTAUDIO_DEVICE structure for a specified device.</LI>
<LI>RtAudio::getStreamBuffer(): returns a pointer to the stream buffer.</LI>
<LI>RtAudio::tickStream(): triggers processing of input/output data for a stream (blocking).</LI>
<LI>RtAudio::closeStream(): closes the specified stream (implicitly called during object destruction). Once a stream is closed, the stream identifier is invalid and should not be used in calling any other RtAudio methods.</LI>
<LI>RtAudio::startStream(): (re)starts the specified stream, typically after it has been stopped with either stopStream() or abortStream() or after first opening the stream.</LI>
<LI>RtAudio::stopStream(): stops the specified stream, allowing any remaining samples in the queue to be played out and/or read in. This does not implicitly call RtAudio::closeStream().</LI>
<LI>RtAudio::abortStream(): stops the specified stream, discarding any remaining samples in the queue. This does not implicitly call closeStream().</LI>
<LI>RtAudio::streamWillBlock(): queries a stream to determine whether a call to the <I>tickStream()</I> method will block. A return value of 0 indicates that the stream will NOT block. A positive return value indicates the number of sample frames that cannot yet be processed without blocking.</LI>
</UL>
\section compiling Compiling
In order to compile RtAudio for a specific OS and audio API, it is necessary to supply the appropriate preprocessor definition and library within the compiler statement:
<P>
<TABLE BORDER=2 COLS=5 WIDTH="100%">
<TR BGCOLOR="beige">
<TD WIDTH="5%"><B>OS:</B></TD>
<TD WIDTH="5%"><B>Audio API:</B></TD>
<TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>
<TD WIDTH="5%"><B>Library:</B></TD>
<TD><B>Example Compiler Statement:</B></TD>
</TR>
<TR>
<TD>Linux</TD>
<TD>ALSA</TD>
<TD>__LINUX_ALSA_</TD>
<TD><TT>libasound, libpthread</TT></TD>
<TD><TT>g++ -Wall -D__LINUX_ALSA_ -o probe probe.cpp RtAudio.cpp -lasound -lpthread</TT></TD>
</TR>
<TR>
<TD>Linux</TD>
<TD>OSS</TD>
<TD>__LINUX_OSS_</TD>
<TD><TT>libpthread</TT></TD>
<TD><TT>g++ -Wall -D__LINUX_OSS_ -o probe probe.cpp RtAudio.cpp -lpthread</TT></TD>
</TR>
<TR>
<TD>Irix</TD>
<TD>AL</TD>
<TD>__IRIX_AL_</TD>
<TD><TT>libaudio, libpthread</TT></TD>
<TD><TT>CC -Wall -D__IRIX_AL_ -o probe probe.cpp RtAudio.cpp -laudio -lpthread</TT></TD>
</TR>
<TR>
<TD>Windows</TD>
<TD>Direct Sound</TD>
<TD>__WINDOWS_DS_</TD>
<TD><TT>dsound.lib (ver. 5.0 or higher), multithreaded</TT></TD>
<TD><I>compiler specific</I></TD>
</TR>
</TABLE>
<P>
The example compiler statements above could be used to compile the <TT>probe.cpp</TT> example file, assuming that <TT>probe.cpp</TT>, <TT>RtAudio.h</TT>, and <TT>RtAudio.cpp</TT> all exist in the same directory.
\section osnotes OS Notes
RtAudio is designed to provide a common API across the various supported operating systems and audio libraries. Despite that, however, some issues need to be mentioned with regard to each.
\subsection linux Linux:
RtAudio for Linux was developed under Redhat distributions 7.0 - 7.2. Two different audio APIs are supported on Linux platforms: OSS and <A href="http://www.alsa-project.org/">ALSA</A>. The OSS API has existed for at least 6 years and the Linux kernel is distributed with free versions of OSS audio drivers. Therefore, a generic Linux system is most likely to have OSS support. The ALSA API is relatively new and at this time is not part of the Linux kernel distribution. Work is in progress to make ALSA part of the 2.5 development kernel series. Despite that, the ALSA API offers significantly better functionality than the OSS API. RtAudio provides support for the 0.9 and higher versions of ALSA. Input/output latency on the order of 15-20 milliseconds can typically be achieved under both OSS or ALSA by fine-tuning the RtAudio buffer parameters (without kernel modifications). Latencies on the order of 5 milliseconds or less can be achieved using a low-latency kernel patch and increasing FIFO scheduling priority. The pthread library, which is used for callback functionality, is a standard component of all Linux distributions.
The ALSA library includes OSS emulation support. That means that you can run programs compiled for the OSS API even when using the ALSA drivers and library. It should be noted however that OSS emulation under ALSA is not perfect. Specifically, channel number queries seem to consistently produce invalid results. While OSS emulation is successful for the majority of RtAudio tests, it is recommended that the native ALSA implementation of RtAudio be used on systems which have ALSA drivers installed.
The ALSA implementation of RtAudio makes no use of the ALSA "plug" interface. All necessary data format conversions, channel compensation, deinterleaving, and byte-swapping is handled by internal RtAudio routines.
\subsection irix Irix (SGI):
The Irix version of RtAudio was written and tested on an SGI Indy running Irix version 6.5 and the newer "al" audio library. RtAudio does not compile under Irix version 6.3 because the C++ compiler is too old. Despite the relatively slow speed of the Indy, RtAudio was found to behave quite well and input/output latency was very good. No problems were found with respect to using the pthread library.
\subsection windows Windows:
RtAudio under Windows is written using the DirectSound API. In order to compile RtAudio under Windows, you must have the header and source files for DirectSound version 0.5 or higher. As far as I know, you cannot compile RtAudio for Windows NT because there is not sufficient DirectSound support. Audio output latency with DirectSound can be reasonably good (on the order of 20 milliseconds). On the other hand, input audio latency tends to be terrible (100 milliseconds or more). Further, DirectSound drivers tend to crash easily when experimenting with buffer parameters. On my system, I found it necessary to use values around nBuffers = 8 and bufferSize = 512 to avoid crashing my system. RtAudio was developed with Visual C++ version 6.0. I was forced in several instances to modify code in order to get it to compile under the non-standard version of C++ that Microsoft so unprofessionally implemented. We can only hope that the developers of Visual C++ 7.0 will have time to read the C++ standard.
\section acknowledge Acknowledgments
The RtAudio API incorporates many of the concepts developed in the <A href="http://www.portaudio.com/">PortAudio</A> project by Phil Burk and Ross Bencina. Early development also incorporated ideas from Bill Schottstaedt's <A href="http://www-ccrma.stanford.edu/software/snd/sndlib/">sndlib</A>. The CCRMA <A href="http://www-ccrma.stanford.edu/groups/soundwire/">SoundWire group</A> provided valuable feedback during the API proposal stages.
RtAudio was slowly developed over the course of many months while in residence at the <A href="http://www.iua.upf.es/">Institut Universitari de L'Audiovisual (IUA)</A> in Barcelona, Spain, the <A href="http://www.acoustics.hut.fi/">Laboratory of Acoustics and Audio Signal Processing</A> at the Helsinki University of Technology, Finland, and the <A href="http://www-ccrma.stanford.edu/">Center for Computer Research in Music and Acoustics (CCRMA)</A> at <A href="http://www.stanford.edu/">Stanford University</A>. This work was supported in part by the United States Air Force Office of Scientific Research (grant \#F49620-99-1-0293).
These documentation files were generated using <A href="http://www.doxygen.org/">doxygen</A> by Dimitri van Heesch.
*/

+ 125
- 0
rtaudio.dsw View File

@@ -0,0 +1,125 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "call_inout"=.\tests\call_inout.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "call_saw"=.\tests\call_saw.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "call_twostreams"=.\tests\call_twostreams.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "in_out"=.\tests\in_out.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "info"=.\tests\info.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "play_raw"=.\tests\play_raw.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "play_saw"=.\tests\play_saw.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "record_raw"=.\tests\record_raw.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "twostreams"=.\tests\twostreams.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

+ 0
- 0
tests/Debug/.placeholder View File


+ 58
- 0
tests/Makefile View File

@@ -0,0 +1,58 @@

OS = $(shell uname)

RM = /bin/rm

ifeq ($(OS),Linux) # These are for Linux
INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams
CC = g++ -Wall -D__LINUX_OSS_# -g -pg -O3
LIBRARY = -lpthread
# CC = g++ -g -Wall -D__LINUX_ALSA_ # -g -pg -O3
# LIBRARY = -lpthread -lasound
INCLUDE = -I../
endif

ifeq ($(OS),IRIX) # These are for SGI
INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams
CC = CC -D__IRIX_AL_ # -g -fullwarn -D__SGI_CC__ -O2
LIBRARY = -laudio -lpthread
INCLUDE = -I../
endif

all: $(INSTR)

clean :
rm $(INSTR) *~ *.raw core *.o

cleanIns :
rm $(INSTR)

strip :
strip $(INSTR)

info: info.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o info info.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

play_saw: play_saw.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o play_saw play_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

play_raw: play_raw.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o play_raw play_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

record_raw: record_raw.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o record_raw record_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

in_out: in_out.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o in_out in_out.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

twostreams: twostreams.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o twostreams twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

call_saw: call_saw.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o call_saw call_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

call_inout: call_inout.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o call_inout call_inout.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

call_twostreams: call_twostreams.cpp ../RtAudio.cpp ../RtAudio.h
$(CC) -o call_twostreams call_twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)

+ 0
- 0
tests/Release/.placeholder View File


+ 100
- 0
tests/call_inout.cpp View File

@@ -0,0 +1,100 @@
/******************************************/
/*
call_inout.c
by Gary P. Scavone, 2001

Records from default input and passes it
through to the output. Takes number of
channels and sample rate as input arguments.
Uses callback functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: call_inout N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int inout(char *buffer, int buffer_size, void *)
{
// Surprise!! We do nothing to pass the data through.
return 0;
}

int main(int argc, char *argv[])
{
int device, stream, chans, fs;
RtAudio *audio;
char input;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
int buffer_size = 512;
device = 0; // default device
try {
audio = new RtAudio(&stream, device, chans, device, chans,
FORMAT, fs, &buffer_size, 8);
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

try {
audio->setStreamCallback(stream, &inout, NULL);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nRunning ... press <enter> to quit.\n";
cin.get(input);

try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;

return 0;
}

+ 110
- 0
tests/call_inout.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="call_inout" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=call_inout - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "call_inout.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "call_inout.mak" CFG="call_inout - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "call_inout - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "call_inout - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "call_inout - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "call_inout___Win32_Release"
# PROP BASE Intermediate_Dir "call_inout___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "call_inout - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "call_inout___Win32_Debug"
# PROP BASE Intermediate_Dir "call_inout___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "call_inout - Win32 Release"
# Name "call_inout - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\call_inout.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 128
- 0
tests/call_saw.cpp View File

@@ -0,0 +1,128 @@
/******************************************/
/*
call_saw.c
by Gary P. Scavone, 2001

Play sawtooth waveforms of distinct frequency.
Takes number of channels and sample rate as
input arguments. Use callback functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24
#define SCALE 2147483647.0

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8
#define SCALE 127.0

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16
#define SCALE 32767.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32
#define SCALE 2147483647.0
*/
typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
#define SCALE 1.0

/*
typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64
#define SCALE 1.0
*/

#define BASE_RATE 0.005
#define TIME 1.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: call_saw N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int chans;

int saw(char *buffer, int buffer_size, void *data)
{
int i, j;
extern int chans;
MY_TYPE *my_buffer = (MY_TYPE *) buffer;
double *my_data = (double *) data;

for (i=0; i<buffer_size; i++) {
for (j=0; j<chans; j++) {
*my_buffer++ = (MY_TYPE) (my_data[j] * SCALE);
my_data[j] += BASE_RATE * (j+1+(j*0.1));
if (my_data[j] >= 1.0) my_data[j] -= 2.0;
}
}

return 0;
}

int main(int argc, char *argv[])
{
int device, stream, buffer_size, fs;
RtAudio *audio;
double *data;
char input;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 256;
device = 0; // default device
try {
audio = new RtAudio(&stream, device, chans, 0, 0,
FORMAT, fs, &buffer_size, 4);
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

data = (double *) calloc(chans, sizeof(double));

try {
audio->setStreamCallback(stream, &saw, (void *)data);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nPlaying ... press <enter> to quit.\n";
cin.get(input);

// Stop the stream.
try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;
if (data) free(data);

return 0;
}

+ 110
- 0
tests/call_saw.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="call_saw" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=call_saw - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "call_saw.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "call_saw.mak" CFG="call_saw - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "call_saw - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "call_saw - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "call_saw - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "call_saw___Win32_Release"
# PROP BASE Intermediate_Dir "call_saw___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "call_saw - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "call_saw___Win32_Debug"
# PROP BASE Intermediate_Dir "call_saw___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "call_saw - Win32 Release"
# Name "call_saw - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\call_saw.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 166
- 0
tests/call_twostreams.cpp View File

@@ -0,0 +1,166 @@
/******************************************/
/*
twostreams.cpp
by Gary P. Scavone, 2001

Text executable using two streams with
callbacks.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24
#define SCALE 2147483647.0

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8
#define SCALE 127.0

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16
#define SCALE 32767.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32
#define SCALE 2147483647.0

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
#define SCALE 1.0
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64
#define SCALE 1.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: call_twostreams N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int chans;

int in(char *buffer, int buffer_size, void *data)
{
extern int chans;
MY_TYPE *my_buffer = (MY_TYPE *) buffer;
MY_TYPE *my_data = (MY_TYPE *) data;
long buffer_bytes = buffer_size * chans * sizeof(MY_TYPE);

memcpy(my_data, my_buffer, buffer_bytes);

return 0;
}

int out(char *buffer, int buffer_size, void *data)
{
extern int chans;
MY_TYPE *my_buffer = (MY_TYPE *) buffer;
MY_TYPE *my_data = (MY_TYPE *) data;
long buffer_bytes = buffer_size * chans * sizeof(MY_TYPE);

memcpy(my_buffer, my_data, buffer_bytes);

return 0;
}

int main(int argc, char *argv[])
{
int device, buffer_size, stream1, stream2, fs;
MY_TYPE *data = 0;
RtAudio *audio;
char input;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 512;
device = 0; // default device
try {
audio = new RtAudio();
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

try {
stream1 = audio->openStream(0, 0, device, chans,
FORMAT, fs, &buffer_size, 8);
stream2 = audio->openStream(device, chans, 0, 0,
FORMAT, fs, &buffer_size, 8);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

data = (MY_TYPE *) calloc(chans*buffer_size, sizeof(MY_TYPE));
try {
audio->setStreamCallback(stream1, &in, (void *)data);
audio->setStreamCallback(stream2, &out, (void *)data);
audio->startStream(stream1);
audio->startStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n";
cin.get(input);

cout << "\nStopping both streams.\n";
try {
audio->stopStream(stream1);
audio->stopStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nPress <enter> to restart streams:\n";
cin.get(input);

try {
audio->startStream(stream1);
audio->startStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n";
cin.get(input);

try {
audio->stopStream(stream1);
audio->stopStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream1);
audio->closeStream(stream2);
delete audio;
if (data) free(data);

return 0;
}

+ 110
- 0
tests/call_twostreams.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="call_twostreams" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=call_twostreams - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "call_twostreams.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "call_twostreams.mak" CFG="call_twostreams - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "call_twostreams - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "call_twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "call_twostreams - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "call_twostreams___Win32_Release"
# PROP BASE Intermediate_Dir "call_twostreams___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "call_twostreams - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "call_twostreams___Win32_Debug"
# PROP BASE Intermediate_Dir "call_twostreams___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "call_twostreams - Win32 Release"
# Name "call_twostreams - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\call_twostreams.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 109
- 0
tests/in_out.cpp View File

@@ -0,0 +1,109 @@
/******************************************/
/*
in_out.c
by Gary P. Scavone, 2001

Records from default input and passes it
through to the output. Takes number of
channels and sample rate as input arguments.
Use blocking functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64

#define TIME 4.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: in_out N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int main(int argc, char *argv[])
{
int chans, fs, device, buffer_size, stream;
long frames, counter = 0;
MY_TYPE *buffer;
RtAudio *audio;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 512;
device = 0; // default device
try {
audio = new RtAudio(&stream, device, chans, device, chans,
FORMAT, fs, &buffer_size, 8);
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

frames = (long) (fs * TIME);

try {
buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nRunning for " << TIME << " seconds ... fragment_size = " << buffer_size << endl;
while (counter < frames) {

try {
audio->tickStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}
counter += buffer_size;
}

try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;

return 0;
}

+ 110
- 0
tests/in_out.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="in_out" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=in_out - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "in_out.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "in_out.mak" CFG="in_out - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "in_out - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "in_out - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "in_out - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "in_out___Win32_Release"
# PROP BASE Intermediate_Dir "in_out___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "in_out - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "in_out___Win32_Debug"
# PROP BASE Intermediate_Dir "in_out___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "in_out - Win32 Release"
# Name "in_out - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\in_out.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 66
- 0
tests/info.cpp View File

@@ -0,0 +1,66 @@
/******************************************/
/*
info.cpp
by Gary P. Scavone, 2001

Prints audio system/device info.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

int main(int argc, char *argv[])
{
RtAudio *audio;
RtAudio::RTAUDIO_DEVICE my_info;
try {
audio = new RtAudio();
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

int devices = audio->getDeviceCount();
cout << "\nFound " << devices << " devices ...\n";

for (int i=0; i<devices; i++) {
try {
audio->getDeviceInfo(i, &my_info);
}
catch (RtAudioError &m) {
m.printMessage();
break;
}

cout << "\nname = " << my_info.name << '\n';
if (my_info.probed == true)
cout << "probe successful\n";
else
cout << "probe unsuccessful\n";
cout << "maxOutputChans = " << my_info.maxOutputChannels << '\n';
cout << "minOutputChans = " << my_info.minOutputChannels << '\n';
cout << "maxInputChans = " << my_info.maxInputChannels << '\n';
cout << "minInputChans = " << my_info.minInputChannels << '\n';
cout << "maxDuplexChans = " << my_info.maxDuplexChannels << '\n';
cout << "minDuplexChans = " << my_info.minDuplexChannels << '\n';
if (my_info.hasDuplexSupport)
cout << "duplex support = true\n";
else
cout << "duplex support = false\n";
cout << "format = " << my_info.nativeFormats << '\n';
if (my_info.nSampleRates == -1)
cout << "min_srate = " << my_info.sampleRates[0] << ", max_srate = " << my_info.sampleRates[1] << '\n';
else {
cout << "sample rates = ";
for (int j=0; j<my_info.nSampleRates; j++)
cout << my_info.sampleRates[j] << " ";
cout << endl;
}
}
cout << endl;

delete audio;
return 0;
}

+ 110
- 0
tests/info.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="info" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=info - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "info.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "info.mak" CFG="info - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "info - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "info - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "info - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "info - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "info___Win32_Debug"
# PROP BASE Intermediate_Dir "info___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "info - Win32 Release"
# Name "info - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\info.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 128
- 0
tests/play_raw.cpp View File

@@ -0,0 +1,128 @@
/******************************************/
/*
play_raw.c
by Gary P. Scavone, 2001

Play a raw file. It is necessary that the
file be of the same format as defined below.
Uses blocking functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>
#include <stdio.h>

/*
typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8
#define SCALE 127.0

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16
#define SCALE 32767.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24
#define SCALE 8388607.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32
#define SCALE 2147483647.0

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
#define SCALE 1.0;
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64
#define SCALE 1.0;

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: play_raw N fs file\n";
cout << " where N = number of channels,\n";
cout << " fs = the sample rate, \n";
cout << " and file = the raw file to play.\n\n";
exit(0);
}

int main(int argc, char *argv[])
{
int chans, fs, device, buffer_size, count, stream;
long counter = 0;
MY_TYPE *buffer;
char *file;
FILE *fd;
RtAudio *audio;

// minimal command-line checking
if (argc != 4) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);
file = argv[3];

fd = fopen(file,"rb");
if (!fd) {
cout << "can't find file!\n";
exit(0);
}

// Open the realtime output device
buffer_size = 256;
device = 0; // default device
try {
audio = new RtAudio(&stream, device, chans, 0, 0,
FORMAT, fs, &buffer_size, 2);
}
catch (RtAudioError &m) {
m.printMessage();
fclose(fd);
exit(EXIT_FAILURE);
}

try {
buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

while (1) {
count = fread(buffer, chans * sizeof(MY_TYPE), buffer_size, fd);

if (count == buffer_size) {
try {
audio->tickStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}
}
else
break;
counter += buffer_size;
}

try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;
fclose(fd);

return 0;
}

+ 110
- 0
tests/play_raw.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="play_raw" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=play_raw - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "play_raw.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "play_raw.mak" CFG="play_raw - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "play_raw - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "play_raw - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "play_raw - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "play_raw - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "play_raw___Win32_Debug"
# PROP BASE Intermediate_Dir "play_raw___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "play_raw - Win32 Release"
# Name "play_raw - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\play_raw.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 128
- 0
tests/play_saw.cpp View File

@@ -0,0 +1,128 @@
/******************************************/
/*
play_saw.c
by Gary P. Scavone, 2001

Play sawtooth waveforms of distinct frequency.
Takes number of channels and sample rate as
input arguments. Uses blocking functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24
#define SCALE 2147483647.0

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8
#define SCALE 127.0

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16
#define SCALE 32767.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32
#define SCALE 2147483647.0
*/
typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
#define SCALE 1.0

/*
typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64
#define SCALE 1.0
*/

#define BASE_RATE 0.005
#define TIME 1.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: play_saw N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int main(int argc, char *argv[])
{
int chans, fs, device, buffer_size, stream;
long frames, counter = 0, i, j;
MY_TYPE *buffer;
RtAudio *audio;
double *data;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 256;
device = 0; // default device
try {
audio = new RtAudio(&stream, device, chans, 0, 0,
FORMAT, fs, &buffer_size, 4);
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

frames = (long) (fs * TIME);
data = (double *) calloc(chans, sizeof(double));

try {
buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nPlaying for " << TIME << " seconds." << endl;
while (counter < frames) {
for (i=0; i<buffer_size; i++) {
for (j=0; j<chans; j++) {
buffer[i*chans+j] = (MY_TYPE) (data[j] * SCALE);
data[j] += BASE_RATE * (j+1+(j*0.1));
if (data[j] >= 1.0) data[j] -= 2.0;
}
}

try {
//cout << "frames until no block = " << audio->streamWillBlock(stream) << endl;
audio->tickStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

counter += buffer_size;
}

try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;
if (data) free(data);

return 0;
}

+ 110
- 0
tests/play_saw.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="play_saw" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=play_saw - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "play_saw.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "play_saw.mak" CFG="play_saw - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "play_saw - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "play_saw - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "play_saw - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "play_saw - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "play_saw___Win32_Debug"
# PROP BASE Intermediate_Dir "play_saw___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "play_saw - Win32 Release"
# Name "play_saw - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\play_saw.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 114
- 0
tests/record_raw.cpp View File

@@ -0,0 +1,114 @@
/******************************************/
/*
record_raw.c
by Gary P. Scavone, 2001

Records from default input. Takes
number of channels and sample rate
as input arguments. Uses blocking calls.
*/
/******************************************/

#include "RtAudio.h"
#include <stdio.h>
#include <iostream.h>

/*
typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64

#define TIME 2.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: record_raw N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int main(int argc, char *argv[])
{
int chans, fs, device, buffer_size, stream;
long frames, counter = 0;
MY_TYPE *buffer;
FILE *fd;
RtAudio *audio;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 512;
device = 0; // default device
try {
audio = new RtAudio(&stream, 0, 0, device, chans,
FORMAT, fs, &buffer_size, 8);
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

fd = fopen("test.raw","wb");
frames = (long) (fs * TIME);

try {
buffer = (MY_TYPE *) audio->getStreamBuffer(stream);
audio->startStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nRecording for " << TIME << " seconds ... writing file test.raw." << endl;
while (counter < frames) {

try {
audio->tickStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

fwrite(buffer, sizeof(MY_TYPE), chans * buffer_size, fd);
counter += buffer_size;
}

try {
audio->stopStream(stream);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream);
delete audio;
fclose(fd);

return 0;
}

+ 110
- 0
tests/record_raw.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="record_raw" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=record_raw - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "record_raw.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "record_raw.mak" CFG="record_raw - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "record_raw - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "record_raw - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "record_raw - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "record_raw - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "record_raw___Win32_Debug"
# PROP BASE Intermediate_Dir "record_raw___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "record_raw - Win32 Release"
# Name "record_raw - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\record_raw.cpp
# End Source File
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

+ 204
- 0
tests/twostreams.cpp View File

@@ -0,0 +1,204 @@
/******************************************/
/*
twostreams.cpp
by Gary P. Scavone, 2001

Text executable for audio playback,
recording, duplex operation, stopping,
starting, and aborting operations.
Takes number of channels and sample
rate as input arguments. Runs input
and output through two separate streams.
Uses blocking functionality.
*/
/******************************************/

#include "RtAudio.h"
#include <iostream.h>
#include <stdio.h>

/*
typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT24
#define SCALE 2147483647.0

typedef char MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT8
#define SCALE 127.0

typedef signed short MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT16
#define SCALE 32767.0

typedef signed long MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_SINT32
#define SCALE 2147483647.0

typedef float MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT32
#define SCALE 1.0
*/

typedef double MY_TYPE;
#define FORMAT RtAudio::RTAUDIO_FLOAT64
#define SCALE 1.0

#define BASE_RATE 0.005
#define TIME 2.0

void usage(void) {
/* Error function in case of incorrect command-line
argument specifications
*/
cout << "\nuseage: twostreams N fs\n";
cout << " where N = number of channels,\n";
cout << " and fs = the sample rate.\n\n";
exit(0);
}

int main(int argc, char *argv[])
{
int chans, fs, device, buffer_size, stream1, stream2;
long frames, counter = 0, i, j;
MY_TYPE *buffer1, *buffer2;
RtAudio *audio;
FILE *fd;
double *data;

// minimal command-line checking
if (argc != 3) usage();

chans = (int) atoi(argv[1]);
fs = (int) atoi(argv[2]);

// Open the realtime output device
buffer_size = 512;
device = 0; // default device
try {
audio = new RtAudio();
}
catch (RtAudioError &m) {
m.printMessage();
exit(EXIT_FAILURE);
}

try {
stream1 = audio->openStream(device, chans, 0, 0,
FORMAT, fs, &buffer_size, 8);
stream2 = audio->openStream(0, 0, device, chans,
FORMAT, fs, &buffer_size, 8);
buffer1 = (MY_TYPE *) audio->getStreamBuffer(stream1);
buffer2 = (MY_TYPE *) audio->getStreamBuffer(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

frames = (long) (fs * TIME);
data = (double *) calloc(chans, sizeof(double));

try {
audio->startStream(stream1);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

cout << "\nStarting sawtooth playback stream for " << TIME << " seconds." << endl;
while (counter < frames) {
for (i=0; i<buffer_size; i++) {
for (j=0; j<chans; j++) {
buffer1[i*chans+j] = (MY_TYPE) (data[j] * SCALE);
data[j] += BASE_RATE * (j+1+(j*0.1));
if (data[j] >= 1.0) data[j] -= 2.0;
}
}

try {
audio->tickStream(stream1);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

counter += buffer_size;
}

cout << "\nStopping playback stream." << endl;
try {
audio->stopStream(stream1);
audio->startStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

fd = fopen("test.raw","wb");

counter = 0;
cout << "\nStarting recording stream for " << TIME << " seconds." << endl;
while (counter < frames) {

try {
audio->tickStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

fwrite(buffer2, sizeof(MY_TYPE), chans * buffer_size, fd);
counter += buffer_size;
}

fclose(fd);
cout << "\nAborting recording." << endl;

try {
audio->abortStream(stream2);
audio->startStream(stream1);
audio->startStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

counter = 0;
cout << "\nStarting playback and record streams (quasi-duplex) for " << TIME << " seconds." << endl;
while (counter < frames) {

try {
audio->tickStream(stream2);
memcpy(buffer1, buffer2, sizeof(MY_TYPE) * chans * buffer_size);
audio->tickStream(stream1);
}
catch (RtAudioError &m) {
m.printMessage();
goto cleanup;
}

counter += buffer_size;
}

cout << "\nStopping both streams." << endl;
try {
audio->stopStream(stream1);
audio->stopStream(stream2);
}
catch (RtAudioError &m) {
m.printMessage();
}

cleanup:
audio->closeStream(stream1);
audio->closeStream(stream2);
delete audio;
if (data) free(data);

return 0;
}

+ 110
- 0
tests/twostreams.dsp View File

@@ -0,0 +1,110 @@
# Microsoft Developer Studio Project File - Name="twostreams" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=twostreams - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "twostreams.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "twostreams.mak" CFG="twostreams - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "twostreams - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "twostreams - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "twostreams___Win32_Release"
# PROP BASE Intermediate_Dir "twostreams___Win32_Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ""
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "twostreams - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "twostreams___Win32_Debug"
# PROP BASE Intermediate_Dir "twostreams___Win32_Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "twostreams - Win32 Release"
# Name "twostreams - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\RtAudio.cpp
# End Source File
# Begin Source File
SOURCE=.\twostreams.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\RtAudio.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

Loading…
Cancel
Save