This project has moved. For the latest updates, please go here.

leveraging drummachinedemo

Sep 13, 2012 at 1:35 PM
Edited Sep 13, 2012 at 7:08 PM

i've been using this code base for a simple metronome app i'm working on.

couple things i did to make it useful for my application..

1.  i had also updated the patternsequencer to smooth out tempo changes. nice to see the recent updates to that code, so i'm switching over to the official code base for this.

2. i have no use for the hardcoded stepsPerBeat = 4, so i've hardcoded to 1.  To make the code reuseable that should be a property

3. I added an event to patternsequencer to pass up an event when a sample is written to drive GUI updates.  The delay really isnt necessary given the buffering/sample size, but at least in my imagination it seems to provide a tighter gui update.

mixerInputs.Add(sampleProvider);
FireSequencerEvent(currentStep, 1000 * sampleProvider.DelayBy / this.drumKit.WaveFormat.SampleRate);

this event needs to be visible to drum machine clients, which i made visible by making some things public, but it should be passed up.

4. I modded DrumKit to use my own samples..  Maybe a constructor to allow samples to be passed in an array would open this up.

5. I modded SampleSource with a method to allow one to be created from a stream - have embedded wav in the resx

Coordinator
Sep 25, 2012 at 6:38 AM

hi, glad you're finding it useful. It's not strictly part of the NAudio library, but I'll bear your suggestions in mind next time I work on it. 2 & 5 are great ideas, and 4 was always planned anyway (the goal was to eventually support loading from SF2 files). As for 3, that can be a little more dangerous, as it would involve raising an event from within a soundcard buffer callback, something that I try to avoid in NAudio as many people don't understand the performance implications - your event handler needs to return as quickly as possible.

Sep 25, 2012 at 3:40 PM

yea 3 is purpose built in a way i can control what happens - just kicks off a task on threadpool or invokes on guithread.  i also tried using an independent timer but the synchronization would drift under load.   thx though, it works great tailored for this app.