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.
- Anonymous asked 16 years ago
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.
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.)
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 need a public variable to store the sound in :
Public myMP3() as Byte
Determine the length of the file in bytes :
FileLength = FileLen(Players(a).FileName)
Now, reserve memory for the file :
ReDim myMP3(FileLength – 1)
Open the file and read the mp3 :
f = FreeFile
Open FileName For Binary As #f
Get #f, , myMP3
Now your file is in memory and you can load it :
Stream = FSOUND_Stream_OpenFile2(myMP3(0), FSOUND_LOADMEMORY, FileLength)
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 :
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
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.
Please login first to submit.