Skip to content

Commit

Permalink
make macos use audio_play_sound_at instead of emitters
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoFlareDev committed Jun 27, 2023
1 parent 13c99ee commit 33f81f0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
35 changes: 34 additions & 1 deletion scripts/play_sound/play_sound.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// @param pan
/// @param fine pitch
function play_sound(argument0, argument1, argument2, argument3, argument4) {

if (os_type != os_macosx) {

var ins, key, vol, pan, newemitter, emitter, pit, keyshift
ins = argument0
Expand All @@ -29,9 +31,40 @@ function play_sound(argument0, argument1, argument2, argument3, argument4) {
//Schedule emitter to be deleted from memory
newemitter = ds_list_create()
ds_list_add(newemitter,emitter) //store emitter id
var length = audio_sound_length(ins.sound) / 4 * (1/audio_emitter_get_pitch(emitter))
var length = audio_sound_length(ins.sound) / (1 + 3 * (os_type = os_windows)) * (1/audio_emitter_get_pitch(emitter))
ds_list_add(newemitter, (get_timer() + length * 1000000)) //store moment at which the emitter should be removed
ds_list_add(emitters_to_remove, newemitter)

} else {

var ins, key, vol, pan, newemitter, emitter, pit, keyshift
ins = argument0
key = argument1
vol = argument2
pan = argument3
pit = argument4

if (!ins.loaded)
return 0
//emitter=audio_emitter_create()
keyshift = key + (ins.key + (pit/100) - 78)
var emitter_pitch = 0.5 * power(2, keyshift / 12)
var emitter_gain = (vol / 100) * mastervol
var emitter_x = 100
if (realstereo = 0) emitter_x = pan

var soundid = audio_play_sound_at(ins.sound, emitter_x, 0, 0, 100, 300, 1, false, 1)
audio_sound_gain(soundid, emitter_gain, 0)
audio_sound_pitch(soundid, emitter_pitch)
sounds++

//Schedule emitter to be deleted from memory
newemitter = ds_list_create()
ds_list_add(newemitter,soundid) //store emitter id
var length = audio_sound_length(ins.sound) / (1 + 3 * (os_type = os_windows)) * (1/emitter_pitch)
ds_list_add(newemitter, (get_timer() + length * 1000000)) //store moment at which the emitter should be removed
ds_list_add(emitters_to_remove, newemitter)

}

}
26 changes: 26 additions & 0 deletions scripts/remove_emitters/remove_emitters.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function remove_emitters() {

if (os_type != os_macosx) {

//Called from control_draw every frame
//Removes emitters from memory to prevent memory leaking
var pos, arr, emitterid, timetoremove
Expand All @@ -17,5 +20,28 @@ function remove_emitters() {
}
}

} else {

//Called from control_draw every frame
//Removes emitters from memory to prevent memory leaking
var pos, arr, emitterid, timetoremove

for(pos = 0; pos < ds_list_size(emitters_to_remove); pos++){
arr = ds_list_find_value(emitters_to_remove,pos)

emitterid = ds_list_find_value(arr,0)
timetoremove = ds_list_find_value(arr,1)

if(get_timer() >= timetoremove){
ds_list_delete(emitters_to_remove,pos)
//audio_emitter_free(emitterid)
audio_stop_sound(emitterid)
//log("freeing emitter with id " + string(emitterid))
sounds--
}
}

}

}

0 comments on commit 33f81f0

Please sign in to comment.