I hope someone would help me.
I’m building a soft that read mp2/3/wav files. I use STREAMCALLBACK to manage on my own the file access, because i only need to read some parts of the files. Everything works fine with WAV files. No clack betwwen files, i even make some process on the buffers before giving it to fmod.
Now, the problem is on mp2/mp3 files. If i understand, i have to use FSOUND_Sample functions to get the RAW WAV data for each mpg sample.
But all i get is an access memory violation on FSOUND_SAMPLE_UPLOAD functions…. snifff,
Here is a part of the code for a better understanding [i hope so 8) ]
function AudioCallBack(Stream: PFSoundStream; Buff: Pointer; Length, Param: Integer): ByteBool; cdecl;
buffer := PCHAR( Buff ); aPlayer := TAudioPlay(Pointer(Param)); Count := 0; aFile := aPlayer.ActualFile; If aFile <> nil then begin While Count < Length do begin // Read the MPEG File ... 1 Quantum 44100/256Kb // MPEGRead := aFile.FileStream.Read( MPEGBuff, 835 ); If MPEGRead = 0 then break; FSAMPLE := FSOUND_Sample_Alloc(FSOUND_FREE, 1, FSOUND_MPEGACCURATE OR FSOUND_STEREO, 44100, 0,127,0); FSOUND_Sample_Upload(FSAMPLE, MPEGBuff, FSOUND_MPEGACCURATE or FSOUND_STEREO ); Diff := Length( FSAMPLE^ ); // Copy the SAMPLE to the Stream Buffer // CopyMemory( @Buffer[Count], PCHAR(FSAMPLE), Diff ); Count := Count + Diff; end; end; Result := (Count = Length); end;
I know that the function is not perfect like this (no memory cleaning, fixed buffer size that will overflow streaming buffer), but the problem appears at the first call… 😥
- Gregggg asked 14 years ago
first of all: I only do C but I think I understand what you’re trying to do.
And I don’t think it’s going to work for mpeg files. You are reading some bytes (why 835?) from an mpeg file, then upload them into a sample.
fmod does not treat this data as mpeg data, but as raw sample data. This is what Sample_Upload is for: uploading raw sample data.
Since .wav – files contain raw sample data, it worked with those.
The docs are a little unclear about what Sample_Upload’s “format conversion” means. I think it does not decompress any data, it converts them from 8/16 bit / mono/stereo to the correct settings for the destination sample.
Still, this does not explain the crash.
I guess it is related to a wrong parameter, normally one would have to give fmod the format of the sample data at Sample_Alloc and Sample_Upload. So it is possible Sample_Alloc failed and Sample_Upload didn’t check.
You really should check fmod error codes of all fmod calls when in debug mode.
OR, maybe I’m all wrong and Sample_Upload DOES decompress data, and it hit the 835 byte limit when trying to get to the mpeg frames.
So in the order :
1- In MPEG2, a quantum (the smallest part of the file) is defined by the the bitrate, the frequency, the mode (stereo / mono) and the layer.
So, for a 44100/256Kb/Stereo file, a quantum is = 835 bytes… a quantum = 24/25 ms. That’s why i try to load one quantum at a time to fill the desired length.
2- The crash is not, at the moment, the real problem. What i need is to know if with Fmod, we can convert ‘on demand’ part of a file. And i don’t want to load the whole file in memory. Which is time and memory consuming. No i need real time conversion and that’s not quite easy.
For information, i checked the Sample_Alloc result, and i get a valid pointer.
i dont know if Sample functions converts data to WAV data… Brettttttttttttt, please . What is the solution ?? I can give you all desired information for a function like GiveMeWAVData( SrcSample : Pointer; DestSample : Pointer; Format & other params !!!)…. 😉
Arggh, Night… thx anyway !
- Anonymous answered 14 years ago
I dont really know the techniques behind the mpeg codec, thanks for the insight
I remember Brett saying something about an exposed mpeg api sometime.
And indeed, my fmod.dll does exhibit FSOUND_Mpeg* functions.
I believe they can be used for realtime decoding, the problem is: they are undocumented, and you’re going to have a hard time figuring out 16 byte of parameters.
Brett, guess we need some info here =)
I suggest you to use Sample_Lock/Unlock, it does the same thing, it doesn’t take attention to the format (pure raw data) and will be more efficient (one call to sample_lock copy the data to the buffer where in your example you upload it and then you copy it). I use them for a simple converter utility and works nicely.
Nice, it’s supposed to work . Now, let’s get deeper in the code…
Tell me if i’m right in this sequence :
[i:354t2bkv]we supposed that the MPEGBuffer is loaded with RAW MPEG Data[/i:354t2bkv]
aSample := FSOUND_Sample_Load( FSound_Unmanaged, MPEGBuff, FSOUND_LOADMEMORY, MPEGBuffLength);
// Lock the sample [/b:354t2bkv]
FSOUND_Sample_Lock(aSample, 0, MPEGBuffLength, Buff1, Buff2, Size1, Size2);
[b:354t2bkv]// Use the Buff1 and Buff2 pointer to copy WAV data to the CallBack Buffer //[/b:354t2bkv]
[b:354t2bkv]// Unlock the sample //[/b:354t2bkv]
FSOUND_Sample_Unlock( aSample, Buff1, Buff2, Size1, Size2 );
[b:354t2bkv]// Release the allocated SAMPLE //[/b:354t2bkv]
FSOUND_Sample_Free( aSample );
If yes, so, i have a problem with the Sample_Load which crashes everytime. 😥
Ok, if i understand i have to give 2 frames. That’s not a problem, and don’t worry, i’m not going to ask you such a thing… it was just a joke, or more a shouting help 😆
No, i just want to know the limit. 2 frames, ok i will do the job with it. Am i on the right way or is it absolutly impossible to do such ONAIR conversion ?
Anyway, nice DLL FMOD, really nice…
Please login first to submit.