Added new versions of RtAudio and RtMidi, updated RtWvIn and RtWvOut for new API, updated demo project for new API.

This commit is contained in:
garyscavone
2023-08-04 09:44:26 -04:00
parent 2af2f1c816
commit 8b29e0ea6d
15 changed files with 4225 additions and 2579 deletions

View File

@@ -11,7 +11,7 @@
RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/
RtAudio: realtime audio i/o C++ classes
Copyright (c) 2001-2021 Gary P. Scavone
Copyright (c) 2001-2023 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
@@ -46,7 +46,24 @@
#ifndef __RTAUDIO_H
#define __RTAUDIO_H
#define RTAUDIO_VERSION "5.2.0"
#define RTAUDIO_VERSION_MAJOR 6
#define RTAUDIO_VERSION_MINOR 0
#define RTAUDIO_VERSION_PATCH 1
#define RTAUDIO_VERSION_BETA 0
#define RTAUDIO_TOSTRING2(n) #n
#define RTAUDIO_TOSTRING(n) RTAUDIO_TOSTRING2(n)
#if RTAUDIO_VERSION_BETA > 0
#define RTAUDIO_VERSION RTAUDIO_TOSTRING(RTAUDIO_VERSION_MAJOR) \
"." RTAUDIO_TOSTRING(RTAUDIO_VERSION_MINOR) \
"." RTAUDIO_TOSTRING(RTAUDIO_VERSION_PATCH) \
"beta" RTAUDIO_TOSTRING(RTAUDIO_VERSION_BETA)
#else
#define RTAUDIO_VERSION RTAUDIO_TOSTRING(RTAUDIO_VERSION_MAJOR) \
"." RTAUDIO_TOSTRING(RTAUDIO_VERSION_MINOR) \
"." RTAUDIO_TOSTRING(RTAUDIO_VERSION_PATCH)
#endif
#if defined _WIN32 || defined __CYGWIN__
#if defined(RTAUDIO_EXPORT)
@@ -64,8 +81,8 @@
#include <string>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <functional>
/*! \typedef typedef unsigned long RtAudioFormat;
\brief RtAudio data format type.
@@ -75,6 +92,8 @@
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.
Note that there are no range checks for floating-point values that
extend beyond plus/minus 1.0.
- \e RTAUDIO_SINT8: 8-bit signed integer.
- \e RTAUDIO_SINT16: 16-bit signed integer.
@@ -206,52 +225,19 @@ typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
RtAudioStreamStatus status,
void *userData );
/************************************************************************/
/*! \class RtAudioError
\brief Exception handling class for RtAudio.
The RtAudioError class is quite simple but it does allow errors to be
"caught" by RtAudioError::Type. See the RtAudio documentation to know
which methods can throw an RtAudioError.
*/
/************************************************************************/
class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
{
public:
//! Defined RtAudioError types.
enum Type {
WARNING, /*!< A non-critical error. */
DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
UNSPECIFIED, /*!< The default, unspecified error type. */
NO_DEVICES_FOUND, /*!< No devices found on system. */
INVALID_DEVICE, /*!< An invalid device ID was specified. */
MEMORY_ERROR, /*!< An error occurred during memory allocation. */
INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
INVALID_USE, /*!< The function was called incorrectly. */
DRIVER_ERROR, /*!< A system driver error occurred. */
SYSTEM_ERROR, /*!< A system error occurred. */
THREAD_ERROR /*!< A thread error occurred. */
};
//! The constructor.
RtAudioError( const std::string& message,
Type type = RtAudioError::UNSPECIFIED )
: std::runtime_error(message), type_(type) {}
//! Prints thrown error message to stderr.
virtual void printMessage( void ) const
{ std::cerr << '\n' << what() << "\n\n"; }
//! Returns the thrown error message type.
virtual const Type& getType(void) const { return type_; }
//! Returns the thrown error message string.
virtual const std::string getMessage(void) const
{ return std::string(what()); }
protected:
Type type_;
enum RtAudioErrorType {
RTAUDIO_NO_ERROR = 0, /*!< No error. */
RTAUDIO_WARNING, /*!< A non-critical error. */
RTAUDIO_UNKNOWN_ERROR, /*!< An unspecified error type. */
RTAUDIO_NO_DEVICES_FOUND, /*!< No devices found on system. */
RTAUDIO_INVALID_DEVICE, /*!< An invalid device ID was specified. */
RTAUDIO_DEVICE_DISCONNECT, /*!< A device in use was disconnected. */
RTAUDIO_MEMORY_ERROR, /*!< An error occurred during memory allocation. */
RTAUDIO_INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
RTAUDIO_INVALID_USE, /*!< The function was called incorrectly. */
RTAUDIO_DRIVER_ERROR, /*!< A system driver error occurred. */
RTAUDIO_SYSTEM_ERROR, /*!< A system error occurred. */
RTAUDIO_THREAD_ERROR /*!< A thread error occurred. */
};
//! RtAudio error callback function prototype.
@@ -259,7 +245,9 @@ class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
\param type Type of error.
\param errorText Error description.
*/
typedef void (*RtAudioErrorCallback)( RtAudioError::Type type, const std::string &errorText );
typedef std::function<void(RtAudioErrorType type,
const std::string &errorText )>
RtAudioErrorCallback;
// **************************************************************** //
//
@@ -283,13 +271,13 @@ class RTAUDIO_DLL_PUBLIC RtAudio
//! Audio API specifier arguments.
enum Api {
UNSPECIFIED, /*!< Search for a working compiled API. */
MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
UNIX_JACK, /*!< The Jack Low-Latency Audio Server API. */
LINUX_PULSE, /*!< The Linux PulseAudio API. */
LINUX_OSS, /*!< The Linux Open Sound System API. */
UNIX_JACK, /*!< The Jack Low-Latency Audio Server API. */
MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
WINDOWS_WASAPI, /*!< The Microsoft WASAPI API. */
WINDOWS_ASIO, /*!< The Steinberg Audio Stream I/O API. */
WINDOWS_WASAPI, /*!< The Microsoft WASAPI API. */
WINDOWS_DS, /*!< The Microsoft DirectSound API. */
RTAUDIO_DUMMY, /*!< A compilable but non-functional API. */
NUM_APIS /*!< Number of values in this enum. */
@@ -297,21 +285,23 @@ class RTAUDIO_DLL_PUBLIC RtAudio
//! The public device information structure for returning queried values.
struct DeviceInfo {
bool probed; /*!< true if the device capabilities were successfully probed. */
std::string name; /*!< Character string device identifier. */
unsigned int ID{}; /*!< Device ID used to specify a device to RtAudio. */
std::string name; /*!< Character string device name. */
unsigned int outputChannels{}; /*!< Maximum output channels supported by device. */
unsigned int inputChannels{}; /*!< Maximum input channels supported by device. */
unsigned int duplexChannels{}; /*!< Maximum simultaneous input/output channels supported by device. */
bool isDefaultOutput{false}; /*!< true if this is the default output device. */
bool isDefaultInput{false}; /*!< true if this is the default input device. */
std::vector<unsigned int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */
unsigned int currentSampleRate{}; /*!< Current sample rate, system sample rate as currently configured. */
unsigned int preferredSampleRate{}; /*!< Preferred sample rate, e.g. for WASAPI the system sample rate. */
RtAudioFormat nativeFormats{}; /*!< Bit mask of supported data formats. */
};
//! The structure for specifying input or output stream parameters.
struct StreamParameters {
unsigned int deviceId{}; /*!< Device index (0 to getDeviceCount() - 1). */
//std::string deviceName{}; /*!< Device name from device list. */
unsigned int deviceId{}; /*!< Device id as provided by getDeviceIds(). */
unsigned int nChannels{}; /*!< Number of channels. */
unsigned int firstChannel{}; /*!< First channel index on device (default = 0). */
};
@@ -369,9 +359,11 @@ class RTAUDIO_DLL_PUBLIC RtAudio
function by the value actually used by the system.
The \c streamName parameter can be used to set the client name
when using the Jack API. By default, the client name is set to
RtApiJack. However, if you wish to create multiple instances of
RtAudio with Jack, each instance must have a unique client name.
when using the Jack API or the application name when using the
Pulse API. By default, the Jack client name is set to RtApiJack.
However, if you wish to create multiple instances of RtAudio with
Jack, each instance must have a unique client name. The default
Pulse application name is set to "RtAudio."
*/
struct StreamOptions {
RtAudioStreamFlags flags{}; /*!< A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE, RTAUDIO_ALSA_USE_DEFAULT). */
@@ -409,21 +401,36 @@ class RTAUDIO_DLL_PUBLIC RtAudio
//! Return the compiled audio API having the given name.
/*!
A case insensitive comparison will check the specified name
against the list of compiled APIs, and return the one which
against the list of compiled APIs, and return the one that
matches. On failure, the function returns UNSPECIFIED.
*/
static RtAudio::Api getCompiledApiByName( const std::string &name );
//! Return the compiled audio API having the given display name.
/*!
A case sensitive comparison will check the specified display name
against the list of compiled APIs, and return the one that
matches. On failure, the function returns UNSPECIFIED.
*/
static RtAudio::Api getCompiledApiByDisplayName( const std::string &name );
//! The class constructor.
/*!
The constructor performs minor initialization tasks. An exception
can be thrown if no API support is compiled.
The constructor attempts to create an RtApi instance.
If no API argument is specified and multiple API support has been
compiled, the default order of use is JACK, ALSA, OSS (Linux
systems) and ASIO, DS (Windows systems).
If an API argument is specified but that API has not been
compiled, a warning is issued and an instance of an available API
is created. If no compiled API is found, the routine will abort
(though this should be impossible because RtDummy is the default
if no API-specific preprocessor definition is provided to the
compiler). If no API argument is specified and multiple API
support has been compiled, the default order of use is JACK, ALSA,
OSS (Linux systems) and ASIO, DS (Windows systems).
An optional errorCallback function can be specified to
subsequently receive warning and error messages.
*/
RtAudio( RtAudio::Api api=UNSPECIFIED );
RtAudio( RtAudio::Api api=UNSPECIFIED, RtAudioErrorCallback&& errorCallback=0 );
//! The destructor.
/*!
@@ -437,65 +444,89 @@ class RTAUDIO_DLL_PUBLIC RtAudio
//! A public function that queries for the number of audio devices available.
/*!
This function performs a system query of available devices each time it
is called, thus supporting devices connected \e after instantiation. If
a system error occurs during processing, a warning will be issued.
This function performs a system query of available devices each
time it is called, thus supporting devices (dis)connected \e after
instantiation. If a system error occurs during processing, a
warning will be issued.
*/
unsigned int getDeviceCount( void );
//! Return an RtAudio::DeviceInfo structure for a specified device number.
//! A public function that returns a vector of audio device IDs.
/*!
Any device integer between 0 and getDeviceCount() - 1 is valid.
If an invalid argument is provided, an RtAudioError (type = INVALID_USE)
will be thrown. If a device is busy or otherwise unavailable, the
structure member "probed" will have a value of "false" and all
other members are undefined. If the specified device is the
current default input or output device, the corresponding
"isDefault" member will have a value of "true".
The ID values returned by this function are used internally by
RtAudio to identify a given device. The values themselves are
arbitrary and do not correspond to device IDs used by the
underlying API (nor are they index values). This function performs
a system query of available devices each time it is called, thus
supporting devices (dis)connected \e after instantiation. If no
devices are available, the vector size will be zero. If a system
error occurs during processing, a warning will be issued.
*/
RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
std::vector<unsigned int> getDeviceIds( void );
//! A function that returns the index of the default output device.
//! A public function that returns a vector of audio device names.
/*!
If the underlying audio API does not provide a "default
device", or if no devices are available, the return value will be
0. Note that this is a valid device identifier and it is the
client's responsibility to verify that a device is available
before attempting to open a stream.
This function performs a system query of available devices each
time it is called, thus supporting devices (dis)connected \e after
instantiation. If no devices are available, the vector size will
be zero. If a system error occurs during processing, a warning
will be issued.
*/
std::vector<std::string> getDeviceNames( void );
//! Return an RtAudio::DeviceInfo structure for a specified device ID.
/*!
Any device ID returned by getDeviceIds() is valid, unless it has
been removed between the call to getDevceIds() and this
function. If an invalid argument is provided, an
RTAUDIO_INVALID_USE will be passed to the user-provided
errorCallback function (or otherwise printed to stderr) and all
members of the returned RtAudio::DeviceInfo structure will be
initialized to default, invalid values (ID = 0, empty name, ...).
If the specified device is the current default input or output
device, the corresponding "isDefault" member will have a value of
"true".
*/
RtAudio::DeviceInfo getDeviceInfo( unsigned int deviceId );
//! A function that returns the ID of the default output device.
/*!
If the underlying audio API does not provide a "default device",
the first probed output device ID will be returned. If no devices
are available, the return value will be 0 (which is an invalid
device identifier).
*/
unsigned int getDefaultOutputDevice( void );
//! A function that returns the index of the default input device.
//! A function that returns the ID of the default input device.
/*!
If the underlying audio API does not provide a "default
device", or if no devices are available, the return value will be
0. Note that this is a valid device identifier and it is the
client's responsibility to verify that a device is available
before attempting to open a stream.
If the underlying audio API does not provide a "default device",
the first probed input device ID will be returned. If no devices
are available, the return value will be 0 (which is an invalid
device identifier).
*/
unsigned int getDefaultInputDevice( void );
//! A public function for opening a stream with the specified parameters.
/*!
An RtAudioError (type = SYSTEM_ERROR) is thrown if a stream cannot be
An RTAUDIO_SYSTEM_ERROR is returned if a stream cannot be
opened with the specified parameters or an error occurs during
processing. An RtAudioError (type = INVALID_USE) is thrown if any
invalid device ID or channel number parameters are specified.
processing. An RTAUDIO_INVALID_USE is returned if a stream
is already open or any invalid stream parameters are specified.
\param outputParameters Specifies output stream parameters to use
when opening a stream, including a device ID, number of channels,
and starting channel number. For input-only streams, this
argument should be NULL. The device ID is an index value between
0 and getDeviceCount() - 1.
argument should be NULL. The device ID is a value returned by
getDeviceIds().
\param inputParameters Specifies input stream parameters to use
when opening a stream, including a device ID, number of channels,
and starting channel number. For output-only streams, this
argument should be NULL. The device ID is an index value between
0 and getDeviceCount() - 1.
argument should be NULL. The device ID is a value returned by
getDeviceIds().
\param format An RtAudioFormat specifying the desired sample data format.
\param sampleRate The desired sample rate (sample frames per second).
\param *bufferFrames A pointer to a value indicating the desired
\param bufferFrames A pointer to a 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
@@ -513,48 +544,52 @@ class RTAUDIO_DLL_PUBLIC RtAudio
chosen. If the RTAUDIO_MINIMIZE_LATENCY flag bit is set, the
lowest allowable value is used. The actual value used is
returned via the structure argument. The parameter is API dependent.
\param errorCallback A client-defined function that will be invoked
when an error has occurred.
*/
void openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData = NULL, RtAudio::StreamOptions *options = NULL, RtAudioErrorCallback errorCallback = NULL );
RtAudioErrorType openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData = NULL, RtAudio::StreamOptions *options = NULL );
//! A function that closes a stream and frees any associated stream memory.
/*!
If a stream is not open, this function issues a warning and
returns (no exception is thrown).
If a stream is not open, an RTAUDIO_WARNING will be passed to the
user-provided errorCallback function (or otherwise printed to
stderr).
*/
void closeStream( void );
//! A function that starts a stream.
/*!
An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
during processing. An RtAudioError (type = INVALID_USE) is thrown if a
stream is not open. A warning is issued if the stream is already
running.
An RTAUDIO_SYSTEM_ERROR is returned if an error occurs during
processing. An RTAUDIO_WARNING is returned if a stream is not open
or is already running.
*/
void startStream( void );
RtAudioErrorType startStream( void );
//! Stop a stream, allowing any samples remaining in the output queue to be played.
/*!
An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
during processing. An RtAudioError (type = INVALID_USE) is thrown if a
stream is not open. A warning is issued if the stream is already
stopped.
An RTAUDIO_SYSTEM_ERROR is returned if an error occurs during
processing. An RTAUDIO_WARNING is returned if a stream is not
open or is already stopped.
*/
void stopStream( void );
RtAudioErrorType stopStream( void );
//! Stop a stream, discarding any samples remaining in the input/output queue.
/*!
An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
during processing. An RtAudioError (type = INVALID_USE) is thrown if a
stream is not open. A warning is issued if the stream is already
stopped.
An RTAUDIO_SYSTEM_ERROR is returned if an error occurs during
processing. An RTAUDIO_WARNING is returned if a stream is not
open or is already stopped.
*/
void abortStream( void );
RtAudioErrorType abortStream( void );
//! Retrieve the error message corresponding to the last error or warning condition.
/*!
This function can be used to get a detailed error message when a
non-zero RtAudioErrorType is returned by a function. This is the
same message sent to the user-provided errorCallback function.
*/
const std::string getErrorText( void );
//! Returns true if a stream is open and false if not.
bool isStreamOpen( void ) const;
@@ -562,16 +597,17 @@ class RTAUDIO_DLL_PUBLIC RtAudio
//! Returns true if the stream is running and false if it is stopped or not open.
bool isStreamRunning( void ) const;
//! Returns the number of elapsed seconds since the stream was started.
//! Returns the number of seconds of processed data since the stream was started.
/*!
If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.
The stream time is calculated from the number of sample frames
processed by the underlying audio system, which will increment by
units of the audio buffer size. It is not an absolute running
time. If a stream is not open, the returned value may not be
valid.
*/
double getStreamTime( void );
//! Set the stream time to a time in seconds greater than or equal to 0.0.
/*!
If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.
*/
void setStreamTime( double time );
//! Returns the internal stream latency in sample frames.
@@ -579,21 +615,29 @@ class RTAUDIO_DLL_PUBLIC RtAudio
The stream latency refers to delay in audio input and/or output
caused by internal buffering by the audio system and/or hardware.
For duplex streams, the returned value will represent the sum of
the input and output latencies. If a stream is not open, an
RtAudioError (type = INVALID_USE) will be thrown. If the API does not
report latency, the return value will be zero.
the input and output latencies. If a stream is not open, the
returned value will be invalid. If the API does not report
latency, the return value will be zero.
*/
long getStreamLatency( void );
//! Returns actual sample rate in use by the stream.
/*!
On some systems, the sample rate used may be slightly different
than that specified in the stream parameters. If a stream is not
open, an RtAudioError (type = INVALID_USE) will be thrown.
*/
//! Returns actual sample rate in use by the (open) stream.
/*!
On some systems, the sample rate used may be slightly different
than that specified in the stream parameters. If a stream is not
open, a value of zero is returned.
*/
unsigned int getStreamSampleRate( void );
//! Specify whether warning messages should be printed to stderr.
//! Set a client-defined function that will be invoked when an error or warning occurs.
void setErrorCallback( RtAudioErrorCallback errorCallback );
//! Specify whether warning messages should be output or not.
/*!
The default behaviour is for warning messages to be output,
either to a client-defined error callback function (if specified)
or to stderr.
*/
void showWarnings( bool value = true );
protected:
@@ -603,7 +647,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio
};
// Operating system dependent thread functionality.
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_MSC_VER)
#ifndef NOMINMAX
#define NOMINMAX
@@ -642,11 +686,11 @@ struct CallbackInfo {
ThreadHandle thread{};
void *callback{};
void *userData{};
void *errorCallback{};
void *apiInfo{}; // void pointer for API specific callback information
bool isRunning{false};
bool doRealtime{false};
int priority{};
bool deviceDisconnected{false};
};
// **************************************************************** //
@@ -705,26 +749,29 @@ public:
RtApi();
virtual ~RtApi();
virtual RtAudio::Api getCurrentApi( void ) = 0;
virtual unsigned int getDeviceCount( void ) = 0;
virtual RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) = 0;
unsigned int getDeviceCount( void );
std::vector<unsigned int> getDeviceIds( void );
std::vector<std::string> getDeviceNames( void );
RtAudio::DeviceInfo getDeviceInfo( unsigned int deviceId );
virtual unsigned int getDefaultInputDevice( void );
virtual unsigned int getDefaultOutputDevice( void );
void openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData, RtAudio::StreamOptions *options,
RtAudioErrorCallback errorCallback );
RtAudioErrorType openStream( RtAudio::StreamParameters *outputParameters,
RtAudio::StreamParameters *inputParameters,
RtAudioFormat format, unsigned int sampleRate,
unsigned int *bufferFrames, RtAudioCallback callback,
void *userData, RtAudio::StreamOptions *options );
virtual void closeStream( void );
virtual void startStream( void ) = 0;
virtual void stopStream( void ) = 0;
virtual void abortStream( void ) = 0;
virtual RtAudioErrorType startStream( void ) = 0;
virtual RtAudioErrorType stopStream( void ) = 0;
virtual RtAudioErrorType abortStream( void ) = 0;
const std::string getErrorText( void ) const { return errorText_; }
long getStreamLatency( void );
unsigned int getStreamSampleRate( void );
virtual double getStreamTime( void );
virtual double getStreamTime( void ) const { return stream_.streamTime; }
virtual void setStreamTime( double time );
bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; }
void setErrorCallback( RtAudioErrorCallback errorCallback ) { errorCallback_ = errorCallback; }
void showWarnings( bool value ) { showWarnings_ = value; }
@@ -760,7 +807,7 @@ protected:
// A protected structure for audio streams.
struct RtApiStream {
unsigned int device[2]; // Playback and record, respectively.
unsigned int deviceId[2]; // Playback and record, respectively.
void *apiHandle; // void pointer for API specific stream handle information
StreamMode mode; // OUTPUT, INPUT, or DUPLEX.
StreamState state; // STOPPED, RUNNING, or CLOSED
@@ -789,7 +836,7 @@ protected:
#endif
RtApiStream()
:apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
:apiHandle(0), deviceBuffer(0) {} // { device[0] = std::string(); device[1] = std::string(); }
};
typedef S24 Int24;
@@ -800,10 +847,22 @@ protected:
std::ostringstream errorStream_;
std::string errorText_;
RtAudioErrorCallback errorCallback_;
bool showWarnings_;
std::vector<RtAudio::DeviceInfo> deviceList_;
unsigned int currentDeviceId_;
RtApiStream stream_;
bool firstErrorOccurred_;
/*!
Protected, api-specific method that attempts to probe all device
capabilities in a system. The function will not re-probe devices
that were previously found and probed. This function MUST be
implemented by all subclasses. If an error is encountered during
the probe, a "warning" message may be reported and the internal
list of devices may be incomplete.
*/
virtual void probeDevices( void );
/*!
Protected, api-specific method that attempts to open a device
with the given parameters. This function MUST be implemented by
@@ -811,7 +870,7 @@ protected:
"warning" message is reported and FAILURE is returned. A
successful probe is indicated by a return value of SUCCESS.
*/
virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
virtual bool probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options );
@@ -822,14 +881,8 @@ protected:
//! Protected common method to clear an RtApiStream structure.
void clearStreamInfo();
/*!
Protected common method that throws an RtAudioError (type =
INVALID_USE) if a stream is not open.
*/
void verifyStream( void );
//! Protected common error method to allow global control over error handling.
void error( RtAudioError::Type type );
RtAudioErrorType error( RtAudioErrorType type );
/*!
Protected method used to perform format, channel number, and/or interleaving
@@ -855,328 +908,25 @@ protected:
inline RtAudio::Api RtAudio :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
inline unsigned int RtAudio :: getDeviceCount( void ) { return rtapi_->getDeviceCount(); }
inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int device ) { return rtapi_->getDeviceInfo( device ); }
inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int deviceId ) { return rtapi_->getDeviceInfo( deviceId ); }
inline std::vector<unsigned int> RtAudio :: getDeviceIds( void ) { return rtapi_->getDeviceIds(); }
inline std::vector<std::string> RtAudio :: getDeviceNames( void ) { return rtapi_->getDeviceNames(); }
inline unsigned int RtAudio :: getDefaultInputDevice( void ) { return rtapi_->getDefaultInputDevice(); }
inline unsigned int RtAudio :: getDefaultOutputDevice( void ) { return rtapi_->getDefaultOutputDevice(); }
inline void RtAudio :: closeStream( void ) { return rtapi_->closeStream(); }
inline void RtAudio :: startStream( void ) { return rtapi_->startStream(); }
inline void RtAudio :: stopStream( void ) { return rtapi_->stopStream(); }
inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
inline RtAudioErrorType RtAudio :: startStream( void ) { return rtapi_->startStream(); }
inline RtAudioErrorType RtAudio :: stopStream( void ) { return rtapi_->stopStream(); }
inline RtAudioErrorType RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
inline const std::string RtAudio :: getErrorText( void ) { return rtapi_->getErrorText(); }
inline bool RtAudio :: isStreamOpen( void ) const { return rtapi_->isStreamOpen(); }
inline bool RtAudio :: isStreamRunning( void ) const { return rtapi_->isStreamRunning(); }
inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); }
inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
inline void RtAudio :: setStreamTime( double time ) { return rtapi_->setStreamTime( time ); }
inline void RtAudio :: setErrorCallback( RtAudioErrorCallback errorCallback ) { rtapi_->setErrorCallback( errorCallback ); }
inline void RtAudio :: showWarnings( bool value ) { rtapi_->showWarnings( value ); }
// RtApi Subclass prototypes.
#if defined(__MACOSX_CORE__)
#include <CoreAudio/AudioHardware.h>
class RtApiCore: public RtApi
{
public:
RtApiCore();
~RtApiCore();
RtAudio::Api getCurrentApi( void ) override { return RtAudio::MACOSX_CORE; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
unsigned int getDefaultOutputDevice( void ) override;
unsigned int getDefaultInputDevice( void ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
bool callbackEvent( AudioDeviceID deviceId,
const AudioBufferList *inBufferList,
const AudioBufferList *outBufferList );
private:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
static const char* getErrorCode( OSStatus code );
};
#endif
#if defined(__UNIX_JACK__)
class RtApiJack: public RtApi
{
public:
RtApiJack();
~RtApiJack();
RtAudio::Api getCurrentApi( void ) override { return RtAudio::UNIX_JACK; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
bool callbackEvent( unsigned long nframes );
private:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
bool shouldAutoconnect_;
};
#endif
#if defined(__WINDOWS_ASIO__)
class RtApiAsio: public RtApi
{
public:
RtApiAsio();
~RtApiAsio();
RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_ASIO; }
unsigned int getDeviceCount( void ) override;
unsigned int getDefaultOutputDevice( void ) override;
unsigned int getDefaultInputDevice( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
bool callbackEvent( long bufferIndex );
private:
std::vector<RtAudio::DeviceInfo> devices_;
void saveDeviceInfo( void );
bool coInitialized_;
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
};
#endif
#if defined(__WINDOWS_DS__)
class RtApiDs: public RtApi
{
public:
RtApiDs();
~RtApiDs();
RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_DS; }
unsigned int getDeviceCount( void ) override;
unsigned int getDefaultOutputDevice( void ) override;
unsigned int getDefaultInputDevice( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
void callbackEvent( void );
private:
bool coInitialized_;
bool buffersRolling;
long duplexPrerollBytes;
std::vector<struct DsDevice> dsDevices;
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
};
#endif
#if defined(__WINDOWS_WASAPI__)
struct IMMDeviceEnumerator;
class RtApiWasapi : public RtApi
{
public:
RtApiWasapi();
virtual ~RtApiWasapi();
RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_WASAPI; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
private:
bool coInitialized_;
IMMDeviceEnumerator* deviceEnumerator_;
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int* bufferSize,
RtAudio::StreamOptions* options ) override;
static DWORD WINAPI runWasapiThread( void* wasapiPtr );
static DWORD WINAPI stopWasapiThread( void* wasapiPtr );
static DWORD WINAPI abortWasapiThread( void* wasapiPtr );
void wasapiThread();
};
#endif
#if defined(__LINUX_ALSA__)
class RtApiAlsa: public RtApi
{
public:
RtApiAlsa();
~RtApiAlsa();
RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_ALSA; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
void callbackEvent( void );
private:
std::vector<RtAudio::DeviceInfo> devices_;
void saveDeviceInfo( void );
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
};
#endif
#if defined(__LINUX_PULSE__)
class RtApiPulse: public RtApi
{
public:
~RtApiPulse();
RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_PULSE; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
void callbackEvent( void );
private:
void collectDeviceInfo( void );
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
};
#endif
#if defined(__LINUX_OSS__)
class RtApiOss: public RtApi
{
public:
RtApiOss();
~RtApiOss();
RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_OSS; }
unsigned int getDeviceCount( void ) override;
RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
void closeStream( void ) override;
void startStream( void ) override;
void stopStream( void ) override;
void abortStream( void ) override;
// This function is intended for internal use only. It must be
// public because it is called by the internal callback handler,
// which is not a member of RtAudio. External use of this function
// will most likely produce highly undesirable results!
void callbackEvent( void );
private:
bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
unsigned int firstChannel, unsigned int sampleRate,
RtAudioFormat format, unsigned int *bufferSize,
RtAudio::StreamOptions *options ) override;
};
#endif
#if defined(__RTAUDIO_DUMMY__)
class RtApiDummy: public RtApi
{
public:
RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); }
RtAudio::Api getCurrentApi( void ) override { return RtAudio::RTAUDIO_DUMMY; }
unsigned int getDeviceCount( void ) override { return 0; }
RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) override { RtAudio::DeviceInfo info; return info; }
void closeStream( void ) override {}
void startStream( void ) override {}
void stopStream( void ) override {}
void abortStream( void ) override {}
private:
bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
RtAudio::StreamOptions * /*options*/ ) override { return false; }
};
#endif
#endif
// Indentation settings for Vim and Emacs

