void sound_direct_sound::pauseAudio(bool pause) { if (pause) { // set the master volume if (stream_buffer != NULL) IDirectSoundBuffer_SetVolume(stream_buffer, DSBVOLUME_MIN); } else { // set the master volume if (stream_buffer != NULL) IDirectSoundBuffer_SetVolume(stream_buffer, (previousAttenuation == -32) ? DSBVOLUME_MIN : previousAttenuation * 100); } /* HRESULT result; if(pause) { result = IDirectSoundBuffer_Stop(stream_buffer); if (result != DS_OK) { printf("DSOUND Error stopping: %08x\n", (UINT32)result); } } else { result = IDirectSoundBuffer_Play(stream_buffer, 0, 0, DSBPLAY_LOOPING); if (result != DS_OK) { printf("DSOUND Error resuming: %08x\n", (UINT32)result); } } */ }
void osd_sound_enable(int enable_it) { if (stream_buffer) { if (enable_it) IDirectSoundBuffer_SetVolume(stream_buffer, attenuation * 100); else IDirectSoundBuffer_SetVolume(stream_buffer, DSBVOLUME_MIN); is_enabled = enable_it; } }
static void gst_directsound_sink_set_volume (GstDirectSoundSink * dsoundsink, gdouble dvolume, gboolean store) { glong volume; volume = dvolume * 100; if (store) dsoundsink->volume = volume; if (dsoundsink->pDSBSecondary) { /* DirectSound controls volume using units of 100th of a decibel, * ranging from -10000 to 0. We use a linear scale of 0 - 100 * here, so remap. */ long dsVolume; if (dsoundsink->volume == 0) dsVolume = -10000; else dsVolume = 100 * (long) (20 * log10 ((double) dsoundsink->volume / 100.)); dsVolume = CLAMP (dsVolume, -10000, 0); GST_DEBUG_OBJECT (dsoundsink, "Setting volume on secondary buffer to %d from %d", (int) dsVolume, (int) dsoundsink->volume); IDirectSoundBuffer_SetVolume (dsoundsink->pDSBSecondary, dsVolume); } }
void I_UpdateSoundParams(int channel, int vol, int sep, int pitch) { // proff 07/04/98: Added for CYGWIN32 compatibility #ifdef HAVE_LIBDSOUND int DSB_Status; if (noDSound == true) return; // proff 07/26/98: Added volume check if (vol==0) { IDirectSoundBuffer_Stop(lpSecondaryDSB[channel]); return; } IDirectSoundBuffer_SetVolume(lpSecondaryDSB[channel],VOL(vol)); IDirectSoundBuffer_SetPan(lpSecondaryDSB[channel],SEP(sep)); IDirectSoundBuffer_SetFrequency (lpSecondaryDSB[channel], ChannelInfo[channel].samplerate+PITCH(pitch)); if (ChannelInfo[channel].playing == true) { IDirectSoundBuffer_GetStatus(lpSecondaryDSB[channel], &DSB_Status); if ((DSB_Status & DSBSTATUS_PLAYING) == 0) IDirectSoundBuffer_Play(lpSecondaryDSB[channel], 0, 0, 0); } #endif // HAVE_LIBDSOUND }
static HRESULT WINAPI DSoundRender_CompleteConnect(BaseRenderer * iface, IPin * pReceivePin) { DSoundRenderImpl *This = impl_from_BaseRenderer(iface); const AM_MEDIA_TYPE * pmt = &This->renderer.pInputPin->pin.mtCurrent; HRESULT hr = S_OK; WAVEFORMATEX *format; DSBUFFERDESC buf_desc; TRACE("(%p)->(%p)\n", This, pReceivePin); dump_AM_MEDIA_TYPE(pmt); TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype)); TRACE("SubType %s\n", debugstr_guid(&pmt->subtype)); TRACE("Format %s\n", debugstr_guid(&pmt->formattype)); TRACE("Size %d\n", pmt->cbFormat); format = (WAVEFORMATEX*)pmt->pbFormat; This->buf_size = format->nAvgBytesPerSec; memset(&buf_desc,0,sizeof(DSBUFFERDESC)); buf_desc.dwSize = sizeof(DSBUFFERDESC); buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2; buf_desc.dwBufferBytes = This->buf_size; buf_desc.lpwfxFormat = format; hr = IDirectSound_CreateSoundBuffer(This->dsound, &buf_desc, &This->dsbuffer, NULL); This->writepos = This->buf_size; if (FAILED(hr)) ERR("Can't create sound buffer (%x)\n", hr); if (SUCCEEDED(hr)) { hr = IDirectSoundBuffer_SetVolume(This->dsbuffer, This->volume); if (FAILED(hr)) ERR("Can't set volume to %d (%x)\n", This->volume, hr); hr = IDirectSoundBuffer_SetPan(This->dsbuffer, This->pan); if (FAILED(hr)) ERR("Can't set pan to %d (%x)\n", This->pan, hr); hr = S_OK; } if (FAILED(hr) && hr != VFW_E_ALREADY_CONNECTED) { if (This->dsbuffer) IDirectSoundBuffer_Release(This->dsbuffer); This->dsbuffer = NULL; } return hr; }
void osd_set_mastervolume(int attenuation) { // clamp the attenuation to 0-32 range if (attenuation > 0) attenuation = 0; if (attenuation < -32) attenuation = -32; // set the master volume if (stream_buffer != NULL) IDirectSoundBuffer_SetVolume(stream_buffer, (attenuation == -32) ? DSBVOLUME_MIN : attenuation * 100); }
static BOOL ModifyChannel( Channel *channel, geSound_Cfg *cfg ) { int Error, Vol, Pan, Freq; assert(channel); if( !cfg ) return( TRUE ); ClearDupBuffers(channel); if( cfg->Volume != channel->cfg.Volume ) { Vol = (DWORD)((1.0 - cfg->Volume ) * DSBVOLUME_MIN); Error = IDirectSoundBuffer_SetVolume(channel->buffer, Vol); if (Error != DS_OK) { geErrorLog_Add(GE_ERR_DS_ERROR, NULL); return FALSE; } channel->cfg.Volume = cfg->Volume; } if( cfg->Pan != channel->cfg.Pan ) { Pan = (int)(cfg->Pan * DSBPAN_RIGHT); Error = IDirectSoundBuffer_SetPan(channel->buffer, Pan); if (Error != DS_OK) { geErrorLog_Add(GE_ERR_DS_ERROR, NULL); return FALSE; } channel->cfg.Pan = cfg->Pan; } if( cfg->Frequency != channel->cfg.Frequency ) { Freq = (DWORD)(channel->BaseFreq * cfg->Frequency); if(Freq < 0) Freq = 0; Error = IDirectSoundBuffer_SetFrequency(channel->buffer, Freq); if (Error != DS_OK) { geErrorLog_Add(GE_ERR_DS_ERROR, NULL); return FALSE; } channel->cfg.Frequency = cfg->Frequency; } return TRUE; }
static void DirectSound_set_mastervolume(int volume) { attenuation = volume; if (attenuation != -1 && dsb != NULL) { HRESULT hr; hr = IDirectSoundBuffer_SetVolume(dsb,100*attenuation); if (FAILED(hr)) ErrorMsg("Unable to set volume %s",DirectXDecodeError(hr)); } }
void osd_set_mastervolume(int _attenuation) { // clamp the attenuation to 0-32 range if (_attenuation > 0) _attenuation = 0; if (_attenuation < -32) _attenuation = -32; attenuation = _attenuation; // set the master volume if (stream_buffer && is_enabled) IDirectSoundBuffer_SetVolume(stream_buffer, attenuation * 100); }
// Vol is linear, from 0 to 1. void I2_SetVolume(sndsource_t *src, float vol) { extern int snd_SfxVolume; int ds_vol; vol *= snd_SfxVolume / 255.0f; if(vol <= 0) ds_vol = DSBVOLUME_MIN; else if(vol >= 1) ds_vol = DSBVOLUME_MAX; else // Straighten the volume curve. { ds_vol = 100 * 20 * log10(vol); if(ds_vol < DSBVOLUME_MIN) ds_vol = DSBVOLUME_MIN; } IDirectSoundBuffer_SetVolume(src->source, ds_vol); }
/*** IBasicAudio methods ***/ static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface, LONG lVolume) { ICOM_THIS_MULTI(DSoundRenderImpl, IBasicAudio_vtbl, iface); TRACE("(%p/%p)->(%d)\n", This, iface, lVolume); if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN) return E_INVALIDARG; if (This->dsbuffer) { if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume))) return E_FAIL; } This->volume = lVolume; return S_OK; }
static void DirectSound_sound_enable(int enable) { if (enable) { osd_set_mastervolume(attenuation); } else { if (dsb != NULL) { HRESULT hr; hr = IDirectSoundBuffer_SetVolume(dsb, DSBVOLUME_MIN); if (FAILED(hr)) ErrorMsg("Unable to set volume %s", DirectXDecodeError(hr)); } } }
/** \brief handle control commands \param cmd command \param arg argument \return CONTROL_OK or CONTROL_UNKNOWN in case the command is not supported */ static int control(struct ao *ao, enum aocontrol cmd, void *arg) { struct priv *p = ao->priv; DWORD volume; switch (cmd) { case AOCONTROL_GET_VOLUME: { ao_control_vol_t *vol = (ao_control_vol_t *)arg; vol->left = vol->right = p->audio_volume; return CONTROL_OK; } case AOCONTROL_SET_VOLUME: { ao_control_vol_t *vol = (ao_control_vol_t *)arg; volume = p->audio_volume = vol->right; if (volume < 1) volume = 1; volume = (DWORD)(log10(volume) * 5000.0) - 10000; IDirectSoundBuffer_SetVolume(p->hdsbuf, volume); return CONTROL_OK; } } return CONTROL_UNKNOWN; }
/* * バッファのボリュームを設定する */ BOOL SetBufferVolume(int nBuffer, float Vol) { LONG dB; Vol = (Vol > 1.0f) ? 1.0f : Vol; Vol = (Vol < 0.0f) ? 0.0f : Vol; /* * 減衰率の対数(dB)を求める * - 0dB(DSBVOLIME_MAX=0)が原音、-100dB(DSBVOLUME_MIN=-10000)が無音 * - 100倍固定少数なので100倍する */ if(Vol <= 0.00001f) dB = DSBVOLUME_MIN; else dB = (LONG)(20.0f * (float)log10(Vol) * 100.0f); assert(dB >= DSBVOLUME_MIN && dB <= DSBVOLUME_MAX); /* バッファのボリュームをセットする */ IDirectSoundBuffer_SetVolume(pDSBuffer[nBuffer], (LONG)dB); return TRUE; }
static void *dsound_init(const char *device, unsigned rate, unsigned latency) { WAVEFORMATEX wfx = {0}; DSBUFFERDESC bufdesc = {0}; struct dsound_dev dev = {0}; dsound_t *ds = (dsound_t*)calloc(1, sizeof(*ds)); if (!ds) goto error; InitializeCriticalSection(&ds->crit); if (device) dev.device = strtoul(device, NULL, 0); RARCH_LOG("DirectSound devices:\n"); #ifndef _XBOX DirectSoundEnumerate(enumerate_cb, &dev); #endif if (DirectSoundCreate(dev.guid, &ds->ds, NULL) != DS_OK) goto error; #ifndef _XBOX if (IDirectSound_SetCooperativeLevel(ds->ds, GetDesktopWindow(), DSSCL_PRIORITY) != DS_OK) goto error; #endif wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = 2; wfx.nSamplesPerSec = rate; wfx.wBitsPerSample = 16; wfx.nBlockAlign = 2 * sizeof(int16_t); wfx.nAvgBytesPerSec = rate * 2 * sizeof(int16_t); ds->buffer_size = (latency * wfx.nAvgBytesPerSec) / 1000; ds->buffer_size /= CHUNK_SIZE; ds->buffer_size *= CHUNK_SIZE; if (ds->buffer_size < 4 * CHUNK_SIZE) ds->buffer_size = 4 * CHUNK_SIZE; RARCH_LOG("[DirectSound]: Setting buffer size of %u bytes\n", ds->buffer_size); RARCH_LOG("[DirectSound]: Latency = %u ms\n", (unsigned)((1000 * ds->buffer_size) / wfx.nAvgBytesPerSec)); bufdesc.dwSize = sizeof(DSBUFFERDESC); bufdesc.dwFlags = 0; #ifndef _XBOX bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; #endif bufdesc.dwBufferBytes = ds->buffer_size; bufdesc.lpwfxFormat = &wfx; ds->event = CreateEvent(NULL, false, false, NULL); if (!ds->event) goto error; ds->buffer = fifo_new(4 * 1024); if (!ds->buffer) goto error; if (IDirectSound_CreateSoundBuffer(ds->ds, &bufdesc, &ds->dsb, 0) != DS_OK) goto error; IDirectSoundBuffer_SetVolume(ds->dsb, DSBVOLUME_MAX); IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); dsound_clear_buffer(ds); if (IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) != DS_OK) goto error; if (!dsound_start_thread(ds)) goto error; return ds; error: RARCH_ERR("[DirectSound] Error occured in init.\n"); dsound_free(ds); return NULL; }
static HRESULT WINAPI DSoundRender_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt) { BaseInputPin *This = (BaseInputPin *)iface; PIN_DIRECTION pindirReceive; DSoundRenderImpl *DSImpl; HRESULT hr = S_OK; TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt); dump_AM_MEDIA_TYPE(pmt); EnterCriticalSection(This->pin.pCritSec); { DSImpl = (DSoundRenderImpl*)This->pin.pinInfo.pFilter; DSImpl->rtLastStop = -1; if (This->pin.pConnectedTo) hr = VFW_E_ALREADY_CONNECTED; if (SUCCEEDED(hr) && This->pin.pFuncsTable->pfnCheckMediaType((BasePin*)This, pmt) != S_OK) hr = VFW_E_TYPE_NOT_ACCEPTED; if (SUCCEEDED(hr)) { IPin_QueryDirection(pReceivePin, &pindirReceive); if (pindirReceive != PINDIR_OUTPUT) { ERR("Can't connect from non-output pin\n"); hr = VFW_E_INVALID_DIRECTION; } } if (SUCCEEDED(hr)) { WAVEFORMATEX *format; DSBUFFERDESC buf_desc; TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype)); TRACE("SubType %s\n", debugstr_guid(&pmt->subtype)); TRACE("Format %s\n", debugstr_guid(&pmt->formattype)); TRACE("Size %d\n", pmt->cbFormat); format = (WAVEFORMATEX*)pmt->pbFormat; DSImpl->buf_size = format->nAvgBytesPerSec; memset(&buf_desc,0,sizeof(DSBUFFERDESC)); buf_desc.dwSize = sizeof(DSBUFFERDESC); buf_desc.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2; buf_desc.dwBufferBytes = DSImpl->buf_size; buf_desc.lpwfxFormat = format; hr = IDirectSound_CreateSoundBuffer(DSImpl->dsound, &buf_desc, &DSImpl->dsbuffer, NULL); if (FAILED(hr)) ERR("Can't create sound buffer (%x)\n", hr); } if (SUCCEEDED(hr)) { hr = IDirectSoundBuffer_SetVolume(DSImpl->dsbuffer, DSImpl->volume); if (FAILED(hr)) ERR("Can't set volume to %d (%x)\n", DSImpl->volume, hr); hr = IDirectSoundBuffer_SetPan(DSImpl->dsbuffer, DSImpl->pan); if (FAILED(hr)) ERR("Can't set pan to %d (%x)\n", DSImpl->pan, hr); DSImpl->write_pos = 0; hr = S_OK; } if (SUCCEEDED(hr)) { CopyMediaType(&This->pin.mtCurrent, pmt); This->pin.pConnectedTo = pReceivePin; IPin_AddRef(pReceivePin); } else if (hr != VFW_E_ALREADY_CONNECTED) { if (DSImpl->dsbuffer) IDirectSoundBuffer_Release(DSImpl->dsbuffer); DSImpl->dsbuffer = NULL; } } LeaveCriticalSection(This->pin.pCritSec); return hr; }
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 ghettoInit(GhettoBufferCallback *callback, void *hwnd) { static const WAVEFORMATEX wfxprimary = { WAVE_FORMAT_PCM, 1, 44100, 44100*2, 2, 16, 0 }; //static const WAVEFORMATEX wfxprimary = { WAVE_FORMAT_PCM, 2, 44100, 44100*2*2, 2*2, 16, 0 }; static const DSBUFFERDESC primdesc = { sizeof(DSBUFFERDESC), DSBCAPS_PRIMARYBUFFER, 0, 0, 0 }; static const DSBUFFERDESC streamdesc = { sizeof(DSBUFFERDESC), DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS, BUFFERLEN, 0, (WAVEFORMATEX*)&wfxprimary }; ZeroMemory(&g_dsound, sizeof(g_dsound)); g_dsound.callback = callback; void *buf1, *buf2; DWORD len1, len2; if (DirectSoundCreate(0, &g_dsound.dssd, 0) != S_OK) printf("dsc\n"); if (IDirectSound_SetCooperativeLevel(g_dsound.dssd, (HWND)hwnd, DSSCL_PRIORITY) != S_OK) printf("setcooperative\n"); if (IDirectSound_CreateSoundBuffer(g_dsound.dssd, &primdesc, &g_dsound.pbuf, 0) != S_OK) printf("createsoundbuffer\n"); if(IDirectSound_CreateSoundBuffer(g_dsound.dssd, &streamdesc, &g_dsound.sbuf, 0) != S_OK) printf("createsoundbuffer2\n"); if (IDirectSoundBuffer_SetFormat(g_dsound.pbuf, &wfxprimary) != S_OK) printf("setformat\n"); if (IDirectSoundBuffer_Lock(g_dsound.sbuf, 0, 0, &buf1, &len1, &buf2, &len2, DSBLOCK_ENTIREBUFFER) != S_OK) // lock secondary buf { printf("lock failed\n"); goto fail; } // clear secondary buffer memset(buf1, 0, len1); memset(buf2, 0, len2); if (IDirectSoundBuffer_Unlock(g_dsound.sbuf, buf1, len1, buf2, len2) != S_OK) goto fail; g_dsound.bufcnt = -BUFFERLEN; g_dsound.ltg = -BUFFERLEN; g_dsound.tickev = CreateEvent(0, FALSE, FALSE, 0); g_dsound.exitev = CreateEvent(0, FALSE, FALSE, 0); InitializeCriticalSection(&g_dsound.crsec); if (IDirectSoundBuffer_Play(g_dsound.sbuf, 0, 0, DSBPLAY_LOOPING) != S_OK) { printf("play failed\n"); goto fail; } IDirectSoundBuffer_SetVolume(g_dsound.sbuf, 5000); // start sound thread g_dsound.thndl = CreateThread(0, 0, bufferLoop, 0, 0, &len1); SetThreadPriority(g_dsound.thndl, THREAD_PRIORITY_ABOVE_NORMAL); return 0; fail: ghettoClose(); return -1; }
int I_StartSound(sfxinfo_t *sound, int vol, int sep, int pitch, int pri) { int channel=0; // proff 07/04/98: Added for CYGWIN32 compatibility #ifdef HAVE_LIBDSOUND HRESULT error; char *snddata; int sndlength; if (noDSound == true) return channel; // load sound data if we have not already I_CacheSound(sound); // find a free channel channel = I_GetFreeChannel(); // proff 07/26/98: Added volume check // proff 10/31/98: Added Stop before updating sound-data error = IDirectSoundBuffer_Stop(lpSecondaryDSB[channel]); ChannelInfo[channel].playing = false; if (vol==0) return channel; snddata = sound->data; ChannelInfo[channel].samplerate = (snddata[3] << 8) + snddata[2]; // proff 10/31/98: Use accurate time for this one ChannelInfo[channel].endtime = I_GetTime_RealTime() + (sound->length * 35) / ChannelInfo[channel].samplerate + 1; // skip past header snddata += 8; sndlength = sound->length - 8; error = IDirectSoundBuffer_SetCurrentPosition(lpSecondaryDSB[channel],0); // proff 11/09/98: Added for a slight speedup if (sound != ChannelInfo[channel].sfx) { DWORD *hand1,*hand2; DWORD len1,len2; ChannelInfo[channel].sfx = sound; error = IDirectSoundBuffer_Lock(lpSecondaryDSB[channel],0,65535, &hand1,&len1,&hand2,&len2, DSBLOCK_FROMWRITECURSOR); if (len1 >= sndlength) { memset(hand1, 128, len1); memcpy(hand1, snddata , sndlength); memset(hand2, 128, len2); } else { memcpy(hand1, snddata, len1); memcpy(hand2, &((char *)snddata)[len1], sndlength-len1); } error = IDirectSoundBuffer_Unlock (lpSecondaryDSB[channel], hand1, len1, hand2, len2); } IDirectSoundBuffer_SetVolume(lpSecondaryDSB[channel], VOL(vol)); IDirectSoundBuffer_SetPan(lpSecondaryDSB[channel], SEP(sep)); IDirectSoundBuffer_SetFrequency(lpSecondaryDSB[channel], ChannelInfo[channel].samplerate+PITCH(pitch)); error = IDirectSoundBuffer_Play(lpSecondaryDSB[channel], 0, 0, 0); ChannelInfo[channel].playing = true; #endif // HAVE_LIBDSOUND return channel; }
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; }
void SOUND_set_vol(int sound, float vol) { IDirectSoundBuffer_SetVolume(sample_buffers[sound], (LONG)vol) ; }