0
0

Hi all,

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

[code:kae1o555]

function AudioCallBack(Stream: PFSoundStream; Buff: Pointer; Length, Param: Integer): ByteBool; cdecl;

var
....
begin

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;

[/code:kae1o555]

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… ๐Ÿ˜ฅ

  • You must to post comments
0
0

Okay,
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.

  • You must to post comments
0
0

Hi [b:30p3xy2m]Night[/b:30p3xy2m],

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 !
Greg[/b]

  • You must to post comments
0
0

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

  • You must to post comments
0
0

I’m pretty sure that the mpeg decompression used in FMOD will work for this purpose (i guess so).

Arffff…

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

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);
[b:354t2bkv]
// 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. ๐Ÿ˜ฅ

  • You must to post comments
0
0

You say that 835 bytes is the smallest size an mp2 stream can have, right ?
And sample_load crashes on first call ?
And you’re sure that your buffer was initialized correctly ?
Then it’s a bug in fmod.

  • You must to post comments
0
0

Hi Brett,

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…

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.