void nova_server::prepare_backend(void) { /* register audio backend ports */ const int blocksize = get_audio_blocksize(); const int input_channels = get_input_count(); const int output_channels = get_output_count(); std::vector<sample*> inputs, outputs; for (int channel = 0; channel != input_channels; ++channel) inputs.push_back(sc_factory->world.mAudioBus + (blocksize * (output_channels + channel))); audio_backend::input_mapping(inputs.begin(), inputs.end()); for (int channel = 0; channel != output_channels; ++channel) outputs.push_back(sc_factory->world.mAudioBus + blocksize * channel); audio_backend::output_mapping(outputs.begin(), outputs.end()); #ifdef __SSE__ /* denormal handling */ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _mm_setcsr(_mm_getcsr() | 0x40); #endif time_per_tick = time_tag::from_samples(blocksize, get_samplerate()); }
void SoundDriver_PortAudio::read_from_outputs(int p_frames) { if (!get_output_count() || current_outputs==0) { //cant copy for (int i=0;i<p_frames*current_outputs;i++) { current_output[process_offset*current_outputs+i]=0; } process_offset+=p_frames; return; } get_output_plug(0)->get_buffer()->copy_to_interleaved(¤t_output[process_offset*current_outputs],p_frames); process_offset+=p_frames; }
bool SoundDriver_PortAudio::init() { last_error=""; if (active) return true; current_inputs = get_input_count()?get_input_plug(0)->get_channels():0; current_outputs = get_output_count()?get_output_plug(0)->get_channels():0; if (current_inputs && (input_devices.get_current()<0 || input_devices.get_current()>=input_device_index.size())) { last_error="No Input Devices"; return true; } if (current_outputs && (output_devices.get_current()<0 || output_devices.get_current()>=output_device_index.size())) { last_error="No Output Devices"; return true; } int in_device=input_device_index[ input_devices.get_current() ]; int out_device=output_device_index[ output_devices.get_current() ]; if (current_inputs==0 && current_outputs==0) { last_error="No Inputs/Outputs!"; return true; } if (sampling_rate_values.empty()) { last_error="wtf? BUG!"; return true; } int buffsize=buffer_sizes[buffer_size.get_current()]; // int buffcount=(int)fragments.get(); mixing_frequency=sampling_rate_values[mix_rate.get_current()]; PaStreamParameters in_params; in_params.device=in_device; in_params.channelCount=current_inputs; in_params.sampleFormat=paFloat32; in_params.suggestedLatency=0; //die in_params.hostApiSpecificStreamInfo=NULL; PaStreamParameters out_params; out_params.device=out_device; out_params.channelCount=current_outputs; out_params.sampleFormat=paFloat32; out_params.suggestedLatency=0; //die out_params.hostApiSpecificStreamInfo=NULL; PaError error = Pa_OpenStream (&stream,(current_inputs>0)?&in_params:NULL,(current_outputs>0)?&out_params:NULL,mixing_frequency,buffsize,paNoFlag,&SoundDriver_PortAudio::static_callback, this); if (error<0) { last_error=Pa_GetErrorText(error); return true; } error=Pa_StartStream(stream); if (error<0) { last_error=Pa_GetErrorText(error); return true; } //printf("OPENING PORTAUDIO\n"); active=true; return false; }