[music-dsp] Hosting playback module for samples

2014-02-26 Thread Mark Garvin
I realize that this is slightly off the beaten path for this group,
but it's a problem that I've been trying to solve for a few years:

I had written software for notation-based composition and playback of
orchestral scores. That was done via MIDI. I was working on porting
the original C++ to C#, and everything went well...except for playback.
The world has changed from MIDI-based rack-mount samplers to computer-
based samples played back via hosted VSTi's.

And unfortunately, hosting a VSTi is another world of involved software
development, even with unmanaged C++ code. Hosting with managed code
(C#) should be possible, but I don't think it has been done yet. So 
I'm stuck. I've spoken to Marc Jacobi, who has a managed wrapper for
VST C++ code, but VSTi hosting is still not that simple. Marc is very
helpful and generous, and I pester him once a year, but it remains an
elusive problem.

It occurred to me that one of the resourceful people here may have 
ideas for working around this. What I'm looking for, short term, is
simply a way to play back orchestral samples or even guitar/bass/drums
as a way of testing my ported C# code. Ideally send note-on, velocity,
note-off, similar to primitive MIDI. Continuous controller for volume
would be icing.

Any ideas, however abstract, would be greatly appreciated.

MG
NYC

--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp 
links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp


Re: [music-dsp] Hosting playback module for samples

2014-02-26 Thread Mark Garvin
1. Re: Hosting playback module for samples (Ross Bencina)

 From: Ross Bencina rossb-li...@audiomulch.com
 Hi Mark,
 
 I'm not really sure that I understand the problem. Can you be more 
 specific about the problems that you're facing?

Hi Ross,

Specific: (Forgive me if you know all of this): My code is C#, but
there is no simple way to bridge the gap between the managed realm
and a module that can play orchestral samples.  

Most sample banks these days seem to be in NKI format (Native 
Instruments). They have the ability to map ranges of a keyboard into
different samples so the timbres don't become munchkin-ized or
Vader-ized. IOW, natural sound within each register.

A playback engine is typically something like Native Instruments'
Kontakt, which is 'hosted' by the main program (my composition
software, for ex). then NI Kontakt can load up NKI files and 
deliver sound when it receives events.

The whole process of linking events, etc is what usually what
stymies programmers who are new to VST-based programming. And
even many who are familiar.

 Personally I would avoid managed code for anything real-time (ducks).

Actually, C# can be faster than pre-compiled code! The first time a given
section of code runs, the JIT (just in time) compiler replaces the 'IL' 
code with highly optimized machine code. Since the JIT module can
test the CPU that it running on, it can optimize for that particular
CPU and chip set. Early on, one of the popular book authors (Richard
Grimes) coded FFT algorithms in both C++ and C#, and C# was faster.

 You're  need to build a simple audio engine (consider PortAudio or the 
 ASIO SDK). And write some VSTi hosting code using the VST SDK. It's this 
 last bit that will require some work. But if you limit yourself to a 
 small number of supported plugins to begin with it should not be too 
 hard. MIDI scheduling in a VSTi is not particularly challenging -- the 
 plugins do the sub-buffer scheduling, you just need to put together a 
 frame of MIDI events for each audio frame.

That's inspiring. I'm not sure that this is done in the same way as a
regular plugin though. And I believe it's pretty difficult to host a
VSIi in managed code. That is pretty much the crux of the problem right
there. I've heard of a lot of people who started the project but were
never aboe to get it off te ground.

 If there's any kind of synchronisation with the outside world things 
 will get trickier, but if you can clock the MIDI time off the 
 accumulated sample position it's not hard.

I could do without sync to external for now.

... I guess the main 
 approaches would be to either (A) schedule MIDI events ahead of time 
 from your C# code and use a priority queue (Knuth Heap is easy and 
 relatively safe for real-time) in the audio thread to work out when to 
 schedule them; or (B) maintain the whole MIDI sequence in a vector and 
 just play through it from the audio thread. Then you need a mechanism to 
 update the sequence when it changes (just swap in a new one?).

The internals of a VSTi host are beyond me at present. I was hoping
for some simple thing that could be accessed by sending MIDI-like events
to a single queue.

Thanks to both who responded. I've signed up for the PortAudio mailing
list. Maybe they have something.

Mark G.
NYC
--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp 
links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp