home *** CD-ROM | disk | FTP | other *** search
/ Kosovo Orphans' Appeal Charity CD / KosovoOrphansAppeal.iso / utilities / _soundcon / docs / playsample < prev   
Encoding:
Text File  |  1995-09-26  |  13.3 KB  |  311 lines

  1.  
  2. The PlaySample module version 2.45        26 Sep 1995
  3. ==================================
  4.  
  5. by Rick Hudson,
  6. rick@actrix.gen.nz
  7.  
  8.  
  9. The PlaySample module is a module that can play samples in a variety of
  10. formats straight from the disc file. It is designed to play samples
  11. accurately at their recorded rate independantly of current sound system
  12. speed and (hopefully) the effects of VIDC enhancers.
  13.  
  14. There are two way that the module can play the sample at the required speed:
  15.  
  16. Frequency modulation:
  17.  
  18.   The default method is to leave the system sound frequency as it is and use
  19.   frequency modulation to ensure that new data is sent to the sound system at
  20.   the required frequency. If the required frequency is higher than the system
  21.   frequency then samples will be skipped as neccessary to keep pace with the
  22.   system frequency. If the required frequency is lower then samples will be
  23.   sent twice occasionally while the system frequency 'catches up'. The
  24.   modulation also allows the frequency to be 'tuned' (using PlaySample_Speed)
  25.   to correct for unusual VIDC frequencies, for example. As no interpolation
  26.   takes place there may be a slight quality drop.
  27.   
  28. Unmodulated:
  29.  
  30.   The alternative is to set the system sound frequency to a frequency as
  31.   close as possible to the required frequency and just send the samples
  32.   verbatum. This means that the sample will be reproduced cleanly but there
  33.   is no fine control of the frequency and so may sound fast or slow.
  34.  
  35. The PlaySample module provides a small number of commands and some SWIs that
  36. can be used to control the playback of samples. It's usual use will be from
  37. the desktop through a program like SoundCon or MTaudio. Command line use is
  38. quite limited as it can only play Armadeus files.
  39.  
  40. Terminology notes for this text:
  41.  
  42.   - A "sample" is the wave amplitude at a given time for ONE given channel
  43.  
  44.   - A "sample frame" or just "frame" is the set of samples on ALL channels
  45.     at a given time. For a mono sound this will mean the same as a sample,
  46.     but for a stereo sound there are two samples per sample frame (one for
  47.     each channel)
  48.  
  49.   - A "sample file" is the disc file containing samples
  50.  
  51.   - "Sample period" is the time interval between sending sample frames to
  52.     the sound system
  53.  
  54.   - "Sample frequency" or "playback frequency" is the rate of sending
  55.     sample frames to the sound system. The actual number of bytes per
  56.     second will depend on the bits per sample and the number of channels.
  57.  
  58.  
  59. Commands:
  60. ========
  61.  
  62.   - SPlay <filename> [<start>]
  63.  
  64.       Start playing the sound in file <filename>. Optionally, the sound
  65.       can be started at byte offset <start>. Note that if manual polling is
  66.       enabled then *SMore must be used regularly to maintain playback. The
  67.       sound must be an Armadeus format file otherwise unpredicable things
  68.       will happen. Playing of other formats is only supported through the
  69.       SWI interface.
  70.  
  71.   - SStop
  72.  
  73.       Stop the sound playing and release the sound system.
  74.  
  75.   - SPause
  76.  
  77.       Toggle start/stop of sound playback.
  78.  
  79.   - SMore
  80.  
  81.       In manual polling mode, this command must be executed regularly (say
  82.       twice a second at least) to maintain playback continuity. If the
  83.       buffer 'runs out' then the sound is stopped (equivalent to an
  84.       explicit *SPause) until the buffer is refilled. This command has no
  85.       effect in automatic polling mode or when no sound is playing.
  86.  
  87.   - SAuto
  88.  
  89.       Switch on automatic polling (see below).
  90.  
  91.   - SManual
  92.  
  93.       Switch off automatic polling (see below).
  94.  
  95.   - SVolume <vol>
  96.  
  97.       Set the volume of PlaySample. <vol> is in the range 1 (quiet) thru 127
  98.       (100%) to 255 (200% amplification). The 1-127 is the same as the system
  99.       command *Volume, the 128-255 amplification feature is new since version
  100.       2.43 of PlaySample. For amplified volume, clipping may occur when
  101.       individual samples are amplified too much. Note that PlaySample uses a
  102.       volume setting independant of the system volume so that the system
  103.       command *Volume will have no effect on it.
  104.  
  105.   - SSpeed <num>
  106.  
  107.       <num> is a tuning value for PlaySample to allow for the correction of
  108.       playback speed when the actual VIDC frequency is different from what
  109.       the sound system is expecting. <num> is <expected freq>/<actual freq>
  110.       * &10000, eg 24000/25175*&10000 = 62447 will slow the sound down
  111.       sightly if it is too fast. The actual frequency can be obtained from
  112.       VduVariable &AC in RISC OS (except if it's very old) and the expected
  113.       frequency is the nearest multiple of 4000Hz to it. Desktop front ends
  114.       should select this automatically.
  115.  
  116. SWIs:
  117. ====
  118.  
  119.   IMPORTANT NOTE:
  120.   
  121.   The SWI interface was changed after version 2.43 and is not backward
  122.   compatible! Software designed to work with version 2.43 or earlier will
  123.   probably not work with newer versions.
  124.   
  125.   PlaySample_Open is now called slightly differently and the SWI
  126.   PlaySample_BeginEnd has been added. PlaySample_Config has also had an
  127.   interface change to make it more versatile and future proof.
  128.  
  129.   Summary:
  130.  
  131.   PlaySample_Status   (&CF8C0)
  132.   PlaySample_Open     (&CF8C1)
  133.   PlaySample_SetPtr   (&CF8C2)
  134.   PlaySample_Play     (&CF8C3)
  135.   PlaySample_Stop     (&CF8C4)
  136.   PlaySample_Pause    (&CF8C5)
  137.   PlaySample_Config   (&CF8C6)
  138.   PlaySample_Volume   (&CF8C7)
  139.   PlaySample_Speed    (&CF8C8)
  140.   PlaySample_Version  (&CF8C9)
  141.   PlaySample_BeginEnd (&CF8CA)
  142.   
  143.   Details:
  144.  
  145.   PlaySample_Status (&CF8C0)
  146.     Playback monitors can use this call to determine what the state of the
  147.     player is. R2, R4 and R5 can be used to determine the time offset into
  148.     the sample using t=R2 / (16e6/R4) / (bits per sample/8*channels).
  149.     On entry: -
  150.     On Exit:  R0 : bit  0 = set if sound is playing
  151.                    bit  1 = set if sound paused
  152.                    bit  2 = set if sound finished
  153.                    bit  3 = set if a sound file is open
  154.                    bit  4 = set if module has voice claimed
  155.                    bit 16 = set if manual polling enabled
  156.                    bit 17 = set if frequency modulation disabled
  157.               R1 = pointer to file leafname
  158.               R2 = current byte offset into sample file
  159.               R3 = size of sample file in bytes
  160.               R4 = sample period (microseconds * 16)
  161.               R5 = voice mode: bit 0 = set if stereo, clear if mono
  162.                                bits 1-7: 0 = 8-bit
  163.                                          1 = 16-bit
  164.                                          2 = 4-bit MS ADPCM
  165.                                          3 = 4-bit DVI ADPCM
  166.  
  167.   PlaySample_Open (&CF8C1)
  168.     Open a file and define its format. Playback is not started (pause mode
  169.     is entered). Use PlaySample_BeginEnd to set play range then
  170.     PlaySample_Play to start the playback.
  171.     On entry: R0 = pointer to filename to open (0 for current file)
  172.               R1 = sample format:
  173.                    <=0 - 8 bit linear signed
  174.                      1 - 8 bit linear unsigned
  175.                      2 - 8 bit mu-law
  176.                      3 - 8 bit A-law
  177.                      4 - 8 bit VIDC
  178.                    5-7 - undefined/reserved
  179.                      8 - 16 bit linear signed little endian
  180.                      9 - 16 bit linear signed big endian
  181.                     10 - 16 bit linear unsigned little endian
  182.                     11 - 16 bit linear unsigned big endian
  183.                  12-15 - undefined/reserved
  184.                     16 - Microsoft (MS) ADPCM
  185.                     17 - DVI ADPCM
  186.                   >=18 - undefined               
  187.               R2 = sample period in microseconds * 16 (if R2=0 and R1=-1,
  188.                    period obtained from first byte of file). eg for 22050Hz,
  189.                    R2=16e6/22050 = 727. Default frequency (if R2 is invalid)
  190.                    is 11111Hz.
  191.               R3 = number of channels (<>2 for mono, 2 for stereo).
  192.               R4 = unused
  193.               if R3<>2 (mono) then
  194.                  R5 = echo delay in sample periods for simulated stereo
  195.                       effect (max 2048). R5=(echo time)*(playfrequency), eg
  196.                       R5 = 0.1secs * 11111Hz = 1111. Normal mono if R5=0.
  197.               if R3=2 (stereo) then
  198.                  R5 = stereo interleave (bytes left, bytes right, etc). eg 1
  199.                       for PCM WAVEs, 8 for AudioWorks. This number must be a
  200.                       power of 2 (ie 1, 2, 4, 8, etc) and the buffer size
  201.                       must be a multiple of 2*interleave to ensure that a
  202.                       left/right chunk is always completely in the buffer.
  203.               if R1=8 or 9 (ADPCM formats) then
  204.                  R6 = number of compressed sample frames in block. ie
  205.                       nFramesPerBlock (bytes &12 and &13 of the WAVE 'fmt '
  206.                       chunk) - frames in block header. ie nFramesPerBlk-1
  207.                       for DVI ADPCM and nFramesPerBlock-2 for MS ADPCM.
  208.     On exit:  R0 - R7 undefined
  209.  
  210.     This call will require knowledge of the file format to fill in all the
  211.     registers properly. ADPCM WAVEs in particular need precise information
  212.     from the header block. Contact the author if you want more information
  213.     on any of the formats supported by SoundCon or if you can supply some
  214.     information on any formats it doesn't support!
  215.  
  216.     Note that to play a normal armadeus sample at the default frequency,
  217.     R1=-1, R2=R3=R4=0.
  218.  
  219.   PlaySample_SetPtr (&CF8C2)
  220.     On entry: R0 = absolute file offset to move to. Used for cueing etc.
  221.     On exit:  all registers preserved
  222.  
  223.   PlaySample_Play (&CF8C3)
  224.     Start playing the sound from the current pointer position.
  225.     On entry: No parameters
  226.     On exit:  R0 undefined, other registers preserved
  227.  
  228.   PlaySample_Stop (&CF8C4)
  229.     If a sound is playing, it is stopped and the sound system is freed. No
  230.     more playback will be possible until another PlaySample_Open is done.
  231.     On entry: No parameters
  232.     On exit:  R0 undefined, other registers preserved
  233.  
  234.   PlaySample_Pause (&CF8C5)
  235.     Stop the sound playing but playback can be restarted with
  236.     PlaySample_Play. PlaySample_SetPtr can be called while paused.
  237.     On entry: No parameters
  238.     On exit:  All registers preserved
  239.  
  240.   PlaySample_Config (&CF8C6)
  241.     Set/read playback buffer size and/or behaviour flags. The flags are set
  242.     using newflags = (oldflags AND (NOT R1) EOR R2). The flags are:
  243.       bit 0: 0=auto poll, 1=manual poll
  244.       bit 1: 0=frequency modulation, 1=no frequency modulation
  245.     On entry: R0 = buffer size (0 for no change - default is 8k)
  246.               R1 = flags clear mask
  247.               R2 = flags exclusive-or mask
  248.     On exit:  R0 = buffer size (after any change)
  249.               R1 = flags (after any change)
  250.               R2 = undefined
  251.               other registers preserved
  252.  
  253.     Important note: For playing ADPCM samples, the buffer size MUST be a
  254.     multiple of the sample block size. ie size = n*nBlockAlign. For other
  255.     samples, the buffer must be a multiple of the number of bytes per frame.
  256.     eg for 16 bit stereo, the buffer must be a multiple of 4 bytes.
  257.  
  258.   PlaySample_Volume (&CF8C7)
  259.     Set or read the PlaySample volume. Note that PlaySample's volume is
  260.     independant of the system volume. 
  261.     On entry: R0 = volume (0 for no change, 1=quiet, 127=loud=100%, 255=200%)
  262.     On exit:  R0 = volume setting
  263.               other registers preserved
  264.  
  265.   PlaySample_Speed (&CF8C8)
  266.     Tune Playsample for sound system speed inaccuracies. See the description
  267.     of *SSpeed (above) for details.
  268.     On entry: R0 = tuning value (<expected freq> / <actual freq> * &10000)
  269.     On exit:  R0 undefined
  270.               other registers preserved
  271.  
  272.   PlaySample_Version (&CF8C9)
  273.     Return the version number*100 of PlaySample (241 for version 2.41)
  274.     On entry: -
  275.     On exit:  R0 = version number * 100
  276.               other registers preserved
  277.     
  278.   PlaySample_BeginEnd (&CF8CA)
  279.     Define the start and end points for sample playback as byte offsets from
  280.     the start of the file. If the current file pointer is outside the given
  281.     play range, it is set to the beginning point.
  282.     so that PlaySample_Play will start from the file offset in R0.
  283.     On entry: R0 = byte offset to start from
  284.               R1 = byte offset to end at+1 (ie R1 = R0 + #bytes to play). If               R1<=R0 it will play to the end of the file.
  285.     On exit:  all regisiters preserved
  286.  
  287. Note that it is not necessary to stop a sample playing before starting a new
  288. one or killing the module.
  289.  
  290.  
  291. Polling mechanism
  292. -----------------
  293.  
  294. The normal polling mechanism makes use of OS_AddCallBack to allow delayed
  295. access to disc SWIs from inside the voice generator code. This may cause
  296. problems in RISC OS 2 (although this version seems ok) where there was a bug
  297. in the call back handler. If errors start occurring (like address exceptions)
  298. then first ensure that the IRQUtils module has been loaded which should fix
  299. this problem. If the PlaySample module is still causing problems then manual
  300. polling can be used (software may or may not allow you to change this).
  301.  
  302. If the sample stops unexpectedly when playing off a floppy disc, try either
  303. decreasing the buffer size to keep the drive running continuously or
  304. increase it to ensure that enough data is in the memory to cover the time it
  305. takes to restart the floppy from a stop. This is a trial and error thing!
  306.  
  307. Heavy interrupt activity of any sort may also cause PlaySample to stop
  308. playing momentarily because the callback system will be delayed a long long
  309. in these circumstances. Sending data to the printer a common cause of
  310. this. Again, increasing the buffer size may alleviate this.
  311.