Permalink
Browse files

Reverts back setPan to -1 to 1. Fixes soundPlayer example to reflect …

…proper range. Closes #1380
  • Loading branch information...
ofTheo committed Jul 5, 2012
1 parent 8b2e7d5 commit 2caff87606389f942886fd834f376277872b7dc8
@@ -39,7 +39,7 @@ ofxOpenALSoundPlayer::ofxOpenALSoundPlayer() {
volume = 1.0f;
pitch = 1.0f;
- pan = 0.5f;
+ pan = 0.0f;
stopped=true;
bPaused=false;
@@ -172,7 +172,7 @@ void ofxOpenALSoundPlayer::setPan(float _pan) {
if(iAmAnMp3)
cerr<<"error, cannot set pan on mp3s in openAL"<<endl;
else {
- float locX = ofMap(_pan, 0, 1, -1, 1);
+ float locX = ofClamp(_pan, -1, 1);
setLocation(locX, location.y, location.z);
}
pan = _pan;
@@ -499,7 +499,7 @@ void ofxOpenALSoundPlayer::setLocation(float x, float y, float z) {
else
{
location.set(x,y,z);
- pan = ofMap(x,-1,1,0,1); // assuming x is -1..1, map to oF pan 0..1
+ pan = ofClamp(x,-1,1); // assuming x clamp pan to -1..1
SoundEngine_SetEffectLocation(myPrimedId, x, y, z);
}
}
@@ -101,7 +101,7 @@ class ofxOpenALSoundPlayer : public ofBaseSoundPlayer{
static void ofxALSoundSetReferenceDistance(float dist); // sets the distance after which attenuation is applied
static void ofxALSoundSetMaxDistance(float dist); // sets the maximum distance for which attenuation is applied
- void setLocation(float x, float y, float z); // x -1..1 gets mapped to pan 0..1
+ void setLocation(float x, float y, float z); // x -1..1 gets mapped to pan -1..1
bool update(); // can this be called at a different time? maybe should be a static function
@@ -97,16 +97,16 @@ void testApp::mouseDragged(int x, int y, int button){
void testApp::mousePressed(int x, int y, int button){
float widthStep = ofGetWidth() / 3.0f;
if (x < widthStep){
- float pct = x / widthStep;
synth.play();
synth.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*10);
- synth.setPan(pct);
+ synth.setPan(ofMap(x, 0, widthStep, -1, 1, true));
} else if (x >= widthStep && x < widthStep*2){
beats.play();
} else {
vocals.play();
vocals.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*3);
- vocals.setPan((float)(x - widthStep*2) / (float)widthStep);
+ //map x within the last third of window to -1 to 1 ( for left / right panning )
+ vocals.setPan( ofMap(x, widthStep*2, widthStep*3, -1, 1, true) );
}
}
@@ -21,7 +21,7 @@ class ofBaseSoundPlayer {
virtual void stop() = 0;
virtual void setVolume(float vol) = 0;
- virtual void setPan(float vol) = 0; // 0 = left, 1 = right
+ virtual void setPan(float vol) = 0; // -1 = left, 1 = right
virtual void setSpeed(float spd) = 0;
virtual void setPaused(bool bP) = 0;
virtual void setLoop(bool bLp) = 0;
@@ -132,7 +132,7 @@ float * ofFmodSoundGetSpectrum(int nBands){
ofFmodSoundPlayer::ofFmodSoundPlayer(){
bLoop = false;
bLoadedOk = false;
- pan = 0.5; // range for oF is 0..1, will be mapped to -1..1 for fmod in setPan()
+ pan = 0.0; // range for oF is -1 to 1
volume = 1.0f;
internalFreq = 44100;
speed = 1;
@@ -305,9 +305,8 @@ int ofFmodSoundPlayer::getPositionMS(){
//------------------------------------------------------------
void ofFmodSoundPlayer::setPan(float p){
- // fmod range is -1 to 1
pan = p;
- p = ofMap(p, 0, 1, -1, 1 );
+ p = ofClamp(p, -1, 1);
if (getIsPlaying() == true){
FMOD_Channel_SetPan(channel,p);
}
@@ -32,7 +32,7 @@ void ofOpenALSoundUpdate(){
ofOpenALSoundPlayer::ofOpenALSoundPlayer(){
bLoop = false;
bLoadedOk = false;
- pan = 0.5f; // range for oF is 0..1, openAl range is -1..1, will be mapped in setPan
+ pan = 0.0f; // range for oF is -1 to 1,
volume = 1.0f;
internalFreq = 44100;
speed = 1;
@@ -661,8 +661,8 @@ int ofOpenALSoundPlayer::getPositionMS(){
//------------------------------------------------------------
void ofOpenALSoundPlayer::setPan(float p){
if(sources.empty()) return;
- pan = p;
- p= ofMap(p, 0, 1, -1, 1);
+ p = ofClamp(p, -1, 1);
+ pan = p;
if(channels==1){
float pos[3] = {p,0,0};
alSourcefv(sources[sources.size()-1],AL_POSITION,pos);
@@ -56,7 +56,7 @@ class ofOpenALSoundPlayer : public ofBaseSoundPlayer, public ofThread {
void stop();
void setVolume(float vol);
- void setPan(float vol); // 0..1
+ void setPan(float vol); // -1 to 1
void setSpeed(float spd);
void setPaused(bool bP);
void setLoop(bool bLp);
@@ -103,7 +103,7 @@ void ofSoundPlayer::setVolume(float vol){
//--------------------------------------------------------------------
void ofSoundPlayer::setPan(float pan){
if( player != NULL ){
- player->setPan(CLAMP(pan,0.0f,1.0f));
+ player->setPan(CLAMP(pan,-1.0f,1.0f));
}
}
@@ -60,7 +60,7 @@ class ofSoundPlayer : public ofBaseSoundPlayer {
void stop();
void setVolume(float vol);
- void setPan(float vol);
+ void setPan(float vol); // -1 to 1
void setSpeed(float spd);
void setPaused(bool bP);
void setLoop(bool bLp);

0 comments on commit 2caff87

Please sign in to comment.