Whitespace cleanup in Java and C++ bindings#458)
This commit is contained in:
parent
3e782f2494
commit
a563f2d39d
43 changed files with 2918 additions and 2950 deletions
|
|
@ -8,44 +8,44 @@
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void printSupportedStandardSampleRates(
|
void printSupportedStandardSampleRates(
|
||||||
const portaudio::DirectionSpecificStreamParameters &inputParameters,
|
const portaudio::DirectionSpecificStreamParameters &inputParameters,
|
||||||
const portaudio::DirectionSpecificStreamParameters &outputParameters)
|
const portaudio::DirectionSpecificStreamParameters &outputParameters)
|
||||||
{
|
{
|
||||||
static double STANDARD_SAMPLE_RATES[] = {
|
static double STANDARD_SAMPLE_RATES[] = {
|
||||||
8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
|
8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
|
||||||
44100.0, 48000.0, 88200.0, 96000.0, -1 }; // negative terminated list
|
44100.0, 48000.0, 88200.0, 96000.0, -1 }; // negative terminated list
|
||||||
|
|
||||||
int printCount = 0;
|
int printCount = 0;
|
||||||
|
|
||||||
for (int i = 0; STANDARD_SAMPLE_RATES[i] > 0; ++i)
|
for (int i = 0; STANDARD_SAMPLE_RATES[i] > 0; ++i)
|
||||||
{
|
{
|
||||||
portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, STANDARD_SAMPLE_RATES[i], 0, paNoFlag);
|
portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, STANDARD_SAMPLE_RATES[i], 0, paNoFlag);
|
||||||
|
|
||||||
if (tmp.isSupported())
|
if (tmp.isSupported())
|
||||||
{
|
{
|
||||||
if (printCount == 0)
|
if (printCount == 0)
|
||||||
{
|
{
|
||||||
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
||||||
printCount = 1;
|
printCount = 1;
|
||||||
}
|
}
|
||||||
else if (printCount == 4)
|
else if (printCount == 4)
|
||||||
{
|
{
|
||||||
std::cout << "," << std::endl;
|
std::cout << "," << std::endl;
|
||||||
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
||||||
printCount = 1;
|
printCount = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << ", " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
std::cout << ", " << STANDARD_SAMPLE_RATES[i]; // 8.2
|
||||||
++printCount;
|
++printCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printCount == 0)
|
if (printCount == 0)
|
||||||
std::cout << "None" << std::endl;
|
std::cout << "None" << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -53,125 +53,125 @@ void printSupportedStandardSampleRates(
|
||||||
int main(int, char*[]);
|
int main(int, char*[]);
|
||||||
int main(int, char*[])
|
int main(int, char*[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
portaudio::AutoSystem autoSys;
|
portaudio::AutoSystem autoSys;
|
||||||
|
|
||||||
portaudio::System &sys = portaudio::System::instance();
|
portaudio::System &sys = portaudio::System::instance();
|
||||||
|
|
||||||
std::cout << "PortAudio version number = " << sys.version() << std::endl;
|
std::cout << "PortAudio version number = " << sys.version() << std::endl;
|
||||||
std::cout << "PortAudio version text = '" << sys.versionText() << "'" << std::endl;
|
std::cout << "PortAudio version text = '" << sys.versionText() << "'" << std::endl;
|
||||||
|
|
||||||
int numDevices = sys.deviceCount();
|
int numDevices = sys.deviceCount();
|
||||||
std::cout << "Number of devices = " << numDevices << std::endl;
|
std::cout << "Number of devices = " << numDevices << std::endl;
|
||||||
|
|
||||||
for (portaudio::System::DeviceIterator i = sys.devicesBegin(); i != sys.devicesEnd(); ++i)
|
for (portaudio::System::DeviceIterator i = sys.devicesBegin(); i != sys.devicesEnd(); ++i)
|
||||||
{
|
{
|
||||||
std::cout << "--------------------------------------- device #" << (*i).index() << std::endl;
|
std::cout << "--------------------------------------- device #" << (*i).index() << std::endl;
|
||||||
|
|
||||||
// Mark global and API specific default devices:
|
// Mark global and API specific default devices:
|
||||||
bool defaultDisplayed = false;
|
bool defaultDisplayed = false;
|
||||||
|
|
||||||
if ((*i).isSystemDefaultInputDevice())
|
if ((*i).isSystemDefaultInputDevice())
|
||||||
{
|
{
|
||||||
std::cout << "[ Default Input";
|
std::cout << "[ Default Input";
|
||||||
defaultDisplayed = true;
|
defaultDisplayed = true;
|
||||||
}
|
}
|
||||||
else if ((*i).isHostApiDefaultInputDevice())
|
else if ((*i).isHostApiDefaultInputDevice())
|
||||||
{
|
{
|
||||||
std::cout << "[ Default " << (*i).hostApi().name() << " Input";
|
std::cout << "[ Default " << (*i).hostApi().name() << " Input";
|
||||||
defaultDisplayed = true;
|
defaultDisplayed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*i).isSystemDefaultOutputDevice())
|
if ((*i).isSystemDefaultOutputDevice())
|
||||||
{
|
{
|
||||||
std::cout << (defaultDisplayed ? "," : "[");
|
std::cout << (defaultDisplayed ? "," : "[");
|
||||||
std::cout << " Default Output";
|
std::cout << " Default Output";
|
||||||
defaultDisplayed = true;
|
defaultDisplayed = true;
|
||||||
}
|
}
|
||||||
else if ((*i).isHostApiDefaultOutputDevice())
|
else if ((*i).isHostApiDefaultOutputDevice())
|
||||||
{
|
{
|
||||||
std::cout << (defaultDisplayed ? "," : "[");
|
std::cout << (defaultDisplayed ? "," : "[");
|
||||||
std::cout << " Default " << (*i).hostApi().name() << " Output";
|
std::cout << " Default " << (*i).hostApi().name() << " Output";
|
||||||
defaultDisplayed = true;
|
defaultDisplayed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultDisplayed)
|
|
||||||
std::cout << " ]" << std::endl;
|
|
||||||
|
|
||||||
// Print device info:
|
if (defaultDisplayed)
|
||||||
std::cout << "Name = " << (*i).name() << std::endl;
|
std::cout << " ]" << std::endl;
|
||||||
std::cout << "Host API = " << (*i).hostApi().name() << std::endl;
|
|
||||||
std::cout << "Max inputs = " << (*i).maxInputChannels() << ", Max outputs = " << (*i).maxOutputChannels() << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Default low input latency = " << (*i).defaultLowInputLatency() << std::endl; // 8.3
|
// Print device info:
|
||||||
std::cout << "Default low output latency = " << (*i).defaultLowOutputLatency() << std::endl; // 8.3
|
std::cout << "Name = " << (*i).name() << std::endl;
|
||||||
std::cout << "Default high input latency = " << (*i).defaultHighInputLatency() << std::endl; // 8.3
|
std::cout << "Host API = " << (*i).hostApi().name() << std::endl;
|
||||||
std::cout << "Default high output latency = " << (*i).defaultHighOutputLatency() << std::endl; // 8.3
|
std::cout << "Max inputs = " << (*i).maxInputChannels() << ", Max outputs = " << (*i).maxOutputChannels() << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Default low input latency = " << (*i).defaultLowInputLatency() << std::endl; // 8.3
|
||||||
|
std::cout << "Default low output latency = " << (*i).defaultLowOutputLatency() << std::endl; // 8.3
|
||||||
|
std::cout << "Default high input latency = " << (*i).defaultHighInputLatency() << std::endl; // 8.3
|
||||||
|
std::cout << "Default high output latency = " << (*i).defaultHighOutputLatency() << std::endl; // 8.3
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// ASIO specific latency information:
|
// ASIO specific latency information:
|
||||||
if ((*i).hostApi().typeId() == paASIO)
|
if ((*i).hostApi().typeId() == paASIO)
|
||||||
{
|
{
|
||||||
portaudio::AsioDeviceAdapter asioDevice((*i));
|
portaudio::AsioDeviceAdapter asioDevice((*i));
|
||||||
|
|
||||||
std::cout << "ASIO minimum buffer size = " << asioDevice.minBufferSize() << std::endl;
|
std::cout << "ASIO minimum buffer size = " << asioDevice.minBufferSize() << std::endl;
|
||||||
std::cout << "ASIO maximum buffer size = " << asioDevice.maxBufferSize() << std::endl;
|
std::cout << "ASIO maximum buffer size = " << asioDevice.maxBufferSize() << std::endl;
|
||||||
std::cout << "ASIO preferred buffer size = " << asioDevice.preferredBufferSize() << std::endl;
|
std::cout << "ASIO preferred buffer size = " << asioDevice.preferredBufferSize() << std::endl;
|
||||||
|
|
||||||
if (asioDevice.granularity() == -1)
|
if (asioDevice.granularity() == -1)
|
||||||
std::cout << "ASIO buffer granularity = power of 2" << std::endl;
|
std::cout << "ASIO buffer granularity = power of 2" << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "ASIO buffer granularity = " << asioDevice.granularity() << std::endl;
|
std::cout << "ASIO buffer granularity = " << asioDevice.granularity() << std::endl;
|
||||||
}
|
}
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
std::cout << "Default sample rate = " << (*i).defaultSampleRate() << std::endl; // 8.2
|
std::cout << "Default sample rate = " << (*i).defaultSampleRate() << std::endl; // 8.2
|
||||||
|
|
||||||
// Poll for standard sample rates:
|
// Poll for standard sample rates:
|
||||||
portaudio::DirectionSpecificStreamParameters inputParameters((*i), (*i).maxInputChannels(), portaudio::INT16, true, 0.0, NULL);
|
portaudio::DirectionSpecificStreamParameters inputParameters((*i), (*i).maxInputChannels(), portaudio::INT16, true, 0.0, NULL);
|
||||||
portaudio::DirectionSpecificStreamParameters outputParameters((*i), (*i).maxOutputChannels(), portaudio::INT16, true, 0.0, NULL);
|
portaudio::DirectionSpecificStreamParameters outputParameters((*i), (*i).maxOutputChannels(), portaudio::INT16, true, 0.0, NULL);
|
||||||
|
|
||||||
if (inputParameters.numChannels() > 0)
|
if (inputParameters.numChannels() > 0)
|
||||||
{
|
{
|
||||||
std::cout << "Supported standard sample rates" << std::endl;
|
std::cout << "Supported standard sample rates" << std::endl;
|
||||||
std::cout << " for half-duplex 16 bit " << inputParameters.numChannels() << " channel input = " << std::endl;
|
std::cout << " for half-duplex 16 bit " << inputParameters.numChannels() << " channel input = " << std::endl;
|
||||||
printSupportedStandardSampleRates(inputParameters, portaudio::DirectionSpecificStreamParameters::null());
|
printSupportedStandardSampleRates(inputParameters, portaudio::DirectionSpecificStreamParameters::null());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputParameters.numChannels() > 0)
|
if (outputParameters.numChannels() > 0)
|
||||||
{
|
{
|
||||||
std::cout << "Supported standard sample rates" << std::endl;
|
std::cout << "Supported standard sample rates" << std::endl;
|
||||||
std::cout << " for half-duplex 16 bit " << outputParameters.numChannels() << " channel output = " << std::endl;
|
std::cout << " for half-duplex 16 bit " << outputParameters.numChannels() << " channel output = " << std::endl;
|
||||||
printSupportedStandardSampleRates(portaudio::DirectionSpecificStreamParameters::null(), outputParameters);
|
printSupportedStandardSampleRates(portaudio::DirectionSpecificStreamParameters::null(), outputParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputParameters.numChannels() > 0 && outputParameters.numChannels() > 0)
|
if (inputParameters.numChannels() > 0 && outputParameters.numChannels() > 0)
|
||||||
{
|
{
|
||||||
std::cout << "Supported standard sample rates" << std::endl;
|
std::cout << "Supported standard sample rates" << std::endl;
|
||||||
std::cout << " for full-duplex 16 bit " << inputParameters.numChannels() << " channel input, " << outputParameters.numChannels() << " channel output = " << std::endl;
|
std::cout << " for full-duplex 16 bit " << inputParameters.numChannels() << " channel input, " << outputParameters.numChannels() << " channel output = " << std::endl;
|
||||||
printSupportedStandardSampleRates(inputParameters, outputParameters);
|
printSupportedStandardSampleRates(inputParameters, outputParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "----------------------------------------------" << std::endl;
|
std::cout << "----------------------------------------------" << std::endl;
|
||||||
}
|
}
|
||||||
catch (const portaudio::PaException &e)
|
catch (const portaudio::PaException &e)
|
||||||
{
|
{
|
||||||
std::cout << "A PortAudio error occurred: " << e.paErrorText() << std::endl;
|
std::cout << "A PortAudio error occurred: " << e.paErrorText() << std::endl;
|
||||||
}
|
}
|
||||||
catch (const portaudio::PaCppException &e)
|
catch (const portaudio::PaCppException &e)
|
||||||
{
|
{
|
||||||
std::cout << "A PortAudioCpp error occurred: " << e.what() << std::endl;
|
std::cout << "A PortAudioCpp error occurred: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
std::cout << "A generic exception occurred: " << e.what() << std::endl;
|
std::cout << "A generic exception occurred: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "An unknown exception occurred." << std::endl;
|
std::cout << "An unknown exception occurred." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,50 +20,50 @@ const int TABLE_SIZE = 200;
|
||||||
class SineGenerator
|
class SineGenerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SineGenerator(int tableSize) : tableSize_(tableSize), leftPhase_(0), rightPhase_(0)
|
SineGenerator(int tableSize) : tableSize_(tableSize), leftPhase_(0), rightPhase_(0)
|
||||||
{
|
{
|
||||||
const double PI = 3.14159265;
|
const double PI = 3.14159265;
|
||||||
table_ = new float[tableSize];
|
table_ = new float[tableSize];
|
||||||
for (int i = 0; i < tableSize; ++i)
|
for (int i = 0; i < tableSize; ++i)
|
||||||
{
|
{
|
||||||
table_[i] = 0.125f * (float)sin(((double)i/(double)tableSize)*PI*2.);
|
table_[i] = 0.125f * (float)sin(((double)i/(double)tableSize)*PI*2.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SineGenerator()
|
~SineGenerator()
|
||||||
{
|
{
|
||||||
delete[] table_;
|
delete[] table_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
|
int generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
|
||||||
{
|
{
|
||||||
assert(outputBuffer != NULL);
|
assert(outputBuffer != NULL);
|
||||||
|
|
||||||
float **out = static_cast<float **>(outputBuffer);
|
float **out = static_cast<float **>(outputBuffer);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < framesPerBuffer; ++i)
|
for (unsigned int i = 0; i < framesPerBuffer; ++i)
|
||||||
{
|
{
|
||||||
out[0][i] = table_[leftPhase_];
|
out[0][i] = table_[leftPhase_];
|
||||||
out[1][i] = table_[rightPhase_];
|
out[1][i] = table_[rightPhase_];
|
||||||
|
|
||||||
leftPhase_ += 1;
|
leftPhase_ += 1;
|
||||||
if (leftPhase_ >= tableSize_)
|
if (leftPhase_ >= tableSize_)
|
||||||
leftPhase_ -= tableSize_;
|
leftPhase_ -= tableSize_;
|
||||||
|
|
||||||
rightPhase_ += 3;
|
rightPhase_ += 3;
|
||||||
if (rightPhase_ >= tableSize_)
|
if (rightPhase_ >= tableSize_)
|
||||||
rightPhase_ -= tableSize_;
|
rightPhase_ -= tableSize_;
|
||||||
}
|
}
|
||||||
|
|
||||||
return paContinue;
|
return paContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float *table_;
|
float *table_;
|
||||||
int tableSize_;
|
int tableSize_;
|
||||||
int leftPhase_;
|
int leftPhase_;
|
||||||
int rightPhase_;
|
int rightPhase_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -72,66 +72,64 @@ private:
|
||||||
int main(int, char *[]);
|
int main(int, char *[]);
|
||||||
int main(int, char *[])
|
int main(int, char *[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create a SineGenerator object:
|
// Create a SineGenerator object:
|
||||||
SineGenerator sineGenerator(TABLE_SIZE);
|
SineGenerator sineGenerator(TABLE_SIZE);
|
||||||
|
|
||||||
std::cout << "Setting up PortAudio..." << std::endl;
|
std::cout << "Setting up PortAudio..." << std::endl;
|
||||||
|
|
||||||
// Set up the System:
|
// Set up the System:
|
||||||
portaudio::AutoSystem autoSys;
|
portaudio::AutoSystem autoSys;
|
||||||
portaudio::System &sys = portaudio::System::instance();
|
portaudio::System &sys = portaudio::System::instance();
|
||||||
|
|
||||||
// Set up the parameters required to open a (Callback)Stream:
|
// Set up the parameters required to open a (Callback)Stream:
|
||||||
portaudio::DirectionSpecificStreamParameters outParams(sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false, sys.defaultOutputDevice().defaultLowOutputLatency(), NULL);
|
portaudio::DirectionSpecificStreamParameters outParams(sys.defaultOutputDevice(), 2, portaudio::FLOAT32, false, sys.defaultOutputDevice().defaultLowOutputLatency(), NULL);
|
||||||
portaudio::StreamParameters params(portaudio::DirectionSpecificStreamParameters::null(), outParams, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff);
|
portaudio::StreamParameters params(portaudio::DirectionSpecificStreamParameters::null(), outParams, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff);
|
||||||
|
|
||||||
std::cout << "Opening stereo output stream..." << std::endl;
|
std::cout << "Opening stereo output stream..." << std::endl;
|
||||||
|
|
||||||
// Create (and open) a new Stream, using the SineGenerator::generate function as a callback:
|
// Create (and open) a new Stream, using the SineGenerator::generate function as a callback:
|
||||||
portaudio::MemFunCallbackStream<SineGenerator> stream(params, sineGenerator, &SineGenerator::generate);
|
portaudio::MemFunCallbackStream<SineGenerator> stream(params, sineGenerator, &SineGenerator::generate);
|
||||||
|
|
||||||
std::cout << "Starting playback for " << NUM_SECONDS << " seconds." << std::endl;
|
std::cout << "Starting playback for " << NUM_SECONDS << " seconds." << std::endl;
|
||||||
|
|
||||||
// Start the Stream (audio playback starts):
|
// Start the Stream (audio playback starts):
|
||||||
stream.start();
|
stream.start();
|
||||||
|
|
||||||
// Wait for 5 seconds:
|
// Wait for 5 seconds:
|
||||||
sys.sleep(NUM_SECONDS * 1000);
|
sys.sleep(NUM_SECONDS * 1000);
|
||||||
|
|
||||||
std::cout << "Closing stream..." <<std::endl;
|
std::cout << "Closing stream..." <<std::endl;
|
||||||
|
|
||||||
// Stop the Stream (not strictly needed as termintating the System will also stop all open Streams):
|
// Stop the Stream (not strictly needed as termintating the System will also stop all open Streams):
|
||||||
stream.stop();
|
stream.stop();
|
||||||
|
|
||||||
// Close the Stream (not strictly needed as terminating the System will also close all open Streams):
|
// Close the Stream (not strictly needed as terminating the System will also close all open Streams):
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
// Terminate the System (not strictly needed as the AutoSystem will also take care of this when it
|
// Terminate the System (not strictly needed as the AutoSystem will also take care of this when it
|
||||||
// goes out of scope):
|
// goes out of scope):
|
||||||
sys.terminate();
|
sys.terminate();
|
||||||
|
|
||||||
std::cout << "Test finished." << std::endl;
|
std::cout << "Test finished." << std::endl;
|
||||||
}
|
}
|
||||||
catch (const portaudio::PaException &e)
|
catch (const portaudio::PaException &e)
|
||||||
{
|
{
|
||||||
std::cout << "A PortAudio error occurred: " << e.paErrorText() << std::endl;
|
std::cout << "A PortAudio error occurred: " << e.paErrorText() << std::endl;
|
||||||
}
|
}
|
||||||
catch (const portaudio::PaCppException &e)
|
catch (const portaudio::PaCppException &e)
|
||||||
{
|
{
|
||||||
std::cout << "A PortAudioCpp error occurred: " << e.what() << std::endl;
|
std::cout << "A PortAudioCpp error occurred: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
std::cout << "A generic exception occurred: " << e.what() << std::endl;
|
std::cout << "A generic exception occurred: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "An unknown exception occurred." << std::endl;
|
std::cout << "An unknown exception occurred." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,41 +4,41 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
// Declaration(s):
|
// Declaration(s):
|
||||||
//////
|
//////
|
||||||
/// @brief Adapts the given Device to an ASIO specific extension.
|
/// @brief Adapts the given Device to an ASIO specific extension.
|
||||||
///
|
///
|
||||||
/// Deleting the AsioDeviceAdapter does not affect the underlying
|
/// Deleting the AsioDeviceAdapter does not affect the underlying
|
||||||
/// Device.
|
/// Device.
|
||||||
//////
|
//////
|
||||||
class AsioDeviceAdapter
|
class AsioDeviceAdapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AsioDeviceAdapter(Device &device);
|
AsioDeviceAdapter(Device &device);
|
||||||
|
|
||||||
Device &device();
|
Device &device();
|
||||||
|
|
||||||
long minBufferSize() const;
|
long minBufferSize() const;
|
||||||
long maxBufferSize() const;
|
long maxBufferSize() const;
|
||||||
long preferredBufferSize() const;
|
long preferredBufferSize() const;
|
||||||
long granularity() const;
|
long granularity() const;
|
||||||
|
|
||||||
void showControlPanel(void *systemSpecific);
|
void showControlPanel(void *systemSpecific);
|
||||||
|
|
||||||
const char *inputChannelName(int channelIndex) const;
|
const char *inputChannelName(int channelIndex) const;
|
||||||
const char *outputChannelName(int channelIndex) const;
|
const char *outputChannelName(int channelIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device *device_;
|
Device *device_;
|
||||||
|
|
||||||
long minBufferSize_;
|
long minBufferSize_;
|
||||||
long maxBufferSize_;
|
long maxBufferSize_;
|
||||||
long preferredBufferSize_;
|
long preferredBufferSize_;
|
||||||
long granularity_;
|
long granularity_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_ASIODEVICEADAPTER_HXX
|
#endif // INCLUDED_PORTAUDIO_ASIODEVICEADAPTER_HXX
|
||||||
|
|
|
||||||
|
|
@ -11,48 +11,48 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief A RAII idiom class to ensure automatic clean-up when an exception is
|
/// @brief A RAII idiom class to ensure automatic clean-up when an exception is
|
||||||
/// raised.
|
/// raised.
|
||||||
///
|
///
|
||||||
/// A simple helper class which uses the 'Resource Acquisition is Initialization'
|
/// A simple helper class which uses the 'Resource Acquisition is Initialization'
|
||||||
/// idiom (RAII). Use this class to initialize/terminate the System rather than
|
/// idiom (RAII). Use this class to initialize/terminate the System rather than
|
||||||
/// using System directly. AutoSystem must be created on stack and must be valid
|
/// using System directly. AutoSystem must be created on stack and must be valid
|
||||||
/// throughout the time you wish to use PortAudioCpp. Your 'main' function might be
|
/// throughout the time you wish to use PortAudioCpp. Your 'main' function might be
|
||||||
/// a good place for it.
|
/// a good place for it.
|
||||||
///
|
///
|
||||||
/// To avoid having to type portaudio::System::instance().xyz() all the time, it's usually
|
/// To avoid having to type portaudio::System::instance().xyz() all the time, it's usually
|
||||||
/// a good idea to make a reference to the System which can be accessed directly.
|
/// a good idea to make a reference to the System which can be accessed directly.
|
||||||
/// @verbatim
|
/// @verbatim
|
||||||
/// portaudio::AutoSys autoSys;
|
/// portaudio::AutoSys autoSys;
|
||||||
/// portaudio::System &sys = portaudio::System::instance();
|
/// portaudio::System &sys = portaudio::System::instance();
|
||||||
/// @endverbatim
|
/// @endverbatim
|
||||||
//////
|
//////
|
||||||
class AutoSystem
|
class AutoSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AutoSystem(bool initialize = true)
|
AutoSystem(bool initialize = true)
|
||||||
{
|
{
|
||||||
if (initialize)
|
if (initialize)
|
||||||
System::initialize();
|
System::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
~AutoSystem()
|
~AutoSystem()
|
||||||
{
|
{
|
||||||
if (System::exists())
|
if (System::exists())
|
||||||
System::terminate();
|
System::terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize()
|
void initialize()
|
||||||
{
|
{
|
||||||
System::initialize();
|
System::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminate()
|
void terminate()
|
||||||
{
|
{
|
||||||
System::terminate();
|
System::terminate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -12,28 +12,28 @@ namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Stream class for blocking read/write-style input and output.
|
/// @brief Stream class for blocking read/write-style input and output.
|
||||||
//////
|
//////
|
||||||
class BlockingStream : public Stream
|
class BlockingStream : public Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BlockingStream();
|
BlockingStream();
|
||||||
BlockingStream(const StreamParameters ¶meters);
|
BlockingStream(const StreamParameters ¶meters);
|
||||||
~BlockingStream();
|
~BlockingStream();
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters);
|
void open(const StreamParameters ¶meters);
|
||||||
|
|
||||||
void read(void *buffer, unsigned long numFrames);
|
void read(void *buffer, unsigned long numFrames);
|
||||||
void write(const void *buffer, unsigned long numFrames);
|
void write(const void *buffer, unsigned long numFrames);
|
||||||
|
|
||||||
signed long availableReadSize() const;
|
signed long availableReadSize() const;
|
||||||
signed long availableWriteSize() const;
|
signed long availableWriteSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlockingStream(const BlockingStream &); // non-copyable
|
BlockingStream(const BlockingStream &); // non-copyable
|
||||||
BlockingStream &operator=(const BlockingStream &); // non-copyable
|
BlockingStream &operator=(const BlockingStream &); // non-copyable
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,4 +42,3 @@ namespace portaudio
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_BLOCKINGSTREAM_HXX
|
#endif // INCLUDED_PORTAUDIO_BLOCKINGSTREAM_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
// Forward declaration(s)
|
// Forward declaration(s)
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class StreamParameters;
|
class StreamParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -20,30 +20,29 @@ namespace portaudio
|
||||||
// Declaration(s):
|
// Declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Callback stream using a free function with C linkage. It's important that the function
|
/// @brief Callback stream using a free function with C linkage. It's important that the function
|
||||||
/// the passed function pointer points to is declared ``extern "C"''.
|
/// the passed function pointer points to is declared ``extern "C"''.
|
||||||
//////
|
//////
|
||||||
class CFunCallbackStream : public CallbackStream
|
class CFunCallbackStream : public CallbackStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CFunCallbackStream();
|
CFunCallbackStream();
|
||||||
CFunCallbackStream(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData);
|
CFunCallbackStream(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData);
|
||||||
~CFunCallbackStream();
|
~CFunCallbackStream();
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData);
|
|
||||||
|
|
||||||
private:
|
void open(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData);
|
||||||
CFunCallbackStream(const CFunCallbackStream &); // non-copyable
|
|
||||||
CFunCallbackStream &operator=(const CFunCallbackStream &); // non-copyable
|
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
private:
|
||||||
|
CFunCallbackStream(const CFunCallbackStream &); // non-copyable
|
||||||
|
CFunCallbackStream &operator=(const CFunCallbackStream &); // non-copyable
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
} // portaudio
|
} // portaudio
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_MEMFUNCALLBACKSTREAM_HXX
|
#endif // INCLUDED_PORTAUDIO_MEMFUNCALLBACKSTREAM_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,34 +9,34 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Interface for an object that's callable as a PortAudioCpp callback object (ie that implements the
|
/// @brief Interface for an object that's callable as a PortAudioCpp callback object (ie that implements the
|
||||||
/// paCallbackFun method).
|
/// paCallbackFun method).
|
||||||
//////
|
//////
|
||||||
class CallbackInterface
|
class CallbackInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~CallbackInterface() {}
|
virtual ~CallbackInterface() {}
|
||||||
|
|
||||||
virtual int paCallbackFun(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
virtual int paCallbackFun(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags) = 0;
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
int callbackInterfaceToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
int callbackInterfaceToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
||||||
void *userData);
|
void *userData);
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,23 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Base class for all Streams which use a callback-based mechanism.
|
/// @brief Base class for all Streams which use a callback-based mechanism.
|
||||||
//////
|
//////
|
||||||
class CallbackStream : public Stream
|
class CallbackStream : public Stream
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CallbackStream();
|
CallbackStream();
|
||||||
virtual ~CallbackStream();
|
virtual ~CallbackStream();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// stream info (time-varying)
|
// stream info (time-varying)
|
||||||
double cpuLoad() const;
|
double cpuLoad() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CallbackStream(const CallbackStream &); // non-copyable
|
CallbackStream(const CallbackStream &); // non-copyable
|
||||||
CallbackStream &operator=(const CallbackStream &); // non-copyable
|
CallbackStream &operator=(const CallbackStream &); // non-copyable
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class StreamParameters;
|
class StreamParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -22,61 +22,61 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
int cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
int cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
||||||
void *userData);
|
void *userData);
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Callback stream using a C++ function (either a free function or a static function)
|
/// @brief Callback stream using a C++ function (either a free function or a static function)
|
||||||
/// callback.
|
/// callback.
|
||||||
//////
|
//////
|
||||||
class FunCallbackStream : public CallbackStream
|
class FunCallbackStream : public CallbackStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef int (*CallbackFunPtr)(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
typedef int (*CallbackFunPtr)(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags,
|
||||||
void *userData);
|
void *userData);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Simple structure containing a function pointer to the C++ callback function and a
|
/// @brief Simple structure containing a function pointer to the C++ callback function and a
|
||||||
/// (void) pointer to the user supplied data.
|
/// (void) pointer to the user supplied data.
|
||||||
//////
|
//////
|
||||||
struct CppToCCallbackData
|
struct CppToCCallbackData
|
||||||
{
|
{
|
||||||
CppToCCallbackData();
|
CppToCCallbackData();
|
||||||
CppToCCallbackData(CallbackFunPtr funPtr, void *userData);
|
CppToCCallbackData(CallbackFunPtr funPtr, void *userData);
|
||||||
void init(CallbackFunPtr funPtr, void *userData);
|
void init(CallbackFunPtr funPtr, void *userData);
|
||||||
|
|
||||||
CallbackFunPtr funPtr;
|
CallbackFunPtr funPtr;
|
||||||
void *userData;
|
void *userData;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
FunCallbackStream();
|
FunCallbackStream();
|
||||||
FunCallbackStream(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData);
|
FunCallbackStream(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData);
|
||||||
~FunCallbackStream();
|
~FunCallbackStream();
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData);
|
void open(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunCallbackStream(const FunCallbackStream &); // non-copyable
|
FunCallbackStream(const FunCallbackStream &); // non-copyable
|
||||||
FunCallbackStream &operator=(const FunCallbackStream &); // non-copyable
|
FunCallbackStream &operator=(const FunCallbackStream &); // non-copyable
|
||||||
|
|
||||||
CppToCCallbackData adapterData_;
|
CppToCCallbackData adapterData_;
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters);
|
void open(const StreamParameters ¶meters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // portaudio
|
} // portaudio
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class System;
|
class System;
|
||||||
class HostApi;
|
class HostApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -24,68 +24,67 @@ namespace portaudio
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Class which represents a PortAudio device in the System.
|
/// @brief Class which represents a PortAudio device in the System.
|
||||||
///
|
///
|
||||||
/// A single physical device in the system may have multiple PortAudio
|
/// A single physical device in the system may have multiple PortAudio
|
||||||
/// Device representations using different HostApi 's though. A Device
|
/// Device representations using different HostApi 's though. A Device
|
||||||
/// can be half-duplex or full-duplex. A half-duplex Device can be used
|
/// can be half-duplex or full-duplex. A half-duplex Device can be used
|
||||||
/// to create a half-duplex Stream. A full-duplex Device can be used to
|
/// to create a half-duplex Stream. A full-duplex Device can be used to
|
||||||
/// create a full-duplex Stream. If supported by the HostApi, two
|
/// create a full-duplex Stream. If supported by the HostApi, two
|
||||||
/// half-duplex Devices can even be used to create a full-duplex Stream.
|
/// half-duplex Devices can even be used to create a full-duplex Stream.
|
||||||
///
|
///
|
||||||
/// Note that Device objects are very light-weight and can be passed around
|
/// Note that Device objects are very light-weight and can be passed around
|
||||||
/// by-value.
|
/// by-value.
|
||||||
//////
|
//////
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// query info: name, max in channels, max out channels,
|
// query info: name, max in channels, max out channels,
|
||||||
// default low/high input/output latency, default sample rate
|
// default low/high input/output latency, default sample rate
|
||||||
PaDeviceIndex index() const;
|
PaDeviceIndex index() const;
|
||||||
const char *name() const;
|
const char *name() const;
|
||||||
int maxInputChannels() const;
|
int maxInputChannels() const;
|
||||||
int maxOutputChannels() const;
|
int maxOutputChannels() const;
|
||||||
PaTime defaultLowInputLatency() const;
|
PaTime defaultLowInputLatency() const;
|
||||||
PaTime defaultHighInputLatency() const;
|
PaTime defaultHighInputLatency() const;
|
||||||
PaTime defaultLowOutputLatency() const;
|
PaTime defaultLowOutputLatency() const;
|
||||||
PaTime defaultHighOutputLatency() const;
|
PaTime defaultHighOutputLatency() const;
|
||||||
double defaultSampleRate() const;
|
double defaultSampleRate() const;
|
||||||
|
|
||||||
bool isInputOnlyDevice() const; // extended
|
bool isInputOnlyDevice() const; // extended
|
||||||
bool isOutputOnlyDevice() const; // extended
|
bool isOutputOnlyDevice() const; // extended
|
||||||
bool isFullDuplexDevice() const; // extended
|
bool isFullDuplexDevice() const; // extended
|
||||||
bool isSystemDefaultInputDevice() const; // extended
|
bool isSystemDefaultInputDevice() const; // extended
|
||||||
bool isSystemDefaultOutputDevice() const; // extended
|
bool isSystemDefaultOutputDevice() const; // extended
|
||||||
bool isHostApiDefaultInputDevice() const; // extended
|
bool isHostApiDefaultInputDevice() const; // extended
|
||||||
bool isHostApiDefaultOutputDevice() const; // extended
|
bool isHostApiDefaultOutputDevice() const; // extended
|
||||||
|
|
||||||
bool operator==(const Device &rhs) const;
|
bool operator==(const Device &rhs) const;
|
||||||
bool operator!=(const Device &rhs) const;
|
bool operator!=(const Device &rhs) const;
|
||||||
|
|
||||||
// host api reference
|
// host api reference
|
||||||
HostApi &hostApi();
|
HostApi &hostApi();
|
||||||
const HostApi &hostApi() const;
|
const HostApi &hostApi() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PaDeviceIndex index_;
|
PaDeviceIndex index_;
|
||||||
const PaDeviceInfo *info_;
|
const PaDeviceInfo *info_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class System;
|
friend class System;
|
||||||
|
|
||||||
explicit Device(PaDeviceIndex index);
|
|
||||||
~Device();
|
|
||||||
|
|
||||||
Device(const Device &); // non-copyable
|
explicit Device(PaDeviceIndex index);
|
||||||
Device &operator=(const Device &); // non-copyable
|
~Device();
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
Device(const Device &); // non-copyable
|
||||||
|
Device &operator=(const Device &); // non-copyable
|
||||||
|
};
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_DEVICE_HXX
|
#endif // INCLUDED_PORTAUDIO_DEVICE_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class Device;
|
class Device;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -24,50 +24,50 @@ namespace portaudio
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief All parameters for one direction (either in or out) of a Stream. Together with
|
/// @brief All parameters for one direction (either in or out) of a Stream. Together with
|
||||||
/// parameters common to both directions, two DirectionSpecificStreamParameters can make up
|
/// parameters common to both directions, two DirectionSpecificStreamParameters can make up
|
||||||
/// a StreamParameters object which contains all parameters for a Stream.
|
/// a StreamParameters object which contains all parameters for a Stream.
|
||||||
//////
|
//////
|
||||||
class DirectionSpecificStreamParameters
|
class DirectionSpecificStreamParameters
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static DirectionSpecificStreamParameters null();
|
static DirectionSpecificStreamParameters null();
|
||||||
|
|
||||||
DirectionSpecificStreamParameters();
|
DirectionSpecificStreamParameters();
|
||||||
DirectionSpecificStreamParameters(const Device &device, int numChannels, SampleDataFormat format,
|
DirectionSpecificStreamParameters(const Device &device, int numChannels, SampleDataFormat format,
|
||||||
bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo);
|
bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo);
|
||||||
|
|
||||||
// Set up methods:
|
// Set up methods:
|
||||||
void setDevice(const Device &device);
|
void setDevice(const Device &device);
|
||||||
void setNumChannels(int numChannels);
|
void setNumChannels(int numChannels);
|
||||||
|
|
||||||
void setSampleFormat(SampleDataFormat format, bool interleaved = true);
|
void setSampleFormat(SampleDataFormat format, bool interleaved = true);
|
||||||
void setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved = true);
|
void setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved = true);
|
||||||
|
|
||||||
void setSuggestedLatency(PaTime latency);
|
void setSuggestedLatency(PaTime latency);
|
||||||
|
|
||||||
void setHostApiSpecificStreamInfo(void *streamInfo);
|
void setHostApiSpecificStreamInfo(void *streamInfo);
|
||||||
|
|
||||||
// Accessor methods:
|
// Accessor methods:
|
||||||
PaStreamParameters *paStreamParameters();
|
PaStreamParameters *paStreamParameters();
|
||||||
const PaStreamParameters *paStreamParameters() const;
|
const PaStreamParameters *paStreamParameters() const;
|
||||||
|
|
||||||
Device &device() const;
|
Device &device() const;
|
||||||
int numChannels() const;
|
int numChannels() const;
|
||||||
|
|
||||||
SampleDataFormat sampleFormat() const;
|
SampleDataFormat sampleFormat() const;
|
||||||
bool isSampleFormatInterleaved() const;
|
bool isSampleFormatInterleaved() const;
|
||||||
bool isSampleFormatHostApiSpecific() const;
|
bool isSampleFormatHostApiSpecific() const;
|
||||||
PaSampleFormat hostApiSpecificSampleFormat() const;
|
PaSampleFormat hostApiSpecificSampleFormat() const;
|
||||||
|
|
||||||
PaTime suggestedLatency() const;
|
PaTime suggestedLatency() const;
|
||||||
|
|
||||||
void *hostApiSpecificStreamInfo() const;
|
void *hostApiSpecificStreamInfo() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PaStreamParameters paStreamParameters_;
|
PaStreamParameters paStreamParameters_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -12,92 +12,92 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Base class for all exceptions PortAudioCpp can throw.
|
/// @brief Base class for all exceptions PortAudioCpp can throw.
|
||||||
///
|
///
|
||||||
/// Class is derived from std::exception.
|
/// Class is derived from std::exception.
|
||||||
//////
|
//////
|
||||||
class Exception : public std::exception
|
class Exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Exception() throw() {}
|
virtual ~Exception() throw() {}
|
||||||
|
|
||||||
virtual const char *what() const throw() = 0;
|
virtual const char *what() const throw() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//////
|
// -----------------------------------------------------------------------------------
|
||||||
/// @brief Wrapper for PortAudio error codes to C++ exceptions.
|
|
||||||
///
|
|
||||||
/// It wraps up PortAudio's error handling mechanism using
|
|
||||||
/// C++ exceptions and is derived from std::exception for
|
|
||||||
/// easy exception handling and to ease integration with
|
|
||||||
/// other code.
|
|
||||||
///
|
|
||||||
/// To know what exceptions each function may throw, look up
|
|
||||||
/// the errors that can occur in the PortAudio documentation
|
|
||||||
/// for the equivalent functions.
|
|
||||||
///
|
|
||||||
/// Some functions are likely to throw an exception (such as
|
|
||||||
/// Stream::open(), etc) and these should always be called in
|
|
||||||
/// try{} catch{} blocks and the thrown exceptions should be
|
|
||||||
/// handled properly (ie. the application shouldn't just abort,
|
|
||||||
/// but merely display a warning dialog to the user or something).
|
|
||||||
/// However nearly all functions in PortAudioCpp are capable
|
|
||||||
/// of throwing exceptions. When a function like Stream::isStopped()
|
|
||||||
/// throws an exception, it's such an exceptional state that it's
|
|
||||||
/// not likely that it can be recovered. PaExceptions such as these
|
|
||||||
/// can ``safely'' be left to be handled by some outer catch-all-like
|
|
||||||
/// mechanism for unrecoverable errors.
|
|
||||||
//////
|
|
||||||
class PaException : public Exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit PaException(PaError error);
|
|
||||||
|
|
||||||
const char *what() const throw();
|
//////
|
||||||
|
/// @brief Wrapper for PortAudio error codes to C++ exceptions.
|
||||||
|
///
|
||||||
|
/// It wraps up PortAudio's error handling mechanism using
|
||||||
|
/// C++ exceptions and is derived from std::exception for
|
||||||
|
/// easy exception handling and to ease integration with
|
||||||
|
/// other code.
|
||||||
|
///
|
||||||
|
/// To know what exceptions each function may throw, look up
|
||||||
|
/// the errors that can occur in the PortAudio documentation
|
||||||
|
/// for the equivalent functions.
|
||||||
|
///
|
||||||
|
/// Some functions are likely to throw an exception (such as
|
||||||
|
/// Stream::open(), etc) and these should always be called in
|
||||||
|
/// try{} catch{} blocks and the thrown exceptions should be
|
||||||
|
/// handled properly (ie. the application shouldn't just abort,
|
||||||
|
/// but merely display a warning dialog to the user or something).
|
||||||
|
/// However nearly all functions in PortAudioCpp are capable
|
||||||
|
/// of throwing exceptions. When a function like Stream::isStopped()
|
||||||
|
/// throws an exception, it's such an exceptional state that it's
|
||||||
|
/// not likely that it can be recovered. PaExceptions such as these
|
||||||
|
/// can ``safely'' be left to be handled by some outer catch-all-like
|
||||||
|
/// mechanism for unrecoverable errors.
|
||||||
|
//////
|
||||||
|
class PaException : public Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit PaException(PaError error);
|
||||||
|
|
||||||
PaError paError() const;
|
const char *what() const throw();
|
||||||
const char *paErrorText() const;
|
|
||||||
|
|
||||||
bool isHostApiError() const; // extended
|
PaError paError() const;
|
||||||
long lastHostApiError() const;
|
const char *paErrorText() const;
|
||||||
const char *lastHostApiErrorText() const;
|
|
||||||
|
|
||||||
bool operator==(const PaException &rhs) const;
|
bool isHostApiError() const; // extended
|
||||||
bool operator!=(const PaException &rhs) const;
|
long lastHostApiError() const;
|
||||||
|
const char *lastHostApiErrorText() const;
|
||||||
|
|
||||||
private:
|
bool operator==(const PaException &rhs) const;
|
||||||
PaError error_;
|
bool operator!=(const PaException &rhs) const;
|
||||||
};
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
private:
|
||||||
|
PaError error_;
|
||||||
|
};
|
||||||
|
|
||||||
//////
|
// -----------------------------------------------------------------------------------
|
||||||
/// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an
|
|
||||||
/// equivalent PortAudio error code).
|
|
||||||
//////
|
|
||||||
class PaCppException : public Exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum ExceptionSpecifier
|
|
||||||
{
|
|
||||||
UNABLE_TO_ADAPT_DEVICE
|
|
||||||
};
|
|
||||||
|
|
||||||
PaCppException(ExceptionSpecifier specifier);
|
//////
|
||||||
|
/// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an
|
||||||
|
/// equivalent PortAudio error code).
|
||||||
|
//////
|
||||||
|
class PaCppException : public Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ExceptionSpecifier
|
||||||
|
{
|
||||||
|
UNABLE_TO_ADAPT_DEVICE
|
||||||
|
};
|
||||||
|
|
||||||
const char *what() const throw();
|
PaCppException(ExceptionSpecifier specifier);
|
||||||
|
|
||||||
ExceptionSpecifier specifier() const;
|
const char *what() const throw();
|
||||||
|
|
||||||
bool operator==(const PaCppException &rhs) const;
|
ExceptionSpecifier specifier() const;
|
||||||
bool operator!=(const PaCppException &rhs) const;
|
|
||||||
|
|
||||||
private:
|
bool operator==(const PaCppException &rhs) const;
|
||||||
ExceptionSpecifier specifier_;
|
bool operator!=(const PaCppException &rhs) const;
|
||||||
};
|
|
||||||
|
private:
|
||||||
|
ExceptionSpecifier specifier_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
@ -105,4 +105,3 @@ namespace portaudio
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX
|
#endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class Device;
|
class Device;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -22,50 +22,50 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief HostApi represents a host API (usually type of driver) in the System.
|
/// @brief HostApi represents a host API (usually type of driver) in the System.
|
||||||
///
|
///
|
||||||
/// A single System can support multiple HostApi's each one typically having
|
/// A single System can support multiple HostApi's each one typically having
|
||||||
/// a set of Devices using that HostApi (usually driver type). All Devices in
|
/// a set of Devices using that HostApi (usually driver type). All Devices in
|
||||||
/// the HostApi can be enumerated and the default input/output Device for this
|
/// the HostApi can be enumerated and the default input/output Device for this
|
||||||
/// HostApi can be retrieved.
|
/// HostApi can be retrieved.
|
||||||
//////
|
//////
|
||||||
class HostApi
|
class HostApi
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef System::DeviceIterator DeviceIterator;
|
typedef System::DeviceIterator DeviceIterator;
|
||||||
|
|
||||||
// query info: id, name, numDevices
|
// query info: id, name, numDevices
|
||||||
PaHostApiTypeId typeId() const;
|
PaHostApiTypeId typeId() const;
|
||||||
PaHostApiIndex index() const;
|
PaHostApiIndex index() const;
|
||||||
const char *name() const;
|
const char *name() const;
|
||||||
int deviceCount() const;
|
int deviceCount() const;
|
||||||
|
|
||||||
// iterate devices
|
// iterate devices
|
||||||
DeviceIterator devicesBegin();
|
DeviceIterator devicesBegin();
|
||||||
DeviceIterator devicesEnd();
|
DeviceIterator devicesEnd();
|
||||||
|
|
||||||
// default devices
|
// default devices
|
||||||
Device &defaultInputDevice() const;
|
Device &defaultInputDevice() const;
|
||||||
Device &defaultOutputDevice() const;
|
Device &defaultOutputDevice() const;
|
||||||
|
|
||||||
// comparison operators
|
// comparison operators
|
||||||
bool operator==(const HostApi &rhs) const;
|
bool operator==(const HostApi &rhs) const;
|
||||||
bool operator!=(const HostApi &rhs) const;
|
bool operator!=(const HostApi &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PaHostApiInfo *info_;
|
const PaHostApiInfo *info_;
|
||||||
Device **devices_;
|
Device **devices_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class System;
|
friend class System;
|
||||||
|
|
||||||
explicit HostApi(PaHostApiIndex index);
|
explicit HostApi(PaHostApiIndex index);
|
||||||
~HostApi();
|
~HostApi();
|
||||||
|
|
||||||
HostApi(const HostApi &); // non-copyable
|
HostApi(const HostApi &); // non-copyable
|
||||||
HostApi &operator=(const HostApi &); // non-copyable
|
HostApi &operator=(const HostApi &); // non-copyable
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -73,4 +73,3 @@ namespace portaudio
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_HOSTAPI_HXX
|
#endif // INCLUDED_PORTAUDIO_HOSTAPI_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
// Forward declaration(s)
|
// Forward declaration(s)
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class StreamParameters;
|
class StreamParameters;
|
||||||
class CallbackInterface;
|
class CallbackInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -23,23 +23,23 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Callback stream using an instance of an object that's derived from the CallbackInterface
|
/// @brief Callback stream using an instance of an object that's derived from the CallbackInterface
|
||||||
/// interface.
|
/// interface.
|
||||||
//////
|
//////
|
||||||
class InterfaceCallbackStream : public CallbackStream
|
class InterfaceCallbackStream : public CallbackStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InterfaceCallbackStream();
|
InterfaceCallbackStream();
|
||||||
InterfaceCallbackStream(const StreamParameters ¶meters, CallbackInterface &instance);
|
InterfaceCallbackStream(const StreamParameters ¶meters, CallbackInterface &instance);
|
||||||
~InterfaceCallbackStream();
|
~InterfaceCallbackStream();
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters, CallbackInterface &instance);
|
|
||||||
|
|
||||||
private:
|
void open(const StreamParameters ¶meters, CallbackInterface &instance);
|
||||||
InterfaceCallbackStream(const InterfaceCallbackStream &); // non-copyable
|
|
||||||
InterfaceCallbackStream &operator=(const InterfaceCallbackStream &); // non-copyable
|
private:
|
||||||
};
|
InterfaceCallbackStream(const InterfaceCallbackStream &); // non-copyable
|
||||||
|
InterfaceCallbackStream &operator=(const InterfaceCallbackStream &); // non-copyable
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // portaudio
|
} // portaudio
|
||||||
|
|
|
||||||
|
|
@ -17,87 +17,87 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Callback stream using a class's member function as a callback. Template argument T is the type of the
|
/// @brief Callback stream using a class's member function as a callback. Template argument T is the type of the
|
||||||
/// class of which a member function is going to be used.
|
/// class of which a member function is going to be used.
|
||||||
///
|
///
|
||||||
/// Example usage:
|
/// Example usage:
|
||||||
/// @verbatim MemFunCallback<MyClass> stream = MemFunCallbackStream(parameters, *this, &MyClass::myCallbackFunction); @endverbatim
|
/// @verbatim MemFunCallback<MyClass> stream = MemFunCallbackStream(parameters, *this, &MyClass::myCallbackFunction); @endverbatim
|
||||||
//////
|
//////
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class MemFunCallbackStream : public CallbackStream
|
class MemFunCallbackStream : public CallbackStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef int (T::*CallbackFunPtr)(const void *, void *, unsigned long, const PaStreamCallbackTimeInfo *,
|
typedef int (T::*CallbackFunPtr)(const void *, void *, unsigned long, const PaStreamCallbackTimeInfo *,
|
||||||
PaStreamCallbackFlags);
|
PaStreamCallbackFlags);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
MemFunCallbackStream()
|
MemFunCallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MemFunCallbackStream(const StreamParameters ¶meters, T &instance, CallbackFunPtr memFun) : adapter_(instance, memFun)
|
MemFunCallbackStream(const StreamParameters ¶meters, T &instance, CallbackFunPtr memFun) : adapter_(instance, memFun)
|
||||||
{
|
{
|
||||||
open(parameters);
|
open(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
~MemFunCallbackStream()
|
~MemFunCallbackStream()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters, T &instance, CallbackFunPtr memFun)
|
void open(const StreamParameters ¶meters, T &instance, CallbackFunPtr memFun)
|
||||||
{
|
{
|
||||||
// XXX: need to check if already open?
|
// XXX: need to check if already open?
|
||||||
|
|
||||||
adapter_.init(instance, memFun);
|
adapter_.init(instance, memFun);
|
||||||
open(parameters);
|
open(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MemFunCallbackStream(const MemFunCallbackStream &); // non-copyable
|
MemFunCallbackStream(const MemFunCallbackStream &); // non-copyable
|
||||||
MemFunCallbackStream &operator=(const MemFunCallbackStream &); // non-copyable
|
MemFunCallbackStream &operator=(const MemFunCallbackStream &); // non-copyable
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Inner class which adapts a member function callback to a CallbackInterface compliant
|
/// @brief Inner class which adapts a member function callback to a CallbackInterface compliant
|
||||||
/// class (so it can be adapted using the paCallbackAdapter function).
|
/// class (so it can be adapted using the paCallbackAdapter function).
|
||||||
//////
|
//////
|
||||||
class MemFunToCallbackInterfaceAdapter : public CallbackInterface
|
class MemFunToCallbackInterfaceAdapter : public CallbackInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MemFunToCallbackInterfaceAdapter() {}
|
MemFunToCallbackInterfaceAdapter() {}
|
||||||
MemFunToCallbackInterfaceAdapter(T &instance, CallbackFunPtr memFun) : instance_(&instance), memFun_(memFun) {}
|
MemFunToCallbackInterfaceAdapter(T &instance, CallbackFunPtr memFun) : instance_(&instance), memFun_(memFun) {}
|
||||||
|
|
||||||
void init(T &instance, CallbackFunPtr memFun)
|
void init(T &instance, CallbackFunPtr memFun)
|
||||||
{
|
{
|
||||||
instance_ = &instance;
|
instance_ = &instance;
|
||||||
memFun_ = memFun;
|
memFun_ = memFun;
|
||||||
}
|
}
|
||||||
|
|
||||||
int paCallbackFun(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
int paCallbackFun(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
|
||||||
{
|
{
|
||||||
return (instance_->*memFun_)(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags);
|
return (instance_->*memFun_)(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T *instance_;
|
T *instance_;
|
||||||
CallbackFunPtr memFun_;
|
CallbackFunPtr memFun_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MemFunToCallbackInterfaceAdapter adapter_;
|
MemFunToCallbackInterfaceAdapter adapter_;
|
||||||
|
|
||||||
void open(const StreamParameters ¶meters)
|
void open(const StreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
||||||
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::callbackInterfaceToPaCallbackAdapter,
|
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::callbackInterfaceToPaCallbackAdapter,
|
||||||
static_cast<void *>(&adapter_));
|
static_cast<void *>(&adapter_));
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // portaudio
|
} // portaudio
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,23 @@
|
||||||
//////
|
//////
|
||||||
/// @mainpage PortAudioCpp
|
/// @mainpage PortAudioCpp
|
||||||
///
|
///
|
||||||
/// <h1>PortAudioCpp - A Native C++ Binding of PortAudio V19</h1>
|
/// <h1>PortAudioCpp - A Native C++ Binding of PortAudio V19</h1>
|
||||||
/// <h2>PortAudio</h2>
|
/// <h2>PortAudio</h2>
|
||||||
/// <p>
|
/// <p>
|
||||||
/// PortAudio is a portable and mature C API for accessing audio hardware. It offers both callback-based and blocking
|
/// PortAudio is a portable and mature C API for accessing audio hardware. It offers both callback-based and blocking
|
||||||
/// style input and output, deals with sample data format conversions, dithering and much more. There are a large number
|
/// style input and output, deals with sample data format conversions, dithering and much more. There are a large number
|
||||||
/// of implementations available for various platforms including Windows MME, Windows DirectX, Windows and MacOS (Classic)
|
/// of implementations available for various platforms including Windows MME, Windows DirectX, Windows and MacOS (Classic)
|
||||||
/// ASIO, MacOS Classic SoundManager, MacOS X CoreAudio, OSS (Linux), Linux ALSA, JACK (MacOS X and Linux) and SGI Irix
|
/// ASIO, MacOS Classic SoundManager, MacOS X CoreAudio, OSS (Linux), Linux ALSA, JACK (MacOS X and Linux) and SGI Irix
|
||||||
/// AL. Note that, currently not all of these implementations are equally complete or up-to-date (as PortAudio V19 is
|
/// AL. Note that, currently not all of these implementations are equally complete or up-to-date (as PortAudio V19 is
|
||||||
/// still in development). Because PortAudio has a C API, it can easily be called from a variety of other programming
|
/// still in development). Because PortAudio has a C API, it can easily be called from a variety of other programming
|
||||||
/// languages.
|
/// languages.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <h2>PortAudioCpp</h2>
|
/// <h2>PortAudioCpp</h2>
|
||||||
/// <p>
|
/// <p>
|
||||||
/// Although, it is possible to use PortAudio's C API from within a C++ program, this is usually a little awkward
|
/// Although, it is possible to use PortAudio's C API from within a C++ program, this is usually a little awkward
|
||||||
/// as procedural and object-oriented paradigms need to be mixed. PortAudioCpp aims to resolve this by encapsulating
|
/// as procedural and object-oriented paradigms need to be mixed. PortAudioCpp aims to resolve this by encapsulating
|
||||||
/// PortAudio's C API to form an equivalent object-oriented C++ API. It provides a more natural integration of PortAudio
|
/// PortAudio's C API to form an equivalent object-oriented C++ API. It provides a more natural integration of PortAudio
|
||||||
/// into C++ programs as well as a more structured interface. PortAudio's concepts were preserved as much as possible and
|
/// into C++ programs as well as a more structured interface. PortAudio's concepts were preserved as much as possible and
|
||||||
/// no additional features were added except for some `convenience methods'.
|
/// no additional features were added except for some `convenience methods'.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <p>
|
/// <p>
|
||||||
|
|
@ -30,15 +30,15 @@
|
||||||
/// <ul>
|
/// <ul>
|
||||||
/// <li>Structured object model.</li>
|
/// <li>Structured object model.</li>
|
||||||
/// <li>C++ exception handling instead of C-style error return codes.</li>
|
/// <li>C++ exception handling instead of C-style error return codes.</li>
|
||||||
/// <li>Handling of callbacks using free functions (C and C++), static functions, member functions or instances of classes
|
/// <li>Handling of callbacks using free functions (C and C++), static functions, member functions or instances of classes
|
||||||
/// derived from a given interface.</li>
|
/// derived from a given interface.</li>
|
||||||
/// <li>STL compliant iterators to host APIs and devices.</li>
|
/// <li>STL compliant iterators to host APIs and devices.</li>
|
||||||
/// <li>Some additional convenience functions to more easily set up and use PortAudio.</li>
|
/// <li>Some additional convenience functions to more easily set up and use PortAudio.</li>
|
||||||
/// </ul>
|
/// </ul>
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <p>
|
/// <p>
|
||||||
/// PortAudioCpp requires a recent version of the PortAudio V19 source code. This can be obtained from CVS or as a snapshot
|
/// PortAudioCpp requires a recent version of the PortAudio V19 source code. This can be obtained from CVS or as a snapshot
|
||||||
/// from the website. The examples also require the ASIO 2 SDK which can be obtained from the Steinberg website. Alternatively, the
|
/// from the website. The examples also require the ASIO 2 SDK which can be obtained from the Steinberg website. Alternatively, the
|
||||||
/// examples can easily be modified to compile without needing ASIO.
|
/// examples can easily be modified to compile without needing ASIO.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <p>
|
/// <p>
|
||||||
|
|
@ -50,12 +50,12 @@
|
||||||
/// Other platforms should be easily supported as PortAudioCpp is platform-independent and (reasonably) C++ standard compliant.
|
/// Other platforms should be easily supported as PortAudioCpp is platform-independent and (reasonably) C++ standard compliant.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <p>
|
/// <p>
|
||||||
/// This documentation mainly provides information specific to PortAudioCpp. For a more complete explanation of all of the
|
/// This documentation mainly provides information specific to PortAudioCpp. For a more complete explanation of all of the
|
||||||
/// concepts used, please consult the PortAudio documentation.
|
/// concepts used, please consult the PortAudio documentation.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <p>
|
/// <p>
|
||||||
/// PortAudioCpp was developed by Merlijn Blaauw with many great suggestions and help from Ross Bencina. Ludwig Schwardt provided
|
/// PortAudioCpp was developed by Merlijn Blaauw with many great suggestions and help from Ross Bencina. Ludwig Schwardt provided
|
||||||
/// GNU/Linux build files and checked G++ compatibility. PortAudioCpp may be used under the same licensing, conditions and
|
/// GNU/Linux build files and checked G++ compatibility. PortAudioCpp may be used under the same licensing, conditions and
|
||||||
/// warranty as PortAudio. See <a href="http://www.portaudio.com/license.html">the PortAudio license</a> for more details.
|
/// warranty as PortAudio. See <a href="http://www.portaudio.com/license.html">the PortAudio license</a> for more details.
|
||||||
/// </p>
|
/// </p>
|
||||||
/// <h2>Links</h2>
|
/// <h2>Links</h2>
|
||||||
|
|
@ -69,8 +69,8 @@
|
||||||
//////
|
//////
|
||||||
/// @namespace portaudio
|
/// @namespace portaudio
|
||||||
///
|
///
|
||||||
/// To avoid name collision, everything in PortAudioCpp is in the portaudio
|
/// To avoid name collision, everything in PortAudioCpp is in the portaudio
|
||||||
/// namespace. If this name is too long it's usually pretty safe to use an
|
/// namespace. If this name is too long it's usually pretty safe to use an
|
||||||
/// alias like ``namespace pa = portaudio;''.
|
/// alias like ``namespace pa = portaudio;''.
|
||||||
//////
|
//////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,21 +11,21 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief PortAudio sample data formats.
|
/// @brief PortAudio sample data formats.
|
||||||
///
|
///
|
||||||
/// Small helper enum to wrap the PortAudio defines.
|
/// Small helper enum to wrap the PortAudio defines.
|
||||||
//////
|
//////
|
||||||
enum SampleDataFormat
|
enum SampleDataFormat
|
||||||
{
|
{
|
||||||
INVALID_FORMAT = 0,
|
INVALID_FORMAT = 0,
|
||||||
FLOAT32 = paFloat32,
|
FLOAT32 = paFloat32,
|
||||||
INT32 = paInt32,
|
INT32 = paInt32,
|
||||||
INT24 = paInt24,
|
INT24 = paInt24,
|
||||||
INT16 = paInt16,
|
INT16 = paInt16,
|
||||||
INT8 = paInt8,
|
INT8 = paInt8,
|
||||||
UINT8 = paUInt8
|
UINT8 = paUInt8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class StreamParameters;
|
class StreamParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -18,65 +18,64 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief A Stream represents an active or inactive input and/or output data
|
/// @brief A Stream represents an active or inactive input and/or output data
|
||||||
/// stream in the System.
|
/// stream in the System.
|
||||||
///
|
///
|
||||||
/// Concrete Stream classes should ensure themselves being in a closed state at
|
/// Concrete Stream classes should ensure themselves being in a closed state at
|
||||||
/// destruction (i.e. by calling their own close() method in their deconstructor).
|
/// destruction (i.e. by calling their own close() method in their deconstructor).
|
||||||
/// Following good C++ programming practices, care must be taken to ensure no
|
/// Following good C++ programming practices, care must be taken to ensure no
|
||||||
/// exceptions are thrown by the deconstructor of these classes. As a consequence,
|
/// exceptions are thrown by the deconstructor of these classes. As a consequence,
|
||||||
/// clients need to explicitly call close() to ensure the stream closed successfully.
|
/// clients need to explicitly call close() to ensure the stream closed successfully.
|
||||||
///
|
///
|
||||||
/// The Stream object can be used to manipulate the Stream's state. Also, time-constant
|
/// The Stream object can be used to manipulate the Stream's state. Also, time-constant
|
||||||
/// and time-varying information about the Stream can be retrieved.
|
/// and time-varying information about the Stream can be retrieved.
|
||||||
//////
|
//////
|
||||||
class Stream
|
class Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Opening/closing:
|
// Opening/closing:
|
||||||
virtual ~Stream();
|
virtual ~Stream();
|
||||||
|
|
||||||
virtual void close();
|
virtual void close();
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
|
|
||||||
// Additional set up:
|
// Additional set up:
|
||||||
void setStreamFinishedCallback(PaStreamFinishedCallback *callback);
|
void setStreamFinishedCallback(PaStreamFinishedCallback *callback);
|
||||||
|
|
||||||
// State management:
|
// State management:
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
void abort();
|
void abort();
|
||||||
|
|
||||||
bool isStopped() const;
|
bool isStopped() const;
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
|
|
||||||
// Stream info (time-constant, but might become time-variant soon):
|
// Stream info (time-constant, but might become time-variant soon):
|
||||||
PaTime inputLatency() const;
|
PaTime inputLatency() const;
|
||||||
PaTime outputLatency() const;
|
PaTime outputLatency() const;
|
||||||
double sampleRate() const;
|
double sampleRate() const;
|
||||||
|
|
||||||
// Stream info (time-varying):
|
// Stream info (time-varying):
|
||||||
PaTime time() const;
|
PaTime time() const;
|
||||||
|
|
||||||
// Accessors for PortAudio PaStream, useful for interfacing
|
// Accessors for PortAudio PaStream, useful for interfacing
|
||||||
// with PortAudio add-ons (such as PortMixer) for instance:
|
// with PortAudio add-ons (such as PortMixer) for instance:
|
||||||
const PaStream *paStream() const;
|
const PaStream *paStream() const;
|
||||||
PaStream *paStream();
|
PaStream *paStream();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Stream(); // abstract class
|
Stream(); // abstract class
|
||||||
|
|
||||||
PaStream *stream_;
|
PaStream *stream_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stream(const Stream &); // non-copyable
|
Stream(const Stream &); // non-copyable
|
||||||
Stream &operator=(const Stream &); // non-copyable
|
Stream &operator=(const Stream &); // non-copyable
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_STREAM_HXX
|
#endif // INCLUDED_PORTAUDIO_STREAM_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,61 +13,61 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief The entire set of parameters needed to configure and open
|
/// @brief The entire set of parameters needed to configure and open
|
||||||
/// a Stream.
|
/// a Stream.
|
||||||
///
|
///
|
||||||
/// It contains parameters of input, output and shared parameters.
|
/// It contains parameters of input, output and shared parameters.
|
||||||
/// Using the isSupported() method, the StreamParameters can be
|
/// Using the isSupported() method, the StreamParameters can be
|
||||||
/// checked if opening a Stream using this StreamParameters would
|
/// checked if opening a Stream using this StreamParameters would
|
||||||
/// succeed or not. Accessors are provided to higher-level parameters
|
/// succeed or not. Accessors are provided to higher-level parameters
|
||||||
/// aswell as the lower-level parameters which are mainly intended for
|
/// aswell as the lower-level parameters which are mainly intended for
|
||||||
/// internal use.
|
/// internal use.
|
||||||
//////
|
//////
|
||||||
class StreamParameters
|
class StreamParameters
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StreamParameters();
|
StreamParameters();
|
||||||
StreamParameters(const DirectionSpecificStreamParameters &inputParameters,
|
StreamParameters(const DirectionSpecificStreamParameters &inputParameters,
|
||||||
const DirectionSpecificStreamParameters &outputParameters, double sampleRate,
|
const DirectionSpecificStreamParameters &outputParameters, double sampleRate,
|
||||||
unsigned long framesPerBuffer, PaStreamFlags flags);
|
unsigned long framesPerBuffer, PaStreamFlags flags);
|
||||||
|
|
||||||
// Set up for direction-specific:
|
// Set up for direction-specific:
|
||||||
void setInputParameters(const DirectionSpecificStreamParameters ¶meters);
|
void setInputParameters(const DirectionSpecificStreamParameters ¶meters);
|
||||||
void setOutputParameters(const DirectionSpecificStreamParameters ¶meters);
|
void setOutputParameters(const DirectionSpecificStreamParameters ¶meters);
|
||||||
|
|
||||||
// Set up for common parameters:
|
// Set up for common parameters:
|
||||||
void setSampleRate(double sampleRate);
|
void setSampleRate(double sampleRate);
|
||||||
void setFramesPerBuffer(unsigned long framesPerBuffer);
|
void setFramesPerBuffer(unsigned long framesPerBuffer);
|
||||||
void setFlag(PaStreamFlags flag);
|
void setFlag(PaStreamFlags flag);
|
||||||
void unsetFlag(PaStreamFlags flag);
|
void unsetFlag(PaStreamFlags flag);
|
||||||
void clearFlags();
|
void clearFlags();
|
||||||
|
|
||||||
// Validation:
|
// Validation:
|
||||||
bool isSupported() const;
|
bool isSupported() const;
|
||||||
|
|
||||||
// Accessors (direction-specific):
|
// Accessors (direction-specific):
|
||||||
DirectionSpecificStreamParameters &inputParameters();
|
DirectionSpecificStreamParameters &inputParameters();
|
||||||
const DirectionSpecificStreamParameters &inputParameters() const;
|
const DirectionSpecificStreamParameters &inputParameters() const;
|
||||||
DirectionSpecificStreamParameters &outputParameters();
|
DirectionSpecificStreamParameters &outputParameters();
|
||||||
const DirectionSpecificStreamParameters &outputParameters() const;
|
const DirectionSpecificStreamParameters &outputParameters() const;
|
||||||
|
|
||||||
// Accessors (common):
|
// Accessors (common):
|
||||||
double sampleRate() const;
|
double sampleRate() const;
|
||||||
unsigned long framesPerBuffer() const;
|
unsigned long framesPerBuffer() const;
|
||||||
PaStreamFlags flags() const;
|
PaStreamFlags flags() const;
|
||||||
bool isFlagSet(PaStreamFlags flag) const;
|
bool isFlagSet(PaStreamFlags flag) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Half-duplex specific parameters:
|
// Half-duplex specific parameters:
|
||||||
DirectionSpecificStreamParameters inputParameters_;
|
DirectionSpecificStreamParameters inputParameters_;
|
||||||
DirectionSpecificStreamParameters outputParameters_;
|
DirectionSpecificStreamParameters outputParameters_;
|
||||||
|
|
||||||
// Common parameters:
|
// Common parameters:
|
||||||
double sampleRate_;
|
double sampleRate_;
|
||||||
unsigned long framesPerBuffer_;
|
unsigned long framesPerBuffer_;
|
||||||
PaStreamFlags flags_;
|
PaStreamFlags flags_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class Device;
|
class Device;
|
||||||
class Stream;
|
class Stream;
|
||||||
class HostApi;
|
class HostApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -22,86 +22,85 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief System singleton which represents the PortAudio system.
|
/// @brief System singleton which represents the PortAudio system.
|
||||||
///
|
///
|
||||||
/// The System is used to initialize/terminate PortAudio and provide
|
/// The System is used to initialize/terminate PortAudio and provide
|
||||||
/// a single access point to the PortAudio System (instance()).
|
/// a single access point to the PortAudio System (instance()).
|
||||||
/// It can be used to iterate through all HostApi 's in the System as
|
/// It can be used to iterate through all HostApi 's in the System as
|
||||||
/// well as all devices in the System. It also provides some utility
|
/// well as all devices in the System. It also provides some utility
|
||||||
/// functionality of PortAudio.
|
/// functionality of PortAudio.
|
||||||
///
|
///
|
||||||
/// Terminating the System will also abort and close the open streams.
|
/// Terminating the System will also abort and close the open streams.
|
||||||
/// The Stream objects will need to be deallocated by the client though
|
/// The Stream objects will need to be deallocated by the client though
|
||||||
/// (it's usually a good idea to have them cleaned up automatically).
|
/// (it's usually a good idea to have them cleaned up automatically).
|
||||||
//////
|
//////
|
||||||
class System
|
class System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class HostApiIterator; // forward declaration
|
class HostApiIterator; // forward declaration
|
||||||
class DeviceIterator; // forward declaration
|
class DeviceIterator; // forward declaration
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
static int version();
|
static int version();
|
||||||
static const char *versionText();
|
static const char *versionText();
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static void terminate();
|
static void terminate();
|
||||||
|
|
||||||
static System &instance();
|
static System &instance();
|
||||||
static bool exists();
|
static bool exists();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
// host apis:
|
// host apis:
|
||||||
HostApiIterator hostApisBegin();
|
HostApiIterator hostApisBegin();
|
||||||
HostApiIterator hostApisEnd();
|
HostApiIterator hostApisEnd();
|
||||||
|
|
||||||
HostApi &defaultHostApi();
|
HostApi &defaultHostApi();
|
||||||
|
|
||||||
HostApi &hostApiByTypeId(PaHostApiTypeId type);
|
HostApi &hostApiByTypeId(PaHostApiTypeId type);
|
||||||
HostApi &hostApiByIndex(PaHostApiIndex index);
|
HostApi &hostApiByIndex(PaHostApiIndex index);
|
||||||
|
|
||||||
int hostApiCount();
|
int hostApiCount();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
// devices:
|
// devices:
|
||||||
DeviceIterator devicesBegin();
|
DeviceIterator devicesBegin();
|
||||||
DeviceIterator devicesEnd();
|
DeviceIterator devicesEnd();
|
||||||
|
|
||||||
Device &defaultInputDevice();
|
Device &defaultInputDevice();
|
||||||
Device &defaultOutputDevice();
|
Device &defaultOutputDevice();
|
||||||
|
|
||||||
Device &deviceByIndex(PaDeviceIndex index);
|
Device &deviceByIndex(PaDeviceIndex index);
|
||||||
|
|
||||||
int deviceCount();
|
int deviceCount();
|
||||||
|
|
||||||
static Device &nullDevice();
|
static Device &nullDevice();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
// misc:
|
// misc:
|
||||||
void sleep(long msec);
|
void sleep(long msec);
|
||||||
int sizeOfSample(PaSampleFormat format);
|
int sizeOfSample(PaSampleFormat format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
System();
|
System();
|
||||||
~System();
|
~System();
|
||||||
|
|
||||||
static System *instance_;
|
static System *instance_;
|
||||||
static int initCount_;
|
static int initCount_;
|
||||||
|
|
||||||
static HostApi **hostApis_;
|
static HostApi **hostApis_;
|
||||||
static Device **devices_;
|
static Device **devices_;
|
||||||
|
|
||||||
static Device *nullDevice_;
|
static Device *nullDevice_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_SYSTEM_HXX
|
#endif // INCLUDED_PORTAUDIO_SYSTEM_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class Device;
|
class Device;
|
||||||
class HostApi;
|
class HostApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -23,39 +23,39 @@ namespace portaudio
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
|
||||||
/// @brief Iterator class for iterating through all Devices in a System.
|
|
||||||
///
|
|
||||||
/// Devices will be iterated by iterating all Devices in each
|
|
||||||
/// HostApi in the System. Compliant with the STL bidirectional
|
|
||||||
/// iterator concept.
|
|
||||||
//////
|
|
||||||
class System::DeviceIterator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::bidirectional_iterator_tag iterator_category;
|
|
||||||
typedef Device value_type;
|
|
||||||
typedef ptrdiff_t difference_type;
|
|
||||||
typedef Device * pointer;
|
|
||||||
typedef Device & reference;
|
|
||||||
|
|
||||||
Device &operator*() const;
|
//////
|
||||||
Device *operator->() const;
|
/// @brief Iterator class for iterating through all Devices in a System.
|
||||||
|
///
|
||||||
|
/// Devices will be iterated by iterating all Devices in each
|
||||||
|
/// HostApi in the System. Compliant with the STL bidirectional
|
||||||
|
/// iterator concept.
|
||||||
|
//////
|
||||||
|
class System::DeviceIterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
typedef Device value_type;
|
||||||
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef Device * pointer;
|
||||||
|
typedef Device & reference;
|
||||||
|
|
||||||
DeviceIterator &operator++();
|
Device &operator*() const;
|
||||||
DeviceIterator operator++(int);
|
Device *operator->() const;
|
||||||
DeviceIterator &operator--();
|
|
||||||
DeviceIterator operator--(int);
|
|
||||||
|
|
||||||
bool operator==(const DeviceIterator &rhs) const;
|
DeviceIterator &operator++();
|
||||||
bool operator!=(const DeviceIterator &rhs) const;
|
DeviceIterator operator++(int);
|
||||||
|
DeviceIterator &operator--();
|
||||||
|
DeviceIterator operator--(int);
|
||||||
|
|
||||||
private:
|
bool operator==(const DeviceIterator &rhs) const;
|
||||||
friend class System;
|
bool operator!=(const DeviceIterator &rhs) const;
|
||||||
friend class HostApi;
|
|
||||||
Device **ptr_;
|
private:
|
||||||
};
|
friend class System;
|
||||||
|
friend class HostApi;
|
||||||
|
Device **ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
@ -63,4 +63,3 @@ namespace portaudio
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif // INCLUDED_PORTAUDIO_SYSTEMDEVICEITERATOR_HXX
|
#endif // INCLUDED_PORTAUDIO_SYSTEMDEVICEITERATOR_HXX
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
// Forward declaration(s):
|
// Forward declaration(s):
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
class HostApi;
|
class HostApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
@ -23,35 +23,35 @@ namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// @brief Iterator class for iterating through all HostApis in a System.
|
/// @brief Iterator class for iterating through all HostApis in a System.
|
||||||
///
|
///
|
||||||
/// Compliant with the STL bidirectional iterator concept.
|
/// Compliant with the STL bidirectional iterator concept.
|
||||||
//////
|
//////
|
||||||
class System::HostApiIterator
|
class System::HostApiIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::bidirectional_iterator_tag iterator_category;
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
typedef Device value_type;
|
typedef Device value_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef HostApi * pointer;
|
typedef HostApi * pointer;
|
||||||
typedef HostApi & reference;
|
typedef HostApi & reference;
|
||||||
|
|
||||||
HostApi &operator*() const;
|
HostApi &operator*() const;
|
||||||
HostApi *operator->() const;
|
HostApi *operator->() const;
|
||||||
|
|
||||||
HostApiIterator &operator++();
|
HostApiIterator &operator++();
|
||||||
HostApiIterator operator++(int);
|
HostApiIterator operator++(int);
|
||||||
HostApiIterator &operator--();
|
HostApiIterator &operator--();
|
||||||
HostApiIterator operator--(int);
|
HostApiIterator operator--(int);
|
||||||
|
|
||||||
bool operator==(const HostApiIterator &rhs) const;
|
bool operator==(const HostApiIterator &rhs) const;
|
||||||
bool operator!=(const HostApiIterator &rhs) const;
|
bool operator!=(const HostApiIterator &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class System;
|
friend class System;
|
||||||
HostApi **ptr_;
|
HostApi **ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -9,75 +9,73 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
AsioDeviceAdapter::AsioDeviceAdapter(Device &device)
|
AsioDeviceAdapter::AsioDeviceAdapter(Device &device)
|
||||||
{
|
{
|
||||||
if (device.hostApi().typeId() != paASIO)
|
if (device.hostApi().typeId() != paASIO)
|
||||||
throw PaCppException(PaCppException::UNABLE_TO_ADAPT_DEVICE);
|
throw PaCppException(PaCppException::UNABLE_TO_ADAPT_DEVICE);
|
||||||
|
|
||||||
device_ = &device;
|
device_ = &device;
|
||||||
|
|
||||||
PaError err = PaAsio_GetAvailableLatencyValues(device_->index(), &minBufferSize_, &maxBufferSize_,
|
PaError err = PaAsio_GetAvailableLatencyValues(device_->index(), &minBufferSize_, &maxBufferSize_,
|
||||||
&preferredBufferSize_, &granularity_);
|
&preferredBufferSize_, &granularity_);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device &AsioDeviceAdapter::device()
|
Device &AsioDeviceAdapter::device()
|
||||||
{
|
{
|
||||||
return *device_;
|
return *device_;
|
||||||
}
|
}
|
||||||
|
|
||||||
long AsioDeviceAdapter::minBufferSize() const
|
long AsioDeviceAdapter::minBufferSize() const
|
||||||
{
|
{
|
||||||
return minBufferSize_;
|
return minBufferSize_;
|
||||||
}
|
}
|
||||||
|
|
||||||
long AsioDeviceAdapter::maxBufferSize() const
|
long AsioDeviceAdapter::maxBufferSize() const
|
||||||
{
|
{
|
||||||
return maxBufferSize_;
|
return maxBufferSize_;
|
||||||
}
|
}
|
||||||
|
|
||||||
long AsioDeviceAdapter::preferredBufferSize() const
|
long AsioDeviceAdapter::preferredBufferSize() const
|
||||||
{
|
{
|
||||||
return preferredBufferSize_;
|
return preferredBufferSize_;
|
||||||
}
|
}
|
||||||
|
|
||||||
long AsioDeviceAdapter::granularity() const
|
long AsioDeviceAdapter::granularity() const
|
||||||
{
|
{
|
||||||
return granularity_;
|
return granularity_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsioDeviceAdapter::showControlPanel(void *systemSpecific)
|
void AsioDeviceAdapter::showControlPanel(void *systemSpecific)
|
||||||
{
|
{
|
||||||
PaError err = PaAsio_ShowControlPanel(device_->index(), systemSpecific);
|
PaError err = PaAsio_ShowControlPanel(device_->index(), systemSpecific);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *AsioDeviceAdapter::inputChannelName(int channelIndex) const
|
const char *AsioDeviceAdapter::inputChannelName(int channelIndex) const
|
||||||
{
|
{
|
||||||
const char *channelName;
|
const char *channelName;
|
||||||
PaError err = PaAsio_GetInputChannelName(device_->index(), channelIndex, &channelName);
|
PaError err = PaAsio_GetInputChannelName(device_->index(), channelIndex, &channelName);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
|
|
||||||
return channelName;
|
return channelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *AsioDeviceAdapter::outputChannelName(int channelIndex) const
|
const char *AsioDeviceAdapter::outputChannelName(int channelIndex) const
|
||||||
{
|
{
|
||||||
const char *channelName;
|
const char *channelName;
|
||||||
PaError err = PaAsio_GetOutputChannelName(device_->index(), channelIndex, &channelName);
|
PaError err = PaAsio_GetOutputChannelName(device_->index(), channelIndex, &channelName);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
|
|
||||||
return channelName;
|
return channelName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,93 +8,90 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
BlockingStream::BlockingStream()
|
BlockingStream::BlockingStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockingStream::BlockingStream(const StreamParameters ¶meters)
|
BlockingStream::BlockingStream(const StreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
open(parameters);
|
open(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockingStream::~BlockingStream()
|
BlockingStream::~BlockingStream()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
// ignore all errors
|
// ignore all errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void BlockingStream::open(const StreamParameters ¶meters)
|
void BlockingStream::open(const StreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
||||||
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), NULL, NULL);
|
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), NULL, NULL);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void BlockingStream::read(void *buffer, unsigned long numFrames)
|
void BlockingStream::read(void *buffer, unsigned long numFrames)
|
||||||
{
|
{
|
||||||
PaError err = Pa_ReadStream(stream_, buffer, numFrames);
|
PaError err = Pa_ReadStream(stream_, buffer, numFrames);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockingStream::write(const void *buffer, unsigned long numFrames)
|
void BlockingStream::write(const void *buffer, unsigned long numFrames)
|
||||||
{
|
{
|
||||||
PaError err = Pa_WriteStream(stream_, buffer, numFrames);
|
PaError err = Pa_WriteStream(stream_, buffer, numFrames);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
signed long BlockingStream::availableReadSize() const
|
signed long BlockingStream::availableReadSize() const
|
||||||
{
|
{
|
||||||
signed long avail = Pa_GetStreamReadAvailable(stream_);
|
signed long avail = Pa_GetStreamReadAvailable(stream_);
|
||||||
|
|
||||||
if (avail < 0)
|
if (avail < 0)
|
||||||
{
|
{
|
||||||
throw PaException(avail);
|
throw PaException(avail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return avail;
|
return avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
signed long BlockingStream::availableWriteSize() const
|
signed long BlockingStream::availableWriteSize() const
|
||||||
{
|
{
|
||||||
signed long avail = Pa_GetStreamWriteAvailable(stream_);
|
signed long avail = Pa_GetStreamWriteAvailable(stream_);
|
||||||
|
|
||||||
if (avail < 0)
|
if (avail < 0)
|
||||||
{
|
{
|
||||||
throw PaException(avail);
|
throw PaException(avail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return avail;
|
return avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // portaudio
|
} // portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,37 +5,37 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
CFunCallbackStream::CFunCallbackStream()
|
CFunCallbackStream::CFunCallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CFunCallbackStream::CFunCallbackStream(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData)
|
CFunCallbackStream::CFunCallbackStream(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData)
|
||||||
{
|
{
|
||||||
open(parameters, funPtr, userData);
|
open(parameters, funPtr, userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFunCallbackStream::~CFunCallbackStream()
|
CFunCallbackStream::~CFunCallbackStream()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
// ignore all errors
|
// ignore all errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------==
|
// ---------------------------------------------------------------------------------==
|
||||||
|
|
||||||
void CFunCallbackStream::open(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData)
|
void CFunCallbackStream::open(const StreamParameters ¶meters, PaStreamCallback *funPtr, void *userData)
|
||||||
{
|
{
|
||||||
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
||||||
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), funPtr, userData);
|
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), funPtr, userData);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,21 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Adapts any CallbackInterface object to a C-callable function (ie this function). A
|
/// Adapts any CallbackInterface object to a C-callable function (ie this function). A
|
||||||
/// pointer to the object should be passed as ``userData'' when setting up the callback.
|
/// pointer to the object should be passed as ``userData'' when setting up the callback.
|
||||||
//////
|
//////
|
||||||
int callbackInterfaceToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
int callbackInterfaceToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
|
||||||
{
|
{
|
||||||
CallbackInterface *cb = static_cast<CallbackInterface *>(userData);
|
CallbackInterface *cb = static_cast<CallbackInterface *>(userData);
|
||||||
return cb->paCallbackFun(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags);
|
return cb->paCallbackFun(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace impl
|
} // namespace impl
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
CallbackStream::CallbackStream()
|
CallbackStream::CallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackStream::~CallbackStream()
|
CallbackStream::~CallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
double CallbackStream::cpuLoad() const
|
double CallbackStream::cpuLoad() const
|
||||||
{
|
{
|
||||||
return Pa_GetStreamCpuLoad(stream_);
|
return Pa_GetStreamCpuLoad(stream_);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -5,77 +5,77 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
namespace impl
|
namespace impl
|
||||||
{
|
{
|
||||||
//////
|
//////
|
||||||
/// Adapts any a C++ callback to a C-callable function (ie this function). A
|
/// Adapts any a C++ callback to a C-callable function (ie this function). A
|
||||||
/// pointer to a struct with the C++ function pointer and the actual user data should be
|
/// pointer to a struct with the C++ function pointer and the actual user data should be
|
||||||
/// passed as the ``userData'' parameter when setting up the callback.
|
/// passed as the ``userData'' parameter when setting up the callback.
|
||||||
//////
|
//////
|
||||||
int cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
int cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames,
|
||||||
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
|
const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
|
||||||
{
|
{
|
||||||
FunCallbackStream::CppToCCallbackData *data = static_cast<FunCallbackStream::CppToCCallbackData *>(userData);
|
FunCallbackStream::CppToCCallbackData *data = static_cast<FunCallbackStream::CppToCCallbackData *>(userData);
|
||||||
return data->funPtr(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags, data->userData);
|
return data->funPtr(inputBuffer, outputBuffer, numFrames, timeInfo, statusFlags, data->userData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
FunCallbackStream::CppToCCallbackData::CppToCCallbackData()
|
FunCallbackStream::CppToCCallbackData::CppToCCallbackData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunCallbackStream::CppToCCallbackData::CppToCCallbackData(CallbackFunPtr funPtr, void *userData) : funPtr(funPtr), userData(userData)
|
FunCallbackStream::CppToCCallbackData::CppToCCallbackData(CallbackFunPtr funPtr, void *userData) : funPtr(funPtr), userData(userData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunCallbackStream::CppToCCallbackData::init(CallbackFunPtr funPtr, void *userData)
|
void FunCallbackStream::CppToCCallbackData::init(CallbackFunPtr funPtr, void *userData)
|
||||||
{
|
{
|
||||||
this->funPtr = funPtr;
|
this->funPtr = funPtr;
|
||||||
this->userData = userData;
|
this->userData = userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
FunCallbackStream::FunCallbackStream()
|
FunCallbackStream::FunCallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FunCallbackStream::FunCallbackStream(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData) : adapterData_(funPtr, userData)
|
FunCallbackStream::FunCallbackStream(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData) : adapterData_(funPtr, userData)
|
||||||
{
|
{
|
||||||
open(parameters);
|
open(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
FunCallbackStream::~FunCallbackStream()
|
FunCallbackStream::~FunCallbackStream()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
// ignore all errors
|
// ignore all errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunCallbackStream::open(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData)
|
void FunCallbackStream::open(const StreamParameters ¶meters, CallbackFunPtr funPtr, void *userData)
|
||||||
{
|
{
|
||||||
adapterData_.init(funPtr, userData);
|
adapterData_.init(funPtr, userData);
|
||||||
open(parameters);
|
open(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunCallbackStream::open(const StreamParameters ¶meters)
|
void FunCallbackStream::open(const StreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
||||||
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::cppCallbackToPaCallbackAdapter,
|
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::cppCallbackToPaCallbackAdapter,
|
||||||
static_cast<void *>(&adapterData_));
|
static_cast<void *>(&adapterData_));
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,160 +9,158 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
Device::Device(PaDeviceIndex index) : index_(index)
|
Device::Device(PaDeviceIndex index) : index_(index)
|
||||||
{
|
{
|
||||||
if (index == paNoDevice)
|
if (index == paNoDevice)
|
||||||
info_ = NULL;
|
info_ = NULL;
|
||||||
else
|
else
|
||||||
info_ = Pa_GetDeviceInfo(index);
|
info_ = Pa_GetDeviceInfo(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PaDeviceIndex Device::index() const
|
PaDeviceIndex Device::index() const
|
||||||
{
|
{
|
||||||
return index_;
|
return index_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Device::name() const
|
const char *Device::name() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return info_->name;
|
return info_->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::maxInputChannels() const
|
int Device::maxInputChannels() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return info_->maxInputChannels;
|
return info_->maxInputChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::maxOutputChannels() const
|
int Device::maxOutputChannels() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return info_->maxOutputChannels;
|
return info_->maxOutputChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaTime Device::defaultLowInputLatency() const
|
PaTime Device::defaultLowInputLatency() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return static_cast<PaTime>(0.0);
|
return static_cast<PaTime>(0.0);
|
||||||
|
|
||||||
return info_->defaultLowInputLatency;
|
return info_->defaultLowInputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaTime Device::defaultHighInputLatency() const
|
PaTime Device::defaultHighInputLatency() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return static_cast<PaTime>(0.0);
|
return static_cast<PaTime>(0.0);
|
||||||
|
|
||||||
return info_->defaultHighInputLatency;
|
return info_->defaultHighInputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaTime Device::defaultLowOutputLatency() const
|
PaTime Device::defaultLowOutputLatency() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return static_cast<PaTime>(0.0);
|
return static_cast<PaTime>(0.0);
|
||||||
|
|
||||||
return info_->defaultLowOutputLatency;
|
return info_->defaultLowOutputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaTime Device::defaultHighOutputLatency() const
|
PaTime Device::defaultHighOutputLatency() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return static_cast<PaTime>(0.0);
|
return static_cast<PaTime>(0.0);
|
||||||
|
|
||||||
return info_->defaultHighOutputLatency;
|
return info_->defaultHighOutputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Device::defaultSampleRate() const
|
double Device::defaultSampleRate() const
|
||||||
{
|
{
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
return info_->defaultSampleRate;
|
return info_->defaultSampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool Device::isInputOnlyDevice() const
|
bool Device::isInputOnlyDevice() const
|
||||||
{
|
{
|
||||||
return (maxOutputChannels() == 0);
|
return (maxOutputChannels() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isOutputOnlyDevice() const
|
bool Device::isOutputOnlyDevice() const
|
||||||
{
|
{
|
||||||
return (maxInputChannels() == 0);
|
return (maxInputChannels() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isFullDuplexDevice() const
|
bool Device::isFullDuplexDevice() const
|
||||||
{
|
{
|
||||||
return (maxInputChannels() > 0 && maxOutputChannels() > 0);
|
return (maxInputChannels() > 0 && maxOutputChannels() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isSystemDefaultInputDevice() const
|
bool Device::isSystemDefaultInputDevice() const
|
||||||
{
|
{
|
||||||
return (System::instance().defaultInputDevice() == *this);
|
return (System::instance().defaultInputDevice() == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isSystemDefaultOutputDevice() const
|
bool Device::isSystemDefaultOutputDevice() const
|
||||||
{
|
{
|
||||||
return (System::instance().defaultOutputDevice() == *this);
|
return (System::instance().defaultOutputDevice() == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isHostApiDefaultInputDevice() const
|
bool Device::isHostApiDefaultInputDevice() const
|
||||||
{
|
{
|
||||||
return (hostApi().defaultInputDevice() == *this);
|
return (hostApi().defaultInputDevice() == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isHostApiDefaultOutputDevice() const
|
bool Device::isHostApiDefaultOutputDevice() const
|
||||||
{
|
{
|
||||||
return (hostApi().defaultOutputDevice() == *this);
|
return (hostApi().defaultOutputDevice() == *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool Device::operator==(const Device &rhs) const
|
bool Device::operator==(const Device &rhs) const
|
||||||
{
|
{
|
||||||
return (index_ == rhs.index_);
|
return (index_ == rhs.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::operator!=(const Device &rhs) const
|
bool Device::operator!=(const Device &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
HostApi &Device::hostApi()
|
HostApi &Device::hostApi()
|
||||||
{
|
{
|
||||||
// NOTE: will cause an exception when called for the null device
|
// NOTE: will cause an exception when called for the null device
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
throw PaException(paInternalError);
|
throw PaException(paInternalError);
|
||||||
|
|
||||||
return System::instance().hostApiByIndex(info_->hostApi);
|
return System::instance().hostApiByIndex(info_->hostApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
const HostApi &Device::hostApi() const
|
const HostApi &Device::hostApi() const
|
||||||
{
|
{
|
||||||
// NOTE; will cause an exception when called for the null device
|
// NOTE; will cause an exception when called for the null device
|
||||||
if (info_ == NULL)
|
if (info_ == NULL)
|
||||||
throw PaException(paInternalError);
|
throw PaException(paInternalError);
|
||||||
|
|
||||||
return System::instance().hostApiByIndex(info_->hostApi);
|
return System::instance().hostApiByIndex(info_->hostApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,159 +5,159 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns a `nil' DirectionSpecificStreamParameters object. This can be used to
|
/// Returns a `nil' DirectionSpecificStreamParameters object. This can be used to
|
||||||
/// specify that one direction of a Stream is not required (i.e. when creating
|
/// specify that one direction of a Stream is not required (i.e. when creating
|
||||||
/// a half-duplex Stream). All fields of the null DirectionSpecificStreamParameters
|
/// a half-duplex Stream). All fields of the null DirectionSpecificStreamParameters
|
||||||
/// object are invalid except for the device and the number of channel, which are set
|
/// object are invalid except for the device and the number of channel, which are set
|
||||||
/// to paNoDevice and 0 respectively.
|
/// to paNoDevice and 0 respectively.
|
||||||
//////
|
//////
|
||||||
DirectionSpecificStreamParameters DirectionSpecificStreamParameters::null()
|
DirectionSpecificStreamParameters DirectionSpecificStreamParameters::null()
|
||||||
{
|
{
|
||||||
DirectionSpecificStreamParameters tmp;
|
DirectionSpecificStreamParameters tmp;
|
||||||
tmp.paStreamParameters_.device = paNoDevice;
|
tmp.paStreamParameters_.device = paNoDevice;
|
||||||
tmp.paStreamParameters_.channelCount = 0;
|
tmp.paStreamParameters_.channelCount = 0;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Default constructor -- all parameters will be uninitialized.
|
/// Default constructor -- all parameters will be uninitialized.
|
||||||
//////
|
//////
|
||||||
DirectionSpecificStreamParameters::DirectionSpecificStreamParameters()
|
DirectionSpecificStreamParameters::DirectionSpecificStreamParameters()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Constructor which sets all required fields.
|
/// Constructor which sets all required fields.
|
||||||
//////
|
//////
|
||||||
DirectionSpecificStreamParameters::DirectionSpecificStreamParameters(const Device &device, int numChannels,
|
DirectionSpecificStreamParameters::DirectionSpecificStreamParameters(const Device &device, int numChannels,
|
||||||
SampleDataFormat format, bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo)
|
SampleDataFormat format, bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo)
|
||||||
{
|
{
|
||||||
setDevice(device);
|
setDevice(device);
|
||||||
setNumChannels(numChannels);
|
setNumChannels(numChannels);
|
||||||
setSampleFormat(format, interleaved);
|
setSampleFormat(format, interleaved);
|
||||||
setSuggestedLatency(suggestedLatency);
|
setSuggestedLatency(suggestedLatency);
|
||||||
setHostApiSpecificStreamInfo(hostApiSpecificStreamInfo);
|
setHostApiSpecificStreamInfo(hostApiSpecificStreamInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setDevice(const Device &device)
|
void DirectionSpecificStreamParameters::setDevice(const Device &device)
|
||||||
{
|
{
|
||||||
paStreamParameters_.device = device.index();
|
paStreamParameters_.device = device.index();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setNumChannels(int numChannels)
|
void DirectionSpecificStreamParameters::setNumChannels(int numChannels)
|
||||||
{
|
{
|
||||||
paStreamParameters_.channelCount = numChannels;
|
paStreamParameters_.channelCount = numChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setSampleFormat(SampleDataFormat format, bool interleaved)
|
void DirectionSpecificStreamParameters::setSampleFormat(SampleDataFormat format, bool interleaved)
|
||||||
{
|
{
|
||||||
paStreamParameters_.sampleFormat = static_cast<PaSampleFormat>(format);
|
paStreamParameters_.sampleFormat = static_cast<PaSampleFormat>(format);
|
||||||
|
|
||||||
if (!interleaved)
|
if (!interleaved)
|
||||||
paStreamParameters_.sampleFormat |= paNonInterleaved;
|
paStreamParameters_.sampleFormat |= paNonInterleaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved)
|
void DirectionSpecificStreamParameters::setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved)
|
||||||
{
|
{
|
||||||
paStreamParameters_.sampleFormat = format;
|
paStreamParameters_.sampleFormat = format;
|
||||||
|
|
||||||
paStreamParameters_.sampleFormat |= paCustomFormat;
|
paStreamParameters_.sampleFormat |= paCustomFormat;
|
||||||
|
|
||||||
if (!interleaved)
|
if (!interleaved)
|
||||||
paStreamParameters_.sampleFormat |= paNonInterleaved;
|
paStreamParameters_.sampleFormat |= paNonInterleaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setSuggestedLatency(PaTime latency)
|
void DirectionSpecificStreamParameters::setSuggestedLatency(PaTime latency)
|
||||||
{
|
{
|
||||||
paStreamParameters_.suggestedLatency = latency;
|
paStreamParameters_.suggestedLatency = latency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectionSpecificStreamParameters::setHostApiSpecificStreamInfo(void *streamInfo)
|
void DirectionSpecificStreamParameters::setHostApiSpecificStreamInfo(void *streamInfo)
|
||||||
{
|
{
|
||||||
paStreamParameters_.hostApiSpecificStreamInfo = streamInfo;
|
paStreamParameters_.hostApiSpecificStreamInfo = streamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters()
|
PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters()
|
||||||
{
|
{
|
||||||
if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
|
if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
|
||||||
return &paStreamParameters_;
|
return &paStreamParameters_;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters() const
|
const PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters() const
|
||||||
{
|
{
|
||||||
if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
|
if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
|
||||||
return &paStreamParameters_;
|
return &paStreamParameters_;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device &DirectionSpecificStreamParameters::device() const
|
Device &DirectionSpecificStreamParameters::device() const
|
||||||
{
|
{
|
||||||
return System::instance().deviceByIndex(paStreamParameters_.device);
|
return System::instance().deviceByIndex(paStreamParameters_.device);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DirectionSpecificStreamParameters::numChannels() const
|
int DirectionSpecificStreamParameters::numChannels() const
|
||||||
{
|
{
|
||||||
return paStreamParameters_.channelCount;
|
return paStreamParameters_.channelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the (non host api-specific) sample format, without including
|
/// Returns the (non host api-specific) sample format, without including
|
||||||
/// the paNonInterleaved flag. If the sample format is host api-spefific,
|
/// the paNonInterleaved flag. If the sample format is host api-spefific,
|
||||||
/// INVALID_FORMAT (0) will be returned.
|
/// INVALID_FORMAT (0) will be returned.
|
||||||
//////
|
//////
|
||||||
SampleDataFormat DirectionSpecificStreamParameters::sampleFormat() const
|
SampleDataFormat DirectionSpecificStreamParameters::sampleFormat() const
|
||||||
{
|
{
|
||||||
if (isSampleFormatHostApiSpecific())
|
if (isSampleFormatHostApiSpecific())
|
||||||
return INVALID_FORMAT;
|
return INVALID_FORMAT;
|
||||||
else
|
else
|
||||||
return static_cast<SampleDataFormat>(paStreamParameters_.sampleFormat & ~paNonInterleaved);
|
return static_cast<SampleDataFormat>(paStreamParameters_.sampleFormat & ~paNonInterleaved);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectionSpecificStreamParameters::isSampleFormatInterleaved() const
|
bool DirectionSpecificStreamParameters::isSampleFormatInterleaved() const
|
||||||
{
|
{
|
||||||
return ((paStreamParameters_.sampleFormat & paNonInterleaved) == 0);
|
return ((paStreamParameters_.sampleFormat & paNonInterleaved) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectionSpecificStreamParameters::isSampleFormatHostApiSpecific() const
|
bool DirectionSpecificStreamParameters::isSampleFormatHostApiSpecific() const
|
||||||
{
|
{
|
||||||
return ((paStreamParameters_.sampleFormat & paCustomFormat) == 0);
|
return ((paStreamParameters_.sampleFormat & paCustomFormat) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the host api-specific sample format, without including any
|
/// Returns the host api-specific sample format, without including any
|
||||||
/// paCustomFormat or paNonInterleaved flags. Will return 0 if the sample format is
|
/// paCustomFormat or paNonInterleaved flags. Will return 0 if the sample format is
|
||||||
/// not host api-specific.
|
/// not host api-specific.
|
||||||
//////
|
//////
|
||||||
PaSampleFormat DirectionSpecificStreamParameters::hostApiSpecificSampleFormat() const
|
PaSampleFormat DirectionSpecificStreamParameters::hostApiSpecificSampleFormat() const
|
||||||
{
|
{
|
||||||
if (isSampleFormatHostApiSpecific())
|
if (isSampleFormatHostApiSpecific())
|
||||||
return paStreamParameters_.sampleFormat & ~paCustomFormat & ~paNonInterleaved;
|
return paStreamParameters_.sampleFormat & ~paCustomFormat & ~paNonInterleaved;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaTime DirectionSpecificStreamParameters::suggestedLatency() const
|
PaTime DirectionSpecificStreamParameters::suggestedLatency() const
|
||||||
{
|
{
|
||||||
return paStreamParameters_.suggestedLatency;
|
return paStreamParameters_.suggestedLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *DirectionSpecificStreamParameters::hostApiSpecificStreamInfo() const
|
void *DirectionSpecificStreamParameters::hostApiSpecificStreamInfo() const
|
||||||
{
|
{
|
||||||
return paStreamParameters_.hostApiSpecificStreamInfo;
|
return paStreamParameters_.hostApiSpecificStreamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -2,122 +2,120 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// PaException:
|
// PaException:
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Wraps a PortAudio error into a PortAudioCpp PaException.
|
/// Wraps a PortAudio error into a PortAudioCpp PaException.
|
||||||
//////
|
//////
|
||||||
PaException::PaException(PaError error) : error_(error)
|
PaException::PaException(PaError error) : error_(error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Alias for paErrorText(), to have std::exception compliance.
|
/// Alias for paErrorText(), to have std::exception compliance.
|
||||||
//////
|
//////
|
||||||
const char *PaException::what() const throw()
|
const char *PaException::what() const throw()
|
||||||
{
|
{
|
||||||
return paErrorText();
|
return paErrorText();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the PortAudio error code (PaError).
|
/// Returns the PortAudio error code (PaError).
|
||||||
//////
|
//////
|
||||||
PaError PaException::paError() const
|
PaError PaException::paError() const
|
||||||
{
|
{
|
||||||
return error_;
|
return error_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the error as a (zero-terminated) text string.
|
/// Returns the error as a (zero-terminated) text string.
|
||||||
//////
|
//////
|
||||||
const char *PaException::paErrorText() const
|
const char *PaException::paErrorText() const
|
||||||
{
|
{
|
||||||
return Pa_GetErrorText(error_);
|
return Pa_GetErrorText(error_);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns true is the error is a HostApi error.
|
/// Returns true is the error is a HostApi error.
|
||||||
//////
|
//////
|
||||||
bool PaException::isHostApiError() const
|
bool PaException::isHostApiError() const
|
||||||
{
|
{
|
||||||
return (error_ == paUnanticipatedHostError);
|
return (error_ == paUnanticipatedHostError);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the last HostApi error (which is the current one if
|
/// Returns the last HostApi error (which is the current one if
|
||||||
/// isHostApiError() returns true) as an error code.
|
/// isHostApiError() returns true) as an error code.
|
||||||
//////
|
//////
|
||||||
long PaException::lastHostApiError() const
|
long PaException::lastHostApiError() const
|
||||||
{
|
{
|
||||||
return Pa_GetLastHostErrorInfo()->errorCode;
|
return Pa_GetLastHostErrorInfo()->errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the last HostApi error (which is the current one if
|
/// Returns the last HostApi error (which is the current one if
|
||||||
/// isHostApiError() returns true) as a (zero-terminated) text
|
/// isHostApiError() returns true) as a (zero-terminated) text
|
||||||
/// string, if it's available.
|
/// string, if it's available.
|
||||||
//////
|
//////
|
||||||
const char *PaException::lastHostApiErrorText() const
|
const char *PaException::lastHostApiErrorText() const
|
||||||
{
|
{
|
||||||
return Pa_GetLastHostErrorInfo()->errorText;
|
return Pa_GetLastHostErrorInfo()->errorText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool PaException::operator==(const PaException &rhs) const
|
bool PaException::operator==(const PaException &rhs) const
|
||||||
{
|
{
|
||||||
return (error_ == rhs.error_);
|
return (error_ == rhs.error_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaException::operator!=(const PaException &rhs) const
|
bool PaException::operator!=(const PaException &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// PaCppException:
|
// PaCppException:
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *PaCppException::what() const throw()
|
PaCppException::PaCppException(ExceptionSpecifier specifier) : specifier_(specifier)
|
||||||
{
|
{
|
||||||
switch (specifier_)
|
}
|
||||||
{
|
|
||||||
case UNABLE_TO_ADAPT_DEVICE:
|
|
||||||
{
|
|
||||||
return "Unable to adapt the given device to the specified host api specific device extension";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Unknown exception";
|
const char *PaCppException::what() const throw()
|
||||||
}
|
{
|
||||||
|
switch (specifier_)
|
||||||
|
{
|
||||||
|
case UNABLE_TO_ADAPT_DEVICE:
|
||||||
|
{
|
||||||
|
return "Unable to adapt the given device to the specified host api specific device extension";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PaCppException::ExceptionSpecifier PaCppException::specifier() const
|
return "Unknown exception";
|
||||||
{
|
}
|
||||||
return specifier_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PaCppException::operator==(const PaCppException &rhs) const
|
PaCppException::ExceptionSpecifier PaCppException::specifier() const
|
||||||
{
|
{
|
||||||
return (specifier_ == rhs.specifier_);
|
return specifier_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaCppException::operator!=(const PaCppException &rhs) const
|
bool PaCppException::operator==(const PaCppException &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return (specifier_ == rhs.specifier_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
bool PaCppException::operator!=(const PaCppException &rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,114 +8,114 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
HostApi::HostApi(PaHostApiIndex index) : devices_(NULL)
|
HostApi::HostApi(PaHostApiIndex index) : devices_(NULL)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
info_ = Pa_GetHostApiInfo(index);
|
info_ = Pa_GetHostApiInfo(index);
|
||||||
|
|
||||||
// Create and populate devices array:
|
// Create and populate devices array:
|
||||||
int numDevices = deviceCount();
|
int numDevices = deviceCount();
|
||||||
|
|
||||||
devices_ = new Device*[numDevices];
|
devices_ = new Device*[numDevices];
|
||||||
|
|
||||||
for (int i = 0; i < numDevices; ++i)
|
for (int i = 0; i < numDevices; ++i)
|
||||||
{
|
{
|
||||||
PaDeviceIndex deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(index, i);
|
PaDeviceIndex deviceIndex = Pa_HostApiDeviceIndexToDeviceIndex(index, i);
|
||||||
|
|
||||||
if (deviceIndex < 0)
|
if (deviceIndex < 0)
|
||||||
{
|
{
|
||||||
throw PaException(deviceIndex);
|
throw PaException(deviceIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
devices_[i] = &System::instance().deviceByIndex(deviceIndex);
|
devices_[i] = &System::instance().deviceByIndex(deviceIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
// Delete any (partially) constructed objects (deconstructor isn't called):
|
// Delete any (partially) constructed objects (deconstructor isn't called):
|
||||||
delete[] devices_; // devices_ is either NULL or valid
|
delete[] devices_; // devices_ is either NULL or valid
|
||||||
|
|
||||||
// Re-throw exception:
|
// Re-throw exception:
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HostApi::~HostApi()
|
HostApi::~HostApi()
|
||||||
{
|
{
|
||||||
// Destroy devices array:
|
// Destroy devices array:
|
||||||
delete[] devices_;
|
delete[] devices_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
PaHostApiTypeId HostApi::typeId() const
|
PaHostApiTypeId HostApi::typeId() const
|
||||||
{
|
{
|
||||||
return info_->type;
|
return info_->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaHostApiIndex HostApi::index() const
|
PaHostApiIndex HostApi::index() const
|
||||||
{
|
{
|
||||||
PaHostApiIndex index = Pa_HostApiTypeIdToHostApiIndex(typeId());
|
PaHostApiIndex index = Pa_HostApiTypeIdToHostApiIndex(typeId());
|
||||||
|
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
throw PaException(index);
|
throw PaException(index);
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *HostApi::name() const
|
const char *HostApi::name() const
|
||||||
{
|
{
|
||||||
return info_->name;
|
return info_->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HostApi::deviceCount() const
|
int HostApi::deviceCount() const
|
||||||
{
|
{
|
||||||
return info_->deviceCount;
|
return info_->deviceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
HostApi::DeviceIterator HostApi::devicesBegin()
|
HostApi::DeviceIterator HostApi::devicesBegin()
|
||||||
{
|
{
|
||||||
DeviceIterator tmp;
|
DeviceIterator tmp;
|
||||||
tmp.ptr_ = &devices_[0]; // begin (first element)
|
tmp.ptr_ = &devices_[0]; // begin (first element)
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostApi::DeviceIterator HostApi::devicesEnd()
|
HostApi::DeviceIterator HostApi::devicesEnd()
|
||||||
{
|
{
|
||||||
DeviceIterator tmp;
|
DeviceIterator tmp;
|
||||||
tmp.ptr_ = &devices_[deviceCount()]; // end (one past last element)
|
tmp.ptr_ = &devices_[deviceCount()]; // end (one past last element)
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
Device &HostApi::defaultInputDevice() const
|
Device &HostApi::defaultInputDevice() const
|
||||||
{
|
{
|
||||||
return System::instance().deviceByIndex(info_->defaultInputDevice);
|
return System::instance().deviceByIndex(info_->defaultInputDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device &HostApi::defaultOutputDevice() const
|
Device &HostApi::defaultOutputDevice() const
|
||||||
{
|
{
|
||||||
return System::instance().deviceByIndex(info_->defaultOutputDevice);
|
return System::instance().deviceByIndex(info_->defaultOutputDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool HostApi::operator==(const HostApi &rhs) const
|
bool HostApi::operator==(const HostApi &rhs) const
|
||||||
{
|
{
|
||||||
return (typeId() == rhs.typeId());
|
return (typeId() == rhs.typeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HostApi::operator!=(const HostApi &rhs) const
|
bool HostApi::operator!=(const HostApi &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -7,39 +7,39 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------==
|
// ---------------------------------------------------------------------------------==
|
||||||
|
|
||||||
InterfaceCallbackStream::InterfaceCallbackStream()
|
InterfaceCallbackStream::InterfaceCallbackStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
InterfaceCallbackStream::InterfaceCallbackStream(const StreamParameters ¶meters, CallbackInterface &instance)
|
InterfaceCallbackStream::InterfaceCallbackStream(const StreamParameters ¶meters, CallbackInterface &instance)
|
||||||
{
|
{
|
||||||
open(parameters, instance);
|
open(parameters, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
InterfaceCallbackStream::~InterfaceCallbackStream()
|
InterfaceCallbackStream::~InterfaceCallbackStream()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
// ignore all errors
|
// ignore all errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------==
|
// ---------------------------------------------------------------------------------==
|
||||||
|
|
||||||
void InterfaceCallbackStream::open(const StreamParameters ¶meters, CallbackInterface &instance)
|
void InterfaceCallbackStream::open(const StreamParameters ¶meters, CallbackInterface &instance)
|
||||||
{
|
{
|
||||||
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
PaError err = Pa_OpenStream(&stream_, parameters.inputParameters().paStreamParameters(), parameters.outputParameters().paStreamParameters(),
|
||||||
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::callbackInterfaceToPaCallbackAdapter, static_cast<void *>(&instance));
|
parameters.sampleRate(), parameters.framesPerBuffer(), parameters.flags(), &impl::callbackInterfaceToPaCallbackAdapter, static_cast<void *>(&instance));
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
{
|
{
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#include "portaudiocpp/MemFunCallbackStream.hxx"
|
#include "portaudiocpp/MemFunCallbackStream.hxx"
|
||||||
|
|
||||||
// (... template class ...)
|
// (... template class ...)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,188 +8,188 @@
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
Stream::Stream() : stream_(NULL)
|
Stream::Stream() : stream_(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream::~Stream()
|
Stream::~Stream()
|
||||||
{
|
{
|
||||||
// (can't call close here,
|
// (can't call close here,
|
||||||
// the derived class should atleast call
|
// the derived class should atleast call
|
||||||
// close() in it's deconstructor)
|
// close() in it's deconstructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Closes the Stream if it's open, else does nothing.
|
/// Closes the Stream if it's open, else does nothing.
|
||||||
//////
|
//////
|
||||||
void Stream::close()
|
void Stream::close()
|
||||||
{
|
{
|
||||||
if (isOpen() && System::exists())
|
if (isOpen() && System::exists())
|
||||||
{
|
{
|
||||||
PaError err = Pa_CloseStream(stream_);
|
PaError err = Pa_CloseStream(stream_);
|
||||||
stream_ = NULL;
|
stream_ = NULL;
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns true if the Stream is open.
|
/// Returns true if the Stream is open.
|
||||||
//////
|
//////
|
||||||
bool Stream::isOpen() const
|
bool Stream::isOpen() const
|
||||||
{
|
{
|
||||||
return (stream_ != NULL);
|
return (stream_ != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
void Stream::setStreamFinishedCallback(PaStreamFinishedCallback *callback)
|
void Stream::setStreamFinishedCallback(PaStreamFinishedCallback *callback)
|
||||||
{
|
{
|
||||||
PaError err = Pa_SetStreamFinishedCallback(stream_, callback);
|
PaError err = Pa_SetStreamFinishedCallback(stream_, callback);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
void Stream::start()
|
void Stream::start()
|
||||||
{
|
{
|
||||||
PaError err = Pa_StartStream(stream_);
|
PaError err = Pa_StartStream(stream_);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::stop()
|
void Stream::stop()
|
||||||
{
|
{
|
||||||
PaError err = Pa_StopStream(stream_);
|
PaError err = Pa_StopStream(stream_);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::abort()
|
void Stream::abort()
|
||||||
{
|
{
|
||||||
PaError err = Pa_AbortStream(stream_);
|
PaError err = Pa_AbortStream(stream_);
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError)
|
||||||
throw PaException(err);
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::isStopped() const
|
bool Stream::isStopped() const
|
||||||
{
|
{
|
||||||
PaError ret = Pa_IsStreamStopped(stream_);
|
PaError ret = Pa_IsStreamStopped(stream_);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
throw PaException(ret);
|
throw PaException(ret);
|
||||||
|
|
||||||
return (ret == 1);
|
return (ret == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stream::isActive() const
|
bool Stream::isActive() const
|
||||||
{
|
{
|
||||||
PaError ret = Pa_IsStreamActive(stream_);
|
PaError ret = Pa_IsStreamActive(stream_);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
throw PaException(ret);
|
throw PaException(ret);
|
||||||
|
|
||||||
return (ret == 1);
|
return (ret == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the best known input latency for the Stream. This value may differ from the
|
/// Returns the best known input latency for the Stream. This value may differ from the
|
||||||
/// suggested input latency set in the StreamParameters. Includes all sources of
|
/// suggested input latency set in the StreamParameters. Includes all sources of
|
||||||
/// latency known to PortAudio such as internal buffering, and Host API reported latency.
|
/// latency known to PortAudio such as internal buffering, and Host API reported latency.
|
||||||
/// Doesn't include any estimates of unknown latency.
|
/// Doesn't include any estimates of unknown latency.
|
||||||
//////
|
//////
|
||||||
PaTime Stream::inputLatency() const
|
PaTime Stream::inputLatency() const
|
||||||
{
|
{
|
||||||
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
{
|
{
|
||||||
throw PaException(paInternalError);
|
throw PaException(paInternalError);
|
||||||
return PaTime(0.0);
|
return PaTime(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return info->inputLatency;
|
return info->inputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the best known output latency for the Stream. This value may differ from the
|
/// Returns the best known output latency for the Stream. This value may differ from the
|
||||||
/// suggested output latency set in the StreamParameters. Includes all sources of
|
/// suggested output latency set in the StreamParameters. Includes all sources of
|
||||||
/// latency known to PortAudio such as internal buffering, and Host API reported latency.
|
/// latency known to PortAudio such as internal buffering, and Host API reported latency.
|
||||||
/// Doesn't include any estimates of unknown latency.
|
/// Doesn't include any estimates of unknown latency.
|
||||||
//////
|
//////
|
||||||
PaTime Stream::outputLatency() const
|
PaTime Stream::outputLatency() const
|
||||||
{
|
{
|
||||||
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
{
|
{
|
||||||
throw PaException(paInternalError);
|
throw PaException(paInternalError);
|
||||||
return PaTime(0.0);
|
return PaTime(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return info->outputLatency;
|
return info->outputLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns the sample rate of the Stream. Usually this will be the
|
/// Returns the sample rate of the Stream. Usually this will be the
|
||||||
/// best known estimate of the used sample rate. For instance when opening a
|
/// best known estimate of the used sample rate. For instance when opening a
|
||||||
/// Stream setting 44100.0 Hz in the StreamParameters, the actual sample
|
/// Stream setting 44100.0 Hz in the StreamParameters, the actual sample
|
||||||
/// rate might be something like 44103.2 Hz (due to imperfections in the
|
/// rate might be something like 44103.2 Hz (due to imperfections in the
|
||||||
/// sound card hardware).
|
/// sound card hardware).
|
||||||
//////
|
//////
|
||||||
double Stream::sampleRate() const
|
double Stream::sampleRate() const
|
||||||
{
|
{
|
||||||
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
const PaStreamInfo *info = Pa_GetStreamInfo(stream_);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
{
|
{
|
||||||
throw PaException(paInternalError);
|
throw PaException(paInternalError);
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return info->sampleRate;
|
return info->sampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
PaTime Stream::time() const
|
PaTime Stream::time() const
|
||||||
{
|
{
|
||||||
return Pa_GetStreamTime(stream_);
|
return Pa_GetStreamTime(stream_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Accessor (const) for PortAudio PaStream pointer, useful for interfacing with
|
/// Accessor (const) for PortAudio PaStream pointer, useful for interfacing with
|
||||||
/// PortAudio add-ons such as PortMixer for instance. Normally accessing this
|
/// PortAudio add-ons such as PortMixer for instance. Normally accessing this
|
||||||
/// pointer should not be needed as PortAudioCpp aims to provide all of PortAudio's
|
/// pointer should not be needed as PortAudioCpp aims to provide all of PortAudio's
|
||||||
/// functionality.
|
/// functionality.
|
||||||
//////
|
//////
|
||||||
const PaStream *Stream::paStream() const
|
const PaStream *Stream::paStream() const
|
||||||
{
|
{
|
||||||
return stream_;
|
return stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Accessor (non-const) for PortAudio PaStream pointer, useful for interfacing with
|
/// Accessor (non-const) for PortAudio PaStream pointer, useful for interfacing with
|
||||||
/// PortAudio add-ons such as PortMixer for instance. Normally accessing this
|
/// PortAudio add-ons such as PortMixer for instance. Normally accessing this
|
||||||
/// pointer should not be needed as PortAudioCpp aims to provide all of PortAudio's
|
/// pointer should not be needed as PortAudioCpp aims to provide all of PortAudio's
|
||||||
/// functionality.
|
/// functionality.
|
||||||
//////
|
//////
|
||||||
PaStream *Stream::paStream()
|
PaStream *Stream::paStream()
|
||||||
{
|
{
|
||||||
return stream_;
|
return stream_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
|
||||||
|
|
@ -6,160 +6,155 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Default constructor; does nothing.
|
/// Default constructor; does nothing.
|
||||||
//////
|
//////
|
||||||
StreamParameters::StreamParameters()
|
StreamParameters::StreamParameters()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Sets up the all parameters needed to open either a half-duplex or full-duplex Stream.
|
/// Sets up the all parameters needed to open either a half-duplex or full-duplex Stream.
|
||||||
///
|
///
|
||||||
/// @param inputParameters The parameters for the input direction of the to-be opened
|
/// @param inputParameters The parameters for the input direction of the to-be opened
|
||||||
/// Stream or DirectionSpecificStreamParameters::null() for an output-only Stream.
|
/// Stream or DirectionSpecificStreamParameters::null() for an output-only Stream.
|
||||||
/// @param outputParameters The parameters for the output direction of the to-be opened
|
/// @param outputParameters The parameters for the output direction of the to-be opened
|
||||||
/// Stream or DirectionSpecificStreamParameters::null() for an input-only Stream.
|
/// Stream or DirectionSpecificStreamParameters::null() for an input-only Stream.
|
||||||
/// @param sampleRate The to-be opened Stream's sample rate in Hz.
|
/// @param sampleRate The to-be opened Stream's sample rate in Hz.
|
||||||
/// @param framesPerBuffer The number of frames per buffer for a CallbackStream, or
|
/// @param framesPerBuffer The number of frames per buffer for a CallbackStream, or
|
||||||
/// the preferred buffer granularity for a BlockingStream.
|
/// the preferred buffer granularity for a BlockingStream.
|
||||||
/// @param flags The flags for the to-be opened Stream; default paNoFlag.
|
/// @param flags The flags for the to-be opened Stream; default paNoFlag.
|
||||||
//////
|
//////
|
||||||
StreamParameters::StreamParameters(const DirectionSpecificStreamParameters &inputParameters,
|
StreamParameters::StreamParameters(const DirectionSpecificStreamParameters &inputParameters,
|
||||||
const DirectionSpecificStreamParameters &outputParameters, double sampleRate, unsigned long framesPerBuffer,
|
const DirectionSpecificStreamParameters &outputParameters, double sampleRate, unsigned long framesPerBuffer,
|
||||||
PaStreamFlags flags) : inputParameters_(inputParameters), outputParameters_(outputParameters),
|
PaStreamFlags flags) : inputParameters_(inputParameters), outputParameters_(outputParameters),
|
||||||
sampleRate_(sampleRate), framesPerBuffer_(framesPerBuffer), flags_(flags)
|
sampleRate_(sampleRate), framesPerBuffer_(framesPerBuffer), flags_(flags)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Sets the requested sample rate. If this sample rate isn't supported by the hardware, the
|
/// Sets the requested sample rate. If this sample rate isn't supported by the hardware, the
|
||||||
/// Stream will fail to open. The real-life sample rate used might differ slightly due to
|
/// Stream will fail to open. The real-life sample rate used might differ slightly due to
|
||||||
/// imperfections in the sound card hardware; use Stream::sampleRate() to retrieve the
|
/// imperfections in the sound card hardware; use Stream::sampleRate() to retrieve the
|
||||||
/// best known estimate for this value.
|
/// best known estimate for this value.
|
||||||
//////
|
//////
|
||||||
void StreamParameters::setSampleRate(double sampleRate)
|
void StreamParameters::setSampleRate(double sampleRate)
|
||||||
{
|
{
|
||||||
sampleRate_ = sampleRate;
|
sampleRate_ = sampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Either the number of frames per buffer for a CallbackStream, or
|
/// Either the number of frames per buffer for a CallbackStream, or
|
||||||
/// the preferred buffer granularity for a BlockingStream. See PortAudio
|
/// the preferred buffer granularity for a BlockingStream. See PortAudio
|
||||||
/// documentation.
|
/// documentation.
|
||||||
//////
|
//////
|
||||||
void StreamParameters::setFramesPerBuffer(unsigned long framesPerBuffer)
|
void StreamParameters::setFramesPerBuffer(unsigned long framesPerBuffer)
|
||||||
{
|
{
|
||||||
framesPerBuffer_ = framesPerBuffer;
|
framesPerBuffer_ = framesPerBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Sets the specified flag or does nothing when the flag is already set. Doesn't
|
/// Sets the specified flag or does nothing when the flag is already set. Doesn't
|
||||||
/// `unset' any previously existing flags (use clearFlags() for that).
|
/// `unset' any previously existing flags (use clearFlags() for that).
|
||||||
//////
|
//////
|
||||||
void StreamParameters::setFlag(PaStreamFlags flag)
|
void StreamParameters::setFlag(PaStreamFlags flag)
|
||||||
{
|
{
|
||||||
flags_ |= flag;
|
flags_ |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Unsets the specified flag or does nothing if the flag isn't set. Doesn't affect
|
/// Unsets the specified flag or does nothing if the flag isn't set. Doesn't affect
|
||||||
/// any other flags.
|
/// any other flags.
|
||||||
//////
|
//////
|
||||||
void StreamParameters::unsetFlag(PaStreamFlags flag)
|
void StreamParameters::unsetFlag(PaStreamFlags flag)
|
||||||
{
|
{
|
||||||
flags_ &= ~flag;
|
flags_ &= ~flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Clears or `unsets' all set flags.
|
/// Clears or `unsets' all set flags.
|
||||||
//////
|
//////
|
||||||
void StreamParameters::clearFlags()
|
void StreamParameters::clearFlags()
|
||||||
{
|
{
|
||||||
flags_ = paNoFlag;
|
flags_ = paNoFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
void StreamParameters::setInputParameters(const DirectionSpecificStreamParameters ¶meters)
|
void StreamParameters::setInputParameters(const DirectionSpecificStreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
inputParameters_ = parameters;
|
inputParameters_ = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamParameters::setOutputParameters(const DirectionSpecificStreamParameters ¶meters)
|
void StreamParameters::setOutputParameters(const DirectionSpecificStreamParameters ¶meters)
|
||||||
{
|
{
|
||||||
outputParameters_ = parameters;
|
outputParameters_ = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool StreamParameters::isSupported() const
|
bool StreamParameters::isSupported() const
|
||||||
{
|
{
|
||||||
return (Pa_IsFormatSupported(inputParameters_.paStreamParameters(),
|
return (Pa_IsFormatSupported(inputParameters_.paStreamParameters(),
|
||||||
outputParameters_.paStreamParameters(), sampleRate_) == paFormatIsSupported);
|
outputParameters_.paStreamParameters(), sampleRate_) == paFormatIsSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
double StreamParameters::sampleRate() const
|
double StreamParameters::sampleRate() const
|
||||||
{
|
{
|
||||||
return sampleRate_;
|
return sampleRate_;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long StreamParameters::framesPerBuffer() const
|
unsigned long StreamParameters::framesPerBuffer() const
|
||||||
{
|
{
|
||||||
return framesPerBuffer_;
|
return framesPerBuffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns all currently set flags as a binary combined
|
/// Returns all currently set flags as a binary combined
|
||||||
/// integer value (PaStreamFlags). Use isFlagSet() to
|
/// integer value (PaStreamFlags). Use isFlagSet() to
|
||||||
/// avoid dealing with the bitmasks.
|
/// avoid dealing with the bitmasks.
|
||||||
//////
|
//////
|
||||||
PaStreamFlags StreamParameters::flags() const
|
PaStreamFlags StreamParameters::flags() const
|
||||||
{
|
{
|
||||||
return flags_;
|
return flags_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
/// Returns true if the specified flag is currently set
|
/// Returns true if the specified flag is currently set
|
||||||
/// or false if it isn't.
|
/// or false if it isn't.
|
||||||
//////
|
//////
|
||||||
bool StreamParameters::isFlagSet(PaStreamFlags flag) const
|
bool StreamParameters::isFlagSet(PaStreamFlags flag) const
|
||||||
{
|
{
|
||||||
return ((flags_ & flag) != 0);
|
return ((flags_ & flag) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
DirectionSpecificStreamParameters &StreamParameters::inputParameters()
|
DirectionSpecificStreamParameters &StreamParameters::inputParameters()
|
||||||
{
|
{
|
||||||
return inputParameters_;
|
return inputParameters_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DirectionSpecificStreamParameters &StreamParameters::inputParameters() const
|
const DirectionSpecificStreamParameters &StreamParameters::inputParameters() const
|
||||||
{
|
{
|
||||||
return inputParameters_;
|
return inputParameters_;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectionSpecificStreamParameters &StreamParameters::outputParameters()
|
DirectionSpecificStreamParameters &StreamParameters::outputParameters()
|
||||||
{
|
{
|
||||||
return outputParameters_;
|
return outputParameters_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DirectionSpecificStreamParameters &StreamParameters::outputParameters() const
|
const DirectionSpecificStreamParameters &StreamParameters::outputParameters() const
|
||||||
{
|
{
|
||||||
return outputParameters_;
|
return outputParameters_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,297 +12,296 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Static members:
|
// Static members:
|
||||||
System *System::instance_ = NULL;
|
System *System::instance_ = NULL;
|
||||||
int System::initCount_ = 0;
|
int System::initCount_ = 0;
|
||||||
HostApi **System::hostApis_ = NULL;
|
HostApi **System::hostApis_ = NULL;
|
||||||
Device **System::devices_ = NULL;
|
Device **System::devices_ = NULL;
|
||||||
Device *System::nullDevice_ = NULL;
|
Device *System::nullDevice_ = NULL;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
int System::version()
|
int System::version()
|
||||||
{
|
{
|
||||||
return Pa_GetVersion();
|
return Pa_GetVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *System::versionText()
|
const char *System::versionText()
|
||||||
{
|
{
|
||||||
return Pa_GetVersionText();
|
return Pa_GetVersionText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::initialize()
|
void System::initialize()
|
||||||
{
|
{
|
||||||
++initCount_;
|
++initCount_;
|
||||||
|
|
||||||
if (initCount_ == 1)
|
|
||||||
{
|
|
||||||
// Create singleton:
|
|
||||||
assert(instance_ == NULL);
|
|
||||||
instance_ = new System();
|
|
||||||
|
|
||||||
// Initialize the PortAudio system:
|
|
||||||
{
|
|
||||||
PaError err = Pa_Initialize();
|
|
||||||
|
|
||||||
if (err != paNoError)
|
|
||||||
throw PaException(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and populate device array:
|
|
||||||
{
|
|
||||||
int numDevices = instance().deviceCount();
|
|
||||||
|
|
||||||
devices_ = new Device*[numDevices];
|
|
||||||
|
|
||||||
for (int i = 0; i < numDevices; ++i)
|
|
||||||
devices_[i] = new Device(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and populate host api array:
|
|
||||||
{
|
|
||||||
int numHostApis = instance().hostApiCount();
|
|
||||||
|
|
||||||
hostApis_ = new HostApi*[numHostApis];
|
|
||||||
|
|
||||||
for (int i = 0; i < numHostApis; ++i)
|
|
||||||
hostApis_[i] = new HostApi(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create null device:
|
|
||||||
nullDevice_ = new Device(paNoDevice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::terminate()
|
|
||||||
{
|
|
||||||
PaError err = paNoError;
|
|
||||||
|
|
||||||
if (initCount_ == 1)
|
|
||||||
{
|
|
||||||
// Destroy null device:
|
|
||||||
delete nullDevice_;
|
|
||||||
|
|
||||||
// Destroy host api array:
|
|
||||||
{
|
|
||||||
if (hostApis_ != NULL)
|
|
||||||
{
|
|
||||||
int numHostApis = instance().hostApiCount();
|
|
||||||
|
|
||||||
for (int i = 0; i < numHostApis; ++i)
|
|
||||||
delete hostApis_[i];
|
|
||||||
|
|
||||||
delete[] hostApis_;
|
|
||||||
hostApis_ = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy device array:
|
if (initCount_ == 1)
|
||||||
{
|
{
|
||||||
if (devices_ != NULL)
|
// Create singleton:
|
||||||
{
|
assert(instance_ == NULL);
|
||||||
int numDevices = instance().deviceCount();
|
instance_ = new System();
|
||||||
|
|
||||||
for (int i = 0; i < numDevices; ++i)
|
// Initialize the PortAudio system:
|
||||||
delete devices_[i];
|
{
|
||||||
|
PaError err = Pa_Initialize();
|
||||||
|
|
||||||
delete[] devices_;
|
if (err != paNoError)
|
||||||
devices_ = NULL;
|
throw PaException(err);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Terminate the PortAudio system:
|
// Create and populate device array:
|
||||||
assert(instance_ != NULL);
|
{
|
||||||
err = Pa_Terminate();
|
int numDevices = instance().deviceCount();
|
||||||
|
|
||||||
// Destroy singleton:
|
devices_ = new Device*[numDevices];
|
||||||
delete instance_;
|
|
||||||
instance_ = NULL;
|
for (int i = 0; i < numDevices; ++i)
|
||||||
}
|
devices_[i] = new Device(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and populate host api array:
|
||||||
|
{
|
||||||
|
int numHostApis = instance().hostApiCount();
|
||||||
|
|
||||||
|
hostApis_ = new HostApi*[numHostApis];
|
||||||
|
|
||||||
if (initCount_ > 0)
|
for (int i = 0; i < numHostApis; ++i)
|
||||||
--initCount_;
|
hostApis_[i] = new HostApi(i);
|
||||||
|
}
|
||||||
if (err != paNoError)
|
|
||||||
throw PaException(err);
|
// Create null device:
|
||||||
}
|
nullDevice_ = new Device(paNoDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
System &System::instance()
|
|
||||||
{
|
void System::terminate()
|
||||||
assert(exists());
|
{
|
||||||
|
PaError err = paNoError;
|
||||||
return *instance_;
|
|
||||||
}
|
if (initCount_ == 1)
|
||||||
|
{
|
||||||
bool System::exists()
|
// Destroy null device:
|
||||||
{
|
delete nullDevice_;
|
||||||
return (instance_ != NULL);
|
|
||||||
}
|
// Destroy host api array:
|
||||||
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
if (hostApis_ != NULL)
|
||||||
|
{
|
||||||
System::HostApiIterator System::hostApisBegin()
|
int numHostApis = instance().hostApiCount();
|
||||||
{
|
|
||||||
System::HostApiIterator tmp;
|
for (int i = 0; i < numHostApis; ++i)
|
||||||
tmp.ptr_ = &hostApis_[0]; // begin (first element)
|
delete hostApis_[i];
|
||||||
return tmp;
|
|
||||||
}
|
delete[] hostApis_;
|
||||||
|
hostApis_ = NULL;
|
||||||
System::HostApiIterator System::hostApisEnd()
|
}
|
||||||
{
|
}
|
||||||
int count = hostApiCount();
|
|
||||||
|
// Destroy device array:
|
||||||
System::HostApiIterator tmp;
|
{
|
||||||
tmp.ptr_ = &hostApis_[count]; // end (one past last element)
|
if (devices_ != NULL)
|
||||||
return tmp;
|
{
|
||||||
}
|
int numDevices = instance().deviceCount();
|
||||||
|
|
||||||
HostApi &System::defaultHostApi()
|
for (int i = 0; i < numDevices; ++i)
|
||||||
{
|
delete devices_[i];
|
||||||
PaHostApiIndex defaultHostApi = Pa_GetDefaultHostApi();
|
|
||||||
|
delete[] devices_;
|
||||||
if (defaultHostApi < 0)
|
devices_ = NULL;
|
||||||
throw PaException(defaultHostApi);
|
}
|
||||||
|
}
|
||||||
return *hostApis_[defaultHostApi];
|
|
||||||
}
|
// Terminate the PortAudio system:
|
||||||
|
assert(instance_ != NULL);
|
||||||
HostApi &System::hostApiByTypeId(PaHostApiTypeId type)
|
err = Pa_Terminate();
|
||||||
{
|
|
||||||
PaHostApiIndex index = Pa_HostApiTypeIdToHostApiIndex(type);
|
// Destroy singleton:
|
||||||
|
delete instance_;
|
||||||
if (index < 0)
|
instance_ = NULL;
|
||||||
throw PaException(index);
|
}
|
||||||
|
|
||||||
return *hostApis_[index];
|
if (initCount_ > 0)
|
||||||
}
|
--initCount_;
|
||||||
|
|
||||||
HostApi &System::hostApiByIndex(PaHostApiIndex index)
|
if (err != paNoError)
|
||||||
{
|
throw PaException(err);
|
||||||
if (index < 0 || index >= hostApiCount())
|
}
|
||||||
throw PaException(paInternalError);
|
|
||||||
|
|
||||||
return *hostApis_[index];
|
System &System::instance()
|
||||||
}
|
{
|
||||||
|
assert(exists());
|
||||||
int System::hostApiCount()
|
|
||||||
{
|
return *instance_;
|
||||||
PaHostApiIndex count = Pa_GetHostApiCount();
|
}
|
||||||
|
|
||||||
if (count < 0)
|
bool System::exists()
|
||||||
throw PaException(count);
|
{
|
||||||
|
return (instance_ != NULL);
|
||||||
return count;
|
}
|
||||||
}
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
|
System::HostApiIterator System::hostApisBegin()
|
||||||
System::DeviceIterator System::devicesBegin()
|
{
|
||||||
{
|
System::HostApiIterator tmp;
|
||||||
DeviceIterator tmp;
|
tmp.ptr_ = &hostApis_[0]; // begin (first element)
|
||||||
tmp.ptr_ = &devices_[0];
|
return tmp;
|
||||||
|
}
|
||||||
return tmp;
|
|
||||||
}
|
System::HostApiIterator System::hostApisEnd()
|
||||||
|
{
|
||||||
System::DeviceIterator System::devicesEnd()
|
int count = hostApiCount();
|
||||||
{
|
|
||||||
int count = deviceCount();
|
System::HostApiIterator tmp;
|
||||||
|
tmp.ptr_ = &hostApis_[count]; // end (one past last element)
|
||||||
DeviceIterator tmp;
|
return tmp;
|
||||||
tmp.ptr_ = &devices_[count];
|
}
|
||||||
|
|
||||||
return tmp;
|
HostApi &System::defaultHostApi()
|
||||||
}
|
{
|
||||||
|
PaHostApiIndex defaultHostApi = Pa_GetDefaultHostApi();
|
||||||
//////
|
|
||||||
/// Returns the System's default input Device, or the null Device if none
|
if (defaultHostApi < 0)
|
||||||
/// was available.
|
throw PaException(defaultHostApi);
|
||||||
//////
|
|
||||||
Device &System::defaultInputDevice()
|
return *hostApis_[defaultHostApi];
|
||||||
{
|
}
|
||||||
PaDeviceIndex index = Pa_GetDefaultInputDevice();
|
|
||||||
return deviceByIndex(index);
|
HostApi &System::hostApiByTypeId(PaHostApiTypeId type)
|
||||||
}
|
{
|
||||||
|
PaHostApiIndex index = Pa_HostApiTypeIdToHostApiIndex(type);
|
||||||
//////
|
|
||||||
/// Returns the System's default output Device, or the null Device if none
|
if (index < 0)
|
||||||
/// was available.
|
throw PaException(index);
|
||||||
//////
|
|
||||||
Device &System::defaultOutputDevice()
|
return *hostApis_[index];
|
||||||
{
|
}
|
||||||
PaDeviceIndex index = Pa_GetDefaultOutputDevice();
|
|
||||||
return deviceByIndex(index);
|
HostApi &System::hostApiByIndex(PaHostApiIndex index)
|
||||||
}
|
{
|
||||||
|
if (index < 0 || index >= hostApiCount())
|
||||||
//////
|
throw PaException(paInternalError);
|
||||||
/// Returns the Device for the given index.
|
|
||||||
/// Will throw a paInternalError equivalent PaException if the given index
|
return *hostApis_[index];
|
||||||
/// is out of range.
|
}
|
||||||
//////
|
|
||||||
Device &System::deviceByIndex(PaDeviceIndex index)
|
int System::hostApiCount()
|
||||||
{
|
{
|
||||||
if (index < -1 || index >= deviceCount())
|
PaHostApiIndex count = Pa_GetHostApiCount();
|
||||||
{
|
|
||||||
throw PaException(paInternalError);
|
if (count < 0)
|
||||||
}
|
throw PaException(count);
|
||||||
|
|
||||||
if (index == -1)
|
return count;
|
||||||
return System::instance().nullDevice();
|
}
|
||||||
|
|
||||||
return *devices_[index];
|
// -----------------------------------------------------------------------------------
|
||||||
}
|
|
||||||
|
System::DeviceIterator System::devicesBegin()
|
||||||
int System::deviceCount()
|
{
|
||||||
{
|
DeviceIterator tmp;
|
||||||
PaDeviceIndex count = Pa_GetDeviceCount();
|
tmp.ptr_ = &devices_[0];
|
||||||
|
|
||||||
if (count < 0)
|
return tmp;
|
||||||
throw PaException(count);
|
}
|
||||||
|
|
||||||
return count;
|
System::DeviceIterator System::devicesEnd()
|
||||||
}
|
{
|
||||||
|
int count = deviceCount();
|
||||||
Device &System::nullDevice()
|
|
||||||
{
|
DeviceIterator tmp;
|
||||||
return *nullDevice_;
|
tmp.ptr_ = &devices_[count];
|
||||||
}
|
|
||||||
|
return tmp;
|
||||||
// -----------------------------------------------------------------------------------
|
}
|
||||||
|
|
||||||
void System::sleep(long msec)
|
//////
|
||||||
{
|
/// Returns the System's default input Device, or the null Device if none
|
||||||
Pa_Sleep(msec);
|
/// was available.
|
||||||
}
|
//////
|
||||||
|
Device &System::defaultInputDevice()
|
||||||
int System::sizeOfSample(PaSampleFormat format)
|
{
|
||||||
{
|
PaDeviceIndex index = Pa_GetDefaultInputDevice();
|
||||||
PaError err = Pa_GetSampleSize(format);
|
return deviceByIndex(index);
|
||||||
if (err < 0)
|
}
|
||||||
{
|
|
||||||
throw PaException(err);
|
//////
|
||||||
return 0;
|
/// Returns the System's default output Device, or the null Device if none
|
||||||
}
|
/// was available.
|
||||||
|
//////
|
||||||
return err;
|
Device &System::defaultOutputDevice()
|
||||||
}
|
{
|
||||||
|
PaDeviceIndex index = Pa_GetDefaultOutputDevice();
|
||||||
// -----------------------------------------------------------------------------------
|
return deviceByIndex(index);
|
||||||
|
}
|
||||||
System::System()
|
|
||||||
{
|
//////
|
||||||
// (left blank intentionally)
|
/// Returns the Device for the given index.
|
||||||
}
|
/// Will throw a paInternalError equivalent PaException if the given index
|
||||||
|
/// is out of range.
|
||||||
System::~System()
|
//////
|
||||||
{
|
Device &System::deviceByIndex(PaDeviceIndex index)
|
||||||
// (left blank intentionally)
|
{
|
||||||
}
|
if (index < -1 || index >= deviceCount())
|
||||||
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
throw PaException(paInternalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == -1)
|
||||||
|
return System::instance().nullDevice();
|
||||||
|
|
||||||
|
return *devices_[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
int System::deviceCount()
|
||||||
|
{
|
||||||
|
PaDeviceIndex count = Pa_GetDeviceCount();
|
||||||
|
|
||||||
|
if (count < 0)
|
||||||
|
throw PaException(count);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
Device &System::nullDevice()
|
||||||
|
{
|
||||||
|
return *nullDevice_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void System::sleep(long msec)
|
||||||
|
{
|
||||||
|
Pa_Sleep(msec);
|
||||||
|
}
|
||||||
|
|
||||||
|
int System::sizeOfSample(PaSampleFormat format)
|
||||||
|
{
|
||||||
|
PaError err = Pa_GetSampleSize(format);
|
||||||
|
if (err < 0)
|
||||||
|
{
|
||||||
|
throw PaException(err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
System::System()
|
||||||
|
{
|
||||||
|
// (left blank intentionally)
|
||||||
|
}
|
||||||
|
|
||||||
|
System::~System()
|
||||||
|
{
|
||||||
|
// (left blank intentionally)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,59 +2,57 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
Device &System::DeviceIterator::operator*() const
|
Device &System::DeviceIterator::operator*() const
|
||||||
{
|
{
|
||||||
return **ptr_;
|
return **ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *System::DeviceIterator::operator->() const
|
Device *System::DeviceIterator::operator->() const
|
||||||
{
|
{
|
||||||
return &**this;
|
return &**this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
System::DeviceIterator &System::DeviceIterator::operator++()
|
System::DeviceIterator &System::DeviceIterator::operator++()
|
||||||
{
|
{
|
||||||
++ptr_;
|
++ptr_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::DeviceIterator System::DeviceIterator::operator++(int)
|
System::DeviceIterator System::DeviceIterator::operator++(int)
|
||||||
{
|
{
|
||||||
System::DeviceIterator prev = *this;
|
System::DeviceIterator prev = *this;
|
||||||
++*this;
|
++*this;
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::DeviceIterator &System::DeviceIterator::operator--()
|
System::DeviceIterator &System::DeviceIterator::operator--()
|
||||||
{
|
{
|
||||||
--ptr_;
|
--ptr_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::DeviceIterator System::DeviceIterator::operator--(int)
|
System::DeviceIterator System::DeviceIterator::operator--(int)
|
||||||
{
|
{
|
||||||
System::DeviceIterator prev = *this;
|
System::DeviceIterator prev = *this;
|
||||||
--*this;
|
--*this;
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool System::DeviceIterator::operator==(const System::DeviceIterator &rhs) const
|
bool System::DeviceIterator::operator==(const System::DeviceIterator &rhs) const
|
||||||
{
|
{
|
||||||
return (ptr_ == rhs.ptr_);
|
return (ptr_ == rhs.ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool System::DeviceIterator::operator!=(const System::DeviceIterator &rhs) const
|
bool System::DeviceIterator::operator!=(const System::DeviceIterator &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,58 +2,57 @@
|
||||||
|
|
||||||
namespace portaudio
|
namespace portaudio
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
HostApi &System::HostApiIterator::operator*() const
|
HostApi &System::HostApiIterator::operator*() const
|
||||||
{
|
{
|
||||||
return **ptr_;
|
return **ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostApi *System::HostApiIterator::operator->() const
|
HostApi *System::HostApiIterator::operator->() const
|
||||||
{
|
{
|
||||||
return &**this;
|
return &**this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
System::HostApiIterator &System::HostApiIterator::operator++()
|
System::HostApiIterator &System::HostApiIterator::operator++()
|
||||||
{
|
{
|
||||||
++ptr_;
|
++ptr_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::HostApiIterator System::HostApiIterator::operator++(int)
|
System::HostApiIterator System::HostApiIterator::operator++(int)
|
||||||
{
|
{
|
||||||
System::HostApiIterator prev = *this;
|
System::HostApiIterator prev = *this;
|
||||||
++*this;
|
++*this;
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::HostApiIterator &System::HostApiIterator::operator--()
|
System::HostApiIterator &System::HostApiIterator::operator--()
|
||||||
{
|
{
|
||||||
--ptr_;
|
--ptr_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
System::HostApiIterator System::HostApiIterator::operator--(int)
|
System::HostApiIterator System::HostApiIterator::operator--(int)
|
||||||
{
|
{
|
||||||
System::HostApiIterator prev = *this;
|
System::HostApiIterator prev = *this;
|
||||||
--*this;
|
--*this;
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool System::HostApiIterator::operator==(const System::HostApiIterator &rhs) const
|
bool System::HostApiIterator::operator==(const System::HostApiIterator &rhs) const
|
||||||
{
|
{
|
||||||
return (ptr_ == rhs.ptr_);
|
return (ptr_ == rhs.ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool System::HostApiIterator::operator!=(const System::HostApiIterator &rhs) const
|
bool System::HostApiIterator::operator!=(const System::HostApiIterator &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
} // namespace portaudio
|
} // namespace portaudio
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The text above constitutes the entire PortAudio license; however,
|
* The text above constitutes the entire PortAudio license; however,
|
||||||
* the PortAudio community also makes the following non-binding requests:
|
* the PortAudio community also makes the following non-binding requests:
|
||||||
*
|
*
|
||||||
* Any person wishing to distribute modifications to the Software is
|
* Any person wishing to distribute modifications to the Software is
|
||||||
* requested to send the modifications to the original developer so that
|
* requested to send the modifications to the original developer so that
|
||||||
* they can be incorporated into the canonical version. It is also
|
* they can be incorporated into the canonical version. It is also
|
||||||
* requested that these non-binding requests be included along with the
|
* requested that these non-binding requests be included along with the
|
||||||
* license above.
|
* license above.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -55,9 +55,9 @@
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getReadAvailable
|
JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getReadAvailable
|
||||||
(JNIEnv *env, jobject blockingStream)
|
(JNIEnv *env, jobject blockingStream)
|
||||||
{
|
{
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream == NULL ) return 0;
|
if( stream == NULL ) return 0;
|
||||||
return Pa_GetStreamReadAvailable( stream );
|
return Pa_GetStreamReadAvailable( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -68,9 +68,9 @@ JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getReadAvailable
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getWriteAvailable
|
JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getWriteAvailable
|
||||||
(JNIEnv *env, jobject blockingStream)
|
(JNIEnv *env, jobject blockingStream)
|
||||||
{
|
{
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream == NULL ) return 0;
|
if( stream == NULL ) return 0;
|
||||||
return Pa_GetStreamWriteAvailable( stream );
|
return Pa_GetStreamWriteAvailable( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -82,33 +82,33 @@ JNIEXPORT jint JNICALL Java_com_portaudio_BlockingStream_getWriteAvailable
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeFloats
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeFloats
|
||||||
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
||||||
{
|
{
|
||||||
jfloat *carr;
|
jfloat *carr;
|
||||||
jint err;
|
jint err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( buffer == NULL )
|
if( buffer == NULL )
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"null stream buffer");
|
"null stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
carr = (*env)->GetFloatArrayElements(env, buffer, NULL);
|
carr = (*env)->GetFloatArrayElements(env, buffer, NULL);
|
||||||
if (carr == NULL)
|
if (carr == NULL)
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"invalid stream buffer");
|
"invalid stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
err = Pa_WriteStream( stream, carr, numFrames );
|
err = Pa_WriteStream( stream, carr, numFrames );
|
||||||
(*env)->ReleaseFloatArrayElements(env, buffer, carr, 0);
|
(*env)->ReleaseFloatArrayElements(env, buffer, carr, 0);
|
||||||
if( err == paOutputUnderflowed )
|
if( err == paOutputUnderflowed )
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -119,33 +119,33 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeFloats
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readFloats
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readFloats
|
||||||
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
||||||
{
|
{
|
||||||
jfloat *carr;
|
jfloat *carr;
|
||||||
jint err;
|
jint err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( buffer == NULL )
|
if( buffer == NULL )
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"null stream buffer");
|
"null stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
carr = (*env)->GetFloatArrayElements(env, buffer, NULL);
|
carr = (*env)->GetFloatArrayElements(env, buffer, NULL);
|
||||||
if (carr == NULL)
|
if (carr == NULL)
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"invalid stream buffer");
|
"invalid stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
err = Pa_ReadStream( stream, carr, numFrames );
|
err = Pa_ReadStream( stream, carr, numFrames );
|
||||||
(*env)->ReleaseFloatArrayElements(env, buffer, carr, 0);
|
(*env)->ReleaseFloatArrayElements(env, buffer, carr, 0);
|
||||||
if( err == paInputOverflowed )
|
if( err == paInputOverflowed )
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -156,33 +156,33 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readFloats
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeShorts
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeShorts
|
||||||
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
||||||
{
|
{
|
||||||
jshort *carr;
|
jshort *carr;
|
||||||
jint err;
|
jint err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( buffer == NULL )
|
if( buffer == NULL )
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"null stream buffer");
|
"null stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
carr = (*env)->GetShortArrayElements(env, buffer, NULL);
|
carr = (*env)->GetShortArrayElements(env, buffer, NULL);
|
||||||
if (carr == NULL)
|
if (carr == NULL)
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"invalid stream buffer");
|
"invalid stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
err = Pa_WriteStream( stream, carr, numFrames );
|
err = Pa_WriteStream( stream, carr, numFrames );
|
||||||
(*env)->ReleaseShortArrayElements(env, buffer, carr, 0);
|
(*env)->ReleaseShortArrayElements(env, buffer, carr, 0);
|
||||||
if( err == paOutputUnderflowed )
|
if( err == paOutputUnderflowed )
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -193,33 +193,33 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_writeShorts
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readShorts
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readShorts
|
||||||
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
(JNIEnv *env, jobject blockingStream, jfloatArray buffer, jint numFrames)
|
||||||
{
|
{
|
||||||
jshort *carr;
|
jshort *carr;
|
||||||
jint err;
|
jint err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( buffer == NULL )
|
if( buffer == NULL )
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"null stream buffer");
|
"null stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
carr = (*env)->GetShortArrayElements(env, buffer, NULL);
|
carr = (*env)->GetShortArrayElements(env, buffer, NULL);
|
||||||
if (carr == NULL)
|
if (carr == NULL)
|
||||||
{
|
{
|
||||||
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
(*env)->ThrowNew( env, (*env)->FindClass(env,"java/lang/RuntimeException"),
|
||||||
"invalid stream buffer");
|
"invalid stream buffer");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
err = Pa_ReadStream( stream, carr, numFrames );
|
err = Pa_ReadStream( stream, carr, numFrames );
|
||||||
(*env)->ReleaseShortArrayElements(env, buffer, carr, 0);
|
(*env)->ReleaseShortArrayElements(env, buffer, carr, 0);
|
||||||
if( err == paInputOverflowed )
|
if( err == paInputOverflowed )
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -230,9 +230,9 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_readShorts
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_start
|
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_start
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
PaStream *stream = jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream = jpa_GetStreamPointer( env, blockingStream );
|
||||||
int err = Pa_StartStream( stream );
|
int err = Pa_StartStream( stream );
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -243,9 +243,9 @@ JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_start
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_stop
|
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_stop
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
int err = Pa_StopStream( stream );
|
int err = Pa_StopStream( stream );
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Class: com_portaudio_BlockingStream
|
* Class: com_portaudio_BlockingStream
|
||||||
|
|
@ -255,9 +255,9 @@ JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_stop
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_abort
|
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_abort
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
int err = Pa_AbortStream( stream );
|
int err = Pa_AbortStream( stream );
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -268,15 +268,15 @@ JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_abort
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_close
|
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_close
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
jclass cls;
|
jclass cls;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream != NULL )
|
if( stream != NULL )
|
||||||
{
|
{
|
||||||
int err = Pa_CloseStream( stream );
|
int err = Pa_CloseStream( stream );
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
cls = (*env)->GetObjectClass(env, blockingStream);
|
cls = (*env)->GetObjectClass(env, blockingStream);
|
||||||
jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) 0 );
|
jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -287,11 +287,11 @@ JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_close
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isStopped
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isStopped
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream == NULL ) return 1;
|
if( stream == NULL ) return 1;
|
||||||
err = Pa_IsStreamStopped( stream );
|
err = Pa_IsStreamStopped( stream );
|
||||||
return (jpa_CheckError( env, err ) > 0);
|
return (jpa_CheckError( env, err ) > 0);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Class: com_portaudio_BlockingStream
|
* Class: com_portaudio_BlockingStream
|
||||||
|
|
@ -301,11 +301,11 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isStopped
|
||||||
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isActive
|
JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isActive
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream == NULL ) return 0;
|
if( stream == NULL ) return 0;
|
||||||
err = Pa_IsStreamActive( stream );
|
err = Pa_IsStreamActive( stream );
|
||||||
return (jpa_CheckError( env, err ) > 0);
|
return (jpa_CheckError( env, err ) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -317,9 +317,9 @@ JNIEXPORT jboolean JNICALL Java_com_portaudio_BlockingStream_isActive
|
||||||
JNIEXPORT jdouble JNICALL Java_com_portaudio_BlockingStream_getTime
|
JNIEXPORT jdouble JNICALL Java_com_portaudio_BlockingStream_getTime
|
||||||
(JNIEnv *env, jobject blockingStream )
|
(JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
if( stream == NULL ) return 0.0;
|
if( stream == NULL ) return 0.0;
|
||||||
return Pa_GetStreamTime( stream );
|
return Pa_GetStreamTime( stream );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -331,22 +331,21 @@ JNIEXPORT jdouble JNICALL Java_com_portaudio_BlockingStream_getTime
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_getInfo
|
JNIEXPORT void JNICALL Java_com_portaudio_BlockingStream_getInfo
|
||||||
(JNIEnv *env, jobject blockingStream, jobject streamInfo)
|
(JNIEnv *env, jobject blockingStream, jobject streamInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
|
||||||
const PaStreamInfo *info = Pa_GetStreamInfo( stream );
|
|
||||||
if( streamInfo == NULL )
|
|
||||||
{
|
|
||||||
jpa_ThrowError( env, "Invalid stream." );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Get a reference to obj's class */
|
|
||||||
jclass cls = (*env)->GetObjectClass(env, streamInfo);
|
|
||||||
|
|
||||||
jpa_SetIntField( env, cls, streamInfo, "structVersion", info->structVersion );
|
|
||||||
jpa_SetDoubleField( env, cls, streamInfo, "inputLatency", info->inputLatency );
|
|
||||||
jpa_SetDoubleField( env, cls, streamInfo, "outputLatency", info->outputLatency );
|
|
||||||
jpa_SetDoubleField( env, cls, streamInfo, "sampleRate", info->sampleRate );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
PaStream *stream =jpa_GetStreamPointer( env, blockingStream );
|
||||||
|
const PaStreamInfo *info = Pa_GetStreamInfo( stream );
|
||||||
|
if( streamInfo == NULL )
|
||||||
|
{
|
||||||
|
jpa_ThrowError( env, "Invalid stream." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Get a reference to obj's class */
|
||||||
|
jclass cls = (*env)->GetObjectClass(env, streamInfo);
|
||||||
|
|
||||||
|
jpa_SetIntField( env, cls, streamInfo, "structVersion", info->structVersion );
|
||||||
|
jpa_SetDoubleField( env, cls, streamInfo, "inputLatency", info->inputLatency );
|
||||||
|
jpa_SetDoubleField( env, cls, streamInfo, "outputLatency", info->outputLatency );
|
||||||
|
jpa_SetDoubleField( env, cls, streamInfo, "sampleRate", info->sampleRate );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The text above constitutes the entire PortAudio license; however,
|
* The text above constitutes the entire PortAudio license; however,
|
||||||
* the PortAudio community also makes the following non-binding requests:
|
* the PortAudio community also makes the following non-binding requests:
|
||||||
*
|
*
|
||||||
* Any person wishing to distribute modifications to the Software is
|
* Any person wishing to distribute modifications to the Software is
|
||||||
* requested to send the modifications to the original developer so that
|
* requested to send the modifications to the original developer so that
|
||||||
* they can be incorporated into the canonical version. It is also
|
* they can be incorporated into the canonical version. It is also
|
||||||
* requested that these non-binding requests be included along with the
|
* requested that these non-binding requests be included along with the
|
||||||
* license above.
|
* license above.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getVersion
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getVersion
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
return Pa_GetVersion();
|
return Pa_GetVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -59,7 +59,7 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getVersion
|
||||||
JNIEXPORT jstring JNICALL Java_com_portaudio_PortAudio_getVersionText
|
JNIEXPORT jstring JNICALL Java_com_portaudio_PortAudio_getVersionText
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
return (*env)->NewStringUTF(env, Pa_GetVersionText() );
|
return (*env)->NewStringUTF(env, Pa_GetVersionText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -70,8 +70,8 @@ JNIEXPORT jstring JNICALL Java_com_portaudio_PortAudio_getVersionText
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_initialize
|
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_initialize
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
PaError err = Pa_Initialize();
|
PaError err = Pa_Initialize();
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -82,8 +82,8 @@ JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_initialize
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_terminate
|
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_terminate
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
PaError err = Pa_Terminate();
|
PaError err = Pa_Terminate();
|
||||||
jpa_CheckError( env, err );
|
jpa_CheckError( env, err );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -94,8 +94,8 @@ JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_terminate
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDeviceCount
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDeviceCount
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
jint count = Pa_GetDeviceCount();
|
jint count = Pa_GetDeviceCount();
|
||||||
return jpa_CheckError( env, count );
|
return jpa_CheckError( env, count );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -106,27 +106,27 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDeviceCount
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getDeviceInfo
|
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getDeviceInfo
|
||||||
(JNIEnv *env, jclass clazz, jint index, jobject deviceInfo)
|
(JNIEnv *env, jclass clazz, jint index, jobject deviceInfo)
|
||||||
{
|
{
|
||||||
const PaDeviceInfo *info;
|
const PaDeviceInfo *info;
|
||||||
/* Get a reference to obj's class */
|
/* Get a reference to obj's class */
|
||||||
jclass cls = (*env)->GetObjectClass(env, deviceInfo);
|
jclass cls = (*env)->GetObjectClass(env, deviceInfo);
|
||||||
|
|
||||||
info = Pa_GetDeviceInfo( index );
|
info = Pa_GetDeviceInfo( index );
|
||||||
if( info == NULL )
|
if( info == NULL )
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Pa_GetDeviceInfo returned NULL." );
|
jpa_ThrowError( env, "Pa_GetDeviceInfo returned NULL." );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_SetStringField( env, cls, deviceInfo, "name", info->name );
|
jpa_SetStringField( env, cls, deviceInfo, "name", info->name );
|
||||||
jpa_SetIntField( env, cls, deviceInfo, "maxInputChannels", info->maxInputChannels );
|
jpa_SetIntField( env, cls, deviceInfo, "maxInputChannels", info->maxInputChannels );
|
||||||
jpa_SetIntField( env, cls, deviceInfo, "maxOutputChannels", info->maxOutputChannels );
|
jpa_SetIntField( env, cls, deviceInfo, "maxOutputChannels", info->maxOutputChannels );
|
||||||
jpa_SetIntField( env, cls, deviceInfo, "hostApi", info->hostApi );
|
jpa_SetIntField( env, cls, deviceInfo, "hostApi", info->hostApi );
|
||||||
jpa_SetDoubleField( env, cls, deviceInfo, "defaultSampleRate", info->defaultSampleRate );
|
jpa_SetDoubleField( env, cls, deviceInfo, "defaultSampleRate", info->defaultSampleRate );
|
||||||
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultLowInputLatency );
|
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultLowInputLatency );
|
||||||
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultHighInputLatency );
|
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowInputLatency", info->defaultHighInputLatency );
|
||||||
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowOutputLatency", info->defaultLowOutputLatency );
|
jpa_SetDoubleField( env, cls, deviceInfo, "defaultLowOutputLatency", info->defaultLowOutputLatency );
|
||||||
jpa_SetDoubleField( env, cls, deviceInfo, "defaultHighOutputLatency", info->defaultHighOutputLatency );
|
jpa_SetDoubleField( env, cls, deviceInfo, "defaultHighOutputLatency", info->defaultHighOutputLatency );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -137,8 +137,8 @@ JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getDeviceInfo
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getHostApiCount
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getHostApiCount
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
jint count = Pa_GetHostApiCount();
|
jint count = Pa_GetHostApiCount();
|
||||||
return jpa_CheckError( env, count );
|
return jpa_CheckError( env, count );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getHostApiCount
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiTypeIdToHostApiIndex
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiTypeIdToHostApiIndex
|
||||||
(JNIEnv *env, jclass clazz, jint hostApiType)
|
(JNIEnv *env, jclass clazz, jint hostApiType)
|
||||||
{
|
{
|
||||||
return Pa_HostApiTypeIdToHostApiIndex( (PaHostApiTypeId) hostApiType );
|
return Pa_HostApiTypeIdToHostApiIndex( (PaHostApiTypeId) hostApiType );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -161,7 +161,7 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiTypeIdToHostApiIndex
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiDeviceIndexToDeviceIndex
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiDeviceIndexToDeviceIndex
|
||||||
(JNIEnv *env, jclass clazz, jint hostApiIndex, jint apiDeviceIndex)
|
(JNIEnv *env, jclass clazz, jint hostApiIndex, jint apiDeviceIndex)
|
||||||
{
|
{
|
||||||
return Pa_HostApiDeviceIndexToDeviceIndex( hostApiIndex, apiDeviceIndex );
|
return Pa_HostApiDeviceIndexToDeviceIndex( hostApiIndex, apiDeviceIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -173,24 +173,24 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_hostApiDeviceIndexToDeviceIn
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getHostApiInfo
|
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getHostApiInfo
|
||||||
(JNIEnv *env, jclass clazz, jint index, jobject hostApiInfo)
|
(JNIEnv *env, jclass clazz, jint index, jobject hostApiInfo)
|
||||||
{
|
{
|
||||||
const PaHostApiInfo *info;
|
const PaHostApiInfo *info;
|
||||||
/* Get a reference to obj's class */
|
/* Get a reference to obj's class */
|
||||||
jclass cls = (*env)->GetObjectClass(env, hostApiInfo);
|
jclass cls = (*env)->GetObjectClass(env, hostApiInfo);
|
||||||
|
|
||||||
info = Pa_GetHostApiInfo( index );
|
info = Pa_GetHostApiInfo( index );
|
||||||
if( info == NULL )
|
if( info == NULL )
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Pa_GetHostApiInfo returned NULL." );
|
jpa_ThrowError( env, "Pa_GetHostApiInfo returned NULL." );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jpa_SetIntField( env, cls, hostApiInfo, "version", info->structVersion );
|
jpa_SetIntField( env, cls, hostApiInfo, "version", info->structVersion );
|
||||||
jpa_SetIntField( env, cls, hostApiInfo, "type", info->type );
|
jpa_SetIntField( env, cls, hostApiInfo, "type", info->type );
|
||||||
jpa_SetStringField( env, cls, hostApiInfo, "name", info->name );
|
jpa_SetStringField( env, cls, hostApiInfo, "name", info->name );
|
||||||
jpa_SetIntField( env, cls, hostApiInfo, "deviceCount", info->deviceCount );
|
jpa_SetIntField( env, cls, hostApiInfo, "deviceCount", info->deviceCount );
|
||||||
jpa_SetIntField( env, cls, hostApiInfo, "defaultInputDevice", info->defaultInputDevice );
|
jpa_SetIntField( env, cls, hostApiInfo, "defaultInputDevice", info->defaultInputDevice );
|
||||||
jpa_SetIntField( env, cls, hostApiInfo, "defaultOutputDevice", info->defaultOutputDevice );
|
jpa_SetIntField( env, cls, hostApiInfo, "defaultOutputDevice", info->defaultOutputDevice );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -201,8 +201,8 @@ JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_getHostApiInfo
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultInputDevice
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultInputDevice
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
jint deviceId = Pa_GetDefaultInputDevice();
|
jint deviceId = Pa_GetDefaultInputDevice();
|
||||||
return jpa_CheckError( env, deviceId );
|
return jpa_CheckError( env, deviceId );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -213,8 +213,8 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultInputDevice
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultOutputDevice
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultOutputDevice
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
jint deviceId = Pa_GetDefaultOutputDevice();
|
jint deviceId = Pa_GetDefaultOutputDevice();
|
||||||
return jpa_CheckError( env, deviceId );
|
return jpa_CheckError( env, deviceId );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -225,8 +225,8 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultOutputDevice
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultHostApi
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultHostApi
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
jint deviceId = Pa_GetDefaultHostApi();
|
jint deviceId = Pa_GetDefaultHostApi();
|
||||||
return jpa_CheckError( env, deviceId );
|
return jpa_CheckError( env, deviceId );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -237,13 +237,13 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_getDefaultHostApi
|
||||||
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_isFormatSupported
|
JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_isFormatSupported
|
||||||
(JNIEnv *env, jclass clazz, jobject inParams, jobject outParams, jint sampleRate )
|
(JNIEnv *env, jclass clazz, jobject inParams, jobject outParams, jint sampleRate )
|
||||||
{
|
{
|
||||||
PaStreamParameters myInParams, *paInParams;
|
PaStreamParameters myInParams, *paInParams;
|
||||||
PaStreamParameters myOutParams, *paOutParams;
|
PaStreamParameters myOutParams, *paOutParams;
|
||||||
|
|
||||||
paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
|
paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
|
||||||
paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
|
paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
|
||||||
|
|
||||||
return Pa_IsFormatSupported( paInParams, paOutParams, sampleRate );
|
return Pa_IsFormatSupported( paInParams, paOutParams, sampleRate );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,25 +255,25 @@ JNIEXPORT jint JNICALL Java_com_portaudio_PortAudio_isFormatSupported
|
||||||
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_openStream
|
JNIEXPORT void JNICALL Java_com_portaudio_PortAudio_openStream
|
||||||
(JNIEnv *env, jclass clazz, jobject blockingStream, jobject inParams, jobject outParams, jint sampleRate, jint framesPerBuffer, jint flags )
|
(JNIEnv *env, jclass clazz, jobject blockingStream, jobject inParams, jobject outParams, jint sampleRate, jint framesPerBuffer, jint flags )
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
PaStreamParameters myInParams, *paInParams;
|
PaStreamParameters myInParams, *paInParams;
|
||||||
PaStreamParameters myOutParams, *paOutParams;
|
PaStreamParameters myOutParams, *paOutParams;
|
||||||
PaStream *stream;
|
PaStream *stream;
|
||||||
|
|
||||||
paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
|
paInParams = jpa_FillStreamParameters( env, inParams, &myInParams );
|
||||||
paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
|
paOutParams = jpa_FillStreamParameters( env, outParams, &myOutParams );
|
||||||
err = Pa_OpenStream( &stream, paInParams, paOutParams, sampleRate, framesPerBuffer, flags, NULL, NULL );
|
err = Pa_OpenStream( &stream, paInParams, paOutParams, sampleRate, framesPerBuffer, flags, NULL, NULL );
|
||||||
if( jpa_CheckError( env, err ) == 0 )
|
if( jpa_CheckError( env, err ) == 0 )
|
||||||
{
|
{
|
||||||
jclass cls = (*env)->GetObjectClass(env, blockingStream);
|
jclass cls = (*env)->GetObjectClass(env, blockingStream);
|
||||||
jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) stream );
|
jpa_SetLongField( env, cls, blockingStream, "nativeStream", (jlong) stream );
|
||||||
if( paInParams != NULL )
|
if( paInParams != NULL )
|
||||||
{
|
{
|
||||||
jpa_SetIntField( env, cls, blockingStream, "inputFormat", paInParams->sampleFormat );
|
jpa_SetIntField( env, cls, blockingStream, "inputFormat", paInParams->sampleFormat );
|
||||||
}
|
}
|
||||||
if( paOutParams != NULL )
|
if( paOutParams != NULL )
|
||||||
{
|
{
|
||||||
jpa_SetIntField( env, cls, blockingStream, "outputFormat", paOutParams->sampleFormat );
|
jpa_SetIntField( env, cls, blockingStream, "outputFormat", paOutParams->sampleFormat );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The text above constitutes the entire PortAudio license; however,
|
* The text above constitutes the entire PortAudio license; however,
|
||||||
* the PortAudio community also makes the following non-binding requests:
|
* the PortAudio community also makes the following non-binding requests:
|
||||||
*
|
*
|
||||||
* Any person wishing to distribute modifications to the Software is
|
* Any person wishing to distribute modifications to the Software is
|
||||||
* requested to send the modifications to the original developer so that
|
* requested to send the modifications to the original developer so that
|
||||||
* they can be incorporated into the canonical version. It is also
|
* they can be incorporated into the canonical version. It is also
|
||||||
* requested that these non-binding requests be included along with the
|
* requested that these non-binding requests be included along with the
|
||||||
* license above.
|
* license above.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -45,14 +45,14 @@ jint jpa_GetIntField( JNIEnv *env, jclass cls, jobject obj, const char *fieldNam
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find integer JNI field." );
|
jpa_ThrowError( env, "Cannot find integer JNI field." );
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (*env)->GetIntField(env, obj, fid );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return (*env)->GetIntField(env, obj, fid );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jpa_SetIntField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, jint value )
|
void jpa_SetIntField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, jint value )
|
||||||
|
|
@ -60,13 +60,13 @@ void jpa_SetIntField( JNIEnv *env, jclass cls, jobject obj, const char *fieldNam
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find integer JNI field." );
|
jpa_ThrowError( env, "Cannot find integer JNI field." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*env)->SetIntField(env, obj, fid, value );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
(*env)->SetIntField(env, obj, fid, value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jlong jpa_GetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName )
|
jlong jpa_GetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName )
|
||||||
|
|
@ -74,14 +74,14 @@ jlong jpa_GetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldN
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find long JNI field." );
|
jpa_ThrowError( env, "Cannot find long JNI field." );
|
||||||
return 0L;
|
return 0L;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (*env)->GetLongField(env, obj, fid );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return (*env)->GetLongField(env, obj, fid );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jpa_SetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, jlong value )
|
void jpa_SetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, jlong value )
|
||||||
|
|
@ -89,13 +89,13 @@ void jpa_SetLongField( JNIEnv *env, jclass cls, jobject obj, const char *fieldNa
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find long JNI field." );
|
jpa_ThrowError( env, "Cannot find long JNI field." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*env)->SetLongField(env, obj, fid, value );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
(*env)->SetLongField(env, obj, fid, value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -104,13 +104,13 @@ void jpa_SetDoubleField( JNIEnv *env, jclass cls, jobject obj, const char *field
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "D");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "D");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find double JNI field." );
|
jpa_ThrowError( env, "Cannot find double JNI field." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*env)->SetDoubleField(env, obj, fid, value );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
(*env)->SetDoubleField(env, obj, fid, value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -119,14 +119,14 @@ jdouble jpa_GetDoubleField( JNIEnv *env, jclass cls, jobject obj, const char *fi
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "D");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "D");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find double JNI field." );
|
jpa_ThrowError( env, "Cannot find double JNI field." );
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (*env)->GetDoubleField(env, obj, fid );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return (*env)->GetDoubleField(env, obj, fid );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jpa_SetStringField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, const char *value )
|
void jpa_SetStringField( JNIEnv *env, jclass cls, jobject obj, const char *fieldName, const char *value )
|
||||||
|
|
@ -134,75 +134,75 @@ void jpa_SetStringField( JNIEnv *env, jclass cls, jobject obj, const char *field
|
||||||
/* Look for the instance field maxInputChannels in cls */
|
/* Look for the instance field maxInputChannels in cls */
|
||||||
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "Ljava/lang/String;");
|
jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "Ljava/lang/String;");
|
||||||
if (fid == NULL)
|
if (fid == NULL)
|
||||||
{
|
{
|
||||||
jpa_ThrowError( env, "Cannot find String JNI field." );
|
jpa_ThrowError( env, "Cannot find String JNI field." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jstring jstr = (*env)->NewStringUTF(env, value);
|
||||||
|
if (jstr == NULL)
|
||||||
|
{
|
||||||
|
jpa_ThrowError( env, "Cannot create new String." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*env)->SetObjectField(env, obj, fid, jstr );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
jstring jstr = (*env)->NewStringUTF(env, value);
|
|
||||||
if (jstr == NULL)
|
|
||||||
{
|
|
||||||
jpa_ThrowError( env, "Cannot create new String." );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*env)->SetObjectField(env, obj, fid, jstr );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PaStreamParameters *jpa_FillStreamParameters( JNIEnv *env, jobject jstreamParam, PaStreamParameters *myParams )
|
PaStreamParameters *jpa_FillStreamParameters( JNIEnv *env, jobject jstreamParam, PaStreamParameters *myParams )
|
||||||
{
|
{
|
||||||
jclass cls;
|
jclass cls;
|
||||||
|
|
||||||
if( jstreamParam == NULL ) return NULL; // OK, not an error
|
|
||||||
|
|
||||||
cls = (*env)->GetObjectClass(env, jstreamParam);
|
if( jstreamParam == NULL ) return NULL; // OK, not an error
|
||||||
|
|
||||||
myParams->channelCount = jpa_GetIntField( env, cls, jstreamParam, "channelCount" );
|
|
||||||
myParams->device = jpa_GetIntField( env, cls, jstreamParam, "device" );
|
|
||||||
myParams->sampleFormat = jpa_GetIntField( env, cls, jstreamParam, "sampleFormat" );
|
|
||||||
myParams->suggestedLatency = jpa_GetDoubleField( env, cls, jstreamParam, "suggestedLatency" );
|
|
||||||
myParams->hostApiSpecificStreamInfo = NULL;
|
|
||||||
|
|
||||||
return myParams;
|
cls = (*env)->GetObjectClass(env, jstreamParam);
|
||||||
|
|
||||||
|
myParams->channelCount = jpa_GetIntField( env, cls, jstreamParam, "channelCount" );
|
||||||
|
myParams->device = jpa_GetIntField( env, cls, jstreamParam, "device" );
|
||||||
|
myParams->sampleFormat = jpa_GetIntField( env, cls, jstreamParam, "sampleFormat" );
|
||||||
|
myParams->suggestedLatency = jpa_GetDoubleField( env, cls, jstreamParam, "suggestedLatency" );
|
||||||
|
myParams->hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
|
return myParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an exception that will be thrown when we return from the JNI call.
|
// Create an exception that will be thrown when we return from the JNI call.
|
||||||
jint jpa_ThrowError( JNIEnv *env, const char *message )
|
jint jpa_ThrowError( JNIEnv *env, const char *message )
|
||||||
{
|
{
|
||||||
return (*env)->ThrowNew(env, (*env)->FindClass( env, "java/lang/RuntimeException"),
|
return (*env)->ThrowNew(env, (*env)->FindClass( env, "java/lang/RuntimeException"),
|
||||||
message );
|
message );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw an exception on error.
|
// Throw an exception on error.
|
||||||
jint jpa_CheckError( JNIEnv *env, PaError err )
|
jint jpa_CheckError( JNIEnv *env, PaError err )
|
||||||
{
|
{
|
||||||
if( err == -1 )
|
if( err == -1 )
|
||||||
{
|
{
|
||||||
return jpa_ThrowError( env, "-1, possibly no available default device" );
|
return jpa_ThrowError( env, "-1, possibly no available default device" );
|
||||||
}
|
}
|
||||||
else if( err < 0 )
|
else if( err < 0 )
|
||||||
{
|
{
|
||||||
if( err == paUnanticipatedHostError )
|
if( err == paUnanticipatedHostError )
|
||||||
{
|
{
|
||||||
const PaHostErrorInfo *hostErrorInfo = Pa_GetLastHostErrorInfo();
|
const PaHostErrorInfo *hostErrorInfo = Pa_GetLastHostErrorInfo();
|
||||||
return jpa_ThrowError( env, hostErrorInfo->errorText );
|
return jpa_ThrowError( env, hostErrorInfo->errorText );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return jpa_ThrowError( env, Pa_GetErrorText( err ) );
|
return jpa_ThrowError( env, Pa_GetErrorText( err ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the stream pointer from a BlockingStream long field.
|
// Get the stream pointer from a BlockingStream long field.
|
||||||
PaStream *jpa_GetStreamPointer( JNIEnv *env, jobject blockingStream )
|
PaStream *jpa_GetStreamPointer( JNIEnv *env, jobject blockingStream )
|
||||||
{
|
{
|
||||||
jclass cls = (*env)->GetObjectClass(env, blockingStream);
|
jclass cls = (*env)->GetObjectClass(env, blockingStream);
|
||||||
return (PaStream *) jpa_GetLongField( env, cls, blockingStream, "nativeStream" );
|
return (PaStream *) jpa_GetLongField( env, cls, blockingStream, "nativeStream" );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The text above constitutes the entire PortAudio license; however,
|
* The text above constitutes the entire PortAudio license; however,
|
||||||
* the PortAudio community also makes the following non-binding requests:
|
* the PortAudio community also makes the following non-binding requests:
|
||||||
*
|
*
|
||||||
* Any person wishing to distribute modifications to the Software is
|
* Any person wishing to distribute modifications to the Software is
|
||||||
* requested to send the modifications to the original developer so that
|
* requested to send the modifications to the original developer so that
|
||||||
* they can be incorporated into the canonical version. It is also
|
* they can be incorporated into the canonical version. It is also
|
||||||
* requested that these non-binding requests be included along with the
|
* requested that these non-binding requests be included along with the
|
||||||
* license above.
|
* license above.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue