Skip to content

Commit

Permalink
feat: use native audio (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
masonschafercodes authored Aug 14, 2023
1 parent b70093e commit 5debf40
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 13 deletions.
Binary file added audio/data/oxdoorlock_sounds.dat54.rel
Binary file not shown.
145 changes: 145 additions & 0 deletions audio/data/oxdoorlock_sounds.dat54.rel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<Dat54>
<Version value="7314721" />
<ContainerPaths>
<Item>dlc_oxdoorlock\oxdoorlock</Item>
</ContainerPaths>
<Items>
<!-- SimpleSounds -->
<Item type="SimpleSound">
<Name>button_remote_simple</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ContainerName>dlc_oxdoorlock/oxdoorlock</ContainerName>
<FileName>button_remote</FileName>
<WaveSlotNum value="0" />
</Item>

<Item type="SimpleSound">
<Name>door_bolt_simple</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ContainerName>dlc_oxdoorlock/oxdoorlock</ContainerName>
<FileName>door_bolt</FileName>
<WaveSlotNum value="0" />
</Item>

<Item type="SimpleSound">
<Name>metal_locker_simple</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ContainerName>dlc_oxdoorlock/oxdoorlock</ContainerName>
<FileName>metal_locker</FileName>
<WaveSlotNum value="0" />
</Item>

<Item type="SimpleSound">
<Name>metallic_creak_simple</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ContainerName>dlc_oxdoorlock/oxdoorlock</ContainerName>
<FileName>metallic_creak</FileName>
<WaveSlotNum value="0" />
</Item>



<!-- SoundSets !-->
<Item type="SoundSet">
<Name>dlc_oxdoorlock_set</Name>
<Header>
<Flags value="0xAAAAAAAA" />
</Header>
<SoundSets>
<Item>
<ScriptName>button_remote</ScriptName>
<ChildSound>button_remote_directional</ChildSound>
</Item>
<Item>
<ScriptName>door_bolt</ScriptName>
<ChildSound>door_bolt_directional</ChildSound>
</Item>
<Item>
<ScriptName>metal_locker</ScriptName>
<ChildSound>metal_locker_directional</ChildSound>
</Item>
<Item>
<ScriptName>metallic_creak</ScriptName>
<ChildSound>metallic_creak_directional</ChildSound>
</Item>
</SoundSets>
</Item>

<Item type="DirectionalSound">
<Name>button_remote_directional</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ChildSound>button_remote_simple</ChildSound>
<InnerAngle value="20" />
<OuterAngle value="65" />
<RearAttenuation value="-3" />
<YawAngle value="90" />
<PitchAngle value="0" />
</Item>

<Item type="DirectionalSound">
<Name>door_bolt_directional</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ChildSound>door_bolt_simple</ChildSound>
<InnerAngle value="20" />
<OuterAngle value="65" />
<RearAttenuation value="-3" />
<YawAngle value="90" />
<PitchAngle value="0" />
</Item>

<Item type="DirectionalSound">
<Name>metal_locker_directional</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ChildSound>metal_locker_simple</ChildSound>
<InnerAngle value="20" />
<OuterAngle value="65" />
<RearAttenuation value="-3" />
<YawAngle value="90" />
<PitchAngle value="0" />
</Item>

<Item type="DirectionalSound">
<Name>metallic_creak_directional</Name>
<Header>
<Flags value="0x00008004" />
<Volume value="200" />
<Category>scripted</Category>
</Header>
<ChildSound>metallic_creak_simple</ChildSound>
<InnerAngle value="20" />
<OuterAngle value="65" />
<RearAttenuation value="-3" />
<YawAngle value="90" />
<PitchAngle value="0" />
</Item>
</Items>
</Dat54>
Binary file added audio/dlc_oxdoorlock/oxdoorlock.awc
Binary file not shown.
107 changes: 107 additions & 0 deletions audio/dlc_oxdoorlock/oxdoorlock.awc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<AudioWaveContainer>
<Version value="1" />
<ChunkIndices value="True" />
<Streams>
<Item>
<Name>button_remote</Name>
<FileName>button_remote.wav</FileName>
<Chunks>
<Item>
<Type>peak</Type>
</Item>
<Item>
<Type>data</Type>
</Item>
<Item>
<Type>format</Type>
<Codec>ADPCM</Codec>
<Samples value="25600" />
<SampleRate value="44100" />
<Headroom value="-161" />
<PlayBegin value="0" />
<PlayEnd value="0" />
<LoopBegin value="0" />
<LoopEnd value="0" />
<LoopPoint value="-1" />
<Peak unk="0" />
</Item>
</Chunks>
</Item>
<Item>
<Name>door_bolt</Name>
<FileName>door_bolt.wav</FileName>
<Chunks>
<Item>
<Type>peak</Type>
</Item>
<Item>
<Type>data</Type>
</Item>
<Item>
<Type>format</Type>
<Codec>ADPCM</Codec>
<Samples value="26069" />
<SampleRate value="44100" />
<Headroom value="-161" />
<PlayBegin value="0" />
<PlayEnd value="0" />
<LoopBegin value="0" />
<LoopEnd value="0" />
<LoopPoint value="-1" />
<Peak unk="0" />
</Item>
</Chunks>
</Item>
<Item>
<Name>metal_locker</Name>
<FileName>metal_locker.wav</FileName>
<Chunks>
<Item>
<Type>peak</Type>
</Item>
<Item>
<Type>data</Type>
</Item>
<Item>
<Type>format</Type>
<Codec>ADPCM</Codec>
<Samples value="36864" />
<SampleRate value="44100" />
<Headroom value="-161" />
<PlayBegin value="0" />
<PlayEnd value="0" />
<LoopBegin value="0" />
<LoopEnd value="0" />
<LoopPoint value="-1" />
<Peak unk="0" />
</Item>
</Chunks>
</Item>
<Item>
<Name>metallic_creak</Name>
<FileName>metallic_creak.wav</FileName>
<Chunks>
<Item>
<Type>peak</Type>
</Item>
<Item>
<Type>data</Type>
</Item>
<Item>
<Type>format</Type>
<Codec>ADPCM</Codec>
<Samples value="17489" />
<SampleRate value="44100" />
<Headroom value="-161" />
<PlayBegin value="0" />
<PlayEnd value="0" />
<LoopBegin value="0" />
<LoopEnd value="0" />
<LoopPoint value="-1" />
<Peak unk="0" />
</Item>
</Chunks>
</Item>
</Streams>
</AudioWaveContainer>
Binary file not shown.
Binary file added audio/dlc_oxdoorlock/oxdoorlock/door_bolt.wav
Binary file not shown.
Binary file added audio/dlc_oxdoorlock/oxdoorlock/metal_locker.wav
Binary file not shown.
Binary file not shown.
34 changes: 23 additions & 11 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,29 @@ RegisterNetEvent('ox_doorlock:setState', function(id, state, source, data)
end

if door.state == state and door.distance and door.distance < 20 then
local volume = (0.01 * GetProfileSetting(300)) / (door.distance / 2)
if volume > 1 then volume = 1 end
local sound = state == 0 and door.unlockSound or door.lockSound or 'door-bolt-4'

SendNUIMessage({
action = 'playSound',
data = {
sound = sound,
volume = volume
}
})
local useNativeAudio = GetConvarInt('doorlock:nativeaudio', 1) == 1

if useNativeAudio then
RequestScriptAudioBank('dlc_oxdoorlock/oxdoorlock', false)
local sound = state == 0 and door.unlockSound or door.lockSound or 'door_bolt'
local soundId = GetSoundId()

PlaySoundFromCoord(soundId, sound, door.coords.x, door.coords.y, door.coords.z, 'DLC_OXDOORLOCK_SET', true, 0, false)
ReleaseSoundId(soundId)
ReleaseNamedScriptAudioBank('dlc_oxdoorlock/oxdoorlock')
else
local volume = (0.01 * GetProfileSetting(300)) / (door.distance / 2)
if volume > 1 then volume = 1 end
local sound = state == 0 and door.unlockSound or door.lockSound or 'door-bolt-4'

SendNUIMessage({
action = 'playSound',
data = {
sound = sound,
volume = volume
}
})
end
end
end)

Expand Down
7 changes: 6 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ ui_page 'web/build/index.html'
files {
'web/build/index.html',
'web/build/**/*',
'locales/*.json'
'locales/*.json',
'audio/data/oxdoorlock_sounds.dat54.rel',
'audio/dlc_oxdoorlock/oxdoorlock.awc',
}

data_file 'AUDIO_WAVEPACK' 'audio/dlc_oxdoorlock'
data_file 'AUDIO_SOUNDDATA' 'audio/data/oxdoorlock_sounds.dat'

dependencies {
'oxmysql',
'ox_lib',
Expand Down
7 changes: 6 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ exports('editDoor', function(id, data)
end
end)

local sounds = require 'server.utils'.getFilesInDirectory('web/build/sounds', '%.ogg')
local useNativeAudio = GetConvarInt('doorlock:nativeaudio', 1) == 1

local soundDirectory = useNativeAudio and 'audio/dlc_oxdoorlock/oxdoorlock' or 'web/build/sounds'
local fileFormat = useNativeAudio and '%.wav' or '%.ogg'

local sounds = require 'server.utils'.getFilesInDirectory(soundDirectory, fileFormat)

local function createDoor(id, door, name)
local double = door.doors
Expand Down

0 comments on commit 5debf40

Please sign in to comment.