I’m writing a callback for an oscilliscope in VB, and I need a way to convert the newbuffer into an array of 1024 elements, I know that this is extremely easy in C++ or delphi but what about VB?? Thanks.

What if you remove the newbuffer = originalbuffer thing, so you are sure you are working on the new buffer?
Also, but probably not the reason of your problems, I think you should count from 0 to ScopeLength – 1, instead of to ScopeLength.

But there are some other problems with it that might cause it not to work correctly :
The documentation says … int length … and I think int is 4 bytes in C, so you should use a Long instead of an Integer in visual basic. (for the length and param arguments)

Another thing is in your GetScope function :
If I’m not mistaking, CopyMemory takes the number of bytes to copy as last argument.
The number of bytes = the number of elements in the array (Ubound(ScopeData) if it starts at zero) * the number of bytes per element.
Since the type you are copying is an Integer (short int in c), this are only 2 bytes.
The correct code would be :
CopyMemory ScopeData(0), lpBuffer, UBound(ScopeData) * 2

If you are using FSOUND_DSP_Create to create your dsp, then you also have to make sure that FMOD’s output mode is not set to FPU.
If you set it to fpu, you have to replace Integer with Single, and Single does take 4 bytes.
To make sure the mixer is not FPU, set it to something else manually before initializing fmod :
FSOUND_SetMixer FSOUND_MIXER_QUALITY_AUTODETECT
I think the autodetect doesn’t select FPU (but I’m not 100% sure).

I’ve tried to do it without newbuffer = originalbuffer and it does the same thing. And every example, except for bretts, has that line. So I dont know. I’ve tried to convert bretts code to VB, but it has the lines:
dest = &OscBuffer[OscBlock * FSOUND_DSP_GetBufferLength()];
And I dont know what that does, and also there is a lot of <<1, which is supposed to convert samples to bytes, and I’m not sure how to do this in VB. So I’m having a bit of bad luck I guess! 😕

Thanks for all of your help! I finished the callback and it’s not too bad, although my code for displaying it doesn’t make the scope look smooth or anything, but at least it works. With the scope data I’m thinking if doing a bunch of different types of visuals with it, it will be interesting. Thanks again!

lol, and also, does anybody know what calloc is and how to do this in VB?? Because I find the line:
[code:2qm92utu]
OscBuffer = calloc(FSOUND_DSP_GetBufferLengthTotal() + 16, 2); /* *2 for mono 16bit buffer */
[/code:2qm92utu]
In Bretts example and I dont know how to do this in VB! Thanks!

You are using Single’s, but you have to make sure that this format matches the output format.
Stream dsp’s depend on the input format, and will in most cases return 16-bit integer values, so you will have to use Integer’s for these.
For normal output dsp’s, this depends on the output format, and only the highest quality fpu output mode will give you Single’s.
The other output formats will also give you Integer’s.

calloc(nelement, size_per_element) : The calloc() function allocates space for an array of nelement of size size_per_element. The space is initialized to zero. In VB, we can do it in two step (CopyMemory or FillMemory to alloc and ZeroMemory to initialize to zero.

Hmmm, I’m finding it a bit difficult to do this. I’ve gotten rid of the “-1.#QNAN” thing, but now, for some reason the values of the scope data never change with the music, and some of the items in the ScopeBuffer array start out at a number and change randomly. Heres my code (remake of my other code):

[code:2c2urju6]
Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal length As Integer, ByVal param As Integer) As Long

And I’ve also tried to do it like this (which I found in a Delphi example):
[code:2c2urju6]
Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal length As Integer, ByVal param As Integer) As Long