/* Minc function that sets output sampling rate (p0), maximum number of output channels (p1), and (optionally) I/O buffer size (p2). On SGI, the optional p3 lets you specify the output port as a string (e.g., "LINE", "DIGITAL", etc.). Based on this information, rtsetparams allocates a mono output buffer for each of the output channels, and opens output devices. */ double RTcmix::mm_rtsetparams(float sr, int nchans, int vecsize, float *mm_inbuf, float *mm_outbuf, char *mm_errbuf) { int i, status; int verbose = Option::print(); int play_audio = Option::play(); int record_audio = Option::record(true); #ifdef SGI static char *out_port_str = NULL; #endif /* SGI */ // BGG mm -- take this out to allow for resetting audio in maxmsp /* if (rtsetparams_called) { die("rtsetparams", "You can only call rtsetparams once!"); return -1; } */ // FIXME: Need better names for NCHANS and RTBUFSAMPS. -JGG // BGG mm SR = sr; NCHANS = nchans; RTBUFSAMPS = vecsize; maxmsp_inbuf = mm_inbuf; // passed in from max/msp via maxmsp_rtsetparams() maxmsp_outbuf = mm_outbuf; // passed in from max/msp via maxmsp_rtsetparams() maxmsp_errbuf = mm_errbuf; // passed in from max/msp via maxmsp_rtsetparams() int numBuffers = Option::bufferCount(); // BGG mm // if (n_args > 3 && pp[3] != 0.0) { #ifdef SGI /* Cast Minc double to char ptr to get string. */ int iarg = (int) pp[3]; out_port_str = (char *) iarg; rtcmix_advise("rtsetparams", "Playing through output port '%s'", out_port_str); #endif /* SGI */ // } if (SR <= 0.0) { die("rtsetparams", "Sampling rate must be greater than 0."); return -1; } if (NCHANS > MAXBUS) { die("rtsetparams", "You can only have up to %d output channels.", MAXBUS - 1); return -1; } /* play_audio is true unless user has called set_option("audio_off") before rtsetparams. This would let user run multiple jobs, as long as only one needs the audio drivers. -JGG record_audio is false unless user has called set_option("full_duplex_on") or has explicity turned record on by itself via set_option("record_on"), or has already called rtinput("AUDIO"). -DS */ if (play_audio || record_audio) { int nframes = RTBUFSAMPS; if (create_audio_devices(record_audio, play_audio, NCHANS, SR, &nframes, numBuffers) < 0) return -1; /* This may have been reset by driver. */ RTBUFSAMPS = nframes; } /* inTraverse waits for this. Set it even if play_audio is false! */ pthread_mutex_lock(&audio_config_lock); audio_config = 1; pthread_mutex_unlock(&audio_config_lock); if (verbose) post("rtcmix~: Audio set: %g sampling rate, %d channels\n", SR, NCHANS); /* Allocate output buffers. Do this *after* opening audio devices, in case OSS changes our buffer size, for example. */ for (i = 0; i < NCHANS; i++) { allocate_out_buffer(i, RTBUFSAMPS); } rtsetparams_called = 1; /* Put this at end to allow re-call due to error */ return 0; }
/* Minc function that sets output sampling rate (p0), maximum number of output channels (p1), and (optionally) I/O buffer size (p2). On SGI, the optional p3 lets you specify the output port as a string (e.g., "LINE", "DIGITAL", etc.). Based on this information, rtsetparams allocates a mono output buffer for each of the output channels, and opens output devices. */ double RTcmix::rtsetparams(float p[], int n_args, double pp[]) { int i, status; int verbose = Option::print(); int play_audio = Option::play(); int record_audio = Option::record(); #ifdef SGI static char *out_port_str = NULL; #endif /* SGI */ if (rtsetparams_was_called()) { die("rtsetparams", "You can only call rtsetparams once!"); return -1; } // FIXME: Need better names for NCHANS and RTBUFSAMPS. -JGG SR = p[0]; NCHANS = (int) p[1]; RTBUFSAMPS = n_args > 2 ? (int) p[2] : (int) Option::bufferFrames(); int numBuffers = Option::bufferCount(); if (n_args > 3 && pp[3] != 0.0) { #ifdef SGI /* Cast Minc double to char ptr to get string. */ int iarg = (int) pp[3]; out_port_str = (char *) iarg; advise("rtsetparams", "Playing through output port '%s'", out_port_str); #endif /* SGI */ } if (SR <= 0.0) { die("rtsetparams", "Sampling rate must be greater than 0."); return -1; } if (NCHANS > MAXBUS) { die("rtsetparams", "You can only have up to %d output channels.", MAXBUS - 1); return -1; } /* play_audio is true unless user has called set_option("audio_off") before rtsetparams. This would let user run multiple jobs, as long as only one needs the audio drivers. -JGG record_audio is false unless user has called set_option("full_duplex_on") or has explicity turned record on by itself via set_option("record_on"), or has already called rtinput("AUDIO"). -DS */ if (play_audio || record_audio) { int nframes = RTBUFSAMPS; if ((audioDevice = create_audio_devices(record_audio, play_audio, NCHANS, SR, &nframes, numBuffers)) == NULL) return -1; /* This may have been reset by driver. */ RTBUFSAMPS = nframes; } /* inTraverse waits for this. Set it even if play_audio is false! */ pthread_mutex_lock(&audio_config_lock); audio_config = 1; pthread_mutex_unlock(&audio_config_lock); if (verbose) printf("Audio set: %g sampling rate, %d channels\n", SR, NCHANS); /* Allocate output buffers. Do this *after* opening audio devices, in case OSS changes our buffer size, for example. */ for (i = 0; i < NCHANS; i++) { allocate_out_buffer(i, RTBUFSAMPS); } #ifdef MULTI_THREAD InputFile::createConversionBuffers(RTBUFSAMPS); #endif rtsetparams_called = 1; /* Put this at end to allow re-call due to error */ return 0; }