summaryrefslogtreecommitdiff
path: root/tests/playsaw.cpp
diff options
context:
space:
mode:
authorGary Scavone <gary.scavone@mcgill.ca>2021-12-09 20:51:28 -0500
committerGary Scavone <gary.scavone@mcgill.ca>2021-12-09 20:51:28 -0500
commitae8ed073b30c58d3faccf815e80d7a46e10d33a3 (patch)
tree6c796217801bbcdbd61090a79a9831de2979d6b0 /tests/playsaw.cpp
parentf9fd8726ccb688baa43aaae642179a69d353f6d2 (diff)
API changes for new device selection/enumeration scheme, implemented only for the Core and Jack APIs.
Diffstat (limited to 'tests/playsaw.cpp')
-rw-r--r--tests/playsaw.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/playsaw.cpp b/tests/playsaw.cpp
index a9c7891..9dea11b 100644
--- a/tests/playsaw.cpp
+++ b/tests/playsaw.cpp
@@ -63,7 +63,7 @@ void usage( void ) {
std::cout << "\nuseage: playsaw N fs <device> <channelOffset> <time>\n";
std::cout << " where N = number of channels,\n";
std::cout << " fs = the sample rate,\n";
- std::cout << " device = optional device to use (default = 0),\n";
+ std::cout << " device = optional device index to use (default = 0),\n";
std::cout << " channelOffset = an optional channel offset on the device (default = 0),\n";
std::cout << " and time = an optional time duration in seconds (default = no limit).\n\n";
exit( 0 );
@@ -75,6 +75,21 @@ void errorCallback( RtAudioErrorType /*type*/, const std::string &errorText )
std::cerr << "\nerrorCallback: " << errorText << "\n\n";
}
+unsigned int getDeviceIndex( std::vector<std::string> deviceNames )
+{
+ unsigned int i;
+ std::string keyHit;
+ std::cout << '\n';
+ for ( i=0; i<deviceNames.size(); i++ )
+ std::cout << " Device #" << i << ": " << deviceNames[i] << '\n';
+ do {
+ std::cout << "\nChoose a device #: ";
+ std::cin >> i;
+ } while ( i >= deviceNames.size() );
+ std::getline( std::cin, keyHit ); // used to clear out stdin
+ return i;
+}
+
unsigned int channels;
RtAudio::StreamOptions options;
unsigned int frameCounter = 0;
@@ -160,8 +175,9 @@ int main( int argc, char *argv[] )
// Specify our own error callback function.
RtAudio dac( RtAudio::UNSPECIFIED, &errorCallback );
-
- if ( dac.getDeviceCount() < 1 ) {
+
+ std::vector<unsigned int> deviceIds = dac.getDeviceIds();
+ if ( deviceIds.size() < 1 ) {
std::cout << "\nNo audio devices found!\n";
exit( 1 );
}
@@ -186,12 +202,16 @@ int main( int argc, char *argv[] )
// Set our stream parameters for output only.
bufferFrames = 512;
RtAudio::StreamParameters oParams;
- oParams.deviceId = device;
oParams.nChannels = channels;
oParams.firstChannel = offset;
if ( device == 0 )
oParams.deviceId = dac.getDefaultOutputDevice();
+ else {
+ if ( device >= deviceIds.size() )
+ device = getDeviceIndex( dac.getDeviceNames() );
+ oParams.deviceId = deviceIds[device];
+ }
options.flags = RTAUDIO_HOG_DEVICE;
options.flags |= RTAUDIO_SCHEDULE_REALTIME;