Fixes to SCHED_FIFO setup with ALSA and OSS drivers and a patch to midishare

from Stephane Letz.
This commit is contained in:
Element Green 2003-06-10 10:04:01 +00:00
parent 75a32f5c75
commit 3472cc18ad
5 changed files with 72 additions and 21 deletions

View File

@ -1,3 +1,10 @@
2003-06-09 Josh Green <jgreen@users.sourceforge.net>
* src/fluid_alsa.c: Added calls to pthread_attr_setschedparam to
properly create SCHED_FIFO threads.
* src/fluid_oss.c: pthread_attr_setschedparam calls added.
* src/fluid_midishare.c: Patch update from Stephane Letz.
2003-05-29 root <mn@bongo>
* src/fluid_synth.c (fluid_synth_one_block): Added a mutex that provides a small degree of

View File

@ -193,6 +193,7 @@ AC_ARG_ENABLE(coreaudio,
[ --enable-coreaudio enable CoreAudio support],[
case "$enableval" in
"yes")
fluid_enable_coreaudio="yes"
;;
"no")
fluid_enable_coreaudio="no"

View File

@ -54,6 +54,11 @@ extern cca_client_t * fluid_cca_client;
#define BUFFER_LENGTH 512
/* SCHED_FIFO priorities for ALSA threads (see pthread_attr_setschedparam) */
#define ALSA_PCM_SCHED_PRIORITY 90
#define ALSA_RAWMIDI_SCHED_PRIORITY 90
#define ALSA_SEQ_SCHED_PRIORITY 90
/** fluid_oss_audio_driver_t
*
* This structure should not be accessed directly. Use audio port
@ -178,6 +183,7 @@ new_fluid_alsa_audio_driver2(fluid_settings_t* settings,
char* device;
pthread_attr_t attr;
int sched = SCHED_FIFO;
struct sched_param priority;
int i, err, dir = 0;
snd_pcm_hw_params_t* hwparams;
snd_pcm_sw_params_t* swparams = NULL;
@ -335,6 +341,10 @@ new_fluid_alsa_audio_driver2(fluid_settings_t* settings,
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? ALSA_PCM_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_alsa_formats[i].run, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the audio output");
@ -587,6 +597,7 @@ new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings,
fluid_alsa_rawmidi_driver_t* dev;
pthread_attr_t attr;
int sched = SCHED_FIFO;
struct sched_param priority;
int count;
struct pollfd *pfd = NULL;
char* device = NULL;
@ -683,6 +694,11 @@ new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings,
goto error_recovery;
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? ALSA_RAWMIDI_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_alsa_midi_run, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the MIDI input");
@ -813,6 +829,7 @@ new_fluid_alsa_seq_driver(fluid_settings_t* settings,
fluid_alsa_seq_driver_t* dev;
pthread_attr_t attr;
int sched = SCHED_FIFO;
struct sched_param priority;
int count;
struct pollfd *pfd = NULL;
char* device = NULL;
@ -928,6 +945,11 @@ new_fluid_alsa_seq_driver(fluid_settings_t* settings,
goto error_recovery;
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? ALSA_SEQ_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_alsa_seq_run, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the MIDI input");
@ -946,7 +968,6 @@ new_fluid_alsa_seq_driver(fluid_settings_t* settings,
error_recovery:
delete_fluid_alsa_seq_driver((fluid_midi_driver_t*) dev);
return NULL;
}
/*

View File

@ -26,13 +26,13 @@
* Interface to Grame's MidiShare drivers (www.grame.fr/MidiShare)
* 21/12/01 : Add a compilation flag (MIDISHARE_DRIVER) for driver or application mode
* 29/01/02 : Compilation on MacOSX, use a task for typeNote management
* 03/06/03 : Adapdation for FluidSynth API
*/
#include "fluidsynth_priv.h"
#if MIDISHARE_SUPPORT
#include "fluid_midi.h"
#include "fluid_mdriver.h"
#include <MidiShare.h>
/* constants definitions */
@ -79,14 +79,14 @@ static void fluid_midishare_close_appl (fluid_midishare_midi_driver_t* dev);
*/
fluid_midi_driver_t*
new_fluid_midishare_midi_driver(fluid_settings_t* settings,
handle_midi_event_func_t handler,
void* data);
handle_midi_event_func_t handler,
void* data)
{
fluid_midishare_midi_driver_t* dev;
int i;
/* not much use doing anything */
if (router == NULL) {
if (handler == NULL) {
FLUID_LOG(FLUID_ERR, "Invalid argument");
return NULL;
}
@ -200,8 +200,8 @@ static void fluid_midishare_keyoff_task (long date, short ref, long a1, long a2,
fluid_midi_event_set_type(&new_event, NOTE_OFF);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, Pitch(e));
fluid_midi_event_set_param2(&new_event, Vel(e)); /* release vel */
fluid_midi_event_set_pitch(&new_event, Pitch(e));
fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -216,19 +216,19 @@ static void fluid_midishare_keyoff_task (long date, short ref, long a1, long a2,
static void fluid_midishare_midi_driver_receive(short ref)
{
fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*)MidiGetInfo(ref);
MidiEvPtr e, e1;
fluid_midi_event_t new_event;
MidiEvPtr e;
while ((e = MidiGetEv(ref))){
switch (EvType (e)){
case typeNote:
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, NOTE_ON);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, Pitch(e));
fluid_midi_event_set_param2(&new_event, Vel(e));
fluid_midi_event_set_pitch(&new_event, Pitch(e));
fluid_midi_event_set_velocity(&new_event, Vel(e));
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -244,8 +244,8 @@ static void fluid_midishare_midi_driver_receive(short ref)
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, NOTE_ON);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, Pitch(e));
fluid_midi_event_set_param2(&new_event, Vel(e));
fluid_midi_event_set_pitch(&new_event, Pitch(e));
fluid_midi_event_set_velocity(&new_event, Vel(e));
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -257,8 +257,8 @@ static void fluid_midishare_midi_driver_receive(short ref)
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, NOTE_OFF);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, Pitch(e));
fluid_midi_event_set_param2(&new_event, Vel(e)); /* release vel */
fluid_midi_event_set_pitch(&new_event, Pitch(e));
fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -270,8 +270,8 @@ static void fluid_midishare_midi_driver_receive(short ref)
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, CONTROL_CHANGE);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, MidiGetField(e,0));
fluid_midi_event_set_param2(&new_event, MidiGetField(e,1));
fluid_midi_event_set_control(&new_event, MidiGetField(e,0));
fluid_midi_event_set_value(&new_event, MidiGetField(e,1));
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -283,7 +283,7 @@ static void fluid_midishare_midi_driver_receive(short ref)
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, PROGRAM_CHANGE);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, MidiGetField(e,0));
fluid_midi_event_set_program(&new_event, MidiGetField(e,0));
/* and send it on its way to the router */
(*dev->driver.handler)(dev->driver.data, &new_event);
@ -295,8 +295,8 @@ static void fluid_midishare_midi_driver_receive(short ref)
/* Copy the data to fluid_midi_event_t */
fluid_midi_event_set_type(&new_event, PITCH_BEND);
fluid_midi_event_set_channel(&new_event, Chan(e));
fluid_midi_event_set_param1(&new_event, ((MidiGetField(e,0)
+ (MidiGetField(e,1) << 7))
fluid_midi_event_set_value(&new_event, ((MidiGetField(e,0)
+ (MidiGetField(e,1) << 7))
- 8192));
/* and send it on its way to the router */

View File

@ -45,6 +45,10 @@
#define BUFFER_LENGTH 512
/* SCHED_FIFO priorities for OSS threads (see pthread_attr_setschedparam) */
#define OSS_PCM_SCHED_PRIORITY 90
#define OSS_MIDI_SCHED_PRIORITY 90
/** fluid_oss_audio_driver_t
*
* This structure should not be accessed directly. Use audio port
@ -119,6 +123,7 @@ new_fluid_oss_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
pthread_attr_t attr;
int err;
int sched = SCHED_FIFO;
struct sched_param priority;
dev = FLUID_NEW(fluid_oss_audio_driver_t);
if (dev == NULL) {
@ -241,6 +246,11 @@ new_fluid_oss_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth)
goto error_recovery;
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? OSS_PCM_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_oss_audio_run, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the audio output");
@ -276,6 +286,7 @@ new_fluid_oss_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func,
pthread_attr_t attr;
int err;
int sched = SCHED_FIFO;
struct sched_param priority;
dev = FLUID_NEW(fluid_oss_audio_driver_t);
if (dev == NULL) {
@ -386,6 +397,11 @@ new_fluid_oss_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func,
goto error_recovery;
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? OSS_PCM_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_oss_audio_run2, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the audio output");
@ -642,6 +658,7 @@ new_fluid_oss_midi_driver(fluid_settings_t* settings,
fluid_oss_midi_driver_t* dev;
pthread_attr_t attr;
int sched = SCHED_FIFO;
struct sched_param priority;
char* device;
/* not much use doing anything */
@ -702,6 +719,11 @@ new_fluid_oss_midi_driver(fluid_settings_t* settings,
goto error_recovery;
}
}
/* SCHED_FIFO will not be active without setting the priority */
priority.sched_priority = (sched == SCHED_FIFO) ? OSS_MIDI_SCHED_PRIORITY : 0;
pthread_attr_setschedparam (&attr, &priority);
err = pthread_create(&dev->thread, &attr, fluid_oss_midi_run, (void*) dev);
if (err) {
FLUID_LOG(FLUID_WARN, "Couldn't set high priority scheduling for the MIDI input");