Skip to content

Commit

Permalink
Delete global sample_gain, accept ptr, size, gain in newSoundData
Browse files Browse the repository at this point in the history
  • Loading branch information
semyon422 committed Oct 4, 2022
1 parent a1ac2ca commit a274d34
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions aqua/audio/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local aquathread = require("aqua.thread")
local bass = require("aqua.audio.bass")
local bass_assert = require("aqua.audio.bass_assert")
local bass_amplify = require("aqua.audio.bass_amplify")
Expand All @@ -7,7 +6,6 @@ local Sample = require("aqua.audio.Sample")
local StreamMemoryTempo = require("aqua.audio.StreamMemoryTempo")

local audio = {}
audio.sample_gain = 0

local SoundData = {}
audio.SoundData = SoundData
Expand Down Expand Up @@ -39,14 +37,10 @@ SoundData.release = function(self)
bass_assert(bass.BASS_SampleFree(self.sample) == 1)
end

audio.newSoundData = function(s)
local fileData = s
if type(s) == "string" then
fileData = love.filesystem.newFileData(s)
end

local sample = bass.BASS_SampleLoad(true, fileData:getFFIPointer(), 0, fileData:getSize(), 65535, 0)
fileData:release()
audio.newSoundData = function(pointer, size, sample_gain)
assert(pointer)
assert(size)
local sample = bass.BASS_SampleLoad(true, pointer, 0, size, 65535, 0)

-- bass_assert(sample ~= 0)
if sample == 0 then
Expand All @@ -63,25 +57,13 @@ audio.newSoundData = function(s)
end
soundData.info = info_table

if audio.sample_gain > 0 then
bass_amplify(sample, audio.sample_gain)
if sample_gain and sample_gain > 0 then
bass_amplify(sample, sample_gain)
end

return setmetatable(soundData, {__index = SoundData})
end

local newSoundDataAsync = aquathread.async(function(s, sample_gain)
local audio = require("aqua.audio")
audio.sample_gain = sample_gain
return audio.newSoundData(s)
end)

audio.newSoundDataAsync = function(s)
local soundData = newSoundDataAsync(s, audio.sample_gain)
if not soundData then return end
return setmetatable(soundData, {__index = SoundData})
end

audio.newAudio = function(self, soundData, mode)
if not soundData then
return
Expand Down

0 comments on commit a274d34

Please sign in to comment.