// // 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); }
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"); }