Specifications
SERIES 3/3A PROGRAMMING GUIDE
3-6
p_ioc5(pcb,E_FSSOUNDCHANNEL1,&sndstat1,&buf1[0],&l1);
p_ioc5(pcb,E_FSSOUNDCHANNEL2,&sndstat2,&buf2[0],&l2);
waitstat2(&sndstat1,&sndstat2);
p_close(pcb);
if (sndstat1 != 0 || sndstat1 != 0)
p_exit(0));
}
GLDEF_C INT main(VOID)
{
WORD notes1[] = {1048,24,524,12};
WORD notes2[] = {1048,4,1320,4,1568,4,2092,4,1568,4,1320,4,1048,12};
WORD len1 = sizeof(notes1)/4,len2 = sizeof(notes2)/4;
INT i;
for (i = 0; i < 6; i++)
{
play_notes(¬es1[0],¬es2[0],len1,len2,i,-1)
p_sleep(1);
}
for (i = 0; i < 6; i++)
{
play_notes(¬es1[0],¬es2[0],len1,len2,-1,140 + i*20)
p_sleep(1);
}
return(0);
}
The
main
routine initialises the note buffers, then repeatedly passes the buffers, the buffer lengths, the
volume and the beats per minute, to the subroutine
play_sound
that plays the tune. The tune is repeated
first at the default beats per minute for all six allowed volume levels, and then at the default volume for
six values of the beats per minute. The default is specified by passing a negative integer for the volume
and/or the beats per minute.
The subroutine
play_sound
opens the
SND:
channel, senses and sets the volume and beats per minute,
plays the notes and closes the
SND:
channel. In the case of an error in, for example, sensing,
play_sound
closes the
SND:
channel and returns with an error code. As mentioned earlier it is essential that the
P_FSSOUNDCHANNELn
requests be made asynchronously using either
p_ioc
or
p_ioc5
Plib library routines,
as these guarantee completion even in the event of low batteries.
A large fraction of the code in
play_sound
is concerned with error checking in order to ensure that the
routine behaves in a sociable way. In particular the
SND:
channel is closed as soon as an error is
discovered so to conserve power - this is essential when running on batteries and such measures should be
standard in any quality application.
The subroutine
waitstat
waits on the process i/o semaphore until completion of the two asynchronous
requests specified by the
pstat1
and
pstat2
status words (for further details of such matters see the
Asynchronous Requests and Semaphores
chapter of the
Plib Reference
library). It is in fact a version of
the Plib library routine
p_waitstat
that waits on two status words rather than one.
The
return(0)
statement at the end of the main routine informs the Series 3a that the program has ended
normally: it can also be omitted entirely. Use of the
return
statement with no return value is not
recommended: in practice this will return a random error code possibly leading to the display of a
spurious full screen error message.