View File

@@ -9,7 +9,7 @@
RtMidi WWW site: http://www.music.mcgill.ca/~gary/rtmidi/
RtMidi: realtime MIDI i/o C++ classes
Copyright (c) 2003-2021 Gary P. Scavone
Copyright (c) 2003-2023 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
@@ -58,7 +58,24 @@
#endif
#endif
#define RTMIDI_VERSION "5.0.0"
#define RTMIDI_VERSION_MAJOR 6
#define RTMIDI_VERSION_MINOR 0
#define RTMIDI_VERSION_PATCH 0
#define RTMIDI_VERSION_BETA 0
#define RTMIDI_TOSTRING2(n) #n
#define RTMIDI_TOSTRING(n) RTMIDI_TOSTRING2(n)
#if RTMIDI_VERSION_BETA > 0
#define RTMIDI_VERSION RTMIDI_TOSTRING(RTMIDI_VERSION_MAJOR) \
"." RTMIDI_TOSTRING(RTMIDI_VERSION_MINOR) \
"." RTMIDI_TOSTRING(RTMIDI_VERSION_PATCH) \
"beta" RTMIDI_TOSTRING(RTMIDI_VERSION_BETA)
#else
#define RTMIDI_VERSION RTMIDI_TOSTRING(RTMIDI_VERSION_MAJOR) \
"." RTMIDI_TOSTRING(RTMIDI_VERSION_MINOR) \
"." RTMIDI_TOSTRING(RTMIDI_VERSION_PATCH)
#endif
#include <exception>
#include <iostream>
@@ -86,12 +103,12 @@ class RTMIDI_DLL_PUBLIC RtMidiError : public std::exception
UNSPECIFIED, /*!< The default, unspecified error type. */
NO_DEVICES_FOUND, /*!< No devices found on system. */
INVALID_DEVICE, /*!< An invalid device ID was specified. */
MEMORY_ERROR, /*!< An error occured during memory allocation. */
MEMORY_ERROR, /*!< An error occurred during memory allocation. */
INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
INVALID_USE, /*!< The function was called incorrectly. */
DRIVER_ERROR, /*!< A system driver error occured. */
SYSTEM_ERROR, /*!< A system error occured. */
THREAD_ERROR /*!< A thread error occured. */
DRIVER_ERROR, /*!< A system driver error occurred. */
SYSTEM_ERROR, /*!< A system error occurred. */
THREAD_ERROR /*!< A thread error occurred. */
};
//! The constructor.
@@ -144,6 +161,8 @@ class RTMIDI_DLL_PUBLIC RtMidi
WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
RTMIDI_DUMMY, /*!< A compilable but non-functional API. */
WEB_MIDI_API, /*!< W3C Web MIDI API. */
WINDOWS_UWP, /*!< The Microsoft Universal Windows Platform MIDI API. */
ANDROID_AMIDI, /*!< Native Android MIDI API. */
NUM_APIS /*!< Number of values in this enum. */
};
@@ -206,9 +225,9 @@ class RTMIDI_DLL_PUBLIC RtMidi
*/
virtual bool isPortOpen( void ) const = 0;
//! Set an error callback function to be invoked when an error has occured.
//! Set an error callback function to be invoked when an error has occurred.
/*!
The callback function will be called whenever an error has occured. It is best
The callback function will be called whenever an error has occurred. It is best
to set the error callback function before opening a port.
*/
virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ) = 0;
@@ -373,9 +392,9 @@ class RTMIDI_DLL_PUBLIC RtMidiIn : public RtMidi
*/
double getMessage( std::vector<unsigned char> *message );
//! Set an error callback function to be invoked when an error has occured.
//! Set an error callback function to be invoked when an error has occurred.
/*!
The callback function will be called whenever an error has occured. It is best
The callback function will be called whenever an error has occurred. It is best
to set the error callback function before opening a port.
*/
virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
@@ -491,9 +510,9 @@ class RTMIDI_DLL_PUBLIC RtMidiOut : public RtMidi
*/
void sendMessage( const unsigned char *message, size_t size );
//! Set an error callback function to be invoked when an error has occured.
//! Set an error callback function to be invoked when an error has occurred.
/*!
The callback function will be called whenever an error has occured. It is best
The callback function will be called whenever an error has occurred. It is best
to set the error callback function before opening a port.
*/
virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
@@ -559,7 +578,7 @@ class RTMIDI_DLL_PUBLIC MidiInApi : public MidiApi
void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
void cancelCallback( void );
virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
double getMessage( std::vector<unsigned char> *message );
virtual double getMessage( std::vector<unsigned char> *message );
virtual void setBufferSize( unsigned int size, unsigned int count );
// A MIDI structure used internally by the class to store incoming

