int digi_start_sound_object(int obj) { int slot; if (!digi_initialised) return -1; LOCK(); slot = get_free_slot(); if (slot<0) { UNLOCK(); return -1; } SoundSlots[slot].soundno = SoundObjects[obj].soundnum; SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data; SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length; SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume); SoundSlots[slot].pan = SoundObjects[obj].pan; SoundSlots[slot].position = 0; SoundSlots[slot].looped = (SoundObjects[obj].flags & SOF_PLAY_FOREVER); SoundSlots[slot].playing = 1; SoundObjects[obj].signature = next_signature++; SoundObjects[obj].handle = slot; SoundObjects[obj].flags |= SOF_PLAYING; //added on 980905 by adb to add sound kill system from original sos digi.c reset_sounds_on_channel(slot); //end edit by adb UNLOCK(); return 0; }
int digi_start_sound(int soundnum, fix volume, fix pan) { int ntries; int slot; if (!digi_initialised) return -1; LOCK(); //added on 980905 by adb from original source to add sound kill system // play at most digi_max_channel samples, if possible kill sample with low volume ntries = 0; TryNextChannel: if ( (SampleHandles[next_handle] >= 0) && (SoundSlots[SampleHandles[next_handle]].playing) ) { if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) ) { next_handle++; if ( next_handle >= digi_max_channels ) next_handle = 0; ntries++; goto TryNextChannel; } SoundSlots[SampleHandles[next_handle]].playing = 0; SampleHandles[next_handle] = -1; } //end edit by adb slot = get_free_slot(); if (slot<0) return -1; SoundSlots[slot].soundno = soundnum; SoundSlots[slot].samples = Sounddat(soundnum)->data; SoundSlots[slot].length = Sounddat(soundnum)->length; SoundSlots[slot].volume = fixmul(digi_volume, volume); SoundSlots[slot].pan = pan; SoundSlots[slot].position = 0; SoundSlots[slot].looped = 0; SoundSlots[slot].playing = 1; //added on 980905 by adb to add sound kill system from original sos digi.c reset_sounds_on_channel(slot); SampleHandles[next_handle] = slot; next_handle++; if ( next_handle >= digi_max_channels ) next_handle = 0; //end edit by adb UNLOCK(); return slot; }
int digi_link_sound_to_pos2( int soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance ) { int i, volume, pan; if ( max_volume < 0 ) return -1; if (!digi_initialised) return -1; if (digi_xlat_sound(soundnum) < 0) return -1; if (Sounddat(soundnum)->data==NULL) { Int3(); return -1; } if ((segnum<0)||(segnum>Highest_segment_index)) return -1; if ( !forever ) { // Hack to keep sounds from building up... digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance ); digi_play_sample_3d( soundnum, pan, volume, 0 ); return -1; } for (i=0; i<MAX_SOUND_OBJECTS; i++ ) if (SoundObjects[i].flags==0) break; if (i==MAX_SOUND_OBJECTS) { mprintf((1, "Too many sound objects!\n" )); return -1; } SoundObjects[i].signature=next_signature++; SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_POS; if ( forever ) SoundObjects[i].flags |= SOF_PLAY_FOREVER; SoundObjects[i].lp_segnum = segnum; SoundObjects[i].lp_sidenum = sidenum; SoundObjects[i].lp_position = *pos; SoundObjects[i].soundnum = soundnum; SoundObjects[i].max_volume = max_volume; SoundObjects[i].max_distance = max_distance; SoundObjects[i].volume = 0; SoundObjects[i].pan = 0; digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &SoundObjects[i].lp_position, SoundObjects[i].lp_segnum, SoundObjects[i].max_volume, &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); if (!forever || SoundObjects[i].volume >= MIN_VOLUME) digi_start_sound_object(i); return SoundObjects[i].signature; }
int digi_link_sound_to_object2( int soundnum, short objnum, int forever, fix max_volume, fix max_distance ) { int i,volume,pan; object * objp; if ( max_volume < 0 ) return -1; // if ( max_volume > F1_0 ) max_volume = F1_0; if (!digi_initialised) return -1; if (digi_xlat_sound(soundnum) < 0 ) return -1; if (Sounddat(soundnum)->data==NULL) { Int3(); return -1; } if ((objnum<0)||(objnum>Highest_object_index)) return -1; if ( !forever ) { // Hack to keep sounds from building up... digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance ); digi_play_sample_3d( soundnum, pan, volume, 0 ); return -1; } for (i=0; i<MAX_SOUND_OBJECTS; i++ ) if (SoundObjects[i].flags==0) break; if (i==MAX_SOUND_OBJECTS) { return -1; } SoundObjects[i].signature=next_signature++; SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_OBJ; if ( forever ) SoundObjects[i].flags |= SOF_PLAY_FOREVER; SoundObjects[i].lo_objnum = objnum; SoundObjects[i].lo_objsignature = Objects[objnum].signature; SoundObjects[i].max_volume = max_volume; SoundObjects[i].max_distance = max_distance; SoundObjects[i].volume = 0; SoundObjects[i].pan = 0; SoundObjects[i].soundnum = soundnum; objp = &Objects[SoundObjects[i].lo_objnum]; digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &objp->pos, objp->segnum, SoundObjects[i].max_volume, &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); if (!forever || SoundObjects[i].volume >= MIN_VOLUME) digi_start_sound_object(i); return SoundObjects[i].signature; }
int digi_start_sound_object(int obj) { int slot; HRESULT hr; if (!digi_initialised) return -1; slot = get_free_slot(); if (slot<0) return -1; SoundSlots[slot].soundno = SoundObjects[obj].soundnum; SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data; SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length; SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume); SoundSlots[slot].pan = SoundObjects[obj].pan; SoundSlots[slot].position = 0; SoundSlots[slot].looped = (SoundObjects[obj].flags & SOF_PLAY_FOREVER); SoundSlots[slot].playing = 1; memset(&waveformat, 0, sizeof(waveformat)); waveformat.wFormatTag=WAVE_FORMAT_PCM; waveformat.wBitsPerSample = Sounddat(SoundObjects[obj].soundnum)->bits; waveformat.nChannels = 1; waveformat.nSamplesPerSec = Sounddat(SoundObjects[obj].soundnum)->freq; waveformat.nBlockAlign = waveformat.nChannels * (waveformat.wBitsPerSample/8); waveformat.nAvgBytesPerSec = waveformat.nSamplesPerSec * waveformat.nBlockAlign; memset(&dsbd, 0, sizeof(dsbd)); dsbd.dwSize = sizeof(dsbd); dsbd.dwFlags = (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME) | DSBCAPS_GETCURRENTPOSITION2; dsbd.dwReserved=0; dsbd.dwBufferBytes = SoundSlots[slot].length; dsbd.lpwfxFormat = &waveformat; hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL); if ( hr != DS_OK ) { abort(); } { char *ptr1, *ptr2; DWORD len1, len2; IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, SoundSlots[slot].length, (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0); memcpy(ptr1, SoundSlots[slot].samples, MIN(len1,(int)SoundSlots[slot].length)); IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, (void *)ptr1, len1, (void *)ptr2, len2); } IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(SoundSlots[slot].pan) * 20000))-10000); IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb,D1vol2DSvol(SoundSlots[slot].volume)); IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, SoundSlots[slot].looped?DSBPLAY_LOOPING:0); SoundObjects[obj].signature = next_signature++; SoundObjects[obj].handle = slot; SoundObjects[obj].flags |= SOF_PLAYING; //added on 980905 by adb to add sound kill system from original sos digi.c reset_sounds_on_channel(slot); //end edit by adb return 0; }
int digi_start_sound(int soundnum, fix volume, fix pan) { int ntries; int slot; HRESULT hr; if (!digi_initialised) return -1; //added on 980905 by adb from original source to add sound kill system // play at most digi_max_channel samples, if possible kill sample with low volume ntries = 0; TryNextChannel: if ( (SampleHandles[next_handle] >= 0) && (SoundSlots[SampleHandles[next_handle]].playing) ) { if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) ) { //mprintf(( 0, "Not stopping loud sound %d.\n", next_handle )); next_handle++; if ( next_handle >= digi_max_channels ) next_handle = 0; ntries++; goto TryNextChannel; } //mprintf(( 0, "[SS:%d]", next_handle )); DS_release_slot(SampleHandles[next_handle],1); SampleHandles[next_handle] = -1; } //end edit by adb slot = get_free_slot(); if (slot<0) return -1; SoundSlots[slot].soundno = soundnum; SoundSlots[slot].samples = Sounddat(soundnum)->data; SoundSlots[slot].length = Sounddat(soundnum)->length; SoundSlots[slot].volume = fixmul(digi_volume, volume); SoundSlots[slot].pan = pan; SoundSlots[slot].position = 0; SoundSlots[slot].looped = 0; SoundSlots[slot].playing = 1; memset(&waveformat, 0, sizeof(waveformat)); waveformat.wFormatTag=WAVE_FORMAT_PCM; waveformat.wBitsPerSample = Sounddat(soundnum)->bits; waveformat.nChannels = 1; waveformat.nSamplesPerSec = Sounddat(soundnum)->freq; waveformat.nBlockAlign = waveformat.nChannels * (waveformat.wBitsPerSample/8); waveformat.nAvgBytesPerSec = waveformat.nSamplesPerSec * waveformat.nBlockAlign; memset(&dsbd, 0, sizeof(dsbd)); dsbd.dwSize = sizeof(dsbd); dsbd.dwFlags = (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME) | DSBCAPS_GETCURRENTPOSITION2; dsbd.dwReserved=0; dsbd.dwBufferBytes = SoundSlots[slot].length; dsbd.lpwfxFormat = &waveformat; hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL); if ( hr != DS_OK ) { printf("Createsoundbuffer failed! hr=0x%X\n", (int)hr); abort(); } { char *ptr1, *ptr2; DWORD len1, len2; IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, Sounddat(soundnum)->length, (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0); memcpy(ptr1,Sounddat(soundnum)->data, MIN((int) len1, Sounddat(soundnum)->length)); IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, ptr1, len1, ptr2, len2); } IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(pan) * 20000.0))-10000); IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, D1vol2DSvol(SoundSlots[slot].volume)); IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, 0); //added on 980905 by adb to add sound kill system from original sos digi.c reset_sounds_on_channel(slot); SampleHandles[next_handle] = slot; next_handle++; if ( next_handle >= digi_max_channels ) next_handle = 0; //end edit by adb return slot; }