コード例 #1
0
/*-----------------------------------------------------------------------------
IMiniportStreamAudioEngineNode::SetStreamChannelVolume 
 
Decscription:

    When handling SET volume KS property for the device, Portcls calls 
    this method, inside its property handlers, to set the current setting on the specific channel.

Parameters:

        _In_ Channel:  the target channel for this GET volume operation
        _In_ TargetVolume: volume value to set 
        _In_ CurveType: type of curve to apply to the ramp
        _In_ CurveDuration: amount of time in hns over which to ramp the volume

Return Value:

   Appropriate NTSTATUS code

Called at PASSIVE_LEVEL

Remarks

-------------------------------------------------------------------------------------------------------------------------*/
STDMETHODIMP_(NTSTATUS) CMiniportWaveRTStream::SetStreamChannelVolume
(
    _In_ UINT32             Channel,
    _In_ LONG	            TargetVolume,
    _In_ AUDIO_CURVE_TYPE   CurveType,
    _In_ ULONGLONG          CurveDuration
)
{
    UNREFERENCED_PARAMETER(CurveType);
    UNREFERENCED_PARAMETER(CurveDuration);
    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;

    PAGED_CODE ();

    DPF_ENTER(("[CMiniportWaveRTStream::SetStreamChannelVolume]"));

    // Snap the volume level to our range of steppings.
    LONG lVolume = VOLUME_NORMALIZE_IN_RANGE(TargetVolume); 

    // If Channel is ALL_CHANNELS_ID, then set the level on all channels
    if ( ALL_CHANNELS_ID == Channel )
    {
        for (UINT32 i = 0; i < m_pWfExt->Format.nChannels; i++)
        {
            ntStatus = SetChannelVolume(i, lVolume);
        }
    }
    else
    {
        ntStatus = SetChannelVolume(Channel, lVolume);
    }

    return ntStatus;
}
コード例 #2
0
ファイル: sound.cpp プロジェクト: AMDmi3/Wyrmgus
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param voice  Type of sound wanted (Ready,Die,Yes,...)
*/
void PlayUnitSound(const CUnit &unit, UnitVoiceGroup voice)
{
	CSound *sound = ChooseUnitVoiceSound(unit, voice);
	if (!sound) {
		return;
	}

	bool selection = (voice == VoiceSelected || voice == VoiceBuilding);
	Origin source = {&unit, unsigned(UnitNumber(unit))};

	//Wyrmgus start
//	if (UnitSoundIsPlaying(&source)) {
	if (UnitSoundIsPlaying(&source) && voice != VoiceHit && voice != VoiceMiss && voice != VoiceStep) {
	//Wyrmgus end
		return;
	}

	int channel = PlaySample(ChooseSample(sound, selection, source), &source);
	if (channel == -1) {
		return;
	}
	//Wyrmgus start
//	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range) * sound->VolumePercent / 100);
	//Wyrmgus end
	SetChannelStereo(channel, CalculateStereo(unit));
	//Wyrmgus start
	SetChannelVoiceGroup(channel, voice);
	//Wyrmgus end
}
コード例 #3
0
ファイル: sound.cpp プロジェクト: AMDmi3/Wyrmgus
/**
**  Ask the sound server to play a sound for a missile.
**
**  @param missile  Sound initiator, missile exploding
**  @param sound    Sound to be generated
*/
void PlayMissileSound(const Missile &missile, CSound *sound)
{
	if (!sound) {
		return;
	}
	int stereo = ((missile.position.x + (missile.Type->G ? missile.Type->G->Width / 2 : 0) +
				   UI.SelectedViewport->MapPos.x * PixelTileSize.x) * 256 /
				  ((UI.SelectedViewport->MapWidth - 1) * PixelTileSize.x)) - 128;
	clamp(&stereo, -128, 127);

	Origin source = {NULL, 0};
	//Wyrmgus start
//	unsigned char volume = CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range);
	unsigned char volume = CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range) * sound->VolumePercent / 100;
	//Wyrmgus end
	if (volume == 0) {
		return;
	}

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, volume);
	SetChannelStereo(channel, stereo);
}
コード例 #4
0
void VoiceManager::AddNoise(VOICE_STREAM_BUFFER *streamBuffer, VU_ID from, int channel)
{
	unsigned long i; 
	int level=255, minLevel=253, volume, nonoise;
	VuEntity *fromEnt = NULL;
	float dist, dx, dy , dz;
	SimBaseClass *ownship = OTWDriver.GraphicsOwnship();

	Flight	awacs = NULL;
	Flight	flight = NULL;
	nonoise = FALSE;

	if(SimDriver.GetPlayerEntity())
	{
		flight = (Flight)SimDriver.GetPlayerEntity()->GetCampaignObject();
		if(flight)
		{
			// AWACS/FAC callsign
			awacs = flight->GetFlightController();
			if (awacs && awacs->Id() == from)
				nonoise = TRUE;

		}
	}

	fromEnt = vuDatabase->Find(from);
	if(fromEnt && ownship && fromEnt != SimDriver.GetPlayerEntity() && !nonoise && SimDriver.InSim())
	{
		dx = fromEnt->XPos() - ownship->XPos();
		dy = fromEnt->YPos() - ownship->YPos();
		dz = fromEnt->ZPos() - ownship->ZPos();
		dist = (float)sqrt(dx*dx + dy*dy + dz*dz);

		dist = min(dist, MAX_RADIO_RANGE - 1.0F);

		minLevel = FloatToInt32(253 - dist/MAX_RADIO_RANGE * 50.0F);	
		
		volume = FloatToInt32(max(-10000,PlayerOptions.GroupVol[COM1_SOUND_GROUP + channel] - dist/MAX_RADIO_RANGE*2000));
		SetChannelVolume(channel, volume);
	}


	unsigned char  *pos = streamBuffer->waveBuffer;

	for(i = 0; i < streamBuffer->dataInWaveBuffer; i++)
	{
		if(!(i%50))
			level = minLevel - rand()%4 - rand()%4;

		if(*pos > level)
			*pos = (uchar)level;

		//if(level < 235)
		//	*pos += (1 - rand()%3);

		pos++;
	}
}
コード例 #5
0
ファイル: sound.cpp プロジェクト: OneSleepyDev/boswars_osd
/**
**  Play a game sound
**
**  @param sound   Sound to play
**  @param volume  Volume level to play the sound
*/
void PlayGameSound(CSound *sound, unsigned char volume)
{
	Origin source = {NULL, 0};

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range));
}
コード例 #6
0
ファイル: sound.cpp プロジェクト: OneSleepyDev/boswars_osd
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param sound  Sound to be generated
*/
void PlayUnitSound(const CUnit *unit, CSound *sound)
{
	Origin source = {unit, unit->Slot};
	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelStereo(channel, CalculateStereo(unit));
}
コード例 #7
0
/**
**  Play a sound file
**
**  @param name      Filename of a sound to play
**  @param listener  Optional lua callback
**
**  @return          Channel number the sound is playing on, -1 for error
*/
int PlayFile(const std::string &name, LuaActionListener *listener)
{
	int channel = -1;
	CSample *sample = LoadSample(name);

	if (sample) {
		channel = PlaySample(sample);
		if (channel != -1) {
			SetChannelVolume(channel, MaxVolume);
			SetChannelFinishedCallback(channel, PlaySoundFileCallback);
			ChannelMap[channel] = listener;
		}
	}
	return channel;
}
コード例 #8
0
/**
**  Ask the sound server to play a sound for a missile.
**
**  @param missile  Sound initiator, missile exploding
**  @param sound    Sound to be generated
*/
void PlayMissileSound(const Missile &missile, CSound *sound)
{
	int stereo = ((missile.position.x + missile.Type->G->Width / 2 -
				   UI.SelectedViewport->MapPos.x * PixelTileSize.x) * 256 /
				  ((UI.SelectedViewport->MapWidth - 1) * PixelTileSize.x)) - 128;
	clamp(&stereo, -128, 127);

	Origin source = {NULL, 0};

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range));
	SetChannelStereo(channel, stereo);
}
コード例 #9
0
ファイル: sound.cpp プロジェクト: bradc6/Stratagus
/**
**  Play a game sound
**
**  @param sound   Sound to play
**  @param volume  Volume level to play the sound
*/
void PlayGameSound(CSound *sound, unsigned char volume, bool always)
{
	Origin source = {NULL, 0};

	CSample *sample = ChooseSample(sound, false, source);

	if (!always && SampleIsPlaying(sample)) {
		return;
	}

	int channel = PlaySample(sample);
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range));
}
コード例 #10
0
void BassSoundEngine::FreeChannel(int chan_id, bool bImmediate)
{
	if(channel[chan_id] == NULL)
		return;
	if(BASS_ChannelIsActive(channel[chan_id])==BASS_ACTIVE_PLAYING)
	{
		if(bImmediate){
			BASS_ChannelStop(channel[chan_id]);
		}else{
			int new_id = GetNewChannel();
			channel[new_id] = channel[chan_id];
			SetChannelVolume(0, new_id, true);
		}
	}
	channel[chan_id] = NULL;
}
コード例 #11
0
ファイル: sound.cpp プロジェクト: OneSleepyDev/boswars_osd
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param voice  Type of sound wanted (Ready,Die,Yes,...)
*/
void PlayUnitSound(const CUnit *unit, UnitVoiceGroup voice)
{
	CSound *sound = ChooseUnitVoiceSound(unit, voice);
	if (!sound) {
		return;
	}

	bool selection = (voice == VoiceSelected || voice == VoiceBuilding);
	Origin source = {unit, unit->Slot};

	int channel = PlaySample(ChooseSample(sound, selection, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
	SetChannelStereo(channel, CalculateStereo(unit));
}
コード例 #12
0
/*-----------------------------------------------------------------------------
IMiniportAudioEngineNode::SetDeviceChannelVolume 
 
Decscription:

    When handling SET volume KS property for the device, Portcls calls 
    this method, inside its property handlers, to set the current setting on the specific channel.

Parameters:

        _In_ _ulNodeId: node id for the target audio engine node
        _In_ _uiChannel:  the target channel for this GET volume operation
		_In_ _Volume: volume value to set 

Return Value:

   Appropriate NTSTATUS code

Called at PASSIVE_LEVEL

Remarks

-------------------------------------------------------------------------------------------------------------------------*/
STDMETHODIMP_(NTSTATUS) CMiniportWaveRT::SetDeviceChannelVolume(_In_  ULONG _ulNodeId, _In_ UINT32 _uiChannel, _In_  LONG  _Volume)
{
    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;

    PAGED_CODE ();

    DPF_ENTER(("[CMiniportWaveRT::SetEndpointChannelVolume]"));
    IF_TRUE_ACTION_JUMP(_ulNodeId != KSNODE_WAVE_AUDIO_ENGINE, ntStatus = STATUS_INVALID_DEVICE_REQUEST, Exit);

    // Snap the volume level to our range of steppings.
    LONG lVolume = VOLUME_NORMALIZE_IN_RANGE(_Volume); 

    ntStatus = SetChannelVolume(_uiChannel, lVolume);

Exit:
    return ntStatus;
}
bool SoundLibrary3dSoftware::Initialise(int _mixFreq, int _numChannels, bool _hw3d, 
										int _mainBufNumSamples, int _musicBufNumSamples )
{
	m_sampleRate = _mixFreq;
	m_musicChannelId = _numChannels - 1;

	int log2NumChannels = ceilf(Log2(_numChannels));
	m_numChannels = 1 << log2NumChannels;
	AppReleaseAssert(m_numChannels == _numChannels, "Num channels must be a power of 2");

	m_channels = new SoftwareChannel[m_numChannels];

	// Initialise music channel
	SetChannel3DMode(m_musicChannelId, 2);
	SetChannelVolume(m_musicChannelId, 10.0f);

	return true;
}
コード例 #14
0
void FmodSoundEngine::FreeChannel(int chan_id, bool bImmediate)
{
	if(channel[chan_id] == NULL)
		return;
	FMOD::Channel **channel = (FMOD::Channel**)this->channel;
	FMOD_RESULT result;
	bool status;
	result = channel[chan_id]->isPlaying(&status);
	if(result==FMOD_OK && status)
	{
		if(bImmediate){
			channel[chan_id]->stop();
		}else{
			int new_id = GetNewChannel();
			channel[new_id] = channel[chan_id];
			SetChannelVolume(0, new_id, true);
		}
	}
	channel[chan_id] = NULL;
}
コード例 #15
0
ファイル: sound.cpp プロジェクト: AMDmi3/Wyrmgus
/**
**  Ask to the sound server to play a sound attached to a unit. The
**  sound server may discard the sound if needed (e.g., when the same
**  unit is already speaking).
**
**  @param unit   Sound initiator, unit speaking
**  @param sound  Sound to be generated
*/
void PlayUnitSound(const CUnit &unit, CSound *sound)
{
	if (!sound) {
		return;
	}
	Origin source = {&unit, unsigned(UnitNumber(unit))};
	//Wyrmgus start
//	unsigned char volume = CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range);
	unsigned char volume = CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range) * sound->VolumePercent / 100;
	//Wyrmgus end
	if (volume == 0) {
		return;
	}

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, volume);
	SetChannelStereo(channel, CalculateStereo(unit));
}
コード例 #16
0
ファイル: sound.cpp プロジェクト: AMDmi3/Wyrmgus
/**
**  Play a game sound
**
**  @param sound   Sound to play
**  @param volume  Volume level to play the sound
*/
void PlayGameSound(CSound *sound, unsigned char volume, bool always)
{
	if (!sound) {
		return;
	}
	Origin source = {NULL, 0};

	CSample *sample = ChooseSample(sound, false, source);

	if (!always && SampleIsPlaying(sample)) {
		return;
	}

	int channel = PlaySample(sample);
	if (channel == -1) {
		return;
	}
	//Wyrmgus start
//	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range));
	SetChannelVolume(channel, CalculateVolume(true, volume, sound->Range) * sound->VolumePercent / 100);
	//Wyrmgus end
}
コード例 #17
0
ファイル: sound.cpp プロジェクト: OneSleepyDev/boswars_osd
/**
**  Ask the sound server to play a sound for a missile.
**
**  @param missile  Sound initiator, missile exploding
**  @param sound    Sound to be generated
*/
void PlayMissileSound(const Missile *missile, CSound *sound)
{
	int stereo;

	stereo = ((missile->X + missile->Type->G->Width / 2 -
		UI.SelectedViewport->MapX * TileSizeX) * 256 /
		((UI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
	if (stereo < -128) {
		stereo = -128;
	} else if (stereo > 127) {
		stereo = 127;
	}

	Origin source = {NULL, 0};

	int channel = PlaySample(ChooseSample(sound, false, source));
	if (channel == -1) {
		return;
	}
	SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToMissile(missile), sound->Range));
	SetChannelStereo(channel, stereo);
}
bool SoundLibrary3dDirectSound::Initialise(int _mixFreq, int _numChannels, bool _hw3d, 
										   int _mainBufNumSamples, int _musicBufNumSamples )
{    
    int errCode;

    AppReleaseAssert( g_systemInfo->m_directXVersion >= 9.0f, APP_NAME " requires DirectX9 or Greater" );
	AppReleaseAssert( _numChannels > 0, "SoundLibrary3d asked to create too few channels" );


    //
    // Initialise COM
    // We need to do this in order to use the directX FX stuff

    errCode = CoInitialize( NULL );

    
    //
	// Create Direct Sound Device

	errCode = DirectSoundCreate8(NULL,              // Specifies default device 
								 &m_directSound->m_device,
								 NULL);             // Has to be NULL - stupid, stupid Microsoft
	SOUNDASSERT(errCode, "Direct Sound couldn't create a sound device");
    

	errCode = m_directSound->m_device->SetCooperativeLevel((HWND)g_windowManager->Window(), DSSCL_PRIORITY);
	SOUNDASSERT(errCode, "Direct Sound couldn't set the cooperative level");

	
    RefreshCapabilities();


	m_sampleRate = _mixFreq;
	m_hw3dDesired = _hw3d;
	m_numChannels = min( _numChannels, GetMaxChannels() ) - 1;	// Reserve one channel for the music
	m_musicChannelId = -1;

    
	// 
	// Create the Primary Sound Buffer
	
	{		
        int flags = DSBCAPS_PRIMARYBUFFER |
                    DSBCAPS_CTRL3D;
        if( Hardware3DSupport() && m_hw3dDesired )   flags |= DSBCAPS_LOCHARDWARE;
        else                                         flags |= DSBCAPS_LOCSOFTWARE;
        
		DSBUFFERDESC dsbd;
		ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
		dsbd.dwSize        = sizeof(DSBUFFERDESC);
		dsbd.dwFlags       = flags;
		dsbd.dwBufferBytes = 0;
		dsbd.lpwfxFormat   = NULL;
       
		errCode = m_directSound->m_device->CreateSoundBuffer(&dsbd, &m_directSound->m_primaryBuffer, NULL);
		SOUNDASSERT(errCode, "Direct sound couldn't create the primary sound buffer");

		WAVEFORMATEX wfx;
		ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); 
		wfx.wFormatTag      = (WORD) WAVE_FORMAT_PCM; 
		wfx.nChannels       = 2; 
		wfx.nSamplesPerSec  = _mixFreq; 
		wfx.wBitsPerSample  = 16;
		wfx.nBlockAlign     = (WORD) (wfx.wBitsPerSample / 8 * wfx.nChannels);
		wfx.nAvgBytesPerSec = (DWORD) (wfx.nSamplesPerSec * wfx.nBlockAlign);

		errCode = m_directSound->m_primaryBuffer->SetFormat(&wfx);
		SOUNDASSERT(errCode, "Direct sound couldn't set the primary sound buffer format");
	}

    
	//
	// Create a streaming secondary buffer for each channel

    m_channels = new DirectSoundChannel[ m_numChannels ];

    for( int i = 0; i < m_numChannels; ++i )
    {
        m_channels[i].m_bufferInterface = CreateSecondaryBuffer(_mainBufNumSamples);

		//
		// Earlier return if CreateSecondaryBuffer fails

		if( !m_channels[i].m_bufferInterface )
		{
			return false;
		}

		m_channels[i].m_numBufferSamples = _mainBufNumSamples;
		m_channels[i].m_lastSampleWritten = m_channels[i].m_numBufferSamples - 1;     // We just filled all of it with zeros remember
		m_channels[i].m_simulatedPlayCursor = -1;
		m_channels[i].m_freq = _mixFreq;

		// Get the DirectSound3DBuffer interface
		errCode = m_channels[i].m_bufferInterface->QueryInterface( IID_IDirectSound3DBuffer, 
														  (void **) &m_channels[i].m_buffer3DInterface );
		SOUNDASSERT(errCode, "Direct sound couldn't get Sound3DBuffer interface");
	}    


	// 
	// Create a streaming secondary buffer for music

	m_musicChannel = new DirectSoundChannel;
	m_musicChannel->m_bufferInterface = CreateSecondaryBuffer(_musicBufNumSamples);

	//
	// Earlier return if CreateSecondaryBuffer fails

	if( !m_musicChannel->m_bufferInterface )
	{
		return false;
	}

	m_musicChannel->m_numBufferSamples = _musicBufNumSamples;
	m_musicChannel->m_lastSampleWritten = m_musicChannel->m_numBufferSamples - 1;
	m_musicChannel->m_simulatedPlayCursor = -1;
	m_musicChannel->m_freq = _mixFreq;
	// Get the DirectSound3DBuffer interface
	errCode = m_musicChannel->m_bufferInterface->QueryInterface( IID_IDirectSound3DBuffer, 
													  (void **)&(m_musicChannel->m_buffer3DInterface) );
	SOUNDASSERT(errCode, "Direct sound couldn't get Sound3DBuffer interface");
	SetChannel3DMode(m_musicChannelId, 2);
	SetChannelVolume(m_musicChannelId, 10.0f);
	SetChannelFrequency(m_musicChannelId, 44100);


    //
    // Set our listener properties

    IDirectSound3DListener *listener = NULL;
    errCode = m_directSound->m_primaryBuffer->QueryInterface( IID_IDirectSound3DListener, (void **) &listener );
    SOUNDASSERT(errCode, "Direct sound couldn't get Sound3DListener interface");

    errCode = listener->SetDopplerFactor( 0.0f, DS3D_IMMEDIATE );

	return true;
}