当前位置: 首页>>代码示例>>C++>>正文


C++ RtAudio类代码示例

本文整理汇总了C++中RtAudio的典型用法代码示例。如果您正苦于以下问题:C++ RtAudio类的具体用法?C++ RtAudio怎么用?C++ RtAudio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RtAudio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  // Set the global sample rate before creating class instances.
  Stk::setSampleRate( 44100.0 );

  SineWave sine;
  RtAudio dac;

  // Figure out how many bytes in an StkFloat and setup the RtAudio stream.
  RtAudio::StreamParameters parameters;
  parameters.deviceId = dac.getDefaultOutputDevice();
  parameters.deviceId = 3;
  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();
    goto cleanup;
  }

  // configuration of oscilator
  sine.setFrequency(440.0);

  

  // start the main real time loop
  try {
    dac.startStream();
  }
  catch ( RtAudioError &error ) {
    error.printMessage();
    goto cleanup;
  }


  // USER interface

  // Block waiting here.
  char keyhit;
  std::cout << "\nPlaying ... press <enter> to quit.\n";
  std::cin.get( keyhit );

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

 cleanup:
  return 0;
}
开发者ID:drmilde,项目名称:neonlicht,代码行数:60,代码来源:engine.cpp

示例2: start

  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(&parameters, NULL, RTAUDIO_SINT16, sampleRate, &got, &process, (void *)&data);
      //dac.openStream(&parameters, 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);
    }
  }
开发者ID:rbtsx,项目名称:latency,代码行数:30,代码来源:search.cpp

示例3: callback

int callback( void *output_buffer, void *input_buffer, unsigned int n_buffer_frames,
	      double stream_time, RtAudioStreamStatus status, void *data )
{
  RtAudio *audio = (RtAudio *)data;
  unsigned int sample_rate = audio->getStreamSampleRate();

  for (unsigned int i = 0; i < n_buffer_frames * 2;) {
    
    double fm_offset = 0;
    if (g_fm_on) {
      double fm_increment =  (2.0 * M_PI) / sample_rate * g_fm_frequency;
      g_fm_phase += fm_increment;
      if (g_fm_phase > 2 * M_PI) {
	g_fm_phase -= 2 * M_PI;
      }
      fm_offset = g_active_fm_ugen(g_fm_phase, g_fm_width) * g_fm_index;
    }

    double increment =  (2.0 * M_PI) / sample_rate * (g_frequency + fm_offset);
    g_phase += increment;
    if (g_phase > 2 * M_PI) {
      g_phase -= 2 * M_PI;
    }
    double samp = g_active_ugen(g_phase, g_width);

    if (g_modulate_input) {
      samp = ((double *)input_buffer)[i / 2] * samp;
    }

    ((double *)output_buffer)[i++] = samp;
    ((double *)output_buffer)[i++] = samp;
  }

  return 0;
}
开发者ID:mrotondo,项目名称:ccrma,代码行数:35,代码来源:SunSine.cpp

示例4: main

int main()
{
    RtAudio dac;
    if ( dac.getDeviceCount() == 0 ) exit( 0 );

    RtAudio::StreamParameters parameters;
    parameters.deviceId = dac.getDefaultOutputDevice();
    parameters.nChannels = 2;
    unsigned int sampleRate = 44100;
    unsigned int bufferFrames = 256; // 256 sample frames

    RtAudio::StreamOptions options;
    options.flags = RTAUDIO_NONINTERLEAVED;

    try {
        dac.openStream( &parameters, NULL, RTAUDIO_FLOAT32,
                        sampleRate, &bufferFrames, &myCallback, NULL, &options );
    }
    catch ( RtError& e ) {
        std::cout << '\n' << e.getMessage() << '\n' << std::endl;
        exit( 0 );
    }

    return 0;
}
开发者ID:brolin,项目名称:BeagleSynth,代码行数:25,代码来源:RtAudioDeviceSettings.cpp

示例5: RtAudio

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;
}
开发者ID:slegroux,项目名称:slgFramework,代码行数:25,代码来源:slgAudio.cpp

示例6: start_audio

