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!
- thedrummer asked 11 years ago
signed short *lockptr;
FSOUND_Sample_Lock(sample, 0, samplelength, &lockptr, 0, 0, 0);
int samplevalue = lockptr[(int)(frequency * t)];
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.
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”
“signed char *lockptr”
and if it is stereo
“int samplevalue = lockptr[(int)(frequency * t)]”
“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)”
😳 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?
Please login first to submit.