views:

227

answers:

1

How can I create a circular buffer on the heap in VB.NET ?

This would be used for audio playback via P/Invoke to winmm.dll waveoutopen and waveoutwrite to support development of a software synth.

I currently use the marshall class to build a regular array of bytes in the heap.

+2  A: 

OK, I'll byte...

Do you really mean CIRCULAR ( as in fixed size) or could you use a linked-list?

And

Why worry about "heap?" This is VB not "c/c++" on an embedded hardware system. Is the use of the term "heap" due to data scope, life cycle, or availability (to other apps? as in ALLOC/MALLOC)

tob

tobrien
I don't think I can use a linked list as I just need to pass a pointer to a block of memory to the winmm API. My work in progress is here: http://waveout.codeplex.com/SourceControl/changeset/view/43602#798077 I'm trying to rotate buffers on the callback from when a buffer playback is complete but this is not strictly a circular buffer
PeanutPower
OK, I took a peek... It seems you create your "samples" into an Queue/array and then Marshall.write byte by byte into heap, then pass the ptr to the multimedia dll.How about creating an explicitly defined data structure (i.e. LChannel data followed immediately by RChannel data ) then passing the pointer to the struct to MM_ddl? You could conceivably be replacing data on the "front end" while the data gets played out. Or you could have a flip-flop arrangement where you pass one array to MM_dll while you fill a second, then pass that one, and go back and fill the first again.
tobrien
The structure would be created large enough to hold the 44100 samples you need per second.
tobrien