Skip to content

Instantly share code, notes, and snippets.

@MartinBspheroid
Created March 31, 2014 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinBspheroid/9900219 to your computer and use it in GitHub Desktop.
Save MartinBspheroid/9900219 to your computer and use it in GitHub Desktop.
FMOD waveforms in Cinder
void Player::getWaveformPreview(vector <Vec2f> &preview, unsigned int size){
if (size == 0)
{
return;
}
preview.clear();
peak = 0;
void *waveData;
void *pointer2;
unsigned int length1;
unsigned int length2;
int factor = ((lenghtSamples)/size)*channels;
mSound->lock(0, lenghtSamples, &waveData , &pointer2, &length1,&length2);
signed short* tempOneChannel=static_cast<signed short*>(waveData);
vector <int> Tempsample;
Tempsample.clear();
for(int i = 0; i < lenghtSamples*channels; i++)
{
if(abs(tempOneChannel[i]) > peak) peak= tempOneChannel[i];
Tempsample.push_back( tempOneChannel[i]);
int l = i%factor;
if(l==0)
{
auto maxSample = std::max_element(std::begin(Tempsample), std::end(Tempsample));
auto minSample = std::min_element(std::begin(Tempsample), std::end(Tempsample));
preview.push_back(Vec2f(*maxSample, *minSample));
Tempsample.clear();
}
}
mSound->unlock(waveData, pointer2, length1, length2);
}
void Player::getPartWaveform(vector <Vec2f> &fullWaveform, int offset, int lenght){
if (offset > lenght)
{
return;
}
fullWaveform.clear();
void *waveData;
void *pointer2;
unsigned int length1 =lenght*4;
unsigned int length2;
ci::app::console() << "start: " << offset << " end: " << lenght<< endl;
mSound->lock(offset*4, lenghtSamples, &waveData , &pointer2, &length1,&length2);
signed short* tempOneChannel=static_cast<signed short*>(waveData);
for(int i = 0; i < (lenght-offset)*channels; i++)
{
if(abs(tempOneChannel[i]) > peak) peak= tempOneChannel[i];
fullWaveform.push_back(Vec2f( i ,tempOneChannel[i] ));
}
mSound->unlock(waveData, pointer2, length1, length2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment