|
From: Josh G. <jg...@us...> - 2003-04-02 00:41:56
|
On Tue, 2003-04-01 at 00:01, Benno Senoner wrote: > Hi guys, > cool that multiple tools exist. > I'm looking forward for AKAI reading support in libinstpatch. > > But OTOH, I think it would be very handy if someone of you could port > libakai to linux (or fix that support lib Sebastien talked about). > It would especially be useful for those like me that experiment with > the audio engine, since for the beginning I'd like to read AKAI samples > (at least basic stuff) as easily as possible. > Of course later the way to go will be using a complete, multiformat and > flexible library like libinstpatch, but I think for now it would be > VERY HANDY if some of you (Christian S., Frank, Sebastien, Paul Kellet, others > .. ?) could fix libakai so that it works out of the box on Linux. > > comments ? > > PS: I'm just programming a Delta 1010 card, ALSA really rocks :-) > > cheers, > Benno > http://linuxsampler.sourceforge.net > If you are just looking for any patch format that has loading support, you could always use SoundFont support with libInstPatch. Maybe this would help the developers here get familiar with the API and get some ideas of what can be improved, etc with libInstPatch as well. As things are now, libInstPatch is compiled with Swami, but the library can be used independently of Swami, once installed. Some example code (note that the loading API will be improved in the near future): IpatchSF2 * linuxsampler_load_soundfont (char *filename) { IpatchSF2 *sf; int fd; if ((fd = open (filename, O_RDONLY)) < 0) { fprintf ("Failed to open file \"%s\": %s", filename, strerror (errno)); return (NULL); } /* this call will look different when loading API is improved */ if (!(sf = ipatch_sf2_load (fd, IPLOAD_ALL, NULL, NULL))) { close (fd); return (NULL); } return (sf); } After loading a SoundFont in this fashion, all the IpatchSampleData objects will contain a single IpatchSampleStoreFile which just holds a location to the relevent sample data in the SoundFont file. A sample data object can contain multiple stores though, so you could load all of them into RAM while still retaining the file stores as well. When it comes to accessing the objects in the SoundFont, there are a number of ways of doing this. If not in a multi-thread environment, you can just access the lists and parameters directly. If multi-thread access to the same objects is desirable, then objects need to be locked when accessing their lists (IPATCH_ITEM_RLOCK/_RUNLOCK and IPATCH_ITEM_WLOCK/_WUNLOCK, currently there is no difference between read or write locking, but in the future there might be) or the somewhat slower iterator system can be used (makes a duplicate of a list under lock, aftwards this list can be used at ones own leasure). I'll just assume single thread access for these examples: There is a nice function for rendering a patch item (currently IpatchSF2Preset, IpatchSF2Inst or IpatchSF2Sample objects) into SoundFont compatible "voices". This comes in real handy when doing actual synthesis (used in FluidSynth plugin). It looks like this: ipatch_sf2_voices_foreach (IpatchSF2Voices *obj, int note, int velocity, IpatchSF2VoicesForeachFunc func, gpointer data) obj is the item to convert to voices. note and velocity are the MIDI note and velocity of the note event. func is the function to call with each rendered voice. The IpatchSF2VoicesForeachFunc is passed a structure containing the original parameters, plus an array of generators (effect parameters), a modulator list (real time effect controls) and a SoundFont sample. From this information a single voice can be created. Here is an example of accessing samples and manipulating its sample stores (in this case we are checking each sample to see if it has a RAM store, if not we create it), essentially loads all samples into RAM: { IpatchSF2 *sf; IpatchSF2Sample *sample; IpatchSampleStore *store, *ramstore; GSList *p; /* glib single linked list type (forward only) */ if (!(sf = linuxsampler_load_soundfont ("test.sf2"))) exit (1); /* single threaded direct list access, a no no for MT environments */ p = sf->samples; while (p) /* loop over SoundFont samples */ { sample = (IpatchSF2Sample *)(p->data); /* find the fastest readable sample data store for the sample */ store = ipatch_sf2_sample_find_store_ref (sample, 0, IPATCH_SAMPLE_STORE_FIND_FASTEST | IPATCH_SAMPLE_STORE_FIND_READABLE); /* if not a RAM sample store, create one */ if (!IPATCH_IS_SAMPLE_STORE_RAM) { ramstore = ipatch_sample_store_duplicate (store, IPATCH_TYPE_SAMPLE_STORE_RAM, &err); if (!ramstore) { fprintf (stderr, "Error duplicating sample data: %s\n", err ? err->message : "<No details>"); exit (1); } } g_object_unref (store); /* remove our reference from find */ p = p->next; /* next list node */ } } Anyways.. Probably writing too much for this email :) I invite anyone who is interested to check things out, ask questions, make suggestions etc. I'd like to start to get an idea of whats good and what could be improved, before things become too dependent. Cheers. Josh Green |