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:
@@ -4,7 +4,6 @@
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "Bullet3Common/b3HashMap.h"
|
||||
|
||||
|
||||
#include "b3SoundEngine.h"
|
||||
#include "b3SoundSource.h"
|
||||
#include <string>
|
||||
@@ -13,27 +12,27 @@
|
||||
struct MyHashString
|
||||
{
|
||||
std::string m_string;
|
||||
unsigned int m_hash;
|
||||
unsigned int m_hash;
|
||||
|
||||
B3_FORCE_INLINE unsigned int getHash()const
|
||||
B3_FORCE_INLINE unsigned int getHash() const
|
||||
{
|
||||
return m_hash;
|
||||
}
|
||||
|
||||
MyHashString(const char* name)
|
||||
:m_string(name)
|
||||
: m_string(name)
|
||||
{
|
||||
/* magic numbers from http://www.isthe.com/chongo/tech/comp/fnv/ */
|
||||
static const unsigned int InitialFNV = 2166136261u;
|
||||
static const unsigned int InitialFNV = 2166136261u;
|
||||
static const unsigned int FNVMultiple = 16777619u;
|
||||
|
||||
/* Fowler / Noll / Vo (FNV) Hash */
|
||||
unsigned int hash = InitialFNV;
|
||||
|
||||
for(int i = 0; m_string[i]; i++)
|
||||
|
||||
for (int i = 0; m_string[i]; i++)
|
||||
{
|
||||
hash = hash ^ (m_string[i]); /* xor the low 8 bits */
|
||||
hash = hash * FNVMultiple; /* multiply by the magic number */
|
||||
hash = hash ^ (m_string[i]); /* xor the low 8 bits */
|
||||
hash = hash * FNVMultiple; /* multiply by the magic number */
|
||||
}
|
||||
m_hash = hash;
|
||||
}
|
||||
@@ -42,38 +41,36 @@ struct MyHashString
|
||||
{
|
||||
return (m_string == other.m_string);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
double base_frequency = 440.0;
|
||||
double base_pitch = 69.0;
|
||||
|
||||
double MidiPitch2Frequency(double incoming_note) {
|
||||
return base_frequency * pow (2.0, (incoming_note - base_pitch) / 12.0);
|
||||
double MidiPitch2Frequency(double incoming_note)
|
||||
{
|
||||
return base_frequency * pow(2.0, (incoming_note - base_pitch) / 12.0);
|
||||
}
|
||||
|
||||
double FrequencytoMidiPitch(double incoming_frequency) {
|
||||
return base_pitch + (12.0 * log(incoming_frequency / base_frequency) / log(2));
|
||||
double FrequencytoMidiPitch(double incoming_frequency)
|
||||
{
|
||||
return base_pitch + (12.0 * log(incoming_frequency / base_frequency) / log(2));
|
||||
}
|
||||
|
||||
|
||||
class TinyAudioExample : public CommonExampleInterface
|
||||
{
|
||||
|
||||
GUIHelperInterface* m_guiHelper;
|
||||
|
||||
|
||||
b3SoundEngine m_soundEngine;
|
||||
int m_wavId;
|
||||
|
||||
b3HashMap<MyHashString,int> m_keyToSoundSource;
|
||||
|
||||
b3HashMap<MyHashString, int> m_keyToSoundSource;
|
||||
|
||||
public:
|
||||
TinyAudioExample(struct GUIHelperInterface* helper)
|
||||
:m_guiHelper(helper)
|
||||
: m_guiHelper(helper)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual ~TinyAudioExample()
|
||||
{
|
||||
}
|
||||
@@ -87,54 +84,50 @@ public:
|
||||
|
||||
m_wavId = m_soundEngine.loadWavFile("wav/xylophone.rosewood.ff.C5B5_1.wav");
|
||||
int sampleRate = m_soundEngine.getSampleRate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual void exitPhysics()
|
||||
{
|
||||
|
||||
m_soundEngine.exit();
|
||||
}
|
||||
|
||||
virtual void renderScene()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void physicsDebugDraw(int debugFlags)
|
||||
virtual void physicsDebugDraw(int debugFlags)
|
||||
{
|
||||
}
|
||||
virtual bool mouseMoveCallback(float x,float y)
|
||||
virtual bool mouseMoveCallback(float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
if (key>='a' && key<='z')
|
||||
if (key >= 'a' && key <= 'z')
|
||||
{
|
||||
char keyStr[2];
|
||||
keyStr[0] = (char)key;
|
||||
keyStr[1] = 0;
|
||||
MyHashString hs (keyStr);
|
||||
MyHashString hs(keyStr);
|
||||
|
||||
if (state)
|
||||
{
|
||||
int soundSourceIndex = m_soundEngine.getAvailableSoundSource();
|
||||
if (soundSourceIndex>=0)
|
||||
if (soundSourceIndex >= 0)
|
||||
{
|
||||
|
||||
int note = key-(97-58);
|
||||
int note = key - (97 - 58);
|
||||
double freq = MidiPitch2Frequency(note);
|
||||
|
||||
|
||||
b3SoundMessage msg;
|
||||
msg.m_type = B3_SOUND_SOURCE_SINE_OSCILLATOR;
|
||||
msg.m_frequency = freq;
|
||||
@@ -147,10 +140,10 @@ public:
|
||||
msg.m_releaseRate = 0.001;
|
||||
|
||||
m_soundEngine.startSound(soundSourceIndex, msg);
|
||||
m_keyToSoundSource.insert(hs,soundSourceIndex);
|
||||
m_keyToSoundSource.insert(hs, soundSourceIndex);
|
||||
//printf("soundSourceIndex:%d\n", soundSourceIndex);
|
||||
|
||||
#if 0
|
||||
|
||||
#if 0
|
||||
b3SoundSource* soundSource = this->m_soundSourcesPool[soundSourceIndex];
|
||||
|
||||
soundSource->setOscillatorFrequency(0, freq );
|
||||
@@ -165,9 +158,10 @@ public:
|
||||
printf("just inserted: %d\n", newIndex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
int* soundSourceIndexPtr = m_keyToSoundSource[hs];
|
||||
if (soundSourceIndexPtr)
|
||||
@@ -176,7 +170,7 @@ public:
|
||||
//printf("releaseSound: %d\n", soundSourceIndex);
|
||||
m_soundEngine.releaseSound(soundSourceIndex);
|
||||
}
|
||||
#if 0
|
||||
#if 0
|
||||
if (soundSourceIndex>=0)
|
||||
{
|
||||
printf("releasing %d\n", soundSourceIndex);
|
||||
@@ -184,11 +178,10 @@ public:
|
||||
soundSource->stopSound();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,17 +190,14 @@ public:
|
||||
float dist = 4;
|
||||
float pitch = 52;
|
||||
float yaw = 35;
|
||||
float targetPos[3]={0,0,0};
|
||||
m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
|
||||
float targetPos[3] = {0, 0, 0};
|
||||
m_guiHelper->resetCamera(dist, pitch, yaw, targetPos[0], targetPos[1], targetPos[2]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CommonExampleInterface* TinyAudioExampleCreateFunc(CommonExampleOptions& options)
|
||||
CommonExampleInterface* TinyAudioExampleCreateFunc(CommonExampleOptions& options)
|
||||
{
|
||||
return new TinyAudioExample(options.m_guiHelper);
|
||||
|
||||
}
|
||||
|
||||
|
||||
B3_STANDALONE_EXAMPLE(TinyAudioExampleCreateFunc)
|
||||
|
||||
Reference in New Issue
Block a user