Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using FMOD (with C++ syntax, not C) and I'm having trouble getting the wave data of a whole sound file.

Channel::GetWave() only gets the wave data of the area on which it is currently playing.

The documentation says:

Do not use this function to try and display the whole waveform of the sound, as this is more of a 'snapshot' of the current waveform at the time it is called, and could return the same data if it is called very quickly in succession.

See the DSP API to capture a continual stream of wave data as it plays, or see Sound::lock / Sound::unlock if you want to simply display the waveform of a sound.

Unfortunately, the Sound::lock and unlock functions are pretty confusing, at least to me.

Lock:

FMOD_RESULT Sound::lock(
  unsigned int  offset, 
  unsigned int  length, 
  void **  ptr1, 
  void **  ptr2, 
  unsigned int *  len1, 
  unsigned int *  len2
);

offset

Offset in bytes to the position you want to lock in the sample buffer.

length

Number of bytes you want to lock in the sample buffer.

ptr1

Address of a pointer that will point to the first part of the locked data.

ptr2

Address of a pointer that will point to the second part of the locked data. This will be null if the data locked hasn't wrapped at the end of the buffer.

len1

Length of data in bytes that was locked for ptr1

len2

Length of data in bytes that was locked for ptr2. This will be 0 if the data locked hasn't wrapped at the end of the buffer.

Unlock:

FMOD_RESULT Sound::unlock(
  void *  ptr1, 
  void *  ptr2, 
  unsigned int  len1, 
  unsigned int  len2
);

ptr1

Pointer to the 1st locked portion of sample data, from Sound::lock.

ptr2

Pointer to the 2nd locked portion of sample data, from Sound::lock.

len1

Length of data in bytes that was locked for ptr1

len2

Length of data in bytes that was locked for ptr2. This will be 0 if the data locked hasn't wrapped at the end of the buffer.

Sorry if this question looks sloppy. I'm just trying to give out as much information on the topic that's necessary.

But as I said, my goal is to by able to get the wave data of the beginning of a song to the end.

Thanks in advance, and any help or info will be apprectiated.

share|improve this question

1 Answer 1

The way I read it, the last four parameters are output parameters. So you basically pass in 4 variables of the requested type and after the function has finished, these are populated with the data you need.

What you do is something along these lines:

void  *pointer1;
void  *pointer2;
unsigned int length1;
unsigned int length2;

// lock the buffer
mySound->lock(0, lengthOfYourSoundInBytes, &pointer1, &pointer2, &length1, &length2);

// when we're here, pointer1, pointer2, length1 and length2 will be populated.
// do something with the sound data found in pointer1.
// the sound data will have a length stored in length1

// unlock the buffer once you're done
mySound->unlock(pointer1, pointer2, length1, length2);

From my understanding you won't need pointer2 and length2 at all. The only thing you'll have to figure out is the length of your sound data (see lengthOfYourSoundInBytes above). Once you locked the buffer, you'll get a pointer to the data and you can do whatever you want with it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.