void av_audio_start() { av_audio_get(); if (rta.isStreamRunning()) { rta.stopStream(); } if (rta.isStreamOpen()) { // close it: rta.closeStream(); } unsigned int devices = rta.getDeviceCount(); if (devices < 1) { printf("No audio devices found\n"); return; } RtAudio::DeviceInfo info; RtAudio::StreamParameters iParams, oParams; printf("Available audio devices (%d):\n", devices); for (unsigned int i=0; i<devices; i++) { info = rta.getDeviceInfo(i); printf("Device %d: %dx%d (%d) %s\n", i, info.inputChannels, info.outputChannels, info.duplexChannels, info.name.c_str()); } printf("device %d\n", audio.indevice); info = rta.getDeviceInfo(audio.indevice); printf("Using audio input %d: %dx%d (%d) %s\n", audio.indevice, info.inputChannels, info.outputChannels, info.duplexChannels, info.name.c_str()); audio.inchannels = info.inputChannels; iParams.deviceId = audio.indevice; iParams.nChannels = audio.inchannels; iParams.firstChannel = 0; info = rta.getDeviceInfo(audio.outdevice); printf("Using audio output %d: %dx%d (%d) %s\n", audio.outdevice, info.inputChannels, info.outputChannels, info.duplexChannels, info.name.c_str()); audio.outchannels = info.outputChannels; oParams.deviceId = audio.outdevice; oParams.nChannels = audio.outchannels; oParams.firstChannel = 0; RtAudio::StreamOptions options; //options.flags |= RTAUDIO_NONINTERLEAVED; options.streamName = "av"; try { rta.openStream( &oParams, &iParams, RTAUDIO_FLOAT32, audio.samplerate, &audio.blocksize, &av_rtaudio_callback, NULL, &options ); rta.startStream(); printf("Audio started\n"); } catch ( RtError& e ) { fprintf(stderr, "%s\n", e.getMessage().c_str()); } }
QString Audio::getInDeviceName(unsigned int device) { unsigned int num = 0; for (unsigned int i=0; i<adc.getDeviceCount(); i++) { if (adc.getDeviceInfo(i).inputChannels) { if (device == num) return QString::fromStdString(adc.getDeviceInfo(i).name); num++; } } return QObject::tr("Unknown audio input device"); }
void slgAudio::info(){ RtAudio *audioTemp = NULL; audioTemp = new RtAudio(); unsigned int devices = audioTemp->getDeviceCount(); RtAudio::DeviceInfo info; for (int i=0;i<devices;i++){ info = audioTemp->getDeviceInfo(i); // std::cout<<"default input: "<<m_audio->getDefaultInputDevice()<<std::endl; // std::cout<<"default output: "<<m_audio->getDefaultOutputDevice()<<std::endl; if (info.probed ==true){ std::cout<<"----------------------------- Device "<<i<<" ---------------------------"<<std::endl; if (info.isDefaultInput) std::cout << "--Default Input"<<std::endl; if (info.isDefaultOutput) std::cout << "--Default Output"<<std::endl; std::cout << "Name = " << info.name << '\n'; std::cout << "Max Input Channels = " << info.inputChannels << '\n'; std::cout << "Max Output Channels = " << info.outputChannels << '\n'; std::cout << "Max Duplex Channels = " << info.duplexChannels << '\n'; } } delete audioTemp; audioTemp = NULL; }
bool Audio::openAudioInputDevice(unsigned int device) { RtAudio::StreamParameters p; double data[2]; unsigned int num = 0; if (inIsOpened) return false; for (unsigned int i=0; i<adc.getDeviceCount(); i++) { if (adc.getDeviceInfo(i).inputChannels) { if (device == num) { p.deviceId = i; break; } num++; } } p.firstChannel = 0; p.nChannels = 2; try { adc.openStream(NULL, &p, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioInputCallback, (void*)&data); adc.startStream(); } catch (RtAudioError& e) { inError = e.getMessage(); return false; } inBuffer=(float*)calloc(bufferFrames, sizeof(float)); inIsOpened=true; return true; }
void start(unsigned int bufferFrames = 512, unsigned int sampleRate = 44100) { this->bufferFrames = bufferFrames; this->sampleRate = sampleRate; if (dac.getDeviceCount() < 1) { std::cout << "\nNo audio devices found!\n"; exit(0); } parameters.deviceId = (id == 1) ? 0 : 1; RtAudio::DeviceInfo info; info = dac.getDeviceInfo(parameters.deviceId); std::cout << "device = " << info.name << std::endl; //parameters.deviceId = dac.getDefaultOutputDevice(); parameters.nChannels = 2; parameters.firstChannel = 0; //RtApiAlsa::getDeviceInfo: snd_pcm_open error for device (default), No such file or directory. try { unsigned int got = bufferFrames; dac.openStream(¶meters, NULL, RTAUDIO_SINT16, sampleRate, &got, &process, (void *)&data); //dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &got, &process, (void *)&data); dac.startStream(); std::cout << "requested " << bufferFrames << " but got " << got << std::endl; } catch (RtAudioError &e) { e.printMessage(); exit(0); } }
//--------------------------------------------------------- void ofSoundStreamListDevices(){ RtAudio *audioTemp = 0; try { audioTemp = new RtAudio(); } catch (RtError &error) { error.printMessage(); } int devices = audioTemp->getDeviceCount(); RtAudio::DeviceInfo info; for (int i=0; i< devices; i++) { try { info = audioTemp->getDeviceInfo(i); } catch (RtError &error) { error.printMessage(); break; } std::cout << "device = " << i << " (" << info.name << ")\n"; if (info.isDefaultInput) std::cout << "----* default ----* \n"; std::cout << "maximum output channels = " << info.outputChannels << "\n"; std::cout << "maximum input channels = " << info.inputChannels << "\n"; std::cout << "-----------------------------------------\n"; } delete audioTemp; }
void validateDevice(unsigned int deviceId, unsigned int deviceCount, RtAudio& adc, bool input) { if (deviceId >= deviceCount) { cout << "Device ID " << deviceId << " must be less than " << deviceCount << endl; exit(0); } RtAudio::DeviceInfo info = adc.getDeviceInfo(deviceId); if (!info.probed) { cout << "Could not probe device ID " << deviceId << endl; exit(0); } if (!isCdQuality(info)) { cout << "Device ID " << deviceId << " is not CD quality" << endl; exit(0); } if (input) { if (info.inputChannels == 0) { cout << "Device ID " << deviceId << " has no input channels" << endl; exit(0); } } else { if (info.outputChannels == 0) { cout << "Device ID " << deviceId << " has no output channels" << endl; exit(0); } } }
bool DeviceManager::getAudioDevices(bool input, std::vector<Device>& devs) { devs.clear(); #if defined(ANDROID) // Under Android, we don't access the device file directly. // Arbitrary use 0 for the mic and 1 for the output. // These ids are used in MediaEngine::SetSoundDevices(in, out); // The strings are for human consumption. if (input) { devs.push_back(Device("audioin", "audiorecord", 0)); } else { devs.push_back(Device("audioout", "audiotrack", 1)); } return true; #elif defined(HAVE_RTAUDIO) // Since we are using RtAudio for audio capture it's best to // use RtAudio to enumerate devices to ensure indexes match. RtAudio audio; // Determine the number of devices available auto ndevices = audio.getDeviceCount(); TraceS(this) << "Get audio devices: " << ndevices << endl; // Scan through devices for various capabilities RtAudio::DeviceInfo info; for (unsigned i = 0; i <= ndevices; i++) { try { info = audio.getDeviceInfo(i); // may throw RtAudioError TraceS(this) << "Device:" << "\n\tName: " << info.name << "\n\tOutput Channels: " << info.outputChannels << "\n\tInput Channels: " << info.inputChannels << "\n\tDuplex Channels: " << info.duplexChannels << "\n\tDefault Output: " << info.isDefaultOutput << "\n\tDefault Input: " << info.isDefaultInput << "\n\tProbed: " << info.probed << endl; if (info.probed == true && ( (input && info.inputChannels > 0) || (!input && info.outputChannels > 0))) { TraceS(this) << "Adding device: " << info.name << endl; Device dev((input ? "audioin" : "audioout"), i, info.name, "", (input ? info.isDefaultInput : info.isDefaultOutput)); devs.push_back(dev); } } catch (RtAudioError& e) { ErrorS(this) << "Cannot probe audio device: " << e.getMessage() << endl; } } return filterDevices(devs, kFilteredAudioDevicesName); #endif }
const char* getAudioDeviceName(unsigned int deviceId) { RtAudio audio; std::string name = audio.getDeviceInfo(deviceId).name; unsigned long len = name.length(); char* c = new char[len+1]; memcpy(c, name.c_str(), len+1); return c; }
// サポートしているデバイスリストを表示 void listDevices() { RtAudio audio; unsigned int devices = audio.getDeviceCount(); RtAudio::DeviceInfo info; for(unsigned int i=0; i<devices; i++) { info = audio.getDeviceInfo(i); std::cout << "============================" << std::endl; std::cout << "\nDevide ID:" << i << std::endl; std::cout << "Name:" << info.name << std::endl; if ( info.probed == false ) std::cout << "Probe Status = UNsuccessful\n"; 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 << std::endl; } } }
int main(int argc, char** argv) { if (argc != 2) { printf("Usage: synth file.sf2\n"); exit(0); } LightFluidSynth *usynth; usynth = new LightFluidSynth(); usynth->loadSF2(argv[1]); // usynth->loadSF2("tim.sf2"); RtMidiIn *midiIn = new RtMidiIn(); if (midiIn->getPortCount() == 0) { std::cout << "No MIDI ports available!\n"; } midiIn->openPort(0); midiIn->setCallback( &midiCallback, (void *)usynth ); midiIn->ignoreTypes( false, false, false ); // RtAudio dac(RtAudio::LINUX_PULSE); RtAudio dac; RtAudio::StreamParameters rtParams; // Determine the number of devices available unsigned int devices = dac.getDeviceCount(); // Scan through devices for various capabilities RtAudio::DeviceInfo info; for ( unsigned int i = 0; i < devices; i++ ) { info = dac.getDeviceInfo( i ); if ( info.probed == true ) { std::cout << "device " << " = " << info.name; std::cout << ": maximum output channels = " << info.outputChannels << "\n"; } } // rtParams.deviceId = 3; rtParams.deviceId = dac.getDefaultOutputDevice(); rtParams.nChannels = 2; unsigned int bufferFrames = FRAME_SIZE; RtAudio::StreamOptions options; options.flags = RTAUDIO_SCHEDULE_REALTIME; dac.openStream( &rtParams, NULL, AUDIO_FORMAT, SAMPLE_RATE, &bufferFrames, &audioCallback, (void *)usynth, &options ); dac.startStream(); printf("\n\nPress Enter to stop\n\n"); cin.get(); dac.stopStream(); delete(usynth); return 0; }
unsigned int Audio::getAudioInputCount() { unsigned int num = 0; unsigned int deviceCount=adc.getDeviceCount(); for (unsigned int i=0; i<deviceCount; i++) { if(adc.getDeviceInfo(i).inputChannels) num++; } return num; }
void AudioThread::enumerateDevices(std::vector<RtAudio::DeviceInfo> &devs) { RtAudio endac; int numDevices = endac.getDeviceCount(); for (int i = 0; i < numDevices; i++) { RtAudio::DeviceInfo info = endac.getDeviceInfo(i); devs.push_back(info); std::cout << std::endl; std::cout << "Audio Device #" << i << " " << info.name << std::endl; std::cout << "\tDefault Output? " << (info.isDefaultOutput ? "Yes" : "No") << std::endl; std::cout << "\tDefault Input? " << (info.isDefaultOutput ? "Yes" : "No") << std::endl; std::cout << "\tInput channels: " << info.inputChannels << std::endl; std::cout << "\tOutput channels: " << info.outputChannels << std::endl; std::cout << "\tDuplex channels: " << info.duplexChannels << std::endl; std::cout << "\t" << "Native formats:" << std::endl; RtAudioFormat nFormats = info.nativeFormats; if (nFormats & RTAUDIO_SINT8) { std::cout << "\t\t8-bit signed integer." << std::endl; } if (nFormats & RTAUDIO_SINT16) { std::cout << "\t\t16-bit signed integer." << std::endl; } if (nFormats & RTAUDIO_SINT24) { std::cout << "\t\t24-bit signed integer." << std::endl; } if (nFormats & RTAUDIO_SINT32) { std::cout << "\t\t32-bit signed integer." << std::endl; } if (nFormats & RTAUDIO_FLOAT32) { std::cout << "\t\t32-bit float normalized between plus/minus 1.0." << std::endl; } if (nFormats & RTAUDIO_FLOAT64) { std::cout << "\t\t32-bit float normalized between plus/minus 1.0." << std::endl; } std::vector<unsigned int>::iterator srate; std::cout << "\t" << "Supported sample rates:" << std::endl; for (srate = info.sampleRates.begin(); srate != info.sampleRates.end(); srate++) { std::cout << "\t\t" << (*srate) << "hz" << std::endl; } std::cout << std::endl; } }
//----------------------------------------------------------------------------- // name: probe() // desc: ... //----------------------------------------------------------------------------- void Digitalio::probe() { #ifndef __DISABLE_RTAUDIO__ RtAudio * rta = NULL; RtAudio::DeviceInfo info; // allocate RtAudio try { rta = new RtAudio( ); } catch( RtError err ) { // problem finding audio devices, most likely EM_error2b( 0, "%s", err.getMessage().c_str() ); return; } // get count int devices = rta->getDeviceCount(); EM_error2b( 0, "found %d device(s) ...", devices ); // EM_error2( 0, "--------------------------" ); EM_reset_msg(); // loop for( int i = 0; i < devices; i++ ) { try { info = rta->getDeviceInfo(i); } catch( RtError & error ) { error.printMessage(); break; } // print EM_error2b( 0, "------( audio device: %d )---------------", i+1 ); print( info ); // skip if( i < devices ) EM_error2( 0, "" ); EM_reset_msg(); } delete rta; #endif // __DISABLE_RTAUDIO__ return; }
QHash<int, QString> BleAudioCapture::availableDevices() { RtAudio rtAudio; int deviceCount = rtAudio.getDeviceCount(); RtAudio::DeviceInfo info; QHash<int, QString> devices; for (int i = 0; i < deviceCount; ++i) { info = rtAudio.getDeviceInfo(i); if (info.inputChannels > 0) { devices.insert(i, QString::fromStdString(info.name)); } } return devices; }
int startAudio() { // Determine the number of devices available unsigned int devices = audio.getDeviceCount(); if(devices==0) { printf("please run 'sudo modprobe snd_bcm2835' to enable the alsa driver\n"); return 1; } // Scan through devices for various capabilities RtAudio::DeviceInfo info; for ( unsigned int i=0; i<devices; i++ ) { info = audio.getDeviceInfo( i ); if ( info.probed == true ) { // Print, for example, the maximum number of output channels for each device std::cout << "device = " << i; std::cout << ": maximum output channels = " << info.outputChannels << "\n"; } } RtAudio::StreamParameters parameters; parameters.deviceId = audio.getDefaultOutputDevice(); parameters.nChannels = 2; parameters.firstChannel = 0; unsigned int sampleRate = SAMPLERATE; unsigned int bufferFrames = BUFFERSIZE; double data[2]; try { audio.openStream( ¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *)&data ); audio.startStream(); } catch ( RtError& e ) { e.printMessage(); return 1; } return 0; }
void showDevices(unsigned int deviceCount, RtAudio& adc) { // Scan through devices for various capabilities RtAudio::DeviceInfo info; for (unsigned int i = 0; i < deviceCount; i++) { info = adc.getDeviceInfo(i); if (info.probed == true) { cout << "Device " << i << " '" << info.name << "', "; cout << "max output channels = " << info.outputChannels; cout << (info.isDefaultOutput ? " (default output)" : ""); cout << ", max input channels = " << info.inputChannels; cout << (info.isDefaultInput ? " (default input)" : ""); if (isCdQuality(info)) { cout << ", CD quality (44,100 Hz)"; } cout << endl; } } }
void initaudio() { using namespace std; /* vector<RtAudio::Api> apis; RtAudio::getCompiledApi(apis); cout << apis.size() << endl; for (size_t i = 0; i < apis.size(); ++i) { cout << apis[i] << endl; } */ int ndevices = adc.getDeviceCount(); if ( ndevices < 1 ) { std::cout << "\nNo audio devices found!\n"; return; } cout << endl; for (int i = 0; i < ndevices; ++i) { RtAudio::DeviceInfo devinfo; devinfo = adc.getDeviceInfo(i); cout << i << " " << devinfo.name << " " << devinfo.inputChannels << endl; } RtAudio::StreamParameters parameters; parameters.deviceId = 2; parameters.nChannels = 1; parameters.firstChannel = 0; unsigned int sampleRate = 1200; unsigned int bufferFrames = 8; // 256 sample frames try { adc.openStream( NULL, ¶meters, RTAUDIO_SINT16, sampleRate, &bufferFrames, &record ); adc.startStream(); } catch ( exception& e ) { std::cout << "EXCEPTION" << endl << e.what(); return; } }
void GOrgueSoundRtPort::addDevices(std::vector<GOrgueSoundDevInfo>& result) { try { std::vector<RtAudio::Api> rtaudio_apis; RtAudio::getCompiledApi(rtaudio_apis); for (unsigned k = 0; k < rtaudio_apis.size(); k++) { RtAudio* audioDevice = 0; try { audioDevice = new RtAudio(rtaudio_apis[k]); for (unsigned i = 0; i < audioDevice->getDeviceCount(); i++) { RtAudio::DeviceInfo dev_info = audioDevice->getDeviceInfo(i); if (!dev_info.probed) continue; if (dev_info.outputChannels < 1) continue; GOrgueSoundDevInfo info; info.channels = dev_info.outputChannels; info.isDefault = dev_info.isDefaultOutput; info.name = getName(rtaudio_apis[k], audioDevice, i); result.push_back(info); } } catch (RtAudioError &e) { wxString error = wxString::FromAscii(e.getMessage().c_str()); wxLogError(_("RtAudio error: %s"), error.c_str()); } if (audioDevice) delete audioDevice; } } catch (RtAudioError &e) { wxString error = wxString::FromAscii(e.getMessage().c_str()); wxLogError(_("RtAudio error: %s"), error.c_str()); } }
unsigned int getAudioInputChannels(unsigned int deviceId) { RtAudio audio; return audio.getDeviceInfo(deviceId).inputChannels; }
//----------------------------------------------------------------------------- // name: device_named() // desc: ... //----------------------------------------------------------------------------- DWORD__ Digitalio::device_named( const std::string & name, t_CKBOOL needs_dac, t_CKBOOL needs_adc ) { #ifndef __DISABLE_RTAUDIO__ RtAudio * rta = NULL; RtAudio::DeviceInfo info; // allocate RtAudio try { rta = new RtAudio( ); } catch( RtError err ) { // problem finding audio devices, most likely EM_error2b( 0, "%s", err.getMessage().c_str() ); return -1; } // get count int devices = rta->getDeviceCount(); int device_no = -1; // loop for( int i = 0; i < devices; i++ ) { try { info = rta->getDeviceInfo(i); } catch( RtError & error ) { error.printMessage(); break; } if( info.name.compare(name) == 0 ) { device_no = i+1; break; } } if( device_no == -1 ) { // no exact match found; try partial match for( int i = 0; i < devices; i++ ) { try { info = rta->getDeviceInfo(i); } catch( RtError & error ) { error.printMessage(); break; } if( info.name.find(name) != std::string::npos ) { if( (needs_dac && info.outputChannels == 0) || (needs_adc && info.inputChannels == 0) ) continue; device_no = i+1; break; } } } // clean up SAFE_DELETE( rta ); // done return device_no; #endif // __DISABLE_RTAUDIO__ return -1; }
int main(int argc, char *argv[]) { RtAudio *audio = 0; RtAudioDeviceInfo info; try { audio = new RtAudio(); } catch (RtError &error) { error.printMessage(); exit(EXIT_FAILURE); } int devices = audio->getDeviceCount(); std::cout << "\nFound " << devices << " device(s) ...\n"; for (int i=1; i<=devices; i++) { try { info = audio->getDeviceInfo(i); } catch (RtError &error) { error.printMessage(); break; } std::cout << "\nDevice Name = " << info.name << '\n'; if (info.probed == false) std::cout << "Probe Status = UNsuccessful\n"; 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.isDefault) std::cout << "This is the default device.\n"; else std::cout << "This is NOT the default 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 << std::endl; } } std::cout << std::endl; delete audio; return 0; }
void Marionette::info() { // Create an api map. std::map<int, std::string> apiMap; apiMap[RtAudio::MACOSX_CORE] = "OS-X Core Audio"; apiMap[RtAudio::WINDOWS_ASIO] = "Windows ASIO"; apiMap[RtAudio::WINDOWS_DS] = "Windows Direct Sound"; apiMap[RtAudio::UNIX_JACK] = "Jack Client"; apiMap[RtAudio::LINUX_ALSA] = "Linux ALSA"; apiMap[RtAudio::LINUX_OSS] = "Linux OSS"; apiMap[RtAudio::RTAUDIO_DUMMY] = "RtAudio Dummy"; 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; RtAudio audio; RtAudio::DeviceInfo info; std::cout << "\nCurrent API: " << apiMap[ audio.getCurrentApi() ] << std::endl; unsigned int devices = audio.getDeviceCount(); std::cout << "\nFound " << devices << " device(s) ...\n"; for (unsigned int i=0; i<devices; i++) { info = audio.getDeviceInfo(i); std::cout << "\nDevice Name = " << info.name << '\n'; if ( info.probed == false ) std::cout << "Probe Status = UNsuccessful\n"; 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 << std::endl; } } std::cout << std::endl; }
t_CKBOOL miniAudicle::probe() { #ifndef __CHIP_MODE__ interfaces.clear(); RtAudio * rta = NULL; RtAudio::DeviceInfo info; // allocate RtAudio try { rta = new RtAudio( ); } catch( RtError & error ) { // problem finding audio devices, most likely EM_log( CK_LOG_WARNING, "(RtAudio): %s", error.getMessage().c_str() ); return FALSE; } // get count int devices = rta->getDeviceCount(); default_input = devices; default_output = devices; // loop for( int i = 0; i < devices; i++ ) { try { interfaces.push_back( rta->getDeviceInfo( i ) ); if( interfaces[i].isDefaultInput && interfaces[i].inputChannels && default_input == devices ) default_input = i; if( interfaces[i].isDefaultOutput && interfaces[i].outputChannels && default_output == devices ) default_output = i; } catch( RtError & error ) { EM_log( CK_LOG_WARNING, "(RtAudio): %s", error.getMessage().c_str() ); break; } } if( default_input == devices ) // no default input found default_input = 0; if( default_output == devices ) // no default output found default_output = 0; delete rta; #endif // __CHIP_MODE__ return TRUE; }
int main( int argc, char *argv[]) { // COMMAND LINE ARG HANDLING map<string, ugen> ugens; ugens["--sine"] = &sine; ugens["--saw"] = &saw; ugens["--pulse"] = &pulse; ugens["--noise"] = &noise; ugens["--impulse"] = &impulse; if (argc < 4 || argc > 10 ) usage(); string type_arg = argv[1]; g_active_ugen = ugens[type_arg]; if (g_active_ugen == NULL) usage(); double freq_arg = atof(argv[2]); if (freq_arg <= 0) usage(); g_frequency = freq_arg; double width_arg = atof(argv[3]); if (width_arg < 0 || width_arg > 1) usage(); g_width = width_arg; if (argc > 4) { // modulation parameters present for (int i = 4; i < argc;) { if (string(argv[i]).compare("--input") == 0) { g_modulate_input = true; i++; } else if (string(argv[i]).compare("--fm") == 0) { g_fm_on = true; string fm_type_arg = argv[++i]; g_active_fm_ugen = ugens[fm_type_arg]; if (g_active_fm_ugen == NULL) usage(); double fm_freq_arg = atof(argv[++i]); if (fm_freq_arg <= 0) usage(); g_fm_frequency = fm_freq_arg; double fm_width_arg = atof(argv[++i]); if (fm_width_arg < 0 || fm_width_arg > 1) usage(); g_fm_width = fm_width_arg; double fm_index_arg = atoi(argv[++i]); g_fm_index = fm_index_arg; i++; } else usage(); } } // AUDIO SETUP RtAudio audio; audio.showWarnings( true ); RtAudio::StreamParameters output_params; RtAudio::StreamParameters input_params; // Choose an audio device and a sample rate unsigned int sample_rate; unsigned int devices = audio.getDeviceCount(); if ( devices < 1 ) { cerr << "No audio device found!" << endl; exit(1); } RtAudio::DeviceInfo info; for (unsigned int i = 0; i < devices; i++ ) { info = audio.getDeviceInfo(i); if ( info.isDefaultOutput ) { output_params.deviceId = i; output_params.nChannels = 2; if (info.sampleRates.size() < 1) { cerr << "No supported sample rates found!" << endl; exit(1); } for (int i = 0; i < info.sampleRates.size(); i++) { sample_rate = info.sampleRates[i]; if (sample_rate == 44100 || sample_rate == 48000) { // Found a nice sample rate, stop looking break; } } cout << "Using sample rate: " << sample_rate << endl; } if ( info.isDefaultInput ) { input_params.deviceId = i; input_params.nChannels = 1; } } cout << "Using output device ID " << output_params.deviceId << " which has " << output_params.nChannels << " output channels." << endl; cout << "Using input device ID " << input_params.deviceId << " which has " << input_params.nChannels << " input channels." << endl; RtAudio::StreamOptions options; options.flags |= RTAUDIO_HOG_DEVICE; options.flags |= RTAUDIO_SCHEDULE_REALTIME; unsigned int buffer_frames = 256; try { audio.openStream( &output_params, // output params &input_params, // input params RTAUDIO_FLOAT64, // audio format sample_rate, // sample rate &buffer_frames, // num frames per buffer (mutable by rtaudio) &callback, // audio callback &audio, // user data pointer HACK HACK :D &options); // stream options audio.startStream(); } catch ( RtError &e ) { e.printMessage(); goto cleanup; } char input; cout << "Playing, press enter to quit (buffer frames = " << buffer_frames << ")." << endl; cin.get( input ); try { audio.stopStream(); } catch ( RtError &e ) { e.printMessage(); } cleanup: if ( audio.isStreamOpen() ) { audio.closeStream(); } return 0; }
//------------------------------------------------------------------------------------------------------------ // SLOTS //------------------------------------------------------------------------------------------------------------ void AudioDeviceConfig::on_audioDevicesList_itemClicked(QTreeWidgetItem* item, int column) { RtAudio* audio; RtAudioDeviceInfo info; infoList->clear(); btnOK->setEnabled(false); selectedAPI_ = RtAudio::UNSPECIFIED; selectedDeviceID_ = 0; selectedDeviceName_ = "default device"; if(item->text(0) == "DirectShow" || item->text(0) == "ASIO") { return; } if(item->parent()->text(0)== "DirectShow") { audio = audioDS_; selectedAPI_ = RtAudio::WINDOWS_DS; } else if(item->parent()->text(0)== "ASIO") { audio = audioASIO_; selectedAPI_ = RtAudio::WINDOWS_ASIO; } else { QMessageBox::warning(this,"Invalid RtAudio API ", item->parent()->text(0)+" is not a supported RtAudio API!", QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); return; } int deviceID = item->text(1).toInt(); //Get Sound Device Info try { info = audio->getDeviceInfo(deviceID); } catch (RtError &error) { QMessageBox::warning(this,"Error obtaining audio device info!", QString::fromStdString(error.getMessage()), QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); infoList->clear(); return; } //populate Info List QTreeWidgetItem* infoHeader; //Sound Device name infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Device Name:"))); QTreeWidgetItem* name = new QTreeWidgetItem(infoHeader, QStringList(QString::fromStdString(info.name))); QFont font; font.setBold(true); name->setFont(0, font); infoList->expandItem(infoHeader); //Probe Successful? if (!info.probed) { infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Device info not available..."))); infoList->expandItem(infoHeader); return; } btnOK->setEnabled(true); selectedDeviceID_ = deviceID; selectedDeviceName_ = QString::fromStdString(info.name); //Default device? if(info.isDefault) new QTreeWidgetItem(name, QStringList(QString("DEFAULT device"))); infoList->expandItem(name); infoList->expandItem(infoHeader); //Sound Device Output Channels infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Output Channels:"))); new QTreeWidgetItem(infoHeader, QStringList(QString::number(info.outputChannels))); infoList->expandItem(infoHeader); //Sound Device Input Channels infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Input Channels:"))); new QTreeWidgetItem(infoHeader, QStringList(QString::number(info.inputChannels))); infoList->expandItem(infoHeader); //Sound Device Duplex Channels infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Duplex Channels:"))); new QTreeWidgetItem(infoHeader, QStringList(QString::number(info.duplexChannels))); infoList->expandItem(infoHeader); //Native Formats infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Natively supported data formats:"))); if(info.nativeFormats == 0) new QTreeWidgetItem(infoHeader, QStringList(QString("No natively supported data formats(?)!"))); else { if ( info.nativeFormats & RTAUDIO_SINT8 ) new QTreeWidgetItem(infoHeader, QStringList(QString("8-bit signed"))); if ( info.nativeFormats & RTAUDIO_SINT16 ) new QTreeWidgetItem(infoHeader, QStringList(QString("16-bit signed"))); if ( info.nativeFormats & RTAUDIO_SINT24 ) new QTreeWidgetItem(infoHeader, QStringList(QString("24-bit signed"))); if ( info.nativeFormats & RTAUDIO_SINT32 ) new QTreeWidgetItem(infoHeader, QStringList(QString("32-bit signed"))); if ( info.nativeFormats & RTAUDIO_FLOAT32 ) new QTreeWidgetItem(infoHeader, QStringList(QString("32-bit float"))); if ( info.nativeFormats & RTAUDIO_FLOAT64 ) new QTreeWidgetItem(infoHeader, QStringList(QString("64-bit float"))); } infoList->expandItem(infoHeader); //Sample rates infoHeader = new QTreeWidgetItem(infoList, QStringList(QString("Supported Sample Rates:"))); if ( info.sampleRates.size() < 1 ) new QTreeWidgetItem(infoHeader, QStringList(QString("No supported sample rates found!"))); else for (unsigned int j=0; j<info.sampleRates.size(); j++) new QTreeWidgetItem(infoHeader, QStringList(QString::number(info.sampleRates[j]))); infoList->expandItem(infoHeader); }