If a task wants to change that frequency for speeding up or slowing down clock-defined audio events or for getting finer or coarser timing control, the task must ask first to own the clock. It can then change the frequency by directly stating a new frequency or by defining a new audio tick duration in DSP frames. As long as the task owns the clock, no other task can change the clock's frequency.
Item OwnAudioClock( void )
OwnAudioClock()
returns the item number of a semaphore used to claim clock ownership. If unsuccessful, OwnAudioClock()
returns a negative value (an error code). Store the returned semaphore item number; you need it to be able to make clock-changing calls.Once a task owns the audio clock, that task alone can change the frequency of the clock. You may want your task to take ownership of the audio clock even if you do not want to change the clock rate. As owner of the clock, you can be sure that no other tasks can unexpectedly change the clock rate, an important safeguard if a stable clock rate is essential to the task's timing.
When a task is no longer concerned with the audio clock rate, it should give up ownership of the clock so that other tasks can own the clock if necessary. To do so, use this call:
Err DisownAudioClock( Item Owner )
Err SetAudioRate( Item Owner, frac16 Rate )
When it executes, SetAudioRate()
checks the semaphore number to be sure that it specifies clock ownership and, if so, the call changes the audio clock rate to the specified new frequency. If successful, SetAudioRate()
returns 0; if unsuccessful, it returns a negative value (an error code).
If you set a high clock rate, the system performance can suffer. Try not to go much higher than 500 Hz.
A task that does not own the clock can successfully use this call as long as it has the proper semaphore item number. This means that the clock owning task can pass that number to a cooperating task (a thread or child task, for example) so that the second task can change the audio rate.
Err SetAudioDuration( Item Owner, uint32 Frames )
When it executes, SetAudioDuration()
checks the semaphore number to be sure that it specifies clock ownership and, if so, changes the duration of the audio tick to the specified number of frames. If successful, the call returns 0; if unsuccessful, it returns a negative value (an error code).
SetAudioDuration()
has the same setting limitations as SetAudioRate()
. If you set a tick duration that's too short, the system performance can suffer. Note that SetAudioDuration()
also accepts the correct ownership item from any task, so the clock owning task can pass that number to another cooperating task if it wishes.
frac16 GetAudioRate( void )
To check the current duration of an audio tick, use this call:
uint32 GetAudioDuration( void )