/** * @brief Plays a voice. */ static int al_playVoice( alVoice *v, alSound *s, ALfloat px, ALfloat py, ALfloat vx, ALfloat vy, ALint relative ) { /* Must be below the limit. */ if (sound_speed > SOUND_SPEED_PLAY_LIMIT) return 0; /* Set up the source and buffer. */ v->u.al.source = sound_al_getSource(); if (v->u.al.source == 0) return -1; v->u.al.buffer = s->u.al.buf; soundLock(); /* Attach buffer. */ alSourcei( v->u.al.source, AL_BUFFER, v->u.al.buffer ); /* Enable positional sound. */ alSourcei( v->u.al.source, AL_SOURCE_RELATIVE, relative ); /* Update position. */ v->u.al.pos[0] = px; v->u.al.pos[1] = py; v->u.al.pos[2] = 0.; v->u.al.vel[0] = vx; v->u.al.vel[1] = vy; v->u.al.vel[2] = 0.; /* Set up properties. */ alSourcef( v->u.al.source, AL_GAIN, svolume*svolume_speed ); alSourcefv( v->u.al.source, AL_POSITION, v->u.al.pos ); alSourcefv( v->u.al.source, AL_VELOCITY, v->u.al.vel ); /* Defaults just in case. */ alSourcei( v->u.al.source, AL_LOOPING, AL_FALSE ); /* Start playing. */ alSourcePlay( v->u.al.source ); /* Check for errors. */ al_checkErr(); soundUnlock(); return 0; }
/** * @brief Plays a voice. */ static int al_playVoice( alVoice *v, alSound *s, ALfloat px, ALfloat py, ALfloat vx, ALfloat vy, ALint relative ) { /* Set up the source and buffer. */ v->u.al.source = sound_al_getSource(); if (v->u.al.source == 0) return -1; v->u.al.buffer = s->u.al.buf; soundLock(); /* Attach buffer. */ alSourcei( v->u.al.source, AL_BUFFER, v->u.al.buffer ); /* Enable positional sound. */ alSourcei( v->u.al.source, AL_SOURCE_RELATIVE, relative ); /* Update position. */ v->u.al.pos[0] = px; v->u.al.pos[1] = py; v->u.al.pos[2] = 0.; v->u.al.vel[0] = vx; v->u.al.vel[1] = vy; v->u.al.vel[2] = 0.; /* Set up properties. */ alSourcef( v->u.al.source, AL_GAIN, svolume ); alSourcefv( v->u.al.source, AL_POSITION, v->u.al.pos ); alSourcefv( v->u.al.source, AL_VELOCITY, v->u.al.vel ); /* Start playing. */ alSourcePlay( v->u.al.source ); /* Check for errors. */ al_checkErr(); soundUnlock(); return 0; }