Click here to Skip to main content
13,198,322 members (56,716 online)

Leslie Sanford - Professional Profile


    Blog RSS
Aside from dabbling in BASIC on his old Atari 1040ST years ago, Leslie's programming experience didn't really begin until he discovered the Internet in the late 90s. There he found a treasure trove of information about two of his favorite interests: MIDI and sound synthesis.

After spending a good deal of time calculating formulas he found on the Internet for creating new sounds by hand, he decided that an easier way would be to program the computer to do the work for him. This led him to learn C. He discovered that beyond using programming as a tool for synthesizing sound, he loved programming in and of itself.

Eventually he taught himself C++ and C#, and along the way he immersed himself in the ideas of object oriented programming. Like many of us, he gotten bitten by the design patterns bug and a copy of GOF is never far from his hands.

Now his primary interest is in creating a complete MIDI toolkit using the C# language. He hopes to create something that will become an indispensable tool for those wanting to write MIDI applications for the .NET framework.

Besides programming, his other interests are photography and playing his Les Paul guitars.


For more information on Reputation please see the FAQ.


Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilverAdmin
Bypass spam checks when posting contentsilversilversilversilversilversilversilverSitebuilder, Subeditor, Mentor, Protector, Editor, Staff, Admin
Store personal files in your account areaplatinumplatinumSitebuilder, Subeditor, Supporter, Editor, Staff
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Edit a Question in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Edit an Answer in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Delete a Question in Q&AYesSubeditor, Protector, Editor, Admin
Delete an Answer in Q&AYesSubeditor, Protector, Editor, Admin
Report an ArticlesilversilversilversilverSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubeditor, Mentor, Protector, Editor, Staff, Admin
Edit other members' articlesSubeditor, Protector, Editor, Admin
Create an article without requiring moderationplatinumSubeditor, Mentor, Protector, Editor, Staff, Admin
Approve/Disapprove a pending QuestionProtector, Admin
Approve/Disapprove a pending AnswerProtector, Admin
Report a forum messagesilversilverbronzeProtector, Editor, Admin
Approve/Disapprove a pending Forum MessageProtector, Admin
Create a new tagsilversilversilversilverAdmin
Modify a tagsilversilversilversilverAdmin

Actions with a green tick can be performed by this member.

GeneralApplying Generic Programming to Runtime Polymorphism Pin
Leslie Sanford22-Feb-10 10:28
memberLeslie Sanford22-Feb-10 10:28 
GeneralGeneric Programming [modified] Pin
Leslie Sanford19-Jul-08 5:53
memberLeslie Sanford19-Jul-08 5:53 
Generic programming has become a bit of an obsession of mine lately. I've been studying this website:

Generic Programming[^]

And I've been intrigued by applying generic programming techiniques to DSP programming. I've posted about this in the past with a generic example of a delay line as well as a small parameter handling toolkit.

A key concept of generic programming is called Lifting[^]. It's where you examine a concrete algorithm and look for ways to make it generic. For example, here is a concrete copy algorithm:

void Copy(float *first, float *last, float *out) 
    while(first != last) 
        *out = *first; 

Fair enough. But what if we wanted a copy algorithm for integers? We'd have to do this:

void Copy(int *first, int *last, int *out) 
    while(first != last) 
        *out = *first; 

In examining the two algorithms we see they are exactly the same except for the type. So we can "lift" the algorithm up by making it type independent:

template<typename InputIterator, typename OutputIterator> 
void Copy(InputIterator *first, 
          InputIterator *last, 
          OutputIterator *out) 
    while(first != last) 
        *out = *first; 

Now we have a Copy function that can work on any type provided that the iterators meet the requirement of the algorithm. This is an important point. It's usually impossible to lift an algorithm to the point that it is so generic it can work on anything. There are usually some requirements. The above algorithm requires that the InputIterator support the postfix increment operator as well as the * operator for reading its value. The OutputIterator must also support the postfix increment operator and the * operator for writing to its value.

So how about applying this to DSP? Can we "lift" some of the algorithms used in DSP and VST programming?

Take a basic sine oscillator function:

float SineOscillator(float *first, 
                     float *last, 
                     float phase, 
                     float increment) 
    while(first != last) 
        phase += increment; 
        while(phase > PI2) 
            phase -= PI2; 
        *first = sin(phase); 
    return phase; 

What can we do to "lift" this algorithm?

We can make it type independent for one. That's easy enough. But it would also be cool to make it waveform independent as well. And it would also be nice to pack up the phase and increment values into one object instead of passing them in seperately.

So applying the above, we come up with this:

template<typename OutputIterator, 
         typename Oscillator, 
         typename Waveform> 
Oscillator Oscillate(OutputIterator first, 
                     OutputIterator last, 
                     Oscillator osc, 
                     Waveform wave) 
    while(first != last) 
        osc.phase += osc.increment; 
        while(osc.phase >= osc.length) 
            osc.phase -= osc.length; 
        *first = wave(osc.phase); 
    return osc; 

The algorithm has several requirements. Oscillator must have a phase, increment, and length values. Waveform must provide a () operator that takes the current phase and returns a result.

One challenge with this kind of approach is maintaining state after each function call. If we call the above function like this:

Oscillate(&buffer[0], &buffer[BUFFER_SIZE], myOsc, sin); 

Both the oscillator and waveform objects are passed in by value. We can update our oscillator object by assigning the return value to it:

myOsc = Oscillate(&buffer[0], 

That's fine but may not be very efficient if the oscillator is very large.

Instead we can pass the oscillator object in as a reference so whatever state changes that take place within the function persist afterwards:

Oscillate<float *, MyOscillator &, Sine>(&buffer[0], 

If we need to persist changes in state to our waveform, we can use the same technique:

Oscillate<float *, MyOscillator &, Sine &>(&buffer[0], 

This just scratches the surface. But the idea is to abstract algorithms to make them generic so that they can be reused in many different contexts.

modified on Sunday, July 20, 2008 9:14 PM

GeneralOff-topic Pin
Rajesh R Subramanian19-Jun-09 12:48
mvpRajesh R Subramanian19-Jun-09 12:48 
GeneralRe: Off-topic Pin
Leslie Sanford19-Jun-09 19:06
memberLeslie Sanford19-Jun-09 19:06 
GeneralEnsuring Object State [modified] Pin
Leslie Sanford27-Jun-07 8:00
memberLeslie Sanford27-Jun-07 8:00 
GeneralEvolution of Messaging Pin
Leslie Sanford19-Oct-06 5:15
memberLeslie Sanford19-Oct-06 5:15 
GeneralEnumerators as Synthesizer Components Pin
Leslie Sanford20-Sep-06 20:53
memberLeslie Sanford20-Sep-06 20:53 
GeneralAnonymous Methods as Glue Pin
Leslie Sanford17-Sep-06 14:30
memberLeslie Sanford17-Sep-06 14:30 
GeneralRefining the approach Pin
Leslie Sanford22-Jan-06 7:52
memberLeslie Sanford22-Jan-06 7:52 
GeneralFlowing down the Sink Pin
Leslie Sanford21-Jan-06 16:45
memberLeslie Sanford21-Jan-06 16:45 
GeneralFlow-Based Programming in C# Pin
Leslie Sanford29-Dec-05 13:07
memberLeslie Sanford29-Dec-05 13:07 
GeneralCombining Visitor, Observer, and Iterator Pin
Leslie Sanford25-Dec-05 21:29
memberLeslie Sanford25-Dec-05 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 21 Oct 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid