コード例 #1
0
void vrpn_Sound_Server_Miles::changeSoundStatus(vrpn_SoundID id, vrpn_SoundDef soundDef)
{
	vrpn_float32 uX = 0, uY = 1, uZ = 0;	// up vector

	if (provider != 0) {

	  // need to negate the Z values to get this into left handed before shipping to Miles..
      soundDef.pose.orientation[2] *= -1.0;
	  soundDef.pose.orientation[3] *= -1.0;
	  soundDef.pose.position[2]    *= -1.0;  

	  //get pose info from quaternion	in soundDef, put it into the above vectors
	  AIL_set_3D_position(getSample(id),soundDef.pose.position[0] , soundDef.pose.position[1], soundDef.pose.position[2]);
	  
	  // normalize
	  soundDef.pose.orientation[0] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[1] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[2] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[3] /= soundDef.pose.orientation[3];

	  AIL_set_3D_orientation(getSample(id), soundDef.pose.orientation[0], soundDef.pose.orientation[1], soundDef.pose.orientation[2], uX, uY, uZ);

	  AIL_set_3D_velocity(getSample(id), soundDef.velocity[0], soundDef.velocity[1], soundDef.velocity[2], soundDef.velocity[3]);

	  /*set the volume to the new level.*/
	  AIL_set_3D_sample_volume(getSample(id), soundDef.volume);
 
	  AIL_set_3D_sample_distances(getSample(id), soundDef.max_front_dist, soundDef.min_front_dist);
	 }
	else fprintf(stderr,"No provider has been set prior to changeSoundStatus\n");
}
コード例 #2
0
void vrpn_Sound_Server_Miles::setProvider(int index, int providerRoomSetting)
{
  DWORD result;

  unloadAllSounds();
  //If a provider is already open, then close it
  AIL_close_3D_provider(provider);

  //load the new provider
  
  result = AIL_open_3D_provider(providers[index]);
  if (result != M3D_NOERR) {
	  fprintf(stderr,"Error Opening 3D Provider: %s\n",AIL_last_error());
  }
  else {
  
    provider = providers[index];
    //open a listener.  Position defaults to the origin, looking down the -Z axis with (
    listener = AIL_open_3D_listener(provider);
    AIL_set_3D_position(listener, 0, 0, 0);
    AIL_set_3D_orientation(listener, 0, 0, -1, 0, 1, 0);
    AIL_set_3D_velocity(listener, 0, 0, 0, 0);
    //set a room style
    AIL_set_3D_provider_preference(provider, "EAX environment selection", &providerRoomSetting);
  }
}
コード例 #3
0
void vrpn_Sound_Server_Miles::changeListenerStatus(vrpn_ListenerDef listenerDef)
//change pose, etc for listener
{
	if (provider != 0) {
	  vrpn_float32 uX = 0, uY = 1, uZ = 0;

	  // switch to left handed
      listenerDef.pose.orientation[2] *= -1.0;
	  listenerDef.pose.orientation[3] *= -1.0;
	  listenerDef.pose.position[2]    *= -1.0;  


	  AIL_set_3D_position(listener, listenerDef.pose.position[0], listenerDef.pose.position[1], listenerDef.pose.position[2]);

	  // normalize
	  listenerDef.pose.orientation[0] /= listenerDef.pose.orientation[3];
	  listenerDef.pose.orientation[1] /= listenerDef.pose.orientation[3];
	  listenerDef.pose.orientation[2] /= listenerDef.pose.orientation[3];
	  listenerDef.pose.orientation[3] /= listenerDef.pose.orientation[3];

	  q_matrix_type mymatrix;
	  q_matrix_type multmatrix;
	  q_type facevec;

	  q_to_row_matrix(mymatrix, listenerDef.pose.orientation);

	  // 90 degree rotation about x
	  multmatrix[0][0] = 1;
	  multmatrix[0][1] = 0;
	  multmatrix[0][2] = 0;
	  multmatrix[0][3] = 0;

	  multmatrix[1][0] = 0;
	  multmatrix[1][1] = 0;
	  multmatrix[1][2] = -1;
	  multmatrix[1][3] = 0;

	  multmatrix[2][0] = 0;
	  multmatrix[2][1] = 1;
	  multmatrix[2][2] = 0;
	  multmatrix[2][3] = 0;

	  multmatrix[3][0] = 0;
	  multmatrix[3][1] = 0;
	  multmatrix[3][2] = 0;
	  multmatrix[3][3] = 1;

	  q_matrix_mult(mymatrix, mymatrix, multmatrix);

	  q_from_row_matrix(facevec, mymatrix);

      AIL_set_3D_orientation(listener, listenerDef.pose.orientation[0], listenerDef.pose.orientation[1], listenerDef.pose.orientation[2], facevec[0], facevec[1], facevec[2]);
	
	  AIL_set_3D_velocity(listener, listenerDef.velocity[0], listenerDef.velocity[1], listenerDef.velocity[2], listenerDef.velocity[3]);
	} else fprintf(stderr,"No provider has been set prior to changeListenerStatus\n");
}
コード例 #4
0
ファイル: vrpn_Sound_Miles.cpp プロジェクト: ASPePeX/vrpn
void vrpn_Sound_Server_Miles::changeSoundStatus(vrpn_SoundID id, vrpn_SoundDef soundDef)
{
	vrpn_float32 uX = 0, uY = 1, uZ = 0;	// up vector

	if (provider != 0) {

	  //get pose info from quaternion	in soundDef, put it into the above vectors
	  AIL_set_3D_position(getSample(id),soundDef.pose.position[0] , soundDef.pose.position[1], soundDef.pose.position[2]);
	  
	  // normalize
	  soundDef.pose.orientation[0] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[1] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[2] /= soundDef.pose.orientation[3];
	  soundDef.pose.orientation[3] /= soundDef.pose.orientation[3];

	  AIL_set_3D_orientation(getSample(id), soundDef.pose.orientation[0], soundDef.pose.orientation[1], soundDef.pose.orientation[2], uX, uY, uZ);

	  AIL_set_3D_velocity(getSample(id), soundDef.velocity[0], soundDef.velocity[1], soundDef.velocity[2], soundDef.velocity[3]);

	  /*set the volume to the new level.*/
	  AIL_set_3D_sample_volume(getSample(id), soundDef.volume);


	  // Since the RSX software sets max front/back to 128.0 * min front/back,
	  // we will divide max front/back by 128 and set this to min 
	  // before giving it to miles
	  // We will change GetCurrentDistances to multiply by 128.0 before displaying
	  // value to the user.. This mess may need to be cleaned up if the Miles people
	  // come to their senses...

	  soundDef.min_back_dist = soundDef.max_back_dist / 128.0;
	  soundDef.min_front_dist = soundDef.max_front_dist / 128.0;
	  
	  AIL_set_3D_sample_distances(getSample(id), soundDef.max_front_dist, soundDef.min_front_dist, soundDef.max_back_dist, soundDef.min_back_dist);
	 }
	else fprintf(stderr,"No provider has been set prior to changeSoundStatus\n");
}
コード例 #5
0
      //
      // Play3D
      //
      // Play a record as a 3D sample (TRUE if actually started)
      //
      Bool Play3D
      (
        Effect *e, Record *r, S32 vol, U32 owner, F32 priority, S32 loop, 
        F32 x, F32 y, F32 z, F32 min, F32 max
      )
      {
        ASSERT(e);
        ASSERT(r);

        // Request a 3D voice
        Voice *voice = Request(priority, TRUE, e->GetVoiceIndex());

        if (!voice)
        {
          return (FALSE);
        }

        ASSERT(voice->flag3D);

        // Request the cache data
        Cache::Item *item = Cache::Request(r);

        if (!item)
        {
          // Unable to load data
          return (FALSE);
        }

        // Stop any sounds from this owner
        if (owner != NO_OWNER) 
        {
          Output::StopByOwner(owner);
        }

        // The current time
        U32 time = AIL_ms_count();

        // Are we under the minimum repeat time
        if ((time - r->lastUse) < MIN_REPEATTIME)
        {
          return (FALSE);
        }

        // Save info about this use
        r->lastUse = time;

        // Initialise the sound effect data
        if (!AIL_set_3D_sample_file(voice->handle3D, item->data))
        {
          LOG_WARN(("Invalid 3D data '%s' (Require MS Mono Uncompressed PCM WAV)", r->Name()));
          r->valid = FALSE;
          return (FALSE);
        }

        // Setup the voice
        voice->effect = e;
        voice->record = r;
        voice->owner = owner;
        voice->priority = priority;

        // Set the volume
        AIL_set_3D_sample_volume(voice->handle3D, vol);

        // Set the loop count for this voice
        AIL_set_3D_sample_loop_count(voice->handle3D, loop);

        // Set the 3D world position
        AIL_set_3D_position(voice->handle3D, x, y, z);

        // Set the distances for this sample
        AIL_set_3D_sample_distances(voice->handle3D, max, min);

        // Always face the listener 
        AIL_set_3D_orientation(voice->handle3D, -x, -y, -z, 0.0F, 1.0F, 0.0F);

        // Start the sample playing
        AIL_start_3D_sample(voice->handle3D);

        return (TRUE);
      }
