Sign in
|
Join
Search
A Portion of Buff
Everybody else had one, so...
Home
About
RSS
Atom
Comments RSS
Recent Posts
Noise 0.3 released
The subdued garbage collector
Noise 0.2 source released
On microbenchmarks and red faces
Keeping it real-time (3)
Tags
Managed DirectX
Navigation
Home
Blogs
Managed DirectX
My First Spinning Cube
(Probably Not) The World's Smallest Video Player
Archives
April 2005 (2)
March 2005 (5)
February 2005 (1)
October 2004 (1)
September 2004 (1)
August 2004 (4)
July 2004 (2)
February 2004 (1)
January 2004 (2)
December 2003 (1)
June 2003 (1)
May 2003 (4)
April 2003 (6)
March 2003 (3)
February 2003 (3)
The subdued garbage collector
I want
Noise
to support any .Net language, not just C# (although why anyone would use another language...). At the moment, the plugin interface exposes unsafe methods - Process and ProcessReplacing - which take float* parameters and are therefore unusable by a pussy language like VB.Net. Pointers are used because it allows us to write directly to the host's memory instead of allocating our own buffers and copying them back to the host.
If we are prepared to take a performance hit, we can make this interface safe. Not only is there the cost of copying unmanaged memory to a managed buffer on the way in, and then back again on the way out, we need to allocate some managed memory in the first place. Allocations lead to collections, collections lead to hate, hate leads to suffering.
However, we can take advantage of the fact that the maximum number of samples being passed to the plugin rarely changes (usually not until the host's latency setting has been changed, which is hardly ever under normal use), although the host is free to send fewer samples if it wishes. The host tells us the maximum block size by calling the SetBlockSize() method, which is a good place to allocate our buffers:
public override void SetBlockSize(int blockSize)
{
leftBufferIn = new float[blockSize];
rightBufferIn = new float[blockSize];
leftBufferOut = new float[blockSize];
rightBufferOut = new float[blockSize];
}
and in the Process or ProcessReplacing methods, we can just fill these buffers using the Marshal class:
public override void ProcessReplacing(float* inLeft, float* inRight, float* outLeft, float* outRight, int sampleFrames)
{
Marshal.Copy(new IntPtr(inLeft), leftBufferIn, 0, sampleFrames);
Marshal.Copy(new IntPtr(inRight), rightBufferIn, 0, sampleFrames);
Marshal.Copy(new IntPtr(outLeft), leftBufferOut, 0, sampleFrames);
Marshal.Copy(new IntPtr(outRight), rightBufferOut, 0, sampleFrames);
//...
}
It doesn't matter if sampleFrames is less than blockSize, we just copy that many samples to our buffers. This enables us to call out to a safe method which deals with float arrays, and performance is constant because no new allocations occur. Hurrah.
Posted:
Apr 06 2005, 12:41 AM
by
jimski3000
| with
2 comment(s)
Comments
Big D
said:
It's not really subdued. It's probably lonely.
#
April 6, 2005 5:40 AM
Big D
said:
And horny.
#
April 6, 2005 9:47 AM
Leave a Comment
Title
(required)
Name
(required)
Your URL
(optional
)
Comments
(required)
Remember Me?