|
UsagesoundObject.registerByteArrayCallback(position, #callbackFunction, [castMemRef], [read-write/read-only flag])
DescriptionByte array method; calls the callback method
specified using #callbackFunction. The byte array
is filled with the audio sample data received from the sound object.
Parameters
Parameter
|
Description
|
Default value
|
position
|
You can specify the #preFilter and #postFilter
in this parameter.
#preFilter specifies the
audio PCM samples before applying the sound object filters.
#postFilter specifies
the audio PCM samples after applying the sound object filters.
|
Required
|
symCallback
|
Registers callbackFunction as
the callback method for the audio data in the sound object.
|
Required
|
castMemRef
|
Specifies a cast member reference when the
callback method is a member of the parent script. Do not specify
the parameter if the callback method is in movieScript.
|
Optional
|
read-write/read-only flag
|
Specifies whether the callback is #readOnly or
#readWrite. #readOnly - The audio bytearray data
is read only in the callback method. #readWrite - The audio bytearray
data is read and write in the callback method. So the data can be
modified in the callback.
|
#readOnly
|
The callbackFunction implementation
is as follows: On callbackFunction byteArray, bitDepth, sampleRate, channelCount
Put byteArray --Audio output implementation
End
Note: Inside the callback handler, if there is any
script that causes runtime errors (such as property not found),
the error messages are not displayed, and the handler execution
is aborted at the point of error. All the subsequent statements
are not executed.
Examples -- BUTTON BEHAVIOR --
global gSound -- soundObject
global gMixer -- mixer object
global counter -- Counter to fill the silence
global fillSilence -- Flag to fill the silence
on mouseUp(me)
-------------------------------------------------------
-- ACTION: Creates a soundObject from the Cast member.
-- The callback handler HAS to be in a Parent Script.
-- See the Movie Script for callback details.
--------------------------------------------------------------------
gMixer = new(#mixer)
gSound = gMixer.createSoundObject("1", member(1))
--Create the sound object from cast member
sPre = new script("Output") -- Output is a parent script
sPost = new script("Output")
sPre.countLimit = 50 -- Setting the Property value for filling the silence
sPost.countLimit = 10
fl = gSound.filterlist
fl.append(audioFilter(#reverbFilter)) -- Adding Reverb Filter
gSound.registerByteArraycallback(#preFilter, #audioOutput,sPre,#readWrite)
-- Registering the callback with preFilter, so that the bytes will be available
--before applying filters
-- Specifying the script reference as sPre, can specify it as movie script if it is
--empty
-- Specifying readWrite, so that the bytes can be modified in the callback method
gSound.registerByteArrayCallback(#postFilter, #audioOutput,sPost,#readWrite)
-- Registering the callback with postFilter, so that the bytes will be available
--after applying filters
gMixer.bufferSize = 200 -- Setting the bufferSize of mixer to 200
gMixer.play() -- Play the sound
end
Callback method (parent script) -- PARENT SCRIPT named OUTPUT --
global gSoundIOInstance -- instance of FileIO for reading sound file
global gSound -- soundObject
global counter -- Counter to fill the silence
global fillSilence -- Flag to fill the silence
property countLimit
--Callback Method
on audioOutput me, aByteArray, bitDepth, sampleFreq, numChannel
------------ --------- ---------------- -------
-- SOURCE: Called back from gSound whenever gSound has finished
-- playing its current contents.
-- INPUT: <aByteArray> will be the byteArray with audio data which has to be
-- modified and the byteArray to send back.
-- ACTION: Transfers the (remaining) contents of the file to
-- aByteArray
-- OUTPUT: Returns TRUE if there was any data to pas to aByteArray
-- FALSE if not.
--------------------------------------------------------------------
if fillSilence = 1 then -- Checking the fillSilence flag
repeat with i = 1 to aByteArray.length -- Looping thru the bytes of audio data
aByteArray[i] = 0 -- Setting the byte to silence
--Modify the bytes before playing, here it is set to 0 means silence
end repeat
end if
put aByteArray
counter = counter + 1 -- Increasing the counter to keep filling the silence
if(counter > countLimit)then -- If the countLimit is reached stop filling the silence
counter = 0
fillSilence = 1 - fillSilence -- Toggling between silence & play
end if
end
|
|
|