Playing a sample (Using DataVox)

On comp.sys.acorn julian@bridge.actrix.gen.nz (Julian Wright) gave this code fragment to play a sample using DataVox:
REM Play a sample using DataVox

channel%=1
datatype%=2       :REM 0 - Log, 1 - Lin Unsign,
                   REM 2 - Lin Sign, 3 - Ulaw (.au)
samplerate%=22000 :REM amend as necessary
DIM data_start% 8192:data_end%=data_start%+8192

REM build a sine wave 'sample'
FOR p%=0 TO 8191
  data_start%?p%=255*SINRADp%+128
NEXT

VOICE channel%,"DataVox-Voice"
SYS "DataVox_SetMemory",channel%,data_start%,data_end%
SYS "DataVox_Type",channel%,datatype%
SYS "DataVox_SampleToPitch",1E6 DIV samplerate%,0 TO pitch%
SYS "DataVox_Pitch",channel%,pitch%
SOUND channel%,&17F,0,0

REM Wait for Sample playback to cease

REPEAT
  SYS "DataVox_ReadAddress",channel% TO ,current_address%
UNTIL current_address%=0
SYS "DataVox_Unset",channel%
If your sample is stored in application space you shouldn't do a Wimp_Poll until playback has ceased otherwise sample playback will either give data aborts or play noise when other applications are paged in. If you use DataLoad with standard sample files, much of this code is eliminated, but your samples are stored in the RMA (at present - plans are afoot to include support for dynamic areas in DataLoad for use with RISC OS 3.5 :-) )
Robin.Watts@prg.ox.ac.uk