Plug-ins, Hosts, Apps,
Hardware, Soundware
Developers
(Brands)
Videos Groups
Whats's in?
Banks & Patches
Download & Upload
Music Search
KVR
   
KVR Forum » DSP and Plug-in Development
Thread Read
My approaches to develop a decent wavetable engine
paoling
KVRist
- profile
- pm
- www
PostPosted: Fri May 18, 2012 3:11 am reply with quote
Hi to all!
I write this post in order to share some concepts I learnt for optimizing my sampling engine and to get more ideas about things I still don't know.

My engine is developed by enhancing the Simple Sampler example from Christian Budde VST Framework.

Everything starts in the main ProcessReplacing call.

Firstly I zeroed the output buffers with FillChar function.
Then I start two nested loops

while VoiceIndex < Voices.Count do

while SampleIndex<SampleFrames do

The first is a counter for the Voices that are going to be processed, while the second is the usual OutputBuffer processor.

Then I start the Voice.Process function that returns a two values array that is going to be summed on the Output array. In this way all the current Voices will be summed and the loop will finish.

At the end of this big loop I run various little routines like Voice Killing, if the voice is not playing anymore. (and others will be added when my sampler will grown in complexity).

The Voice object has this so called Process function.
This function has a big CASE statement. A BRANCH!!!
Uhm yes, because I didn't know how to avoid that Very Happy
But this shouldn't be a problem since the program flow will keep the same path in the whole voice life.

I did this because I needed to pass between interpolation methods and Lowpass filtering depending of the note that I will playing. In relation to the sample rate of the original file. Now if the sample is going to be played at a slow speed the interpolation has a greater importance. When the sample is going to be played ad an higher speed the interpolation lessen its importance and at extreme levels, when it is going to be played at 8x or 16x of its speed the Lowpass is needed to avoid aliasing.

The CASE statements has different paths for the different cases, beginning with a cubic interpolation, linear interpolation+littlelowpass, linearinterpolation+mediumlowpass, nointerpolation+strong lowpass.

Since I'm not a math guy I used the simple lowpassing technique of: (sample1+sample2)/2 for halving the samplerate of the signal. I don't know if it is a valid method but is works and it should be lightweight CPU wise.

Since the process function needs a truncation mode I used a single Asm64 instruction to do this, that it's faster than the delphi trunc function.

function FastTrunc(FloatNumber: Single) : integer;

  asm
    CVTSS2SI EAX,xmm0
  end;


There's a comparable instruction in asm 32bit but I don't remember the name now.

There's an ADSR filter that I implemented by calculating the values in a table. So at processing time the ADSR influence is just a multiplication for the value in the table. I could go for linear interpolating the values to save memory, but I'm still checking it.

As usual the Sampler has a mapping feature, that will choose the correct sample when playing the note.

I'm very esigent about CPU consuming and since Delphi is not helping me to achieve the spectacular results I'm looking to find tricks to enhance performance.

One could be to filter all the voices in the same filtering case at once. I don't think that it will work with interpolation but I'm quite confident that it can work for lowpass filtering. I just need to review the engine structure.

I also unrolled some loops in the main ProcessReplacing.
^ Joined: 24 Jan 2012  Member: #273585  
Ichad.c
KVRist
- profile
- pm
- e-mail
- www
PostPosted: Fri May 18, 2012 6:37 am reply with quote
paoling wrote:

Since I'm not a math guy I used the simple lowpassing technique of: (sample1+sample2)/2 for halving the samplerate of the signal. I don't know if it is a valid method but is works and it should be lightweight CPU wise.


That's called a moving average filter btw. I've read somewhere that you could add feedback to it to improve it a bit.

Just my 2cents.

Regards
Andrew
^ Joined: 08 Feb 2012  Member: #274678  Location: South - Africa
paoling
KVRist
- profile
- pm
- www
PostPosted: Fri May 18, 2012 7:16 am reply with quote
Thank you so much, in programming and maths it's sometimes useful just to know how to name something that you realize by intuition. Now I'll have some other interesting things to read Smile
^ Joined: 24 Jan 2012  Member: #273585  
All times are GMT - 8 Hours

Printable version
Page 1 of 1
Display posts from previous:   
ReplyNew TopicPrevious TopicNext Topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Username: Password:  
KVR Developer Challenge 2012