0
0

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.

  • You must to post comments
0
0

I try to convert the reverb effect to vb with no succes :roll:

Paranoid_Android>

dest = &OscBuffer[OscBlock * FSOUND_DSP_GetBufferLength()];

In VB (i think) :

dest = VarPtr(OscBuffer (OscBlock * FSOUND_DSP_GetBufferLength)

Also, try to change the ScopeBuffer as a static array of integer.

  • You must to post comments
0
0

I had though calloc just made enough space. But I’m not too good at C++… ๐Ÿ˜ณ

  • You must to post comments
0
0

Oups, i forgot to login ๐Ÿ˜ณ

  • You must to post comments
0
0

The GetSpectrum code that can be found in fmod.bas does exactly that.
You can create a similar function to that, and you’ll also have to create a function that copies the array back to the pointer.

  • You must to post comments
0
0

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 must to post comments
0
0

Oh, I see, thanks.

  • You must to post comments
0
0

You can use ZeroMemory to empty the buffer :

Private Declare Sub ZeroMemory Lib “kernel32.dll” Alias “RtlZeroMemory” (Destination As Any, ByVal Length As Long)

  • You must to post comments
0
0

Ok, so heres my code. When I run my program it runs normally, but the ScopeBuffer values are all crazy, like “-1.#QNAN”.

[code:1u6fjnze]

Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal length As Integer, ByVal param As Integer) As Long

Dim Count As Integer
Dim Data(1024) As Single

newbuffer = originalbuffer

Call GetScope(Data, newbuffer)

For Count = 0 To 1023
    ScopeBuffer(Count) = Int(Data(Count))
Next Count

ScopeCallback = newbuffer

End Function

Private Function GetScope(ByRef ScopeData() As Single, ByVal lpBuffer As Long)

Dim nrOfVals As Long
If UBound(ScopeData) > 1023 Then nrOfVals = 1024 Else nrOfVals = UBound(ScopeData) + 1
CopyMemory ScopeData(0), lpBuffer, nrOfVals * 4

End Function

[/code:1u6fjnze]

Does anyone know what the problem could be?? Oh and couldn’t I use VarPtr (which is an undocumented VB function to retrieve the pointer from a variable) to copy the array back to the pointer?? Thanks.

  • You must to post comments
0
0

Is this what calloc does???

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

Hmm, ok. But does that explain the weird number values, like 1.#QNAN?

  • You must to post comments
0
0

Or just create an array of the appropriate type and use ReDim on it to initialize and allocate it.

  • You must to post comments
0
0

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

Dim Count As Integer
Dim Data() As Integer

newbuffer = originalbuffer

ScopeLength = Int(length)
ReDim Data(ScopeLength) As Integer
ReDim ScopeBuffer(ScopeLength) As Integer

GetScope Data, newbuffer
For Count = 0 To ScopeLength
    ScopeBuffer(Count) = Int(Data(Count))
Next Count

ScopeCallback = newbuffer

End Function
[/code:2c2urju6]

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

newbuffer = originalbuffer
Blockcount = FSOUND_DSP_GetBufferLength
ReDim ScopeBuffer(Blockcount) As Integer
GetScope ScopeBuffer, newbuffer
ScopeCallback = newbuffer

End Function
[/code:2c2urju6]
Ive had the same luck with this code, just like the other one, the items in the ScopeBuffer array start out at a number and change randomly.

Thanks for any feedback

  • You must to post comments
0
0

Well, I’ve just been using redim. Its really gettting annoying though! when I use my callback I, basically get random data from the buffer. Does anybody know what the problem might be, becuase I’ve run out of things to do!

Heres the code I tried:
[code:1d6bq8md]
Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal Length As Integer, ByVal param As Integer) As Long

Dim Count As Integer
Dim Data() As Integer

ReDim ScopeBuffer(Length) As Integer
ReDim Data(Length) As Integer

GetScope Data, newbuffer
For Count = 0 To Length - 1
    ScopeBuffer(Count) = Int(Data(Count))
Next Count

ScopeCallback = newbuffer

End Function
[/code:1d6bq8md]

And, to copy the pointer to an array:
[code:1d6bq8md]
Private Function GetScope(ByRef ScopeData() As Integer, ByVal lpBuffer As Long)

CopyMemory ScopeData(0), lpBuffer, (UBound(ScopeData) + 1) * 4

End Function
[/code:1d6bq8md]

Thanks!

  • You must to post comments
0
0

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.

Could you post the code of GetScope if it still doesn’t work?

  • You must to post comments
0
0

I can’t see a real problem with the code…

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).

  • You must to post comments
0
0

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! ๐Ÿ˜•

  • You must to post comments
0
0

Oh, I see, I think I may have found the problem. Thanks!

  • You must to post comments
0
0

<<1 is a bit shift, and you can replace it with *2 in vb.
>>1 can be replaced with \ 2 in vb.
When I have some time I’ll try to create an example myself, and see if I can get it to work.

  • You must to post comments
Showing 1 - 20 of 21 results
Your Answer

Please first to submit.