bool Source::SetAttribute(EAttributes nAttribute, const Vector3 &vV) { // Set value m_vAttributes[nAttribute] = vV; // Currently playing? if (m_nChannel > -1) { // Set sound API value switch (nAttribute) { case Position: FSOUND_3D_SetAttributes(m_nChannel, vV, m_vAttributes[Position]); break; case Velocity: FSOUND_3D_SetAttributes(m_nChannel, m_vAttributes[Velocity], vV); break; // Error! default: return false; } } // Done return true; }
void LLAudioChannelFMOD::update3DPosition() { if (!mChannelID) { // We're not actually a live channel (i.e., we're not playing back anything) return; } LLAudioBufferFMOD *bufferp = (LLAudioBufferFMOD *)mCurrentBufferp; if (!bufferp) { // We don't have a buffer associated with us (should really have been picked up // by the above if. return; } if (mCurrentSourcep->isAmbient()) { // Ambient sound, don't need to do any positional updates. bufferp->set3DMode(false); } else { // Localized sound. Update the position and velocity of the sound. bufferp->set3DMode(true); LLVector3 float_pos; float_pos.setVec(mCurrentSourcep->getPositionGlobal()); if (!FSOUND_3D_SetAttributes(mChannelID, float_pos.mV, mCurrentSourcep->getVelocity().mV)) { LL_DEBUGS("FMOD") << "LLAudioChannelFMOD::update3DPosition error: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; } } }
//Copy rel chan static INT32 relcopy(INT32 handle) { FSOUND_SAMPLE *fmsample = NULL; INT32 chan = -1; float pos[3]; float vel[3]; if (!FSOUND_3D_GetAttributes(handle,&pos[0],&vel[0])) if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_3D_GetAttributes, Channel # %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); fmsample = FSOUND_GetCurrentSample(handle); if (fmsample) { #ifdef REL2D if (!FSOUND_Sample_SetMode(fmsample, FSOUND_2D)) DBG_Printf("FMOD(relcopy, FSOUND_Sample_SetMode, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); #endif chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); if (chan == -1) { if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_PlaySoundEx, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); return FSOUND_FREE; } #ifdef MORESTUFF else DBG_Printf("FMOD(relcopy, Main): Copy Handle#%i to channel#%i\n",handle,chan); #endif } else { if (FSOUND_GetError() != FMOD_ERR_NONE) DBG_Printf("FMOD(relcopy, FSOUND_GetCurrentSample, handle# %i): %s\n",handle,FMOD_ErrorString(FSOUND_GetError())); chan = FSOUND_PlaySoundEx(FSOUND_FREE,blankfmsample,NULL,true); //return FSOUND_FREE; } if (FSOUND_GetCurrentSample(chan)) { if (!FSOUND_SetCurrentPosition(chan, 0)) DBG_Printf("FMOD(relcopy, FSOUND_SetCurrentPosition, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); #ifndef REL2D if (!FSOUND_3D_SetAttributes(chan,pos,vel)) DBG_Printf("FMOD(relcopy, FSOUND_3D_SetAttributes, handle#%i, channel#%i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); #endif /* if (!FSOUND_SetReserved(chan, TURE)) DBG_Printf("FMOD(relcopy, FSOUND_SetReserved, handle#%i, channel# %i): %s\n",handle,chan,FMOD_ErrorString(FSOUND_GetError())); */ return chan; } return FSOUND_FREE; }
void CSound::Play3dSound(FSOUND_SAMPLE *sound, int volume, float x, float y) { if (p->Options->sound == 1) { float xPos = (p->Player[p->Winsock->MyIndex]->X - x) / 2400.0f; float yPos = (p->Player[p->Winsock->MyIndex]->Y - y) / 2400.0f; if (xPos >= -1.0f && xPos <= 1.0f && yPos >= -1.0f && yPos <= 1.0f) //Within hearing range? { float soundPos[3] = {xPos, yPos, 0.0f}; int returnedChannel = FSOUND_PlaySound(FSOUND_FREE, sound); FSOUND_SetVolume(returnedChannel, volume); FSOUND_3D_SetAttributes(returnedChannel, soundPos, NULL); FSOUND_3D_SetMinMaxDistance(returnedChannel, 0.15f, 1.0f); FSOUND_Update(); } } }
//update the rel chans static void relupdate(INT32 handle) { if (handle == FSOUND_FREE) { INT32 stack; for (stack = 0; stack <= STATIC_SOURCES_NUM;stack++) { //if (FSOUND_GetCurrentSample(relarray[stack].handle)) // relarray[stack].chan = relcopy(relarray[stack].handle); if (relarray[stack].chan != FSOUND_FREE) { relarray[stack].pos.active = false; relupdate(relarray[stack].chan); } else relarray[stack].pos.active = false; } } else if (handle == relcheckup(handle)) return; #ifndef REL2D else { float pos[3], vel[3]; INT32 stack = relstack(handle); INT32 chan = relcheckup(handle); INT32 which = relarray[stack].listener; pos[0] = relarray[stack].pos.pos[0] + rellistener[which].pos[0]; pos[1] = relarray[stack].pos.pos[1] + rellistener[which].pos[1]; pos[2] = relarray[stack].pos.pos[2] + rellistener[which].pos[2]; vel[0] = relarray[stack].pos.vel[0] + rellistener[which].vel[0]; vel[1] = relarray[stack].pos.vel[1] + rellistener[which].vel[1]; vel[2] = relarray[stack].pos.vel[2] + rellistener[which].vel[2]; if (!FSOUND_3D_SetAttributes(chan,pos,vel)) DBG_Printf("FMOD(relupdate, FSOUND_3D_SetAttributes, Handle #%i,Channel #%i): %s\n",handle, chan,FMOD_ErrorString(FSOUND_GetError())); } #endif }
EXPORT INT32 HWRAPI (Add3DSource) (source3D_data_t *src, sfx_data_t *sfx) { FSOUND_SAMPLE *fmsample = NULL; INT32 chan = -1; float pos[3]; float vel[3]; #ifdef MORESTUFF src->min_distance = MIN_DISTANCE; src->max_distance = MAX_DISTANCE; #endif pos[0] = src->pos.x; pos[1] = src->pos.z; pos[2] = src->pos.y; vel[0] = src->pos.momx; vel[1] = src->pos.momz; vel[2] = src->pos.momy; if (sfx) fmsample = FSOUND_Sample_Load(FSOUND_FREE, INT2CHAR(sfx->data), FSOUND_DOOMLOAD, SFXLENGTH); else fmsample = blankfmsample; if (fmsample) { if (sfx && !FSOUND_Sample_SetDefaults(fmsample, (INT32)((*((UINT16 *)sfx->data+1))*recalc_pitch(sfx->pitch)), (sfx->volume == -1 ? 255 : sfx->volume), (sfx->sep == NORMAL_SEP ? FSOUND_STEREOPAN : sfx->sep), (sfx->priority) ) ) DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetDefaults, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); #if 0 if (!FSOUND_Sample_SetMinMaxDistance(fmsample, src->min_distance, src->max_distance)) DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_SetMinMaxDistance, SFX's ID# %i): %s\n", sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); #endif chan = FSOUND_PlaySoundEx(FSOUND_FREE,fmsample,NULL,true); if (chan == -1) { DBG_Printf("FMOD(Add3DSource, FSOUND_PlaySoundEx, SFX's ID# %i): %s\n",sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); return chan; } else { if (!sfx) DBG_Printf("FMOD(Add3DSource, Main): Added blank-sound added to channel %i\n",chan); #ifdef MORESTUFF else DBG_Printf("FMOD(Add3DSource, Main): Added sfxid# %i added to channel %i\n",sfx->id,chan); #endif } } else { if (sfx) DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Load, sfxid# %i): %s\n",sfx->id,FMOD_ErrorString(FSOUND_GetError())); else DBG_Printf("FMOD(Add3DSource, FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); return chan; } if (FSOUND_GetCurrentSample(chan)) { if (!FSOUND_SetCurrentPosition(chan, 0)) DBG_Printf("FMOD(Add3DSource, FSOUND_SetCurrentPosition, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); if (!FSOUND_3D_SetAttributes(chan,pos,vel)) DBG_Printf("FMOD(Add3DSource, FSOUND_3D_SetAttributes, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); if (!FSOUND_SetReserved(chan, (signed char)src->permanent)) DBG_Printf("FMOD(Add3DSource, FSOUND_SetReserved, channel %i, sfxid# %i): %s\n", chan,sfx?sfx->id:0,FMOD_ErrorString(FSOUND_GetError())); if (src->head_relative) reladd(chan); } return chan; }