bool CClientSound::Play3D ( const SString& strPath, const CVector& vecPosition, bool bLoop ) { long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_3D | BASS_SAMPLE_MONO; if ( bLoop ) lFlags |= BASS_SAMPLE_LOOP; // Try to load the sound file if ( ( m_pSound = BASS_StreamCreateFile ( false, strPath, 0, 0, lFlags ) ) || ( m_pSound = BASS_MusicLoad ( false, strPath, 0, 0, lFlags, 0) ) ) { m_b3D = true; m_strPath = strPath; m_vecPosition = vecPosition; BASS_3DVECTOR pos ( vecPosition.fX, vecPosition.fY, vecPosition.fZ ); BASS_ChannelSet3DPosition ( m_pSound, &pos, NULL, NULL ); BASS_ChannelSet3DAttributes ( m_pSound, BASS_3DMODE_NORMAL, 1.0f, 0.5f, 360, 360, 1.0f ); BASS_ChannelPlay ( m_pSound, false ); BASS_ChannelGetAttribute ( m_pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency ); return true; } g_pCore->GetConsole()->Printf ( "BASS ERROR %d in Play3D path = %s", BASS_ErrorGetCode(), strPath.c_str() ); return false; }
// play void BassSound3D::Play() { m_channel = BASS_SampleGetChannel(m_handle, FALSE); if (m_looping) { BASS_ChannelFlags(m_channel, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); } else { BASS_ChannelFlags(m_channel, 0, BASS_SAMPLE_LOOP); } BASS_ChannelSetAttribute(m_channel, BASS_ATTRIB_VOL, m_volume); BASS_ChannelSet3DAttributes(m_channel, -1, m_minDistance, m_maxDistance, -1, -1, -1); BASS_3DVECTOR pos(m_Position.x, m_Position.y, m_Position.z); BASS_3DVECTOR vel(m_velocity.x, m_velocity.y, m_velocity.z); BASS_ChannelSet3DPosition(m_channel, &pos, NULL, &vel); BASS_Apply3D(); BASS_ChannelPlay(m_channel, FALSE); }
void CClientSound::ThreadCallback ( HSTREAM pSound ) { if ( pSound ) { m_pSound = pSound; if ( m_b3D ) { BASS_3DVECTOR pos ( m_vecPosition.fX, m_vecPosition.fY, m_vecPosition.fZ ); BASS_ChannelSet3DPosition ( pSound, &pos, NULL, NULL ); BASS_ChannelSet3DAttributes ( pSound, BASS_3DMODE_NORMAL, 1.0f, 0.5f, 360, 360, 1.0f ); } // Set a Callback function for download finished BASS_ChannelSetSync ( pSound, BASS_SYNC_DOWNLOAD, 0, &DownloadSync, this ); BASS_ChannelGetAttribute ( pSound, BASS_ATTRIB_FREQ, &m_fDefaultFrequency ); BASS_ChannelPlay ( pSound, false ); } else g_pCore->GetConsole()->Printf ( "BASS ERROR %d in PlayStream b3D = %s path = %s", BASS_ErrorGetCode(), m_b3D ? "true" : "false", m_strPath.c_str() ); // Call onClientSoundStream LUA event CLuaArguments Arguments; Arguments.PushBoolean ( pSound ? true : false ); Arguments.PushNumber ( GetLength () ); this->CallEvent ( "onClientSoundStream", Arguments, true ); }
// SetVelocity void BassSound3D::SetVelocity(const math::Vector& v) { m_velocity = v; BASS_3DVECTOR vel(m_velocity.x, m_velocity.y, m_velocity.z); BASS_ChannelSet3DPosition(m_channel, NULL, NULL, &vel); BASS_Apply3D(); }
// SetPosition void BassSound3D::SetPosition(const math::Vector &v) { m_Position = v; BASS_3DVECTOR pos(m_Position.x, m_Position.y, m_Position.z); BASS_ChannelSet3DPosition(m_channel, &pos, NULL, NULL); BASS_Apply3D(); }
void CClientSound::SetVelocity ( const CVector& vecVelocity ) { if ( m_pSound ) { m_vecVelocity = vecVelocity; BASS_3DVECTOR vel ( vecVelocity.fX, vecVelocity.fY, vecVelocity.fZ ); BASS_ChannelSet3DPosition ( m_pSound, NULL, NULL, &vel); } }
void CClientSound::SetPosition ( const CVector& vecPosition ) { if ( m_pSound ) { m_vecPosition = vecPosition; BASS_3DVECTOR pos ( vecPosition.fX, vecPosition.fY, vecPosition.fZ ); BASS_ChannelSet3DPosition ( m_pSound, &pos, NULL, NULL); } }
gboolean Update(gpointer data) { int c,x,y,cx,cy; GtkWidget *dc=GetWidget("drawingarea1"); GdkGC *gc=dc->style->fg_gc[GTK_WIDGET_STATE(dc)]; GdkGCValues gcsave; gdk_gc_get_values(gc,&gcsave); cx=dc->allocation.width/2; cy=dc->allocation.height/2; { // clear the display GdkColor c={0,0xffff,0xffff,0xffff}; gdk_gc_set_rgb_fg_color(gc,&c); gdk_draw_rectangle(dc->window,gc,TRUE,0,0,dc->allocation.width,dc->allocation.height); } { // Draw the listener GdkColor c={0,0x8000,0x8000,0x8000}; gdk_gc_set_rgb_fg_color(gc,&c); gdk_draw_arc(dc->window,gc,TRUE,cx-4,cy-4,8,8,0,360*64); } for (c=0;c<chanc;c++) { // If the channel's playing then update it's position if (BASS_ChannelIsActive(chans[c].channel)==BASS_ACTIVE_PLAYING) { // Check if channel has reached the max distance if (chans[c].pos.z>=MAXDIST || chans[c].pos.z<=-MAXDIST) chans[c].vel.z=-chans[c].vel.z; if (chans[c].pos.x>=MAXDIST || chans[c].pos.x<=-MAXDIST) chans[c].vel.x=-chans[c].vel.x; // Update channel position chans[c].pos.z+=chans[c].vel.z*TIMERPERIOD/1000; chans[c].pos.x+=chans[c].vel.x*TIMERPERIOD/1000; BASS_ChannelSet3DPosition(chans[c].channel,&chans[c].pos,NULL,&chans[c].vel); } { // Draw the channel position indicator static GdkColor cols[2]={{0,0xffff,0xc000,0xc000},{0,0xffff,0,0}}; gdk_gc_set_rgb_fg_color(gc,&cols[chan==c]); x=cx+(int)((cx-10)*chans[c].pos.x/MAXDIST); y=cy-(int)((cy-10)*chans[c].pos.z/MAXDIST); gdk_draw_arc(dc->window,gc,TRUE,x-4,y-4,8,8,0,360*64); } } // Apply the 3D changes BASS_Apply3D(); gdk_gc_set_values(gc,&gcsave,GDK_GC_FOREGROUND); return TRUE; }
int _Spit::Callback(unsigned int msg, unsigned int wParam, int lParam) { switch(msg) { case ENTITYMSG_UPDATE: //update velocity SetVel(GetDir()*m_spd.MoveUpdate(g_timeElapse)); //update sound position if(m_tSnd) { BASS_3DVECTOR pos, orient, vel; memcpy(&pos, (float*)GetLoc(), sizeof(pos)); pos.z *= -1; memcpy(&orient, (float*)GetDir(), sizeof(orient)); orient.z *= -1; memcpy(&vel, (float*)GetVel(), sizeof(vel)); vel.z *= -1; BASS_ChannelSet3DPosition(m_tSnd, &pos, &orient, &vel); } break; case ENTITYMSG_ENTITYCOLLIDE://, (WPARAM)pEntity { EntityCommon *pEntity = (EntityCommon *)wParam; EntityCommon *pOwner = (EntityCommon *)IDPageQuery(GetOwner()); //check to see if the owner is not the same type as entity if(pOwner) { if(pOwner->GetEntityType() != pEntity->GetEntityType()) { //check to see if the entity is a creature if((pEntity->GetEntityType() == ENTITY_TYPE_TATA || pEntity->GetEntityType() == ENTITY_TYPE_ENEMY) && !pEntity->CheckFlag(CRE_FLAG_SPITIMMUNE)) { //hit this fella Creature *pCre = (Creature *)pEntity; if(pCre->Hit()) { int sndInd = -1; pOwner->Callback(ENTITYMSG_REQUESTSOUND, SND_REQ_PROJ_HIT_CRE, (LPARAM)&sndInd); pCre->CREPlaySound(sndInd); } SetFlag(ENTITY_FLAG_POLLDEATH, true); } } } if(!m_bBounce || m_bounceCur == m_bounceMax) SetFlag(ENTITY_FLAG_POLLDEATH, true); else { //bounce off gfxTrace *pTrace = (gfxTrace*)lParam; D3DXVECTOR3 norm(pTrace->norm), refl; float nd = D3DXVec3Dot(&GetDir(), &norm); refl = GetDir() - (2*nd*norm); SetDir(refl); m_bounceCur++; } } break; case ENTITYMSG_WORLDCOLLIDE: { if(!m_bBounce || m_bounceCur == m_bounceMax) SetFlag(ENTITY_FLAG_POLLDEATH, true); else { //bounce off gfxTrace *pTrace = (gfxTrace*)lParam; D3DXVECTOR3 norm(pTrace->norm), refl; float nd = D3DXVec3Dot(&GetDir(), &norm); refl = GetDir() - (2*nd*norm); SetDir(refl); m_bounceCur++; } } break; case ENTITYMSG_DEATH: //cool FX explosion break; case ENTITYMSG_ALLOWGRAVITY: //simply don't allow gravity return 0; } return RETCODE_SUCCESS; }
/// <summary> /// Reproduce sonidos usando el volumen dado. /// </summary> ///<param name="SoundName">Nombre del sonido a reproducir.</param> void CSoundManager::PlaySoundVolume (const std::string &SoundName, float _fVolume) { bool pass = false; std::map<std::string, SSoundData>::iterator iter = m_Resources.find(SoundName); if(iter == m_Resources.end()) { // Guarda mensaje de error en el log std::string msg_error = "CSoundManager::PlaySound->No se encontró el identificador del sonido: "; msg_error.append(SoundName.c_str()); LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); return; } SSoundData sData = iter->second; if (sData.m_type == false) // False si es sample { sData.m_Id = BASS_SampleGetChannel(sData.m_Id, FALSE); //Agregarlo a canal de sample en el vector m_Channels; //Canales 2 - 19 if (m_iSamplerChannels == 19) { // El número de canales de sonidos ha llegado a su máximo // Liberar el canal 2 y asignar este sonido a este canal m_iSamplerChannels = 2; } else { // Asignar esta música al canal que corresponde ++m_iSamplerChannels; } m_Channels[m_iSamplerChannels].m_dwSource = sData.m_Id; m_Channels[m_iSamplerChannels].m_fVolumen = _fVolume; } // True si es música else { // En caso de que los dos canales de música ya estén asignados if (m_iMusicChannels == 1) { m_iMusicChannels = 0; } else { // Asignar esta música al canal 1 ++m_iMusicChannels; } //Agregarlo a canal de música en el vector m_Channels; m_Channels[m_iMusicChannels].m_dwSource = sData.m_Id; m_Channels[m_iMusicChannels].m_fVolumen = _fVolume; } // Añade la configuración del canal pass = BASS_ChannelSetAttribute(sData.m_Id, BASS_ATTRIB_VOL, _fVolume) ? true : false; if (pass == false) { int errorCode = BASS_ErrorGetCode(); errorCode = 0; } // Looping sound if (sData.m_Loop == true) { //BASS_ChannelFlags(sData.m_Id, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set LOOP flag to true } if (sData.m_ThreeDimensional == true) { BASS_3DVECTOR vector; vector.x = sData.m_Position.x; vector.y = sData.m_Position.y; vector.z = sData.m_Position.z; bool result = BASS_ChannelSet3DPosition(sData.m_Id, &vector, NULL, NULL)?true:false; if (result == true) { BASS_Apply3D(); } else { int errorCode = BASS_ErrorGetCode(); errorCode = 0; } } if (pass) { // Reproducción del canal pass = BASS_ChannelPlay(sData.m_Id, FALSE)?true:false; if (pass) { std::string msg_debug = "Sonido reproducido con éxito"; } } }
void main(int argc, char **argv) { BUFSTUFF b,b2; BASS_3DVECTOR p={0,0,0}; printf("BASS 2 stereo channels on 4 speakers example : MOD/MPx/OGG/WAV\n" "--------------------------------------------------------------\n" " Set your soundcard's output to 4 or 5.1 speakers\n"); /* check that BASS 1.6 was loaded */ if (BASS_GetVersion()!=MAKELONG(1,6)) { printf("BASS version 1.6 was not loaded\n"); return; } if (argc!=3) { printf("\tusage: 4speaker <file1> <file2>\n"); return; } /* setup output - default device, 44100hz, stereo, 16 bits */ if (!BASS_Init(-1,44100,BASS_DEVICE_3D,0)) Error("Can't initialize device"); /* try initializing the 1st (front) file */ if (!(b.dstr=BASS_StreamCreateFile(FALSE,argv[1],0,0,BASS_STREAM_DECODE))) if (!(b.dstr=BASS_MusicLoad(FALSE,argv[1],0,0,BASS_MUSIC_DECODE|BASS_MUSIC_RAMPS))) Error("Can't play the 1st file"); if (BASS_ChannelGetFlags(b.dstr)&BASS_SAMPLE_MONO) Error("The 1st stream is mono!"); /* try initializing the 2nd (rear) file */ if (!(b2.dstr=BASS_StreamCreateFile(FALSE,argv[2],0,0,BASS_STREAM_DECODE))) if (!(b2.dstr=BASS_MusicLoad(FALSE,argv[2],0,0,BASS_MUSIC_DECODE|BASS_MUSIC_RAMPS))) Error("Can't play the 2nd file"); if (BASS_ChannelGetFlags(b2.dstr)&BASS_SAMPLE_MONO) Error("The 2nd stream is mono!"); printf("front : %s\n",argv[1]); printf("rear : %s\n",argv[2]); /* Get sample rates and allocate buffers */ BASS_ChannelGetAttributes(b.dstr,&b.freq,0,0); b.buf=malloc(b.freq*4); // 1 sec buffer BASS_ChannelGetAttributes(b2.dstr,&b2.freq,0,0); b2.buf=malloc(b2.freq*4); // 1 sec buffer /* Create streams to play the 1st decoded data, and link them */ b.lstr=BASS_StreamCreate(b.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_left,(DWORD)&b); b.rstr=BASS_StreamCreate(b.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_right,(DWORD)&b); BASS_ChannelSetLink(b.lstr,b.rstr); /* Create streams to play the 2nd decoded data, and link them */ b2.lstr=BASS_StreamCreate(b2.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_left,(DWORD)&b2); b2.rstr=BASS_StreamCreate(b2.freq,BASS_SAMPLE_MONO|BASS_SAMPLE_3D,(STREAMPROC*)&stream_right,(DWORD)&b2); BASS_ChannelSetLink(b2.lstr,b2.rstr); /* position the streams */ p.z=3; // front p.x=-1.5; // left BASS_ChannelSet3DPosition(b.lstr,&p,0,0); p.x=1.5; // right BASS_ChannelSet3DPosition(b.rstr,&p,0,0); p.z=-3; // rear p.x=-1.5; // left BASS_ChannelSet3DPosition(b2.lstr,&p,0,0); p.x=1.5; // right BASS_ChannelSet3DPosition(b2.rstr,&p,0,0); BASS_Apply3D(); BASS_Start(); /* start it! */ b.writepos=b.readposl=b.readposr=0; BASS_StreamPlay(b.lstr,FALSE,0); // start front b2.writepos=b2.readposl=b2.readposr=0; BASS_StreamPlay(b2.lstr,FALSE,0); // start rear while (!_kbhit() && (BASS_ChannelIsActive(b.lstr) || BASS_ChannelIsActive(b2.lstr))) { /* display some stuff and wait a bit */ printf("pos %09I64d %09I64d - cpu %.1f%% \r", BASS_ChannelGetPosition(b.lstr)*2,BASS_ChannelGetPosition(b2.lstr)*2,BASS_GetCPU()); Sleep(50); } BASS_Free(); free(b.buf); }
void Plane::setSoundPosition(Vector3 p){ BASS_3DVECTOR pos = BASS_3DVECTOR(p.x,p.y,p.z); BASS_ChannelSet3DPosition(motorSampleChannel,&pos,NULL,NULL); BASS_ChannelSet3DPosition(bulletSampleChannel,&pos,NULL,NULL); }