Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -1,9 +1,8 @@
#include "b3SoundSource.h"
#define MY2PI (2.*3.14159265)
#define MY2PI (2. * 3.14159265)
#include <math.h>
#include "Bullet3Common/b3FileUtils.h"
#include "b3ReadWavFile.h"
#include "b3ADSR.h"
@@ -15,19 +14,18 @@ struct b3SoundOscillator
double m_frequency;
double m_amplitude;
double m_phase;
b3WavTicker m_wavTicker;
b3WavTicker m_wavTicker;
double sampleSineWaveForm(double sampleRate)
{
while (m_phase >= MY2PI)
m_phase -= MY2PI;
double z = sinf(m_phase);
double sample = m_amplitude*z;
double z = sinf(m_phase);
double sample = m_amplitude * z;
m_phase += MY2PI * (1./sampleRate) * m_frequency;
m_phase += MY2PI * (1. / sampleRate) * m_frequency;
return sample;
}
@@ -36,10 +34,10 @@ struct b3SoundOscillator
while (m_phase >= MY2PI)
m_phase -= MY2PI;
double z = 2.*(m_phase)/MY2PI-1.;
double sample = m_amplitude*z;
double z = 2. * (m_phase) / MY2PI - 1.;
double sample = m_amplitude * z;
m_phase += MY2PI * (1./sampleRate) * m_frequency;
m_phase += MY2PI * (1. / sampleRate) * m_frequency;
return sample;
}
@@ -49,12 +47,11 @@ struct b3SoundOscillator
}
b3SoundOscillator()
:m_type(0),
m_frequency(442.),
m_amplitude(1),
m_phase(0)
: m_type(0),
m_frequency(442.),
m_amplitude(1),
m_phase(0)
{
}
};
#define MAX_OSCILLATORS 2
@@ -65,7 +62,7 @@ struct b3SoundSourceInternalData
b3ADSR m_envelope;
b3ReadWavFile* m_wavFilePtr;
b3SoundSourceInternalData()
:m_wavFilePtr(0)
: m_wavFilePtr(0)
{
}
};
@@ -80,30 +77,28 @@ b3SoundSource::~b3SoundSource()
delete m_data;
}
void b3SoundSource::setADSR( double attack, double decay, double sustain, double release)
void b3SoundSource::setADSR(double attack, double decay, double sustain, double release)
{
m_data->m_envelope.setValues(attack,decay,sustain,release);
m_data->m_envelope.setValues(attack, decay, sustain, release);
}
bool b3SoundSource::computeSamples(double* sampleBuffer, int numSamples, double sampleRate)
{
double* outputSamples = sampleBuffer;
int numActive = 0;
for (int i=0;i<numSamples;i++)
for (int i = 0; i < numSamples; i++)
{
double samples[MAX_OSCILLATORS] ={0};
double samples[MAX_OSCILLATORS] = {0};
double env = m_data->m_envelope.tick();
if (env)
{
for (int osc=0;osc<MAX_OSCILLATORS;osc++)
for (int osc = 0; osc < MAX_OSCILLATORS; osc++)
{
if (m_data->m_oscillators[osc].m_type == 0)
{
samples[osc] += env * m_data->m_oscillators[osc].sampleSineWaveForm(sampleRate);
samples[osc] += env * m_data->m_oscillators[osc].sampleSineWaveForm(sampleRate);
numActive++;
}
@@ -116,14 +111,15 @@ bool b3SoundSource::computeSamples(double* sampleBuffer, int numSamples, double
if (m_data->m_oscillators[osc].m_type == 128)
{
int frame = 0;
double data = env * m_data->m_oscillators[osc].m_amplitude * m_data->m_wavFilePtr->tick(frame,&m_data->m_oscillators[osc].m_wavTicker);
double data = env * m_data->m_oscillators[osc].m_amplitude * m_data->m_wavFilePtr->tick(frame, &m_data->m_oscillators[osc].m_wavTicker);
samples[osc] += data;
numActive++;
}
}
} else
}
}
else
{
for (int osc=0;osc<MAX_OSCILLATORS;osc++)
for (int osc = 0; osc < MAX_OSCILLATORS; osc++)
{
if (m_data->m_oscillators[osc].m_type == 128)
{
@@ -140,10 +136,10 @@ bool b3SoundSource::computeSamples(double* sampleBuffer, int numSamples, double
}
*outputSamples++ = sampleRight;
*outputSamples++ = sampleLeft ;
*outputSamples++ = sampleLeft;
}
/* if (m_data->m_flags & looping)
/* if (m_data->m_flags & looping)
{
for (int osc=0;osc<MAX_OSCILLATORS;osc++)
{
@@ -152,8 +148,8 @@ bool b3SoundSource::computeSamples(double* sampleBuffer, int numSamples, double
}
}
*/
return numActive>0;
// return false;
return numActive > 0;
// return false;
}
int b3SoundSource::getNumOscillators() const
@@ -187,25 +183,24 @@ void b3SoundSource::startSound(bool autoKeyOff)
{
if (m_data->m_envelope.isIdle())
{
for (int osc=0;osc<MAX_OSCILLATORS;osc++)
for (int osc = 0; osc < MAX_OSCILLATORS; osc++)
{
m_data->m_oscillators[osc].reset();
if (m_data->m_oscillators[osc].m_type == B3_SOUND_SOURCE_WAV_FILE)// .m_wavTicker.finished_)
if (m_data->m_oscillators[osc].m_type == B3_SOUND_SOURCE_WAV_FILE) // .m_wavTicker.finished_)
{
//test reverse playback of wav
//m_data->m_oscillators[osc].m_wavTicker.rate_ *= -1;
if (m_data->m_oscillators[osc].m_wavTicker.rate_<0)
if (m_data->m_oscillators[osc].m_wavTicker.rate_ < 0)
{
m_data->m_oscillators[osc].m_wavTicker.time_ = m_data->m_wavFilePtr->getNumFrames()-1.;
} else
m_data->m_oscillators[osc].m_wavTicker.time_ = m_data->m_wavFilePtr->getNumFrames() - 1.;
}
else
{
m_data->m_oscillators[osc].m_wavTicker.time_ = 0.f;
}
m_data->m_oscillators[osc].m_wavTicker.finished_ = false;
}
}
}
@@ -217,21 +212,20 @@ void b3SoundSource::stopSound()
m_data->m_envelope.keyOff();
}
bool b3SoundSource::setWavFile(int oscillatorIndex, b3ReadWavFile* wavFilePtr, int sampleRate)
{
{
m_data->m_wavFilePtr = wavFilePtr;
m_data->m_oscillators[oscillatorIndex].m_wavTicker = m_data->m_wavFilePtr->createWavTicker(sampleRate);
// waveIn.openFile(resourcePath);
// waveIn.openFile(resourcePath);
double rate = 1.0;
// rate = waveIn.getFileRate() / stkSampleRate;
// waveIn.setRate( rate );
// waveIn.ignoreSampleRateChange();
// rate = waveIn.getFileRate() / stkSampleRate;
// waveIn.setRate( rate );
// waveIn.ignoreSampleRateChange();
// Find out how many channels we have.
// int channels = waveIn.channelsOut();
// m_data->m_oscillators[oscillatorIndex].m_frames.resize( 1, channels );
// int channels = waveIn.channelsOut();
// m_data->m_oscillators[oscillatorIndex].m_frames.resize( 1, channels );
m_data->m_oscillators[oscillatorIndex].m_type = 128;
return true;
}