Spaces:
Runtime error
Runtime error
File size: 6,255 Bytes
83418c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
#include <iostream>
#include "portaudiocpp/PortAudioCpp.hxx"
#ifdef WIN32
#include "portaudiocpp/AsioDeviceAdapter.hxx"
#endif
// ---------------------------------------------------------------------------------------
void printSupportedStandardSampleRates(
const portaudio::DirectionSpecificStreamParameters &inputParameters,
const portaudio::DirectionSpecificStreamParameters &outputParameters)
{
static double STANDARD_SAMPLE_RATES[] = {
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
int printCount = 0;
for (int i = 0; STANDARD_SAMPLE_RATES[i] > 0; ++i)
{
portaudio::StreamParameters tmp = portaudio::StreamParameters(inputParameters, outputParameters, STANDARD_SAMPLE_RATES[i], 0, paNoFlag);
if (tmp.isSupported())
{
if (printCount == 0)
{
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
printCount = 1;
}
else if (printCount == 4)
{
std::cout << "," << std::endl;
std::cout << " " << STANDARD_SAMPLE_RATES[i]; // 8.2
printCount = 1;
}
else
{
std::cout << ", " << STANDARD_SAMPLE_RATES[i]; // 8.2
++printCount;
}
}
}
if (printCount == 0)
std::cout << "None" << std::endl;
else
std::cout << std::endl;
}
// ---------------------------------------------------------------------------------------
int main(int, char*[]);
int main(int, char*[])
{
try
{
portaudio::AutoSystem autoSys;
portaudio::System &sys = portaudio::System::instance();
std::cout << "PortAudio version number = " << sys.version() << std::endl;
std::cout << "PortAudio version text = '" << sys.versionText() << "'" << std::endl;
int numDevices = sys.deviceCount();
std::cout << "Number of devices = " << numDevices << std::endl;
for (portaudio::System::DeviceIterator i = sys.devicesBegin(); i != sys.devicesEnd(); ++i)
{
std::cout << "--------------------------------------- device #" << (*i).index() << std::endl;
// Mark global and API specific default devices:
bool defaultDisplayed = false;
if ((*i).isSystemDefaultInputDevice())
{
std::cout << "[ Default Input";
defaultDisplayed = true;
}
else if ((*i).isHostApiDefaultInputDevice())
{
std::cout << "[ Default " << (*i).hostApi().name() << " Input";
defaultDisplayed = true;
}
if ((*i).isSystemDefaultOutputDevice())
{
std::cout << (defaultDisplayed ? "," : "[");
std::cout << " Default Output";
defaultDisplayed = true;
}
else if ((*i).isHostApiDefaultOutputDevice())
{
std::cout << (defaultDisplayed ? "," : "[");
std::cout << " Default " << (*i).hostApi().name() << " Output";
defaultDisplayed = true;
}
if (defaultDisplayed)
std::cout << " ]" << std::endl;
// Print device info:
std::cout << "Name = " << (*i).name() << 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
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
// ASIO specific latency information:
if ((*i).hostApi().typeId() == paASIO)
{
portaudio::AsioDeviceAdapter asioDevice((*i));
std::cout << "ASIO minimum buffer size = " << asioDevice.minBufferSize() << std::endl;
std::cout << "ASIO maximum buffer size = " << asioDevice.maxBufferSize() << std::endl;
std::cout << "ASIO preferred buffer size = " << asioDevice.preferredBufferSize() << std::endl;
if (asioDevice.granularity() == -1)
std::cout << "ASIO buffer granularity = power of 2" << std::endl;
else
std::cout << "ASIO buffer granularity = " << asioDevice.granularity() << std::endl;
}
#endif // WIN32
std::cout << "Default sample rate = " << (*i).defaultSampleRate() << std::endl; // 8.2
// Poll for standard sample rates:
portaudio::DirectionSpecificStreamParameters inputParameters((*i), (*i).maxInputChannels(), portaudio::INT16, true, 0.0, NULL);
portaudio::DirectionSpecificStreamParameters outputParameters((*i), (*i).maxOutputChannels(), portaudio::INT16, true, 0.0, NULL);
if (inputParameters.numChannels() > 0)
{
std::cout << "Supported standard sample rates" << std::endl;
std::cout << " for half-duplex 16 bit " << inputParameters.numChannels() << " channel input = " << std::endl;
printSupportedStandardSampleRates(inputParameters, portaudio::DirectionSpecificStreamParameters::null());
}
if (outputParameters.numChannels() > 0)
{
std::cout << "Supported standard sample rates" << std::endl;
std::cout << " for half-duplex 16 bit " << outputParameters.numChannels() << " channel output = " << std::endl;
printSupportedStandardSampleRates(portaudio::DirectionSpecificStreamParameters::null(), outputParameters);
}
if (inputParameters.numChannels() > 0 && outputParameters.numChannels() > 0)
{
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;
printSupportedStandardSampleRates(inputParameters, outputParameters);
}
}
std::cout << "----------------------------------------------" << std::endl;
}
catch (const portaudio::PaException &e)
{
std::cout << "A PortAudio error occurred: " << e.paErrorText() << std::endl;
}
catch (const portaudio::PaCppException &e)
{
std::cout << "A PortAudioCpp error occurred: " << e.what() << std::endl;
}
catch (const std::exception &e)
{
std::cout << "A generic exception occurred: " << e.what() << std::endl;
}
catch (...)
{
std::cout << "An unknown exception occurred." << std::endl;
}
return 0;
}
|