int main(int argc, char *argv[]) { int buffer_size, fs, device = 0; RtAudio *audio; double *data; char input; // minimal command-line checking if (argc != 3 && argc != 4 ) usage(); chans = (int) atoi(argv[1]); fs = (int) atoi(argv[2]); if ( argc == 4 ) device = (int) atoi(argv[3]); // Open the realtime output device buffer_size = 1024; try { audio = new RtAudio(device, chans, 0, 0, FORMAT, fs, &buffer_size, 4); } catch (RtError &error) { error.printMessage(); exit(EXIT_FAILURE); } data = (double *) calloc(chans, sizeof(double)); try { audio->setStreamCallback(&saw, (void *)data); audio->startStream(); } catch (RtError &error) { error.printMessage(); goto cleanup; } std::cout << "\nPlaying ... press <enter> to quit (buffer size = " << buffer_size << ").\n"; std::cin.get(input); // Stop the stream. try { audio->stopStream(); } catch (RtError &error) { error.printMessage(); } cleanup: audio->closeStream(); delete audio; if (data) free(data); return 0; }
int main(int argc, char *argv[]) { int chans, fs, device = 0; RtAudio *audio; char input; // minimal command-line checking if (argc != 3 && argc != 4 ) usage(); chans = (int) atoi(argv[1]); fs = (int) atoi(argv[2]); if ( argc == 4 ) device = (int) atoi(argv[3]); // Open the realtime output device int buffer_size = 512; try { audio = new RtAudio(device, chans, device, chans, FORMAT, fs, &buffer_size, 8); } catch (RtError &error) { error.printMessage(); exit(EXIT_FAILURE); } try { audio->setStreamCallback(&inout, NULL); audio->startStream(); } catch (RtError &error) { error.printMessage(); goto cleanup; } std::cout << "\nRunning ... press <enter> to quit (buffer size = " << buffer_size << ").\n"; std::cin.get(input); try { audio->stopStream(); } catch (RtError &error) { error.printMessage(); } cleanup: audio->closeStream(); delete audio; return 0; }
// entry point int main( int argc, char ** argv ) { // initialize GLUT glutInit( &argc, argv ); // double buffer, use rgb color, enable depth buffer glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); // initialize the window size glutInitWindowSize( g_width, g_height ); // set the window postion glutInitWindowPosition( 100, 100 ); // create the window glutCreateWindow( "VisualSine" ); // set the idle function - called when idle glutIdleFunc( idleFunc ); // set the display function - called when redrawing glutDisplayFunc( displayFunc ); // set the reshape function - called when client area changes glutReshapeFunc( reshapeFunc ); // set the keyboard function - called on keyboard events glutKeyboardFunc( keyboardFunc ); // set the mouse function - called on mouse stuff glutMouseFunc( mouseFunc ); // RtAudio pointer RtAudio * audio = NULL; // buffer size int buffer_size = 512; // create the RtAudio try { audio = new RtAudio( 0, // device number of output 1, // number of output channels 1, // device number for input 1, // number of input channels RTAUDIO_FLOAT64, // format MY_SRATE, // sample rate &buffer_size, // buffer size 8 // number of buffers ); } catch( RtError & err ) { err.printMessage(); exit(1); } // allocate global buffer g_buffer = new SAMPLE[buffer_size]; g_bufferSize = buffer_size; // set the callback try { audio->setStreamCallback( &callme, NULL ); audio->startStream(); } catch( RtError & err ) { // do stuff err.printMessage(); goto cleanup; } // let GLUT handle the current thread from here glutMainLoop(); // if we get here, then stop! try { audio->stopStream(); } catch( RtError & err ) { // do stuff err.printMessage(); } cleanup: audio->closeStream(); delete audio; return 0; }