Skip to content

Commit

Permalink
Updates to eguitar, ragamatic and examples project files for new RtAu…
Browse files Browse the repository at this point in the history
…dio API.
  • Loading branch information
garyscavone committed Aug 4, 2023
1 parent 7f97ab5 commit fd5e378
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 231 deletions.
1 change: 0 additions & 1 deletion projects/demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ int main( int argc, char *argv[] )
int i;

#if defined(__STK_REALTIME__)
//RtAudio dac( RtAudio::UNSPECIFIED );
RtAudio *dac = 0;
#endif

Expand Down
30 changes: 10 additions & 20 deletions projects/eguitar/eguitar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int main( int argc, char *argv[] )
int i;

#if defined(__STK_REALTIME__)
RtAudio dac;
RtAudio *dac = 0;
#endif

// If you want to change the default sample rate (set in Stk.h), do
Expand Down Expand Up @@ -294,16 +294,14 @@ int main( int argc, char *argv[] )
// If realtime output, allocate the dac here.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
dac = (RtAudio *) new RtAudio( RtAudio::UNSPECIFIED );
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
RtAudio::StreamParameters parameters;
parameters.deviceId = dac.getDefaultOutputDevice();
parameters.deviceId = dac->getDefaultOutputDevice();
parameters.nChannels = data.channels;
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
}
catch ( RtAudioError& error ) {
error.printMessage();
if ( dac->openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
std::cout << dac->getErrorText() << std::endl;
goto cleanup;
}
}
Expand Down Expand Up @@ -335,11 +333,8 @@ int main( int argc, char *argv[] )
// If realtime output, set our callback function and start the dac.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
try {
dac.startStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac->startStream() ) {
std::cout << dac->getErrorText() << std::endl;
goto cleanup;
}
}
Expand All @@ -359,21 +354,16 @@ int main( int argc, char *argv[] )

// Shut down the output stream.
#if defined(__STK_REALTIME__)
if ( data.realtime ) {
try {
dac.closeStream();
}
catch ( RtAudioError& error ) {
error.printMessage();
}
}
if ( data.realtime )
dac->closeStream();
#endif

cleanup:

for ( i=0; i<(int)data.nWvOuts; i++ ) delete data.wvout[i];
free( data.wvout );
delete data.guitar;
delete dac;

std::cout << "\nStk eguitar finished ... goodbye.\n\n";
return 0;
Expand Down
139 changes: 85 additions & 54 deletions projects/examples/audioprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,107 @@
#include <iostream>
#include <map>

