0
0

hi, after a long time i got to grips with sound:lock(), i have an array of signed shorts to handle 16 bit amplitude data (still not sure if its the correct datatype) and i have a wavefor drawn on my screen but its completely inaccurate. how im drawing it is say i have a 200 pixel area in which to draw, ill take 1/2 the length of the data array (stereo) then divide by 200, then when i loop through the data array, any time i get to a factor of this number, ill add all of the values since the last time then divide by the number, like this

[code:jkw9ogzn]
void ofSoundPlayer::getWaveData()
{
wavedataArraySize = 200; //pixels in draw area = number of array members required
int factor = ((length/2)/200)2+1; //length of raw data array / 2 (account for stereo) / 200
FMOD_Sound_Lock(sound, 0, length, &waveData , NULL, &length, 0);
signed short
tempOneChannel=static_cast<signed short*>(waveData); //get start of raw data array
oneChannel = NULL; //reset pointer to drawing array
oneChannel=new signed short[wavedataArraySize];
int j = 0; // controls wavedata array size
int k = 0; //temporarily holds amplitude data
for(int i = 0; i+1 < length; i++) // loop through entire raw data array
{
k+=tempOneChannel[i]; //sum k with amplitude data
int l = i%factor;
if(l==0) //until we reach the factor
{
oneChannel[j] = k/factor; // dump sum of amplitude data / factor to get
j++; //average amplitude
k=0; reset k
}
}
FMOD_Sound_Unlock(sound, waveData, NULL, length, 0 );
}
[/code:jkw9ogzn]

but the waveform really doesnt match what im hearing, peaks and troughs will appear when theres little change in sound. can anyone see what im doing wrong?

edit: if anyones seraching for how to do it, i figured it out. i just make an array twice as large as pixel display area and populate it with average positive and negative values and use them to draw vertical lines.

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.