mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-11-10 15:01:40 +00:00
adjust implementation of audio drivers for fluid_synth_process()
This commit is contained in:
parent
723816cd5d
commit
c309e417c5
7 changed files with 53 additions and 32 deletions
|
@ -38,7 +38,7 @@ struct fx_data_t {
|
|||
* zero, or the buffers will be filled with zero samples.
|
||||
*/
|
||||
int fx_function(void* data, int len,
|
||||
int nin, float** in,
|
||||
int nfx, float** fx,
|
||||
int nout, float** out)
|
||||
{
|
||||
struct fx_data_t* fx_data = (struct fx_data_t*) data;
|
||||
|
@ -47,9 +47,9 @@ int fx_function(void* data, int len,
|
|||
|
||||
/* Call the synthesizer to fill the output buffers with its
|
||||
* audio output. */
|
||||
if (fluid_synth_process(fx_data->synth, len, nin, in, nout, out) != 0) {
|
||||
if (fluid_synth_process(fx_data->synth, len, nfx, fx, nout, out) != FLUID_OK) {
|
||||
/* Some error occured. Very unlikely to happen, though. */
|
||||
return -1;
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
/* Apply your effects here. In this example, the gain is
|
||||
|
@ -61,7 +61,7 @@ int fx_function(void* data, int len,
|
|||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -396,6 +396,9 @@ static fluid_thread_return_t fluid_alsa_audio_run_float (void *d)
|
|||
if (dev->callback)
|
||||
{
|
||||
while (dev->cont) {
|
||||
FLUID_MEMSET(left, 0, buffer_size * sizeof(float));
|
||||
FLUID_MEMSET(right, 0, buffer_size * sizeof(float));
|
||||
|
||||
handle[0] = left;
|
||||
handle[1] = right;
|
||||
|
||||
|
|
|
@ -136,8 +136,8 @@ fluid_audio_driver_t*
|
|||
new_fluid_core_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
|
||||
{
|
||||
return new_fluid_core_audio_driver2 ( settings,
|
||||
(fluid_audio_func_t) fluid_synth_process,
|
||||
(void*) synth );
|
||||
fluid_synth_process,
|
||||
synth );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -349,6 +349,9 @@ fluid_core_audio_callback ( void *data,
|
|||
float* left = dev->buffers[0];
|
||||
float* right = dev->buffers[1];
|
||||
|
||||
FLUID_MEMSET(left, 0, len * sizeof(float));
|
||||
FLUID_MEMSET(right, 0, len * sizeof(float));
|
||||
|
||||
(*dev->callback)(dev->data, len, 0, NULL, 2, dev->buffers);
|
||||
|
||||
for (i = 0, k = 0; i < len; i++) {
|
||||
|
|
|
@ -532,7 +532,7 @@ fluid_jack_driver_process (jack_nframes_t nframes, void *arg)
|
|||
fluid_jack_audio_driver_t *audio_driver;
|
||||
fluid_jack_midi_driver_t *midi_driver;
|
||||
float *left, *right;
|
||||
int i, k;
|
||||
int i;
|
||||
|
||||
jack_midi_event_t midi_event;
|
||||
fluid_midi_event_t *evt;
|
||||
|
@ -574,42 +574,48 @@ fluid_jack_driver_process (jack_nframes_t nframes, void *arg)
|
|||
audio_driver = fluid_atomic_pointer_get (&client->audio_driver);
|
||||
if (!audio_driver) return 0;
|
||||
|
||||
if (audio_driver->callback != NULL)
|
||||
{
|
||||
for (i = 0; i < audio_driver->num_output_ports * 2; i++)
|
||||
audio_driver->output_bufs[i] = (float *)jack_port_get_buffer (audio_driver->output_ports[i], nframes);
|
||||
|
||||
return (*audio_driver->callback)(audio_driver->data, nframes, 0, NULL,
|
||||
2 * audio_driver->num_output_ports,
|
||||
audio_driver->output_bufs);
|
||||
}
|
||||
else if (audio_driver->num_output_ports == 1 && audio_driver->num_fx_ports == 0) /* i.e. audio.jack.multi=no */
|
||||
if (audio_driver->callback == NULL && audio_driver->num_output_ports == 1 && audio_driver->num_fx_ports == 0) /* i.e. audio.jack.multi=no */
|
||||
{
|
||||
left = (float*) jack_port_get_buffer (audio_driver->output_ports[0], nframes);
|
||||
right = (float*) jack_port_get_buffer (audio_driver->output_ports[1], nframes);
|
||||
|
||||
fluid_synth_write_float (audio_driver->data, nframes, left, 0, 1, right, 0, 1);
|
||||
return fluid_synth_write_float (audio_driver->data, nframes, left, 0, 1, right, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0, k = audio_driver->num_output_ports; i < audio_driver->num_output_ports; i++, k++) {
|
||||
audio_driver->output_bufs[i] = (float *)jack_port_get_buffer (audio_driver->output_ports[2*i], nframes);
|
||||
audio_driver->output_bufs[k] = (float *)jack_port_get_buffer (audio_driver->output_ports[2*i+1], nframes);
|
||||
fluid_audio_func_t callback = (audio_driver->callback != NULL) ? audio_driver->callback : fluid_synth_process;
|
||||
|
||||
for (i = 0; i < audio_driver->num_output_ports; i++)
|
||||
{
|
||||
int k = i*2;
|
||||
|
||||
audio_driver->output_bufs[k] = (float *)jack_port_get_buffer (audio_driver->output_ports[k], nframes);
|
||||
FLUID_MEMSET(audio_driver->output_bufs[k], 0, nframes * sizeof(float));
|
||||
|
||||
k = 2*i+1;
|
||||
audio_driver->output_bufs[k] = (float *)jack_port_get_buffer (audio_driver->output_ports[k], nframes);
|
||||
FLUID_MEMSET(audio_driver->output_bufs[k], 0, nframes * sizeof(float));
|
||||
}
|
||||
for (i = 0, k = audio_driver->num_fx_ports; i < audio_driver->num_fx_ports; i++, k++) {
|
||||
audio_driver->fx_bufs[i] = (float*) jack_port_get_buffer(audio_driver->fx_ports[2*i], nframes);
|
||||
audio_driver->fx_bufs[k] = (float*) jack_port_get_buffer(audio_driver->fx_ports[2*i+1], nframes);
|
||||
|
||||
for (i = 0; i < audio_driver->num_fx_ports; i++)
|
||||
{
|
||||
int k = i*2;
|
||||
|
||||
audio_driver->fx_bufs[k] = (float*) jack_port_get_buffer(audio_driver->fx_ports[k], nframes);
|
||||
FLUID_MEMSET(audio_driver->fx_bufs[k], 0, nframes * sizeof(float));
|
||||
|
||||
k = 2*i+1;
|
||||
audio_driver->fx_bufs[k] = (float*) jack_port_get_buffer(audio_driver->fx_ports[k], nframes);
|
||||
FLUID_MEMSET(audio_driver->fx_bufs[k], 0, nframes * sizeof(float));
|
||||
}
|
||||
|
||||
fluid_synth_nwrite_float (audio_driver->data,
|
||||
nframes,
|
||||
audio_driver->output_bufs,
|
||||
audio_driver->output_bufs + audio_driver->num_output_ports,
|
||||
audio_driver->fx_bufs,
|
||||
audio_driver->fx_bufs + audio_driver->num_fx_ports);
|
||||
return callback(audio_driver->data,
|
||||
nframes,
|
||||
audio_driver->num_fx_ports * 2,
|
||||
audio_driver->fx_bufs,
|
||||
audio_driver->num_output_ports * 2,
|
||||
audio_driver->output_bufs);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -481,6 +481,9 @@ fluid_oss_audio_run2(void* d)
|
|||
/* it's as simple as that: */
|
||||
while (dev->cont)
|
||||
{
|
||||
FLUID_MEMSET(left, 0, buffer_size * sizeof(float));
|
||||
FLUID_MEMSET(right, 0, buffer_size * sizeof(float));
|
||||
|
||||
(*dev->callback)(dev->data, buffer_size, 0, NULL, 2, dev->buffers);
|
||||
|
||||
fluid_synth_dither_s16 (&dither_index, buffer_size, left, right,
|
||||
|
|
|
@ -270,6 +270,9 @@ fluid_pulse_audio_run2(void* d)
|
|||
|
||||
while (dev->cont)
|
||||
{
|
||||
FLUID_MEMSET(left, 0, buffer_size * sizeof(float));
|
||||
FLUID_MEMSET(right, 0, buffer_size * sizeof(float));
|
||||
|
||||
(*dev->callback)(synth, buffer_size, 0, NULL, 2, handle);
|
||||
|
||||
/* Interleave the floating point data */
|
||||
|
|
|
@ -272,6 +272,9 @@ void pascal fluid_sndmgr_callback(SndChannelPtr chan, SndDoubleBufferPtr double
|
|||
/* float API : conversion to signed short */
|
||||
left = dev->convbuffers[0];
|
||||
right = dev->convbuffers[1];
|
||||
|
||||
FLUID_MEMSET(left, 0, buffer_size * sizeof(float));
|
||||
FLUID_MEMSET(right, 0, buffer_size * sizeof(float));
|
||||
|
||||
(*dev->callback)(dev->data, buffer_size, 0, NULL, 2, dev->convbuffers);
|
||||
|
||||
|
|
Loading…
Reference in a new issue