0
0

Hi,

I am trying to use the sound->getLength() to get the sample size of a song.

unsigned int len;
sound->getLength(&len, FMOD_TIMEUNIT_PCM);

But when I draw the wave of the song using this size (len), it only shows about a half of the entire wave(I get it from some software).
This means the size is only half of the sample size. Why?

  • You must to post comments
0
0

Number of samples = bytes / channels / sample size
In this context a sample consists of several values, one for each channel.

You already have the bytes.
You can get channels from Sound::getFormat
You can derive sample size from bits in Sound::getFormat

  • You must to post comments
0
0

But I need the size in number of the samples. That is why I tried the method in my original question.

  • You must to post comments
0
0

The size of ptr1 is len1 and the size of ptr2 is len2 (these values are in bytes).

  • You must to post comments
0
0

[quote="mathew":20dafyuv]Perhaps the sound is stereo? In that case the count would be half what you are expecting.

If you wish to access all the sound data to draw the waveform you could do:

Sound::getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
Sound::lock(0, length, &ptr1, &ptr2, &len1, &len2);

All the sound data can be accessed through ptr variables.[/quote:20dafyuv]

Yeah, but when I need access each individual variable in ptr, I will do something like:

for (int i = 0; i < ptr.size() ; i++)
plot(ptr[i]);

So I still need to know the size of ptr.
or is there any better approach?

  • You must to post comments
0
0

Perhaps the sound is stereo? In that case the count would be half what you are expecting.

If you wish to access all the sound data to draw the waveform you could do:

Sound::getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
Sound::lock(0, length, &ptr1, &ptr2, &len1, &len2);

All the sound data can be accessed through ptr variables.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.