int main()
{
// Create an api map.
std::map<int, std::string> apiMap;
apiMap[RtAudio::MACOSX_CORE] = "OS-X CoreAudio";
apiMap[RtAudio::WINDOWS_ASIO] = "Windows ASIO";
apiMap[RtAudio::WINDOWS_DS] = "Windows DirectSound";
apiMap[RtAudio::UNIX_JACK] = "Jack Client";
apiMap[RtAudio::LINUX_ALSA] = "Linux ALSA";
apiMap[RtAudio::LINUX_OSS] = "Linux OSS";
apiMap[RtAudio::RTAUDIO_DUMMY] = "RtAudio Dummy";
void usage( void ) {
// Error function in case of incorrect command-line
// argument specifications
std::cout << "\nuseage: audioprobe <apiname> <nRepeats>\n";
std::cout << " where apiname = an optional api (ex., 'core', default = all compiled),\n";
std::cout << " and nRepeats = an optional number of times to repeat the device query (default = 0),\n";
std::cout << " which can be used to test device (dis)connections.\n\n";
exit( 0 );
}

std::vector< RtAudio::Api > listApis()
{
std::vector< RtAudio::Api > apis;
RtAudio :: getCompiledApi( apis );

std::cout << "\nCompiled APIs:\n";
for ( unsigned int i=0; i<apis.size(); i++ )
std::cout << " " << apiMap[ apis[i] ] << std::endl;
for ( size_t i=0; i<apis.size(); i++ )
std::cout << i << ". " << RtAudio::getApiDisplayName(apis[i])
<< " (" << RtAudio::getApiName(apis[i]) << ")" << std::endl;

return apis;
}

RtAudio audio;
void listDevices( RtAudio& audio )
{
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::cout << "\nFound " << devices << " device(s) ...\n";
std::vector<unsigned int> devices = audio.getDeviceIds();
std::cout << "\nFound " << devices.size() << " device(s) ...\n";

for (unsigned int i=0; i<devices; i++) {
info = audio.getDeviceInfo(i);
for (unsigned int i=0; i<devices.size(); i++) {
info = audio.getDeviceInfo( devices[i] );

std::cout << "\nDevice Name = " << info.name << '\n';
if ( info.probed == false )
std::cout << "Probe Status = UNsuccessful\n";
std::cout << "Device Index = " << i << '\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 {
std::cout << "Probe Status = Successful\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 {
std::cout << "Natively supported data formats:\n";
if ( info.nativeFormats & RTAUDIO_SINT8 )
std::cout << " 8-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT16 )
std::cout << " 16-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT24 )
std::cout << " 24-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT32 )
std::cout << " 32-bit int\n";
if ( info.nativeFormats & RTAUDIO_FLOAT32 )
std::cout << " 32-bit float\n";
if ( info.nativeFormats & RTAUDIO_FLOAT64 )
std::cout << " 64-bit float\n";
}
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 << "Natively supported data formats:\n";
if ( info.nativeFormats & RTAUDIO_SINT8 )
std::cout << " 8-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT16 )
std::cout << " 16-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT24 )
std::cout << " 24-bit int\n";
if ( info.nativeFormats & RTAUDIO_SINT32 )
std::cout << " 32-bit int\n";
if ( info.nativeFormats & RTAUDIO_FLOAT32 )
std::cout << " 32-bit float\n";
if ( info.nativeFormats & RTAUDIO_FLOAT64 )
std::cout << " 64-bit float\n";
}
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;
if ( info.preferredSampleRate == 0 )
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);
}
}
std::cout << std::endl;
}
}
std::cout << std::endl;

return 0;
}
21 changes: 5 additions & 16 deletions projects/examples/bethree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ int main()
parameters.nChannels = 1;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
}
catch ( RtAudioError& error ) {
error.printMessage();
if ( dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

Expand All @@ -75,11 +72,8 @@ int main()
data.frequency = 220.0;
data.instrument->noteOn( data.frequency, 0.5 );

try {
dac.startStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac.startStream() ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

Expand All @@ -88,12 +82,7 @@ int main()
Stk::sleep( 100 );

// Shut down the callback and output stream.
try {
dac.closeStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
}
dac.closeStream();

cleanup:
delete data.instrument;
Expand Down
21 changes: 5 additions & 16 deletions projects/examples/controlbee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ int main( int argc, char *argv[] )
parameters.nChannels = 1;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data ) ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

Expand All @@ -149,11 +146,8 @@ int main( int argc, char *argv[] )
if ( data.messager.setScoreFile( argv[1] ) == false )
goto cleanup;

try {
dac.startStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac.startStream() ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

Expand All @@ -162,12 +156,7 @@ int main( int argc, char *argv[] )
Stk::sleep( 100 );

// Shut down the output stream.
try {
dac.closeStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
}
dac.closeStream();

cleanup:
delete data.instrument;
Expand Down
21 changes: 5 additions & 16 deletions projects/examples/crtsine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ int main()
parameters.nChannels = 1;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&sine );
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&sine ) ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

sine.setFrequency(440.0);

try {
dac.startStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
if ( dac.startStream() ) {
std::cout << dac.getErrorText() << std::endl;
goto cleanup;
}

Expand All @@ -57,12 +51,7 @@ int main()
std::cin.get( keyhit );

// Shut down the output stream.
try {
dac.closeStream();
}
catch ( RtAudioError &error ) {
error.printMessage();
}
dac.closeStream();

cleanup:

Expand Down
Loading

0 comments on commit fd5e378

Please sign in to comment.