use of mutex for t_ transform in audio callback ?

Pixilang programming language
Post Reply
ainegil
Posts: 168
Joined: Thu Sep 22, 2022 11:37 pm

use of mutex for t_ transform in audio callback ?

Post by ainegil »

I am using t_ transforms for a 3D audio oscillator.

The code is in a function call within the audio callback for convenience

However there it also affects the screen code randomly,
so I tried mutex, but I have no experience with this and it does nit work
as expected

Code: Select all

lock4audio = mutex_create()

fn tick_osc( $v, $scal){ 
mutex_lock( lock4audio )
	t_set_matrix( matrix )
    
	$deg = get_prop( osc_point[ $v ], "om" )
	$rt = get_prop( osc_point[ $v ], "rt" )
	$rt2 = get_prop( osc_point[ $v ], "rt2" )
	t_rotate( $deg, 1, $rt, $rt2 )
	t_scale( $scal, $scal, $scal)
	t_point( osc_point[ $v ] )
	
	t_reset()
mutex_unlock( lock4audio )
ret
}
the function is called in audio callback, but the screen drawing is affected by the transform

so, question, am I doing it wrong, or is it not possible with the audiocallback?
its on Android
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: use of mutex for t_ transform in audio callback ?

Post by NightRadio »

You also need to wrap the whole screen drawing code with this mutex:
mutex_lock( lock4audio )
... screen drawing code ...
mutex_unlock( lock4audio )

But I don't recommend doing that because the sound callback can sleep for too long if it waits for the drawing to finish.
ainegil
Posts: 168
Joined: Thu Sep 22, 2022 11:37 pm

Re: use of mutex for t_ transform in audio callback ?

Post by ainegil »

thanks.

at the moment this is just an audio experiment with not much on the screen so performance is not critical.
Post Reply