mirror of
https://github.com/thestk/stk
synced 2026-01-12 20:41:52 +00:00
Updates to eguitar, ragamatic and examples project files for new RtAudio API.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/******************************************/
|
||||
/*
|
||||
duplex.cpp
|
||||
by Gary P. Scavone, 2006-2007.
|
||||
by Gary P. Scavone, 2006-2019.
|
||||
|
||||
This program opens a duplex stream and passes
|
||||
input directly through to the output.
|
||||
@@ -14,24 +14,26 @@
|
||||
#include <cstring>
|
||||
|
||||
/*
|
||||
typedef signed long MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT24
|
||||
|
||||
typedef char MY_TYPE;
|
||||
typedef char MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT8
|
||||
|
||||
typedef signed short MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT16
|
||||
|
||||
typedef signed long MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT32
|
||||
|
||||
typedef float MY_TYPE;
|
||||
#define FORMAT RTAUDIO_FLOAT32
|
||||
*/
|
||||
|
||||
typedef double MY_TYPE;
|
||||
typedef signed short MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT16
|
||||
|
||||
/*
|
||||
typedef S24 MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT24
|
||||
|
||||
typedef signed long MY_TYPE;
|
||||
#define FORMAT RTAUDIO_SINT32
|
||||
|
||||
typedef float MY_TYPE;
|
||||
#define FORMAT RTAUDIO_FLOAT32
|
||||
|
||||
typedef double MY_TYPE;
|
||||
#define FORMAT RTAUDIO_FLOAT64
|
||||
*/
|
||||
|
||||
void usage( void ) {
|
||||
// Error function in case of incorrect command-line
|
||||
@@ -39,26 +41,52 @@ void usage( void ) {
|
||||
std::cout << "\nuseage: duplex N fs <iDevice> <oDevice> <iChannelOffset> <oChannelOffset>\n";
|
||||
std::cout << " where N = number of channels,\n";
|
||||
std::cout << " fs = the sample rate,\n";
|
||||
std::cout << " iDevice = optional input device to use (default = 0),\n";
|
||||
std::cout << " oDevice = optional output device to use (default = 0),\n";
|
||||
std::cout << " iDevice = optional input device index to use (default = 0),\n";
|
||||
std::cout << " oDevice = optional output device index to use (default = 0),\n";
|
||||
std::cout << " iChannelOffset = an optional input channel offset (default = 0),\n";
|
||||
std::cout << " and oChannelOffset = optional output channel offset (default = 0).\n\n";
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
|
||||
unsigned int getDeviceIndex( std::vector<std::string> deviceNames, bool isInput = false )
|
||||
{
|
||||
unsigned int i;
|
||||
std::string keyHit;
|
||||
std::cout << '\n';
|
||||
for ( i=0; i<deviceNames.size(); i++ )
|
||||
std::cout << " Device #" << i << ": " << deviceNames[i] << '\n';
|
||||
do {
|
||||
if ( isInput )
|
||||
std::cout << "\nChoose an input device #: ";
|
||||
else
|
||||
std::cout << "\nChoose an output device #: ";
|
||||
std::cin >> i;
|
||||
} while ( i >= deviceNames.size() );
|
||||
std::getline( std::cin, keyHit ); // used to clear out stdin
|
||||
return i;
|
||||
}
|
||||
|
||||
double streamTimePrintIncrement = 1.0; // seconds
|
||||
double streamTimePrintTime = 1.0; // seconds
|
||||
|
||||
int inout( void *outputBuffer, void *inputBuffer, unsigned int /*nBufferFrames*/,
|
||||
double streamTime, RtAudioStreamStatus status, void *data )
|
||||
{
|
||||
// Since the number of input and output channels is equal, we can do
|
||||
// a simple buffer copy operation here.
|
||||
if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
|
||||
|
||||
unsigned long *bytes = (unsigned long *) data;
|
||||
if ( streamTime >= streamTimePrintTime ) {
|
||||
std::cout << "streamTime = " << streamTime << std::endl;
|
||||
streamTimePrintTime += streamTimePrintIncrement;
|
||||
}
|
||||
|
||||
unsigned int *bytes = (unsigned int *) data;
|
||||
memcpy( outputBuffer, inputBuffer, *bytes );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
unsigned int channels, fs, bufferBytes, oDevice = 0, iDevice = 0, iOffset = 0, oOffset = 0;
|
||||
|
||||
@@ -66,9 +94,10 @@ int main(int argc, char *argv[])
|
||||
if (argc < 3 || argc > 7 ) usage();
|
||||
|
||||
RtAudio adac;
|
||||
if ( adac.getDeviceCount() < 1 ) {
|
||||
std::vector<unsigned int> deviceIds = adac.getDeviceIds();
|
||||
if ( deviceIds.size() < 1 ) {
|
||||
std::cout << "\nNo audio devices found!\n";
|
||||
exit( 0 );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
channels = (unsigned int) atoi(argv[1]);
|
||||
@@ -88,48 +117,48 @@ int main(int argc, char *argv[])
|
||||
// Set the same number of channels for both input and output.
|
||||
unsigned int bufferFrames = 512;
|
||||
RtAudio::StreamParameters iParams, oParams;
|
||||
if ( iDevice == 0 )
|
||||
iParams.deviceId = adac.getDefaultInputDevice();
|
||||
else
|
||||
iParams.deviceId = iDevice - 1;
|
||||
iParams.nChannels = channels;
|
||||
iParams.firstChannel = iOffset;
|
||||
if ( oDevice == 0 )
|
||||
oParams.deviceId = adac.getDefaultOutputDevice();
|
||||
else
|
||||
oParams.deviceId = oDevice - 1;
|
||||
oParams.nChannels = channels;
|
||||
oParams.firstChannel = oOffset;
|
||||
|
||||
if ( iDevice == 0 )
|
||||
iParams.deviceId = adac.getDefaultInputDevice();
|
||||
else {
|
||||
if ( iDevice >= deviceIds.size() )
|
||||
iDevice = getDeviceIndex( adac.getDeviceNames(), true );
|
||||
iParams.deviceId = deviceIds[iDevice];
|
||||
}
|
||||
if ( oDevice == 0 )
|
||||
oParams.deviceId = adac.getDefaultOutputDevice();
|
||||
else {
|
||||
if ( oDevice >= deviceIds.size() )
|
||||
oDevice = getDeviceIndex( adac.getDeviceNames() );
|
||||
oParams.deviceId = deviceIds[oDevice];
|
||||
}
|
||||
|
||||
RtAudio::StreamOptions options;
|
||||
//options.flags |= RTAUDIO_NONINTERLEAVED;
|
||||
|
||||
bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
|
||||
try {
|
||||
adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
|
||||
}
|
||||
catch ( RtAudioError& e ) {
|
||||
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
|
||||
exit( 1 );
|
||||
if ( adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options ) ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( adac.isStreamOpen() == false ) goto cleanup;
|
||||
|
||||
// Test RtAudio functionality for reporting latency.
|
||||
std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
|
||||
|
||||
try {
|
||||
adac.startStream();
|
||||
if ( adac.startStream() ) goto cleanup;
|
||||
|
||||
char input;
|
||||
std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
|
||||
std::cin.get(input);
|
||||
char input;
|
||||
std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
|
||||
std::cin.get(input);
|
||||
|
||||
// Stop the stream.
|
||||
// Stop the stream.
|
||||
if ( adac.isStreamRunning() )
|
||||
adac.stopStream();
|
||||
}
|
||||
catch ( RtAudioError& e ) {
|
||||
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if ( adac.isStreamOpen() ) adac.closeStream();
|
||||
|
||||
Reference in New Issue
Block a user