0
0

Hi all,
I found some subjects on it, but no real code.
I want to draw the waveform of a wav, mp3 or ogg file. I read a post on it where Brett says that it’s a good idea to read the whole file with FSOUND_Sample_Load, then lock the data with FSOUND_Sample_Lock, I guess, and then access to the data. I would like to know just the little part of code that would tell me how to read what is the value of the sample at the time (float) t (in seconds) of the sample?
Thanks for your help and for the great FMOD of course!
David

  • You must to post comments
0
0

[code:31m99am4]
signed short *lockptr;

FSOUND_Sample_Lock(sample, 0, samplelength, &lockptr, 0, 0, 0);

int samplevalue = lockptr[(int)(frequency * t)];
[/code:31m99am4]

This works for a mono, 16bit sample. Frequency is the samplerate of the sample i.e. 44100, 22050 or whatever. Check out the docs on FSOUND_Sample_Lock for more details.

  • You must to post comments
0
0

Great! Andrew that’s exactly what I wanted.
I just would like to be sure:

If it is 8bits data, you replace:
“signed short *lockptr”
by
“signed char *lockptr”

and if it is stereo
“int samplevalue = lockptr[(int)(frequency * t)]”
by
“int samplevalue = lockptr[(int)(2 * frequency * t)]” where the first value is the left one and the second value the right one?

and there’s nothing to change in any case in the
“FSOUND_Sample_Lock(sample, 0, samplelength, &lockptr, 0, 0, 0)”
line?

Thanks again
David

  • You must to post comments
0
0

Spot on mate :)

[code:25pjiyb7]
signed short leftsamplevalue = lockptr[(int)(2 * frequency * t)];
signed short rightsamplevalue = lockptr[(int)(2 * frequency * t) + 1];
[/code:25pjiyb7]

  • You must to post comments
0
0

Thanks again for all and mainly to be so quick answering!
David 😀

  • You must to post comments
0
0

😳 Oops sorry but I need some more informations:
in “FSOUND_Sample_Lock(sample, 0, samplelength, &lockptr, 0, 0, 0);”, I need to know what samplelength is, because when I open a MP3 or OGG, I don’t know what will be the size of the (uncompressed, I guess) data after FSOUND_sample_Load.
and in “lockptr[(int)(frequency * t)]”, is “frequency” the frequency of the original file (how to get it???) or the frequency declared in FSOUND_Init (more logical I think?
Thanks
David

  • You must to post comments
0
0

I just discovered “FSOUND_Sample_GetLength” but I don’t see the meaning of SAMPLES in “the length of the sample in SAMPLES”.

  • You must to post comments
0
0

In this context, “the length of the sample in samples” is referring to the number of discrete data values in the whole thing. Use FSOUND_Sample_GetLength in your call to FSOUND_Sample_Lock.

  • You must to post comments
0
0

and so? what about the frequency in “lockptr[(int)(2 * frequency * t)]”? it’s the FSOUND_Init one or the original file one?

  • You must to post comments
0
0

File.

  • You must to post comments
0
0

Ok thanks again for all the info. I’ll post a message with the code I wrote when I’ll get something working… If it may help somebody who wants to write a waveforme display code, too.
David

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.