コード例 #6
0
void vrpn_Sound_Server_Miles::loadSound(char* filename, vrpn_SoundID id)
/*loads a .wav file into memory.  gives back id to reference the sound
currently (7/28/99) this does not reuse space previously vacated in 
samples by unloading sounds*/
{
	if (provider != 0) {
      fprintf(stdout,"Loading sound: #%d %s\n", id, filename);
	  ChangeSoundIdBox(0,id);
	  //load into handle
	  unsigned long *s;
	  long type;
	  H3DSAMPLE handle;
	  void *sample_address;
	  void *d;
	  AILSOUNDINFO info;

	  LastSoundId = id;

	  //load the .wav file into memory
	  s = (unsigned long *)AIL_file_read(filename, FILE_READ_WITH_SIZE);

	  if (s==0)
        return;

	  type=AIL_file_type(s+1,s[0]);

	  switch (type) {
        case AILFILETYPE_PCM_WAV:
          sample_address = s+1;
	      break;

        case AILFILETYPE_ADPCM_WAV:
          AIL_WAV_info(s+1,&info);
          AIL_decompress_ADPCM(&info,&d,0);
          AIL_mem_free_lock(s);
	      sample_address = d;
          break;

        default:
          AIL_mem_free_lock(s);
          return;
	  }

	  //initialize handle
      handle = AIL_allocate_3D_sample_handle(provider);
	  //tell handle where the .wav file is in memory
	  AIL_set_3D_sample_file(handle, sample_address);
	  //set defaults
	  AIL_set_3D_sample_volume(handle, 100);	//default volume is 100 on 0...127 inclusive
	  AIL_set_3D_position(handle,0,0,0);
	  AIL_set_3D_orientation(handle, 0,0,-1,0,1,0);
	  AIL_set_3D_velocity(handle,0,0,-1,0);
	  AIL_set_3D_sample_distances(handle, 200, 20);

	  //load handle into samples
	  addSample(handle, id);

	  /*Sample level environment preferences (ie, EAX_ENVIRONMENT_BATHROOM)
	  could be added in here as a passed-in parameter*/
	}
	else fprintf(stderr,"No provider has been set prior to LoadSound\n");
}