13
0

Extract freewheel processing in PortAudioBackend into new method

This commit is contained in:
Tim Mayberry 2015-08-27 11:41:00 +10:00
parent cf81caa798
commit f27d8e1e23
2 changed files with 36 additions and 20 deletions

View File

@ -1574,29 +1574,10 @@ PortAudioBackend::main_blocking_process_thread ()
}
} else {
// Freewheelin'
// zero audio input buffers
for (std::vector<PamPort*>::const_iterator it = _system_inputs.begin (); it != _system_inputs.end (); ++it) {
memset ((*it)->get_buffer (_samples_per_period), 0, _samples_per_period * sizeof (Sample));
}
// TODO clear midi or stop midi recv when entering fwheelin'
if (engine.process_callback (_samples_per_period)) {
_pcmio->close_stream();
_active = false;
if (!blocking_process_freewheel()) {
return 0;
}
// drop all outgoing MIDI messages
for (std::vector<PamPort*>::const_iterator it = _system_midi_out.begin (); it != _system_midi_out.end (); ++it) {
void *bptr = (*it)->get_buffer(0);
midi_clear(bptr);
}
_dsp_load = 1.0;
Glib::usleep (100); // don't hog cpu
}
process_port_connection_changes();
@ -1614,6 +1595,39 @@ PortAudioBackend::main_blocking_process_thread ()
return 0;
}
bool
PortAudioBackend::blocking_process_freewheel ()
{
// zero audio input buffers
for (std::vector<PamPort*>::const_iterator it = _system_inputs.begin();
it != _system_inputs.end();
++it) {
memset((*it)->get_buffer(_samples_per_period),
0,
_samples_per_period * sizeof(Sample));
}
// TODO clear midi or stop midi recv when entering fwheelin'
if (engine.process_callback(_samples_per_period)) {
_pcmio->close_stream();
_active = false;
return false;
}
// drop all outgoing MIDI messages
for (std::vector<PamPort*>::const_iterator it = _system_midi_out.begin();
it != _system_midi_out.end();
++it) {
void* bptr = (*it)->get_buffer(0);
midi_clear(bptr);
}
_dsp_load = 1.0;
Glib::usleep(100); // don't hog cpu
return true;
}
void
PortAudioBackend::process_port_connection_changes ()
{

View File

@ -322,9 +322,11 @@ class PortAudioBackend : public AudioBackend {
private: // Methods
bool start_blocking_process_thread ();
bool stop_blocking_process_thread ();
bool blocking_process_freewheel ();
void process_port_connection_changes ();
private:
std::string _instance_name;
PortAudioIO *_pcmio;