Visualizing Waveform in FMOD 5

Having only the wave data in mind, would this be copying the buffer correctly or I’m missing something?

Yes this would work. Its up to you to interpret the data in the way you want after getting it in the main thread

The wave data value count should match the FMOD_DSP_FFT_SPECTRUMDATA buffer in this case. How should we set the equivalent of FMOD_DSP_FFT_WINDOWSIZE to the wave data buffer?

I assume you mean you want a variable size buffer, this is an exercise for you, you have to create a bigger buffer, and copy it into it in the form of a ringbuffer, instead of just overwriting the same buffer each time.

How about adding the drawing of all values including every channels to the code?

I don’t understand how you think printing more numbers helps you. The bulk of the code is there and the rest is for you to interpret it how you want (ie draw it on a screen as a waveform)

The wave data values seems to be very small, is there a common way to amplify the result with FMOD 5? Could the values be scaled linearly?

The wave data is exactly as it comes in, unless it has been panned or volume scaled somewhere in the mix. Scale it linearly to make it ‘louder’

The wave data values seems to be very edgy, is there a common way to smooth the result with FMOD 5?

Thats an interpretation issue. You can draw it the way it is to be correct. smoothing it makes it less correct but maybe more aesthetically pleasing. If you want the edges rounded off, put a lowpass filter before the custom dsp.

Thanks again for your input Brett.

I assume you mean you want a variable size buffer, this is an exercise for you, you have to create a bigger buffer, and copy it into it in the form of a ringbuffer, instead of just overwriting the same buffer each time.

I mean, how do we set the block size? I need the wave data to fit inside a 512 Float array. Where is the dsp_state->callbacks->getblocksize comes from?

I don’t understand how you think printing more numbers helps you. The bulk of the code is there and the rest is for you to interpret it how you want (ie draw it on a screen as a waveform)””

I’d like to print ALL wave data collected within every channels. Would this be accurate?

for (Int channel = 0; channel < 8; channel++)
	for (UInt samples = 0; samples < length; samples++)
		Draw("chan %d = %f \n", channel, buffer[(samples * 8) + channel]);

Then again, how is the length being set? Could we set it to 512?

UInt length;
m_DspWave->getParameterData(0, (void**)&m_DataWave, &length, NULL, 0);

put a lowpass filter before the custom dsp.

When you say “filter” do you mean adding another DSP? When you say “before” do you mean inside the wave data callback? Would you mind elaborating on this?

Please use a comment reply to keep the thread relevant.

I mean, how do we set the block size? I need the wave data to fit inside a 512 Float array. Where is the dsp_state->callbacks->getblocksize comes from?

You dont set the block size. You change the size of your allocated buffer and turn it into a ring buffer, as I said in the original reply.
System::setDSPBufferSize lets you change the buffer size, but dont use it

I’d like to print ALL wave data collected within every channels. Would this be accurate?

No, because you are printing ‘8’ instead of the correct number of channels that was passed into the read callback. You can store that somewhere.

Then again, how is the length being set? Could we set it to 512?

Already answered above. Dont set fmod’s block size, change your own memory buffer block size, or the amount you consume in one go.

When you say “filter” do you mean adding another DSP? When you say “before” do you mean inside the wave data callback? Would you mind elaborating on this?

Yes adding another DSP, but I dont recommend doing this anyway (because the sound will come out muffled), you would be better off filtering it yourself.

My apologies but the comments doesn’t behave well with code. The posts seems to be reordering themselves so yeah, it’s difficult to keep the flow.

Regarding to your example. The wave data buffer returns (8 * ~32k) values. 8 is the max number of speakers… wish still a mystery to me. What we really want is the number of channel in the audio file, no? Why are we carrying unused data?

Dont set fmod’s block size, change your own memory buffer block size, or the amount you consume in one go.

I was expecting to set it like we do with the spectrum FMOD_DSP_FFT_WINDOWSIZE but apparently the block size is determined differently.

So I guess my question is, how do we crunch the wave data buffer to a range from 0 to 512?

float *waveDataToDraw = new float[512];

for (UInt sample = 0; sample < length; sample++)
{
	for (Int channel = 0; channel < 8; channel++)
	{
		waveDataToDraw[???] += waveData[(sample * 8) + channel];
	}
}

for (UInt i = 0; i < 512; i++)
waveDataToDraw[i] /= ???;

How would you get the ???.

No, because you are printing ‘8’ instead of the correct number of channels that was passed into the read callback. You can store that somewhere.

I’m using 8 because that is the number in the example you provided. How would you set the current channel count to the call back, and retrieve it in the main thread?

you would remember what you got passed in the read callback when it comes to channels.

I’ve updated the original example code post to display info per channel and a bunch of other stuff.