fluid-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [fluid-dev] FluidSynth on embedded platforms, zero boot time?


From: Carlo Bramini
Subject: Re: [fluid-dev] FluidSynth on embedded platforms, zero boot time?
Date: Tue, 1 Jan 2019 12:58:29 +0100 (CET)

Hello,
since you are using Raspberry Pi Zero, I also suggest you to:

1) compile FluidSynth with "enable-threads" optionset to "off", or remove 
definition of ENABLE_MIXER_THREADS from your config.h file for disabling 
parallel rendering. Since the BCM2835 is a single core ARM11, having 
multithreading is unnecessary.

2) If you will decide to not use threading, when you will port to your RTOS, 
probably you can leave all these functions just empty:

fluid_curtime
fluid_utime
fluid_thread_self_set_prio
fluid_mutex_init
fluid_mutex_destroy
fluid_mutex_lock
fluid_mutex_unlock
fluid_cond_mutex_lock
fluid_cond_mutex_unlock
new_fluid_cond_mutex
delete_fluid_cond_mutex
fluid_rec_mutex_init
fluid_rec_mutex_destroy
fluid_rec_mutex_lock
fluid_rec_mutex_unlock
fluid_private_init
fluid_private_free
fluid_private_get
fluid_private_set
fluid_cond_signal
fluid_cond_broadcast
fluid_cond_wait
new_fluid_cond
delete_fluid_cond
new_fluid_thread
delete_fluid_thread
fluid_thread_join

This function is not stricly necessary, but it will be useful for not locking 
the CPU at 100% usage when you will wait that the playback of a MIDI file is 
finished:

fluid_msleep

it has to just call the function for leaving the control to the IDLE process, 
so it should not be a big problem. Finally, write the atomic functions in a 
very simple manner (this is my implementation):

void fluid_atomic_int_inc(volatile int *_pi) { *_pi++; }
int fluid_atomic_int_add(volatile int *_pi, int _add)
{
    int prev = *_pi;
    *_pi = prev + _add;
    return prev;
}
int  fluid_atomic_int_get(volatile int *_pi) { return *_pi; }
void fluid_atomic_int_set(volatile int *_pi, int data) { *_pi = data; }
int  fluid_atomic_int_dec_and_test(volatile int *_pi)
{
    int data = *_pi - 1;
    *_pi = data;
    return data == 0;
}

int  fluid_atomic_int_compare_and_exchange(volatile int *_pi, int _old, int 
_new)
{
    if (*_pi == _old)
    {
        *_pi = _new;
        return 1;
    } else
        return 0;
}

int  fluid_atomic_int_exchange_and_add(volatile int *_pi, int _add)
{
    int ret = *_pi;
    *_pi += _add;
    return ret;
}

void fluid_atomic_float_set(volatile float *fptr, float val)
{
    fluid_atomic_int_set((volatile int *)fptr, val);
}

float fluid_atomic_float_get(volatile float *fptr)
{
    union {
        int32_t i;
        float   f;
    } val;

    val.i = fluid_atomic_int_get((volatile int *)fptr);

    return val.f;
}

Of course, you must be sure that the functions of FluidSynth are called from a 
single thread and this depends how you will write your final application.

Sincerely.


> Il 31 dicembre 2018 alle 23.57 Geoff Plitt <address@hidden> ha scritto: 
> 
> Thanks! Yes I'm getting great results with RPi Zero, using an I2S DAC. I will 
> look into FreeRTOS, ChibiOS, eCos.
> 
> On Mon, Dec 31, 2018 at 5:50 AM Carlo Bramini < address@hidden> wrote: 
> > Hello! 
> >  yes, I succeded to run FluidSynth on an embedded platform. 
> >  I have built a digital piano and I used FluidSynth as a rendering engine. 
> > 
> >  First of all, I would like to suggest you to read this message: 
> > 
> >  http://lists.nongnu.org/archive/html/fluid-dev/2018-11/msg00022.html 
> > 
> >  with some results from my experiments. 
> > 
> >  I suggest you to abandon the idea to use things like Arduino and similar, 
> > they are simply not powerful enough. Technically, something like the 
> > Raspberry Pi, even the Zero version, and other single board computers are 
> > the best and the cheapest solution for running FluidSynth. 
> >  But as you already noticed, their boot time is very slow, if compared to 
> > an usual microcontroller which is up and running in few milliseconds. I 
> > know that there are some ports of RTOS for the Raspberry Pi, like FreeRTOS, 
> > ChibiOS and eCos, but I never tried them. 
> > 
> >  It depends on what you want to do: in my project, I did a small board with 
> > a PIC18F25K50 for scanning the keyboard matrix of the piano and provides an 
> > USB port and the legacy MIDI-IN/MIDI-OUT. Then, I could connect to the USB 
> > port with several hosts like a PC or a phone. 
> >  I also tried to do some all-in-one solutions, with an embedded ARM Cortex 
> > M3 or a PDA, but I was not able to get decent results, as you could read in 
> > the report that I linked in this email. 
> > 
> >  So, if the all-in-one is what you want, my suggestion is to try again with 
> > a single board computer (Raspberry Pi is good, but you must also remember 
> > to add an I2S DAC because PWM audio is bad and slow) and try one of the 
> > RTOS solutions currently available. Porting is not difficult, I did some of 
> > them (Windows, DJGPP and others) without much problems. However, if you 
> > have some doubts, just ask. 
> > 
> >  Sincerely. 
> > 
> > > Il 30 dicembre 2018 alle 20.55 Geoff Plitt < address@hidden> ha scritto: 
> > > 
> > > I'm working on a musical instrument that uses FluidSynth for playing 
> > > SoundFonts, works great. But I'm using Raspberry Pi (Raspbian) and 
> > > there's a 30-60 second boot time, so I'm looking at other platforms with 
> > > sub-5-second boot time. I'm really looking to replicate the experience of 
> > > hardware synths, where you turn it on and it's ready to make sounds in a 
> > > few seconds at most. 
> > > 
> > > Has anyone had success building/running FluidSynth on an embedded 
> > > platform with minimal OS, like Arduino, Teensy, Adafruit Feather, etc? 
> > > Let's say the system has an SD card and DAC/amp to output audio to little 
> > > speakers, but not a full POSIX environment. 
> > > 
> > > I foundĀ  https://github.com/divideconcept/FluidLite but it doesn't 
> > > include audio output and doesn't look maintained. 
> > > 
> > > My other approach might be to strip out unnecessary parts of Raspbian to 
> > > get a fast boot time, but the documentation I've found still indicates 
> > > it's hard to get under 10 seconds. 
> > > 
> > > _______________________________________________ 
> > > fluid-dev mailing list 
> > > address@hidden 
> > > https://lists.nongnu.org/mailman/listinfo/fluid-dev 
> > 
> >  _______________________________________________ 
> >  fluid-dev mailing list 
> >  address@hidden 
> >  https://lists.nongnu.org/mailman/listinfo/fluid-dev
> 
> _______________________________________________ 
> fluid-dev mailing list 
> address@hidden 
> https://lists.nongnu.org/mailman/listinfo/fluid-dev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]