Mercurial > mm7
changeset 2105:7ee21636d67a
PlaySound() continue
author | Ritor1 |
---|---|
date | Thu, 19 Dec 2013 00:55:16 +0600 |
parents | 9574c5bfb96f |
children | b52c09e01e7e |
files | AudioPlayer.cpp Spells.cpp |
diffstat | 2 files changed, 225 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/AudioPlayer.cpp Wed Dec 18 17:33:04 2013 +0600 +++ b/AudioPlayer.cpp Thu Dec 19 00:55:16 2013 +0600 @@ -684,12 +684,26 @@ Log::Warning(L"SoundID = %u not found", eSoundID); return; } + assert(sound_id < pSoundList->sNumSounds); + SoundDesc* sound_desc = &pSoundList->pSounds[sound_id]; + if ( !a7 ) + { + //pSoundDesc = pSoundList->pSounds; + //pSoundDesc2 = &pSoundList->pSounds[sound_id]; + if ( !sound_desc->pSoundData[0] ) + { + if ( sound_desc->eType == SOUND_DESC_SWAP ) + pSoundList->LoadSound(eSoundID, 0); + } + } + //v72 = 4 * (a7 + 30 * sound_id) + 44; + if ( !pSoundList->pSounds[sound_id].pSoundData[a7] ) + return; int start_channel = 0, end_channel = 0; v62 = start_channel; - assert(sound_id < pSoundList->sNumSounds); - SoundDesc* sound_desc = &pSoundList->pSounds[sound_id]; + if (!b3DSoundInitialized || sound_desc->Is3D()) { if (a3 == 0) // generic sound like from UI @@ -733,20 +747,94 @@ switch (object_type) { case OBJECT_BLVDoor: - case OBJECT_Player: { - for ( int i = 10; i <= 12; ++i) + assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); + assert(object_id < pIndoor->uNumDoors); + if ( !pIndoor->pDoors[object_id].uDoorID ) + return; + + start_channel = 10; + end_channel = 12; + for (uint i = start_channel; i <= end_channel; ++i) + { + if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) + { + if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) + return; // already playing the same sound from the same source - return + AIL_end_sample( pMixerChannels[i].hSample); // requested new sound from the same source - end & switch + FreeChannel(&pMixerChannels[i]); + } + } + for ( uint j = start_channel; j <= end_channel; j++ ) { - if (AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Done) + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) { - AIL_end_sample(pMixerChannels[i].hSample); - if ( pMixerChannels[i].uSourceTrackIdx ) - FreeChannel(&pMixerChannels[i]); - break; + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (!GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0], pIndoor->pDoors[object_id].pZOffsets[0])) + { + AIL_end_sample(pMixerChannels[j].hSample); + FreeChannel(&pMixerChannels[j]); + return; + } + AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0])); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; } } } - break; + return; + + case OBJECT_Player: + { + start_channel = 10; + end_channel = 12; + for (uint i = start_channel; i <= end_channel; ++i) + { + if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) + { + if ( pMixerChannels[i].uSourceTrackIdx == sound_id ) + return; // already playing the same sound from the same source - return + AIL_end_sample( pMixerChannels[i].hSample); // requested new sound from the same source - end & switch + FreeChannel(&pMixerChannels[i]); + } + } + for ( uint j = start_channel; j <= end_channel; j++ ) + { + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) + { + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; + } + } + } + return; case OBJECT_Actor: { @@ -756,7 +844,7 @@ sample_volume = GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z); if (!sample_volume) return; - for (uint i = 0; i < uMixerChannels; ++i) + for (uint i = start_channel; i <= end_channel; ++i) { if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) { @@ -766,20 +854,43 @@ FreeChannel(&pMixerChannels[i]); } } + for ( uint j = start_channel; j <= end_channel; j++ ) + { + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) + { + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (!GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z)) + return; + AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y)); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; + } + } } - break; + return; case OBJECT_Decoration: { start_channel = 4; end_channel = 4; - v62 = 4; - assert(object_id < uNumLevelDecorations); sample_volume = GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z); if (!sample_volume) return; - for (uint i = 0; i < uMixerChannels; ++i) + for (uint i = start_channel; i <= end_channel; ++i) { if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )//звук фонтана и шагов не проходят проверку на повтор { @@ -789,20 +900,44 @@ FreeChannel(&pMixerChannels[i]); } } + for ( uint j = start_channel; j <= end_channel; j++ ) + { + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) + { + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (!GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z)) + return; + AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y)); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; + } + } } - break; + return; case OBJECT_Item: { - //start_channel = 5; - //end_channel = 7; + start_channel = 5; + end_channel = 7; assert(object_id < uNumSpriteObjects); sample_volume = GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z); if (!sample_volume) return; - for (uint i = 5; i <= 7; ++i) + for (uint i = start_channel; i <= end_channel; ++i) { - //MixerChannel* channel = &pMixerChannels[i]; if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) { if (pMixerChannels[i].uSourceTrackIdx == sound_id) @@ -811,14 +946,39 @@ FreeChannel(&pMixerChannels[i]); } } + for ( uint j = start_channel; j <= end_channel; j++ ) + { + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) + { + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (!GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z) ) + return; + AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y)); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; + } + } } - break; + return; case OBJECT_BModel: { - //start_channel = 8; - //end_channel = 9; - for (uint i = 8; i <= 9; ++i) + start_channel = 8; + end_channel = 9; + for (uint i = start_channel; i <= end_channel; ++i) { if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing ) { @@ -828,8 +988,30 @@ FreeChannel(&pMixerChannels[i]); } } + for ( uint j = start_channel; j <= end_channel; j++ ) + { + if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done ) + { + AIL_init_sample(pMixerChannels[j].hSample); + AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); + if (uVolume) + sample_volume = uVolume; + AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1); + pMixerChannels[j].uSourceTrackIdx = sound_id; + pMixerChannels[j].source_pid = a3; + pMixerChannels[j].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[j].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0); + return; + } + } } - break; + return; default: assert(false); @@ -899,7 +1081,6 @@ if (v62 > end_channel)//10!=13 return; -//LABEL_150: if ( sample_volume == 10000 ) sample_volume = uMasterVolume; @@ -935,7 +1116,7 @@ AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(PartyX, PartyY)); AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z)); } - else if (object_type == OBJECT_BLVDoor) + /*else if (object_type == OBJECT_BLVDoor) { assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); assert(object_id < pIndoor->uNumDoors); @@ -963,6 +1144,17 @@ if (!GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z)) return; AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y)); + if (uNumRepeats) + AIL_set_sample_loop_count(pMixerChannels[v62].hSample, uNumRepeats - 1); + pMixerChannels[v62].uSourceTrackIdx = sound_id; + pMixerChannels[v62].source_pid = a3; + pMixerChannels[v62].uSourceTrackID = eSoundID; + int rval = AIL_start_sample(pMixerChannels[v62].hSample); + if ( sPlaybackRate ) + AIL_set_sample_playback_rate(pMixerChannels[v62].hSample, sPlaybackRate); + if (object_type == OBJECT_Player) + AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0); + return; } else if (object_type == OBJECT_Decoration) { @@ -981,9 +1173,8 @@ if (object_type == OBJECT_Player) AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0); return; - } + } */ -//LABEL_184: if (uNumRepeats) AIL_set_sample_loop_count(pMixerChannels[v62].hSample, uNumRepeats - 1); pMixerChannels[v62].uSourceTrackIdx = sound_id; @@ -994,9 +1185,10 @@ AIL_set_sample_playback_rate(pMixerChannels[v62].hSample, sPlaybackRate); if (object_type == OBJECT_Player) AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0); - return; + return; } - + else + { __debugbreak(); // 3d sound stuff, refactor v12 = 13; if ( a3 < 0 ) @@ -1319,6 +1511,7 @@ goto LABEL_101; } } + } } //----- (0040DEA5) --------------------------------------------------------
--- a/Spells.cpp Wed Dec 18 17:33:04 2013 +0600 +++ b/Spells.cpp Thu Dec 19 00:55:16 2013 +0600 @@ -992,7 +992,7 @@ pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1); pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2); pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3); - pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0); + pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);//звук алтаря return; case SPELL_AIR_SHIELD: case SPELL_EARTH_STONESKIN: