mirror of
https://github.com/thestk/stk
synced 2026-02-07 01:36:16 +00:00
Updates to eguitar, ragamatic and examples project files for new RtAudio API.
This commit is contained in:
@@ -203,7 +203,6 @@ int main( int argc, char *argv[] )
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
#if defined(__STK_REALTIME__)
|
#if defined(__STK_REALTIME__)
|
||||||
//RtAudio dac( RtAudio::UNSPECIFIED );
|
|
||||||
RtAudio *dac = 0;
|
RtAudio *dac = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ int main( int argc, char *argv[] )
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
#if defined(__STK_REALTIME__)
|
#if defined(__STK_REALTIME__)
|
||||||
RtAudio dac;
|
RtAudio *dac = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If you want to change the default sample rate (set in Stk.h), do
|
// If you want to change the default sample rate (set in Stk.h), do
|
||||||
@@ -294,16 +294,14 @@ int main( int argc, char *argv[] )
|
|||||||
// If realtime output, allocate the dac here.
|
// If realtime output, allocate the dac here.
|
||||||
#if defined(__STK_REALTIME__)
|
#if defined(__STK_REALTIME__)
|
||||||
if ( data.realtime ) {
|
if ( data.realtime ) {
|
||||||
|
dac = (RtAudio *) new RtAudio( RtAudio::UNSPECIFIED );
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
RtAudio::StreamParameters parameters;
|
RtAudio::StreamParameters parameters;
|
||||||
parameters.deviceId = dac.getDefaultOutputDevice();
|
parameters.deviceId = dac->getDefaultOutputDevice();
|
||||||
parameters.nChannels = data.channels;
|
parameters.nChannels = data.channels;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac->openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << dac->getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,11 +333,8 @@ int main( int argc, char *argv[] )
|
|||||||
// If realtime output, set our callback function and start the dac.
|
// If realtime output, set our callback function and start the dac.
|
||||||
#if defined(__STK_REALTIME__)
|
#if defined(__STK_REALTIME__)
|
||||||
if ( data.realtime ) {
|
if ( data.realtime ) {
|
||||||
try {
|
if ( dac->startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac->getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,14 +354,8 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
// Shut down the output stream.
|
// Shut down the output stream.
|
||||||
#if defined(__STK_REALTIME__)
|
#if defined(__STK_REALTIME__)
|
||||||
if ( data.realtime ) {
|
if ( data.realtime )
|
||||||
try {
|
dac->closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@@ -374,6 +363,7 @@ int main( int argc, char *argv[] )
|
|||||||
for ( i=0; i<(int)data.nWvOuts; i++ ) delete data.wvout[i];
|
for ( i=0; i<(int)data.nWvOuts; i++ ) delete data.wvout[i];
|
||||||
free( data.wvout );
|
free( data.wvout );
|
||||||
delete data.guitar;
|
delete data.guitar;
|
||||||
|
delete dac;
|
||||||
|
|
||||||
std::cout << "\nStk eguitar finished ... goodbye.\n\n";
|
std::cout << "\nStk eguitar finished ... goodbye.\n\n";
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -11,76 +11,107 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
int main()
|
void usage( void ) {
|
||||||
{
|
// Error function in case of incorrect command-line
|
||||||
// Create an api map.
|
// argument specifications
|
||||||
std::map<int, std::string> apiMap;
|
std::cout << "\nuseage: audioprobe <apiname> <nRepeats>\n";
|
||||||
apiMap[RtAudio::MACOSX_CORE] = "OS-X CoreAudio";
|
std::cout << " where apiname = an optional api (ex., 'core', default = all compiled),\n";
|
||||||
apiMap[RtAudio::WINDOWS_ASIO] = "Windows ASIO";
|
std::cout << " and nRepeats = an optional number of times to repeat the device query (default = 0),\n";
|
||||||
apiMap[RtAudio::WINDOWS_DS] = "Windows DirectSound";
|
std::cout << " which can be used to test device (dis)connections.\n\n";
|
||||||
apiMap[RtAudio::UNIX_JACK] = "Jack Client";
|
exit( 0 );
|
||||||
apiMap[RtAudio::LINUX_ALSA] = "Linux ALSA";
|
}
|
||||||
apiMap[RtAudio::LINUX_OSS] = "Linux OSS";
|
|
||||||
apiMap[RtAudio::RTAUDIO_DUMMY] = "RtAudio Dummy";
|
|
||||||
|
|
||||||
|
std::vector< RtAudio::Api > listApis()
|
||||||
|
{
|
||||||
std::vector< RtAudio::Api > apis;
|
std::vector< RtAudio::Api > apis;
|
||||||
RtAudio :: getCompiledApi( apis );
|
RtAudio :: getCompiledApi( apis );
|
||||||
|
|
||||||
std::cout << "\nCompiled APIs:\n";
|
std::cout << "\nCompiled APIs:\n";
|
||||||
for ( unsigned int i=0; i<apis.size(); i++ )
|
for ( size_t i=0; i<apis.size(); i++ )
|
||||||
std::cout << " " << apiMap[ apis[i] ] << std::endl;
|
std::cout << i << ". " << RtAudio::getApiDisplayName(apis[i])
|
||||||
|
<< " (" << RtAudio::getApiName(apis[i]) << ")" << std::endl;
|
||||||
|
|
||||||
RtAudio audio;
|
return apis;
|
||||||
|
}
|
||||||
|
|
||||||
|
void listDevices( RtAudio& audio )
|
||||||
|
{
|
||||||
RtAudio::DeviceInfo info;
|
RtAudio::DeviceInfo info;
|
||||||
|
|
||||||
std::cout << "\nCurrent API: " << apiMap[ audio.getCurrentApi() ] << std::endl;
|
std::cout << "\nAPI: " << RtAudio::getApiDisplayName(audio.getCurrentApi()) << std::endl;
|
||||||
|
|
||||||
unsigned int devices = audio.getDeviceCount();
|
std::vector<unsigned int> devices = audio.getDeviceIds();
|
||||||
std::cout << "\nFound " << devices << " device(s) ...\n";
|
std::cout << "\nFound " << devices.size() << " device(s) ...\n";
|
||||||
|
|
||||||
for (unsigned int i=0; i<devices; i++) {
|
for (unsigned int i=0; i<devices.size(); i++) {
|
||||||
info = audio.getDeviceInfo(i);
|
info = audio.getDeviceInfo( devices[i] );
|
||||||
|
|
||||||
std::cout << "\nDevice Name = " << info.name << '\n';
|
std::cout << "\nDevice Name = " << info.name << '\n';
|
||||||
if ( info.probed == false )
|
std::cout << "Device Index = " << i << '\n';
|
||||||
std::cout << "Probe Status = UNsuccessful\n";
|
std::cout << "Output Channels = " << info.outputChannels << '\n';
|
||||||
|
std::cout << "Input Channels = " << info.inputChannels << '\n';
|
||||||
|
std::cout << "Duplex Channels = " << info.duplexChannels << '\n';
|
||||||
|
if ( info.isDefaultOutput ) std::cout << "This is the default output device.\n";
|
||||||
|
else std::cout << "This is NOT the default output device.\n";
|
||||||
|
if ( info.isDefaultInput ) std::cout << "This is the default input device.\n";
|
||||||
|
else std::cout << "This is NOT the default input device.\n";
|
||||||
|
if ( info.nativeFormats == 0 )
|
||||||
|
std::cout << "No natively supported data formats(?)!";
|
||||||
else {
|
else {
|
||||||
std::cout << "Probe Status = Successful\n";
|
std::cout << "Natively supported data formats:\n";
|
||||||
std::cout << "Output Channels = " << info.outputChannels << '\n';
|
if ( info.nativeFormats & RTAUDIO_SINT8 )
|
||||||
std::cout << "Input Channels = " << info.inputChannels << '\n';
|
std::cout << " 8-bit int\n";
|
||||||
std::cout << "Duplex Channels = " << info.duplexChannels << '\n';
|
if ( info.nativeFormats & RTAUDIO_SINT16 )
|
||||||
if ( info.isDefaultOutput ) std::cout << "This is the default output device.\n";
|
std::cout << " 16-bit int\n";
|
||||||
else std::cout << "This is NOT the default output device.\n";
|
if ( info.nativeFormats & RTAUDIO_SINT24 )
|
||||||
if ( info.isDefaultInput ) std::cout << "This is the default input device.\n";
|
std::cout << " 24-bit int\n";
|
||||||
else std::cout << "This is NOT the default input device.\n";
|
if ( info.nativeFormats & RTAUDIO_SINT32 )
|
||||||
if ( info.nativeFormats == 0 )
|
std::cout << " 32-bit int\n";
|
||||||
std::cout << "No natively supported data formats(?)!";
|
if ( info.nativeFormats & RTAUDIO_FLOAT32 )
|
||||||
else {
|
std::cout << " 32-bit float\n";
|
||||||
std::cout << "Natively supported data formats:\n";
|
if ( info.nativeFormats & RTAUDIO_FLOAT64 )
|
||||||
if ( info.nativeFormats & RTAUDIO_SINT8 )
|
std::cout << " 64-bit float\n";
|
||||||
std::cout << " 8-bit int\n";
|
}
|
||||||
if ( info.nativeFormats & RTAUDIO_SINT16 )
|
if ( info.sampleRates.size() < 1 )
|
||||||
std::cout << " 16-bit int\n";
|
std::cout << "No supported sample rates found!";
|
||||||
if ( info.nativeFormats & RTAUDIO_SINT24 )
|
else {
|
||||||
std::cout << " 24-bit int\n";
|
std::cout << "Supported sample rates = ";
|
||||||
if ( info.nativeFormats & RTAUDIO_SINT32 )
|
for (unsigned int j=0; j<info.sampleRates.size(); j++)
|
||||||
std::cout << " 32-bit int\n";
|
std::cout << info.sampleRates[j] << " ";
|
||||||
if ( info.nativeFormats & RTAUDIO_FLOAT32 )
|
}
|
||||||
std::cout << " 32-bit float\n";
|
std::cout << std::endl;
|
||||||
if ( info.nativeFormats & RTAUDIO_FLOAT64 )
|
if ( info.preferredSampleRate == 0 )
|
||||||
std::cout << " 64-bit float\n";
|
std::cout << "No preferred sample rate found!" << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "Preferred sample rate = " << info.preferredSampleRate << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
std::cout << "\nRtAudio Version " << RtAudio::getVersion() << std::endl;
|
||||||
|
|
||||||
|
std::vector< RtAudio::Api > apis = listApis();
|
||||||
|
|
||||||
|
// minimal command-line checking
|
||||||
|
if (argc > 3 ) usage();
|
||||||
|
unsigned int nRepeats = 0;
|
||||||
|
if ( argc > 2 ) nRepeats = (unsigned int) atoi( argv[2] );
|
||||||
|
|
||||||
|
char input;
|
||||||
|
for ( size_t api=0; api < apis.size(); api++ ) {
|
||||||
|
if (argc < 2 || apis[api] == RtAudio::getCompiledApiByName(argv[1]) ) {
|
||||||
|
RtAudio audio(apis[api]);
|
||||||
|
for ( size_t n=0; n <= nRepeats; n++ ) {
|
||||||
|
listDevices(audio);
|
||||||
|
if ( n < nRepeats ) {
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "\nWaiting ... press <enter> to repeat.\n";
|
||||||
|
std::cin.get(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( info.sampleRates.size() < 1 )
|
|
||||||
std::cout << "No supported sample rates found!";
|
|
||||||
else {
|
|
||||||
std::cout << "Supported sample rates = ";
|
|
||||||
for (unsigned int j=0; j<info.sampleRates.size(); j++)
|
|
||||||
std::cout << info.sampleRates[j] << " ";
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,8 @@ int main()
|
|||||||
parameters.nChannels = 1;
|
parameters.nChannels = 1;
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +72,8 @@ int main()
|
|||||||
data.frequency = 220.0;
|
data.frequency = 220.0;
|
||||||
data.instrument->noteOn( data.frequency, 0.5 );
|
data.instrument->noteOn( data.frequency, 0.5 );
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +82,7 @@ int main()
|
|||||||
Stk::sleep( 100 );
|
Stk::sleep( 100 );
|
||||||
|
|
||||||
// Shut down the callback and output stream.
|
// Shut down the callback and output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
delete data.instrument;
|
delete data.instrument;
|
||||||
|
|||||||
@@ -130,11 +130,8 @@ int main( int argc, char *argv[] )
|
|||||||
parameters.nChannels = 1;
|
parameters.nChannels = 1;
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,11 +146,8 @@ int main( int argc, char *argv[] )
|
|||||||
if ( data.messager.setScoreFile( argv[1] ) == false )
|
if ( data.messager.setScoreFile( argv[1] ) == false )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,12 +156,7 @@ int main( int argc, char *argv[] )
|
|||||||
Stk::sleep( 100 );
|
Stk::sleep( 100 );
|
||||||
|
|
||||||
// Shut down the output stream.
|
// Shut down the output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
delete data.instrument;
|
delete data.instrument;
|
||||||
|
|||||||
@@ -33,21 +33,15 @@ int main()
|
|||||||
parameters.nChannels = 1;
|
parameters.nChannels = 1;
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&sine ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&sine );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
sine.setFrequency(440.0);
|
sine.setFrequency(440.0);
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,12 +51,7 @@ int main()
|
|||||||
std::cin.get( keyhit );
|
std::cin.get( keyhit );
|
||||||
|
|
||||||
// Shut down the output stream.
|
// Shut down the output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/******************************************/
|
/******************************************/
|
||||||
/*
|
/*
|
||||||
duplex.cpp
|
duplex.cpp
|
||||||
by Gary P. Scavone, 2006-2007.
|
by Gary P. Scavone, 2006-2019.
|
||||||
|
|
||||||
This program opens a duplex stream and passes
|
This program opens a duplex stream and passes
|
||||||
input directly through to the output.
|
input directly through to the output.
|
||||||
@@ -14,24 +14,26 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
typedef signed long MY_TYPE;
|
typedef char MY_TYPE;
|
||||||
#define FORMAT RTAUDIO_SINT24
|
|
||||||
|
|
||||||
typedef char MY_TYPE;
|
|
||||||
#define FORMAT RTAUDIO_SINT8
|
#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
|
#define FORMAT RTAUDIO_FLOAT64
|
||||||
|
*/
|
||||||
|
|
||||||
void usage( void ) {
|
void usage( void ) {
|
||||||
// Error function in case of incorrect command-line
|
// 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 << "\nuseage: duplex N fs <iDevice> <oDevice> <iChannelOffset> <oChannelOffset>\n";
|
||||||
std::cout << " where N = number of channels,\n";
|
std::cout << " where N = number of channels,\n";
|
||||||
std::cout << " fs = the sample rate,\n";
|
std::cout << " fs = the sample rate,\n";
|
||||||
std::cout << " iDevice = optional input device to use (default = 0),\n";
|
std::cout << " iDevice = optional input device index to use (default = 0),\n";
|
||||||
std::cout << " oDevice = optional output device 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 << " iChannelOffset = an optional input channel offset (default = 0),\n";
|
||||||
std::cout << " and oChannelOffset = optional output channel offset (default = 0).\n\n";
|
std::cout << " and oChannelOffset = optional output channel offset (default = 0).\n\n";
|
||||||
exit( 0 );
|
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 )
|
double streamTime, RtAudioStreamStatus status, void *data )
|
||||||
{
|
{
|
||||||
// Since the number of input and output channels is equal, we can do
|
// Since the number of input and output channels is equal, we can do
|
||||||
// a simple buffer copy operation here.
|
// a simple buffer copy operation here.
|
||||||
if ( status ) std::cout << "Stream over/underflow detected." << std::endl;
|
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 );
|
memcpy( outputBuffer, inputBuffer, *bytes );
|
||||||
return 0;
|
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;
|
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();
|
if (argc < 3 || argc > 7 ) usage();
|
||||||
|
|
||||||
RtAudio adac;
|
RtAudio adac;
|
||||||
if ( adac.getDeviceCount() < 1 ) {
|
std::vector<unsigned int> deviceIds = adac.getDeviceIds();
|
||||||
|
if ( deviceIds.size() < 1 ) {
|
||||||
std::cout << "\nNo audio devices found!\n";
|
std::cout << "\nNo audio devices found!\n";
|
||||||
exit( 0 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
channels = (unsigned int) atoi(argv[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.
|
// Set the same number of channels for both input and output.
|
||||||
unsigned int bufferFrames = 512;
|
unsigned int bufferFrames = 512;
|
||||||
RtAudio::StreamParameters iParams, oParams;
|
RtAudio::StreamParameters iParams, oParams;
|
||||||
if ( iDevice == 0 )
|
|
||||||
iParams.deviceId = adac.getDefaultInputDevice();
|
|
||||||
else
|
|
||||||
iParams.deviceId = iDevice - 1;
|
|
||||||
iParams.nChannels = channels;
|
iParams.nChannels = channels;
|
||||||
iParams.firstChannel = iOffset;
|
iParams.firstChannel = iOffset;
|
||||||
if ( oDevice == 0 )
|
|
||||||
oParams.deviceId = adac.getDefaultOutputDevice();
|
|
||||||
else
|
|
||||||
oParams.deviceId = oDevice - 1;
|
|
||||||
oParams.nChannels = channels;
|
oParams.nChannels = channels;
|
||||||
oParams.firstChannel = oOffset;
|
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;
|
RtAudio::StreamOptions options;
|
||||||
//options.flags |= RTAUDIO_NONINTERLEAVED;
|
//options.flags |= RTAUDIO_NONINTERLEAVED;
|
||||||
|
|
||||||
bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
|
bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
|
||||||
try {
|
if ( adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options ) ) {
|
||||||
adac.openStream( &oParams, &iParams, FORMAT, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
|
goto cleanup;
|
||||||
}
|
|
||||||
catch ( RtAudioError& e ) {
|
|
||||||
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
|
|
||||||
exit( 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( adac.isStreamOpen() == false ) goto cleanup;
|
||||||
|
|
||||||
// Test RtAudio functionality for reporting latency.
|
// Test RtAudio functionality for reporting latency.
|
||||||
std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
|
std::cout << "\nStream latency = " << adac.getStreamLatency() << " frames" << std::endl;
|
||||||
|
|
||||||
try {
|
if ( adac.startStream() ) goto cleanup;
|
||||||
adac.startStream();
|
|
||||||
|
|
||||||
char input;
|
char input;
|
||||||
std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
|
std::cout << "\nRunning ... press <enter> to quit (buffer frames = " << bufferFrames << ").\n";
|
||||||
std::cin.get(input);
|
std::cin.get(input);
|
||||||
|
|
||||||
// Stop the stream.
|
// Stop the stream.
|
||||||
|
if ( adac.isStreamRunning() )
|
||||||
adac.stopStream();
|
adac.stopStream();
|
||||||
}
|
|
||||||
catch ( RtAudioError& e ) {
|
|
||||||
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if ( adac.isStreamOpen() ) adac.closeStream();
|
if ( adac.isStreamOpen() ) adac.closeStream();
|
||||||
|
|||||||
@@ -79,35 +79,23 @@ int main( int argc, char *argv[] )
|
|||||||
parameters.nChannels = grani.channelsOut();
|
parameters.nChannels = grani.channelsOut();
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&grani ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&grani );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Block waiting here.
|
// Block waiting here.
|
||||||
char keyhit;
|
char keyhit;
|
||||||
std::cout << "\nPlaying ... press <enter> to quit.\n";
|
std::cout << "\nPlaying ... press <enter> to quit.\n";
|
||||||
std::cin.get( keyhit );
|
std::cin.get( keyhit );
|
||||||
|
|
||||||
// Shut down the callback and output stream.
|
// Shut down the callback and output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
|
|||||||
@@ -99,11 +99,8 @@ int main(int argc, char *argv[])
|
|||||||
parameters.nChannels = ( channels == 1 ) ? 2 : channels; // Play mono files as stereo.
|
parameters.nChannels = ( channels == 1 ) ? 2 : channels; // Play mono files as stereo.
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&input ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&input );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,11 +110,8 @@ int main(int argc, char *argv[])
|
|||||||
// Resize the StkFrames object appropriately.
|
// Resize the StkFrames object appropriately.
|
||||||
frames.resize( bufferFrames, channels );
|
frames.resize( bufferFrames, channels );
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,12 +121,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// By returning a non-zero value in the callback above, the stream
|
// By returning a non-zero value in the callback above, the stream
|
||||||
// is automatically stopped. But we should still close it.
|
// is automatically stopped. But we should still close it.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -130,11 +130,8 @@ int main()
|
|||||||
parameters.nChannels = 1;
|
parameters.nChannels = 1;
|
||||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,11 +151,8 @@ int main()
|
|||||||
if ( data.messager.startStdInput() == false )
|
if ( data.messager.startStdInput() == false )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,12 +161,7 @@ int main()
|
|||||||
Stk::sleep( 100 );
|
Stk::sleep( 100 );
|
||||||
|
|
||||||
// Shut down the callback and output stream.
|
// Shut down the callback and output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for ( i=0; i<3; i++ ) delete instrument[i];
|
for ( i=0; i<3; i++ ) delete instrument[i];
|
||||||
|
|||||||
@@ -291,11 +291,8 @@ int main( int argc, char *argv[] )
|
|||||||
parameters.deviceId = dac.getDefaultOutputDevice();
|
parameters.deviceId = dac.getDefaultOutputDevice();
|
||||||
parameters.nChannels = 2;
|
parameters.nChannels = 2;
|
||||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||||
try {
|
if ( dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
|
||||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,11 +311,8 @@ int main( int argc, char *argv[] )
|
|||||||
(void) signal( SIGINT, finish );
|
(void) signal( SIGINT, finish );
|
||||||
|
|
||||||
// If realtime output, set our callback function and start the dac.
|
// If realtime output, set our callback function and start the dac.
|
||||||
try {
|
if ( dac.startStream() ) {
|
||||||
dac.startStream();
|
std::cout << dac.getErrorText() << std::endl;
|
||||||
}
|
|
||||||
catch ( RtAudioError &error ) {
|
|
||||||
error.printMessage();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,15 +323,9 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shut down the output stream.
|
// Shut down the output stream.
|
||||||
try {
|
dac.closeStream();
|
||||||
dac.closeStream();
|
|
||||||
}
|
|
||||||
catch ( RtAudioError& error ) {
|
|
||||||
error.printMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user