View File

@@ -33,14 +33,14 @@ class RtWvIn : public WvIn
public:
//! Default constructor.
/*!
The default \e device argument value (zero) will select the
The default \e deviceIndex argument value (zero) will select the
default input device on your system. The first device enumerated
by the underlying audio API is specified with a value of one. The
default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An
StkError will be thrown if an error occurs duing instantiation.
*/
RtWvIn( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(),
int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 );
int deviceIndex = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 );
//! Class destructor.
~RtWvIn();

View File

@@ -33,14 +33,14 @@ class RtWvOut : public WvOut
//! Default constructor.
/*!
The default \e device argument value (zero) will select the
The default \e deviceIndex argument value (zero) will select the
default output device on your system. The first device enumerated
by the underlying audio API is specified with a value of one. The
default buffer size of RT_BUFFER_SIZE is defined in Stk.h. An
StkError will be thrown if an error occurs duing instantiation.
*/
RtWvOut( unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(),
int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 );
int deviceIndex = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 20 );
//! Class destructor.
~RtWvOut();

View File

@@ -40,10 +40,10 @@ void midiCallback( double deltatime, std::vector< unsigned char > *bytes, void *
// Parse the MIDI bytes ... only keep MIDI channel messages.
if ( bytes->at(0) > 239 ) return;
register long type = bytes->at(0) & 0xF0;
register int channel = bytes->at(0) & 0x0F;
register long databyte1 = bytes->at(1);
register long databyte2 = 0;
long type = bytes->at(0) & 0xF0;
int channel = bytes->at(0) & 0x0F;
long databyte1 = bytes->at(1);
long databyte2 = 0;
if ( ( type != 0xC0 ) && ( type != 0xD0 ) ) {
if ( bytes->size() < 3 ) return;
databyte2 = bytes->at(2);

View File

@@ -203,7 +203,8 @@ int main( int argc, char *argv[] )
int i;
#if defined(__STK_REALTIME__)
RtAudio dac;
//RtAudio dac( RtAudio::UNSPECIFIED );
RtAudio *dac = 0;
#endif
// If you want to change the default sample rate (set in Stk.h), do
@@ -254,16 +255,14 @@ int main( int argc, char *argv[] )
// If realtime output, allocate the dac here.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
dac = (RtAudio *) new RtAudio( RtAudio::UNSPECIFIED );
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
RtAudio::StreamParameters parameters;
parameters.deviceId = dac.getDefaultOutputDevice();
parameters.deviceId = dac->getDefaultOutputDevice();
parameters.nChannels = data.channels;
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
}
catch ( RtAudioError& error ) {
error.printMessage();
if ( dac->openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
std::cout << dac->getErrorText() << std::endl;
goto cleanup;
}
}
@@ -279,11 +278,8 @@ int main( int argc, char *argv[] )
// If realtime output, set our callback function and start the dac.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
try {
dac.startStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac->startStream() ) {
std::cout << dac->getErrorText() << std::endl;
goto cleanup;
}
}
@@ -303,14 +299,8 @@ int main( int argc, char *argv[] )
// Shut down the output stream.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
try {
dac.closeStream();
}
catch ( RtAudioError& error ) {
error.printMessage();
}
}
if ( data.realtime )
dac->closeStream();
#endif
cleanup:
@@ -319,6 +309,7 @@ int main( int argc, char *argv[] )
free( data.wvout );
delete data.voicer;
delete dac;
for ( i=0; i<data.nVoices; i++ ) delete data.instrument[i];
free( data.instrument );

