0
0

Im probably sure that this question was asked multiple times,and I think this is pretty easy to do, but it seems I can not get it done without help.
My question is can somebody tell me how can I get a waveform from an audio file without playing the file?, using Fmod.
I am new to Fmod and don
t know very much about.
It would be helpful if some of you provide me with some c++ code.

Thank you.

  • You must to post comments
0
0

Check out FMOD::Sound::lock/unlock in the documentation (fmodex.chm).

  • You must to post comments
0
0

And how is FMOD::Sound::lock/unlock going to help me?

  • You must to post comments
0
0

It will give you access to the sample data.

  • You must to post comments
0
0

I saw the documentation about Sound::lock but I don`t understand the parameters.
Can you give me an example?
thanks

  • You must to post comments
0
0

Sure, this is a little bit tricky.

[code:3afrosqs]FMOD_RESULT Sound::lock(
unsigned int offset,
unsigned int length,
void ** ptr1,
void ** ptr2,
unsigned int * len1,
unsigned int * len2
);
[/code:3afrosqs]

If you want to get the waveform for the entire sound then you would use:

[code:3afrosqs]
FMOD::Sound *mySound = NULL;
system->createSound("C:/media/drumloop.wav", FMOD_DEFAULT, NULL, &mySound);

unsigned int lenBytes = 0;
mySound->getLength(&lenBytes, FMOD_TIMEUNIT_PCMBYTES);

void* myBuffer = NULL;
mySound->lock(0, lenBytes, &myBuffer, NULL, &lenBytes, 0);

//Now that we have the sound data in our buffer we need to work out what kind of data it is.
int bitsPerSample = 0;
mySound->getFormat(NULL, NULL, NULL, &bitsPerSample);

if (bitsPerSample == 8)
{
    char* sampleData = static_cast<char*>(myBuffer);
    //do stuff
}
else if (bitsPerSample == 16)
{
    short* sampleData = static_cast<short*>(myBuffer);
    //do stuff 
}

[/code:3afrosqs]

Most of the time it will be 16-bit sound. There are a couple of things you can do to improve the ‘bitPerSample’ part of the code, but I didn’t want to over complicate the example.

-Pete

  • You must to post comments
0
0

thanks peter, your code works just fine,but I have no idea what do I have to do next!
How do I plot the values stored in the buffer?

  • You must to post comments
0
0

This code is where you draw stuff:

[code:2hg519d7] if (bitsPerSample == 8)
{
char* sampleData = static_cast<char>(myBuffer);
//do stuff
}
else if (bitsPerSample == 16)
{
short
sampleData = static_cast<short*>(myBuffer);
//do stuff
} [/code:2hg519d7]

That array has the wavedata in it, so just draw those values.

-Pete

  • You must to post comments
0
0

Note lenBytes = 0 is wrong, it should be the length of the sound in bytes. Ie use mySound->getLength(&lenBytes, FMOD_TIMEUNIT_PCMBYTES);

  • You must to post comments
0
0

Thanks Brett, I updated the example code.

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.