# Visualizing Waveform in FMOD 5

**URL:** <https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954>\
**Category:** FMOD Engine\
**Created:** [January 30, 2017, 5:51am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954 "2017-01-30T05:51:47Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [February 8, 2017, 12:47am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/21 "2017-02-08T00:47:29Z")

</div>

> [@](#):
>
> That is very handy. Thank you Brett.
> 
> dsp\_state-\>functions seems to translate to dsp\_state-\>callbacks but nonetheless, we’re getting wave data! We’re almost there as I have a few more questions.
> 
> Since the out buffer doesn’t need to be modified, (or does it?)
> 
> ```
> memcpy(dsp_state->plugindata, in_buffer, in_length * in_channels * sizeof(Float));
> 
> ```
> 
> Having only the wave data in mind, would this be copying the buffer correctly or I’m missing something?
> 
> 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?
> 
> Common\_Draw("buffer = … seems to be cutting corners. For the sake of having a complete example and once again, if it is not too much too ask. How about adding the drawing of all values including every channels to the code?
> 
> 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 values seems to be very edgy, is there a common way to smooth the result with 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.

---

<div class="post-metadata">

**Author:** ![neosettler1](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@neosettler1](https://qa.fmod.com/u/neosettler1)\
**Post date:** [February 8, 2017, 1:37am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/22 "2017-02-08T01:37:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [February 8, 2017, 3:12am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/23 "2017-02-08T03:12:56Z")

</div>

> [@](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![neosettler1](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@neosettler1](https://qa.fmod.com/u/neosettler1)\
**Post date:** [February 8, 2017, 3:52am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/24 "2017-02-08T03:52:43Z")

</div>

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 ???.

---

<div class="post-metadata">

**Author:** ![neosettler1](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@neosettler1](https://qa.fmod.com/u/neosettler1)\
**Post date:** [February 8, 2017, 4:10am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/25 "2017-02-08T04:10:05Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [February 8, 2017, 5:28am UTC](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954/26 "2017-02-08T05:28:57Z")

</div>

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.

[Previous page](https://qa.fmod.com/t/visualizing-waveform-in-fmod-5/12954.md?page=1)
