Вы находитесь на странице: 1из 3

Audio.

c Pseudocode
Definitions
AUDIOPORT, the definition for the port being used
Definitions for the Data, Shift, and Register pins
Definitions specifying the Data, Shift, and Register pins both high and
low
TRACKX specifies the uint32_t for track X. X takes on values 1-18
Module Level Variables
uint8_t MyPriority to store priority number
boolean noInterrupts to make a track not interruptible
Helper functions
SR_Write3Bytes to specify all the states of the shift register (SR) pins
for the desired track
SR_Shift1Byte, to write one byte at a time to the shift registers
SR_StoreAllBytes, to set the SR outputs to the current state of the inte
rnal pins
InitializeAudio
Accepts a service priority number, returns True
Set the module level variable recording priority equal to the passed in p
arameter
Initialize the port clock
Wait until the port clock is initialized to continue
Enable Data, Shift, and Register pins as digital I/O pins
Enable Data, Shift, and Register pins as outputs
Return True
End InitalizeAudio
PostAudioService
Accepts an ES_Event type event, returns True if the event is successfull
y posted, false otherwise
Post the passed-in event to the audio service using its posting function
Return True if the event is successfully posted, false otherwise
End PostAudioService
RunAudio
Accepts an ES_Event type event, returns an event with type of no event,
which assumes no error
Create a variable to store the appropriate track number to play in respo
nse to event
Create a variable to store a second track number to play
If the event is an ES_OPEN event (curtain opened)
Track to play 1 is the theme
Else If the event is an ES_WIND event (windmill blown)
Track to play 1 is wind sound effect
Else If the event is an ES_LIGHTNING event (windmill blown fast enough)
Track to play 1 is a lightning sound effect
Make the track not interruptible by setting the module level boo
lean noInterrupts True
Set a time to wait to kill the track (in ms)
Set the kill track timer with this time
Else If the event is an ES_GROW event (wind scene is over)
Track to play 1 is a heavy rain sound effect
Track to play 2 is a light, fading rain sound effect
Set a time to wait before beginning a second track
Set the second track timer with this time
Else If the event is an ES_PLANTGROWN event (plant has grown)
Track to play 1 is a plant growing sound effect
Set a time to wait to kill the track (in ms)

Set the kill track timer with this time


Else If the event is an ES_CONSTRUCTION event (all plants grown, village
saved/built)
Track to play 2 is set to a hooray sound effect, without setting
track 1
Set a time to wait to play track 2 (effectively a delay)
Set the second track timer with this time
Else If the event is an ES_NIGHTFALL event (the night phase of the backg
round lights has begun)
Track to play 1 is a long clip of crickets chirping
Track to play 2 is a horned owl call and response
Set a time to wait before beginning a second track
Set the second track timer with this time
Else If the event is an ES_TIMEOUT event with a parameter indicating a k
ill track timer timeout
Call the SRWrite3Bytes function directly, writing all shift regi
ster pins low
Set the module level Boolean noInterrupts to false to allow trac
k interrupts again
Else If the event is an ES_TIMEOUT event with a parameter indicating a t
rack 2 timer timeout
Set track to play 1 equal to the value of track to play 2
Create a variable to store the track kill audio timer time
If the second track to play is the hooray sound effect
Set a particular kill audio timer time
If the second track to play is the owl hoot sound effect
Set a particular kill audio timer time
If the second track to play is the light rain sound effect
Set a particular kill audio timer time
Else
Set a default kill audio timer time
Set the kill track timer with the chosen time
Else if the event is an ES_RESET event
Call the SRWrite3Bytes function directly, playing a blank track
to immediately kill audio
Set the module level Boolean noInterrupts to false to allow trac
k interrupts again
Set track to play 1 equal to zero (no track to play)
Set track to play 2 equal to zero (no track to play)
End if statement cascade
If track to play 1 is not zero and interrupts are allowed (noInterrupts
is false)
Call the SRWrite3Bytes function, passing in track to play 1 as t
he parameter
End if
Return the event type of no event
End RunAudio
SR_Write3Bytes
Accepts a uint32_t specifying the track to play, returns nothing
Create the first byte to send to the shift registers by shifting 8 MSBs
to LSB position
Create the second byte to send to the shift registers by shifting MSBs 9
-16 to LSB position
Create the third byte to send by masking the 8 LSBs (not necessary, for
clarity)
Call the SRWrite1Byte function, passing in the first byte to send to the
shift registers
Call the SRWrite1Byte function, passing in the second byte to send to th
e shift registers

Call the SRWrite1Byte function, passing in the third byte to send to the
shift registers
Call the StoreAllBytes() function, which sets all SR pin outputs to the c
urrent pin states
End SR_Write3Bytes
SR_Shift1Byte
Accepts a uint32_t specifying a byte to send, returns nothing
Declare a loop variable to represent the number of bits already passed to the SR
s
Save a local copy of the passed in byte. Save a uint32_t as a uint8_t t
o isolate 8 LSBs to send.
Turn the Register pin low before writing data to the SRs
For the loop variable less than 9, starting at 1, incremented by 1 each
loop
Shift the MSB to the LSB position
If the LSB is zero
Set the Data pin low
If the LSB is one
Set the Data pin high
End if
Set the shift pin high and then low to shift in the value on the
data pin
Shift the local copy bits to the left by one, to get a new MSB
End for loop
End SR_Shift1Byte
SR_StoreAllBytes
Accepts nothing, returns nothing
Turn the Register pin high to set SR output pins to the current internal
pin states
End SR_StoreAllBytes
End of Audio.c Pseudocode

Вам также может понравиться