View File

@@ -172,8 +172,8 @@ void BlowHole :: startBlowing( StkFloat amplitude, StkFloat rate )
void BlowHole :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "BlowHole::stopBlowing: argument is less than or equal to zero!";
if ( rate < 0.0 ) {
oStream_ << "BlowHole::stopBlowing: argument is less than zero!";
handleError( StkError::WARNING ); return;
}

View File

@@ -105,8 +105,8 @@ void Brass :: startBlowing( StkFloat amplitude, StkFloat rate )
void Brass :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "Brass::stopBlowing: argument is less than or equal to zero!";
if ( rate < 0.0 ) {
oStream_ << "Brass::stopBlowing: argument is less than zero!";
handleError( StkError::WARNING ); return;
}

View File

@@ -86,8 +86,8 @@ void Clarinet :: startBlowing( StkFloat amplitude, StkFloat rate )
void Clarinet :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "Clarinet::stopBlowing: argument is less than or equal to zero!";
if ( rate < 0.0 ) {
oStream_ << "Clarinet::stopBlowing: argument is less than zero!";
handleError( StkError::WARNING ); return;
}

View File

@@ -110,8 +110,8 @@ void Flute :: startBlowing( StkFloat amplitude, StkFloat rate )
void Flute :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "Flute::stopBlowing: argument is less than or equal to zero!";
if ( rate < 0.0 ) {
oStream_ << "Flute::stopBlowing: argument is less than zero!";
handleError( StkError::WARNING ); return;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -70,24 +70,28 @@ void RtWvIn :: fillBuffer( void *buffer, unsigned int nFrames )
}
}
RtWvIn :: RtWvIn( unsigned int nChannels, StkFloat sampleRate, int device, int bufferFrames, int nBuffers )
RtWvIn :: RtWvIn( unsigned int nChannels, StkFloat sampleRate, int deviceIndex, int bufferFrames, int nBuffers )
: stopped_( true ), readIndex_( 0 ), writeIndex_( 0 ), framesFilled_( 0 )
{
std::vector<unsigned int> deviceIds = adc_.getDeviceIds();
if ( deviceIds.size() < 1 )
handleError( "RtWvIn: No audio devices found!", StkError::AUDIO_SYSTEM );
// We'll let RtAudio deal with channel and sample rate limitations.
RtAudio::StreamParameters parameters;
if ( device == 0 )
if ( deviceIndex == 0 )
parameters.deviceId = adc_.getDefaultInputDevice();
else
parameters.deviceId = device - 1;
else {
if ( deviceIndex >= deviceIds.size() )
handleError( "RtWvIn: Device index is invalid.", StkError::AUDIO_SYSTEM );
parameters.deviceId = deviceIds[deviceIndex-1];
}
parameters.nChannels = nChannels;
unsigned int size = bufferFrames;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
try {
adc_.openStream( NULL, &parameters, format, (unsigned int)Stk::sampleRate(), &size, &read, (void *)this );
}
catch ( RtAudioError &error ) {
handleError( error.what(), StkError::AUDIO_SYSTEM );
if ( adc_.openStream( NULL, &parameters, format, (unsigned int)Stk::sampleRate(), &size, &read, (void *)this ) ) {
handleError( adc_.getErrorText(), StkError::AUDIO_SYSTEM );
}
data_.resize( size * nBuffers, nChannels );

View File

@@ -90,25 +90,29 @@ int RtWvOut :: readBuffer( void *buffer, unsigned int frameCount )
}
RtWvOut :: RtWvOut( unsigned int nChannels, StkFloat sampleRate, int device, int bufferFrames, int nBuffers )
RtWvOut :: RtWvOut( unsigned int nChannels, StkFloat sampleRate, int deviceIndex, int bufferFrames, int nBuffers )
: stopped_( true ), readIndex_( 0 ), writeIndex_( 0 ), framesFilled_( 0 ), status_(0)
{
std::vector<unsigned int> deviceIds = dac_.getDeviceIds();
if ( deviceIds.size() < 1 )
handleError( "RtWvOut: No audio devices found!", StkError::AUDIO_SYSTEM );
// We'll let RtAudio deal with channel and sample rate limitations.
RtAudio::StreamParameters parameters;
if ( device == 0 )
if ( deviceIndex == 0 )
parameters.deviceId = dac_.getDefaultOutputDevice();
else
parameters.deviceId = device - 1;
else {
if ( deviceIndex >= deviceIds.size() )
handleError( "RtWvOut: Device index is invalid.", StkError::AUDIO_SYSTEM );
parameters.deviceId = deviceIds[deviceIndex-1];
}
parameters.nChannels = nChannels;
unsigned int size = bufferFrames;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
// Open a stream and set the callback function.
try {
dac_.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &size, &write, (void *)this );
}
catch ( RtAudioError &error ) {
handleError( error.what(), StkError::AUDIO_SYSTEM );
if ( dac_.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &size, &write, (void *)this ) ) {
handleError( dac_.getErrorText(), StkError::AUDIO_SYSTEM );
}
data_.resize( size * nBuffers, nChannels );

View File

@@ -121,8 +121,8 @@ void Saxofony :: startBlowing( StkFloat amplitude, StkFloat rate )
void Saxofony :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "Saxofony::stopBlowing: argument is less than or equal to zero!";
if ( rate < 0.0 ) {
oStream_ << "Saxofony::stopBlowing: argument is less than zero!";
handleError( StkError::WARNING ); return;
}