0
0

Hi. I read in the fmod documentation that

“FSOUND_MPEGACCURATE is to be used cautiously. To open a file with this mode turned on, it has to scan the whole MP3 first. This can take several seconds if the file is big, or the harddisk/cpu is slow. A way to speed up this process would be to load the compressed mp3 into memory first, and use the FSOUND_LOADMEMORY flag with this function.”

This may sound quite simple, but I have no idea how to do it in VB (i’m using version 6). How do I load the compressed mp3 into memory?

As I read along the forums, there’s no other way of getting accurate timing/positioning with VBR files right now. But as i’m getting an about 1 second pause loading an VBR mp3 from HD, any help with the above would be very appreciated. Thanks in advance.

  • You must to post comments
0
0

To fix the problem, you need to instruct VB that the value is a Long, not an Integer (in VB, all numbers are signed). This is done by adding an ampersand (‘&’) to the end of the number (HEX or decimal).
[code:ddr0o2vo]num = &H8000 ‘ num = -32768
num = &Hffff ‘ num = -1
num = &H8000& ‘ num = 32768
num = &Hffff& ‘ num = 65535[/code:ddr0o2vo]
Numbers outside the valid range of an Integer (-32768 through 32767) are automatically upgraded to Long status. That’s most likely why “32768” works but “&H8000” doesn’t.

  • You must to post comments
0
0

Thanks, I didn’t know that yet.
Still strange it is converted to Integer up to &Hffff, and only after that to Long (&H10000 works as it should).

  • You must to post comments
0
0

It’s from the old days of BASIC. Rather than have types, you used put a suffix on the variable name to indicate the type. The most common suffix was the infamous ‘$’ for strings. Visual Basic is more strongly typed, so variables can do without a suffix. But just like C/C++, literals still need some help. Here is a handy chart of data types for VB and C/C++ with their appropriate [i:16bqj7dn]type-declaration characters[/i:16bqj7dn]. (It may be incomplete, but this should cover the main ones.)
[code:16bqj7dn]———————————————————————-

VB VB VB VB VB VB VB VB VB VB VB VB VB VB VB VB VB VB

‘ All VB types are signed, except Byte which can only be unsigned.
‘ Decimal type can only be used within a Variant, through CDec().

Byte var = 123 ‘ No suffix.
Integer var% = 1234%
Long var& = 98765&
Single var! = 0.1234!
Double var# = 1234.56789#
Currency var@ = 3.1415926535897932384626@
Date var = #6/1/2002# ‘ Note prefix as well.
String var$ = "Hello, World!" ‘ Note prefix as well.


C/C++ C/C++ C/C++ C/C++ C/C++ C/C++ C/C++ C/C++ C/C++ C/C++ C/C++

// Integral types can be signed or unsigned.
// Combine the suffixes to get the desired result.

unsigned var = 12u; // Or U.
signed var = 12; // No suffix.

short var = 1234; // No suffix.
long var = 98765l; // Or L.
__int64 var = 9988776655i64; // Or I64.
float var = 0.1234f; // Or F.
double var = 1234.56789; // No suffix.
long double var = 3.1415926535897932384626l; // Or L.
char var = ‘A’; // Note prefix as well.
wchar var = L’A’; // Note additional prefix.
(string) var = "Hello, World!"; // Note prefix as well.
(wstring) var = L"Hello, World!"; // Note additional prefix.[/code:16bqj7dn]

  • You must to post comments
0
0

You need a public variable to store the sound in :

[code:2xra2kqh]
Public myMP3() as Byte
[/code:2xra2kqh]

Determine the length of the file in bytes :

[code:2xra2kqh]
FileLength = FileLen(Players(a).FileName)
[/code:2xra2kqh]

Now, reserve memory for the file :

[code:2xra2kqh]
ReDim myMP3(FileLength – 1)
[/code:2xra2kqh]

Open the file and read the mp3 :

[code:2xra2kqh]
f = FreeFile
Open FileName For Binary As #f
Get #f, , myMP3
Close #1
[/code:2xra2kqh]

Now your file is in memory and you can load it :

[code:2xra2kqh]
Stream = FSOUND_Stream_OpenFile2(myMP3(0), FSOUND_LOADMEMORY, FileLength)
[/code:2xra2kqh]

You should check fmod.bas, and if you only find FSOUND_Stream_OpenFile, but not FSOUND_Stream_OpenFile2 there, then add the following line below OpenFile :
[code:2xra2kqh]
Public Declare Function FSOUND_Stream_OpenFile2 Lib “fmod.dll” Alias “_FSOUND_Stream_OpenFile@12” (ByRef data As Byte, ByVal mode As FSOUND_MODES, ByVal memlength As Long) As Long
[/code:2xra2kqh]

  • You must to post comments
0
0

Thank you very much for your help Adion.

  • You must to post comments
0
0

Well, everything works fine now, but there’s a problem. I can only hear noise and FSOUND_Stream_GetLengthMs returns a wrong value for the files (big and small mp3s and wavs). I’m using the code you posted. What may I be doing wrong?

  • You must to post comments
0
0

Don’t know if that is the problem, but search for FSOUND_LOADMEMORY in fmod.bas, the declaration should be like :

FSOUND_LOADMEMORY = 32768

  • You must to post comments
0
0

Curious. Well, i don’t know a thing about this, but it was declared as &H8000 (32768 HEX i suppose). At first I was a bit dissapointed, but switching that to 32768 decimal did the trick. But looking at the code I see that everything else is declared as HEX values. Anyway, now using “FSOUND_LOADMEMORY Or FSOUND_MPEGACCURATE” in LOAD_STREAM does the trick for me. Much better loading time now. Thank you so very much man.

  • You must to post comments
0
0

I don’t know why, but the HEX value of 32768 wouldn’t be translated to 32768 but to another value (I think -32768), all the other HEX values seem to work fine, so I suppose it’s a bug in Visual Basic.

  • You must to post comments
0
0

Yes, it’s a normal way of functioning.
If that number is a two-byte SIGNED integer, every value above 32767, not included, will be negative. (I suppose….)
Bye..
😮

  • You must to post comments
0
0

But values like +-64000 are correct again, it is only 32768 and some other values around it that are incorrect.

  • You must to post comments
Showing 11 results
Your Answer

Please first to submit.