/* returns 0 on failure */
int
start_audio(AudioCallback _callback, int sample_rate, void *data)
{
	if(audio.getDeviceCount() < 1) {
		std::cout << "No audio devices found!\n";
		return 0;
	}
	
	RtAudio::StreamParameters iparams, oparams;
	
	/* configure input (microphone) */
	iparams.deviceId = audio.getDefaultInputDevice();
	iparams.nChannels = 1;
	iparams.firstChannel = 0;
	
	/* configure output */
	oparams.deviceId = audio.getDefaultOutputDevice();
	oparams.nChannels = 2;
	oparams.firstChannel = 0;
	unsigned int bufferFrames = 256;
	
	callback = _callback;
	
	try {
		audio.openStream(&oparams, &iparams, RTAUDIO_FLOAT64 /* double */, sample_rate, &bufferFrames, &render, data);
		audio.startStream();
	} catch(RtError& e) {
		e.printMessage();
		return 0;
	}
	
	return 1;
}
开发者ID:alltom,项目名称:ckv,代码行数:34,代码来源:rtaudio_wrapper.cpp

示例7: catch

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;
}
开发者ID:hzoli17,项目名称:ZSFEdit,代码行数:34,代码来源:audio.cpp

示例8: ofSoundStreamListDevices

//---------------------------------------------------------
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;
}
开发者ID:alfredoBorboa,项目名称:openFrameworks,代码行数:26,代码来源:ofSoundStream.cpp

示例9: av_audio_start

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());
	}
}
开发者ID:AlloSphere-Research-Group,项目名称:alive,代码行数:59,代码来源:audio.cpp

示例10: defined

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
}
开发者ID:ComputerVisionWorks,项目名称:libsourcey,代码行数:59,代码来源:devicemanager.cpp

示例11: main

int main(int argc, const char * argv[])
{
    RtAudio dac;
    RtAudio::StreamParameters rtParams;
    rtParams.deviceId = dac.getDefaultOutputDevice();
    rtParams.nChannels = nChannels;
#if RASPI
    unsigned int sampleRate = 22000;
#else
    unsigned int sampleRate = 44100;
#endif
    unsigned int bufferFrames = 512; // 512 sample frames
    
    Tonic::setSampleRate(sampleRate);
    
    std::vector<Synth> synths;
    synths.push_back(*new BassDrum());
    synths.push_back(*new Snare());
    synths.push_back(*new HiHat());
    synths.push_back(*new Funky());
    
    // Test write pattern
    
    DrumMachine *drumMachine = new DrumMachine(synths);
    
    drumMachine->loadPattern(0);
    
    ControlMetro metro = ControlMetro().bpm(480);
    
    ControlCallback drumMachineTick = ControlCallback(&mixer, [&](ControlGeneratorOutput output){
        drumMachine->tick();
    }).input(metro);
    
    Generator mixedSignal;
    for(int i = 0; i < NUM_TRACKS; i++)
    {
        mixedSignal = mixedSignal + synths[i];
    }
    mixer.setOutputGen(mixedSignal);
    
    try
    {
        dac.openStream( &rtParams, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &renderCallback, NULL, NULL );
        dac.startStream();
        
        // Send a pointer to our global drumMachine instance
        // to the serial communications layer.
        listenForMessages( drumMachine );
        
        dac.stopStream();
    }
    catch ( RtError& e )
    {
        std::cout << '\n' << e.getMessage() << '\n' << std::endl;
        exit( 0 );
    }
    
    return 0;
}
开发者ID:kreldjarn,项目名称:spilados,代码行数:59,代码来源:main.cpp

示例12: getAudioDeviceName

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;
}
开发者ID:Moqi,项目名称:UnityNativeAudioPlugin,代码行数:8,代码来源:UnityNativeAudio.cpp

示例13: stop

 void stop() {
   try {
     // Stop the stream
     dac.stopStream();
   } catch (RtAudioError &e) {
     e.printMessage();
   }
   if (dac.isStreamOpen()) dac.closeStream();
 }
开发者ID:rbtsx,项目名称:latency,代码行数:9,代码来源:search.cpp

示例14: listDevices

// サポートしているデバイスリストを表示
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;
        }
    }
}
开发者ID:Moqi,项目名称:UnityNativeAudioPlugin,代码行数:57,代码来源:UnityNativeAudio.cpp

示例15: main

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;
}
开发者ID:Kirushanr,项目名称:audacity,代码行数:55,代码来源:call_saw.cpp


注:本文中的RtAudio类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。