
                  ATARI STE Direct Memory Access SOUND
                  
                                 By Morf
                      with an extract from ST WORLD

     I  said last month  that  I  could  write  a  section  on the  STE's
hardware sound processors.  Well here it is. I will cover the :-

     STE Volume/Tone Control Registers
     and  STE DMA Sound Registers.

     Basically  the Volume/Tone controller (so  I've  heard) is  the same
type of chip that you would find  in most TV's  with  digital volume  and
tone controls.   It  enables  all  sonic  output   from   the  STE  to be
filtered. You can control the amount of  treble and bass, mix or mask the
ST sound chips output and  also  set  the  left,  right and master volume
controls.

     The  DMA sound chip is  much  more  interesting  however.  This lets
you play  sound  samples  in  the  background  (ie.   without   using any
processor time) and in stereo !  The  main disadvantages with it are that
there are  only  4  set  frequencies  at  which  you  can   output sound.
(6.258khz,  12.517khz,  25.033khz  and  50.066khz  -  which  is  above CD
sample frequency ! (but it is only  8  bit  as  opposed to CD which is 16
bit))

So how do they work !

   ------------------------------------------------------------------

                   STE Volume/Tone Control Registers.
                   

     To  control  this   you  need  to  write   to   the   MICROWIRE  bus
interface registers. Which is fairly easy !

     Since the MICROWIRE interface needs all of it's incoming data  to be
masked you first have to create a  mask.  The V/TC has a  common mask for
all of its data which makes life simple.

The value for the mask is $07ff

The data is slightly more complex.

Volume/Tone Controller Commands:-
The device address (high byte of word)  is  always set to $04. These  are
bit representations of the value you need  to   store  in the low byte of
the data register.

The first 3 bits are  the  command,  the  following  6  are the data. x's
represent 'DON'T CARE' bits which are ignored.

011 DDD DDD Set Master Volume
    000 000 -80 dB
    010 100 -40 dB
    101 xxx   0 dB

101 xDD DDD Set Left Channel Volume
     00 000 -40 dB
     01 010 -20 dB
     10 1xx   0 dB

100 xDD DDD Set Right Channel Volume
     00 000 -40 dB
     01 010 -20 dB
     10 1xx   0 dB

010 xxD DDD Set Treble
      0 000 -12 dB
      0 110   0 dB
      1 100 +12 dB

001 xxD DDD Set Bass
      0 000 -12 dB
      0 110   0 dB
      1 100 +12 dB

000 xxx xDD Set Mix
         00 -12 dB
         01 Mix GI sound output (ST Sound Chip)
         10 Do not mix GI sound output
         11 RESERVED

The addresses for the data and mask registers are:-

$ff8922 MICROWIRE data register.
$ff8924 MICROWIRE mask register.

So  to  set the master  volume  to  -80  dB  you  need  to set  the  mask
register to $07ff using

     move.w    #$07ff, voltone_mask

and then set the data register to %0000 0100 1100 0000 = $04C0 using

     move.w    #$04C0, voltone_data

of    course    you   would   need    equates    for    voltone_mask  and
voltone_data. ie.

voltone_mask   EQU  $ff8924
voltone_data   EQU  $ff8922

And thats all there is to that !!!!!

   ------------------------------------------------------------------

    I  have included a simple  piece  of  source called VOL_TONE.S  which
sets the volume to -80dB (silence !!).  To  change the data you just need
to set the variable VT_data to whatever  you want - using  the first move
instruction.

   ------------------------------------------------------------------

                        STE DMA Sound Registers.
                        

     Since  I found an article in  an  old magazine  which  explains this
pretty well (and because I've never  used  the  bit  which  lets you  use
repeated frames - except endless loops !) I'll copy  bits of it out.  The
original text can be found in ST World (now  sadly deceased  !  Which  is
a GREAT shame  because  it  had   an   EXCELLENT  section  on Programming
advice.  :- March 1990 -  Issue  49-P87.  Original author Mathew Lodge (I
think !) Here we go anyway:-

     Sampled sound data is stored in  memory  as a series of  bytes, each
representing  speaker  displacement,   from  -128  to   +127   (in signed
format).  Note that in unsigned format  the  data  is stored 0 to  255  -
however,  the STE is not capable   of  playing  unsigned samples  and  so
if the data is unsigned  it  must  first   be   signed before  use.  With
signed data, zero represents  neutral,   or  no displacement   from   the
speakers   central   position.   These displacements  are updated x times
a second,  giving the impression  of   an   analogue  signal.  In the STE
the 4  rates  available  are 6.25khz, 12.5khz, 25khz, 50khz.

     During  the horizontal blanking  phase  (when  the  electron  gun in
the  monitor is adjusted for  the  next  scan line)  samples  are fetched
from memory by the DMA sound chip,   and  fed into a Digital to  Analogue
Converter  (DAC).  The output of  the  DAC  is  then filtered  by a four-
pole low pass filter to  a  frequency   equal   to  around  40  %  of the
sample frequency.  The  signal  then   passes  through  a  two-pole 16khz
low-pass filter,  and is fed  into   the Volume/Tone Controller chip (LMC
1992).  Don't worry if you  don't  understand  any  of that (I don't).  I
just put it in in case  anyone knew  what  it all meant and might find it
useful !

     Both  stereo  and mono sample replay is  provided,  but  both stereo
channels are mixed along with  the  ST's  sound  chip  output for monitor
speaker output.  Sound chip output can also  be sent to the stereo output
jacks as well (the two phonos which you connect to a hifi)

     In stereo mode the data is regarded as words,  as opposed  to bytes.
The high byte of each word is  the displacement for the left channel  and
the low byte is the  right  channel.   (If   you   sample in stereo using
almost any sound sampler (esp.  ones which do  AVR format)  you will find
that they follow this convention). In   mono  mode each byte is output to
both the left and right channels,  but data  is still fetched a word at a
time.  So this means that  mono samples also have to be an even number of
bytes in length.

     Each  sample  you use is called a frame.  Each frame  can  be played
once,  or repeated forever (until  stopped).   Two  registers are  loaded
with  the frame  start  and  end   addresses   -   the   end  address  is
actually the first byte beyond the  end  of  the   sample. So  a 512 byte
sample with a frame start  address  of   101024   would  have a frame end
address of 101536. The registers are as follows:-

                      STE DMA Sound Register table.
                      

Register  Access    Desc.

$ff8900   r/w       00 - sound disabled (reset state)
                    01 - sound enabled, disable at end of frame
                    11 - sound enabled, repeat forever

$ff8902   r/w       Frame base address (High)
$ff8904   r/w       Frame base address (middle)
$ff8906   r/w       Frame base address (low)
$ff8908   ro        Frame address counter (high)
$ff890a   ro        Frame address counter (middle)
$ff890c   ro        Frame address counter (low)
$ff890e   r/w       Frame end address (high)
$ff8910   r/w       Frame end address (middle)
$ff8912   r/w       Frame end address (low)

$ff8920   r/w       Sound mode control - bit layout :-
                    xxxx xxxx m000 00rr
                    Where for m:
                    0 Stereo mode
                    1 Monophonic mode
                    Where for rr:
                    00  6258 Hz sample rate (reset state)
                    01 12517 Hz sample rate
                    10 25033 Hz sample rate
                    11 50066 Hz sample rate

     To play a sample it is simply  a  case  of loading the start and end
address registers with  the  addresses  of  the  start  and  end  of your
sample.  Setting  mono/stereo,   and  the  sample  rate  with   the  mode
control register.  Then  finally  writing  a  1  to   $ff8900   the sound
control register.  The sample will then play once. Or if you write a 3 it
will play forever - until you write zero to it.

Now the bit I've never tried  so  I'll  stick  to what ST World wrote, in
case I get it wrong !

     Producing  continuous sound and  linking  frames   together  are the
next  steps,  and  hardware support   is  provided  for  these processes.
The DMA sound  chip  produces  a  'DMA  sound  active'  signal  which  is
connected to the external input of  MFP   Timer   A.  The signal is a one
when samples are being  played,  and  zero  otherwise.  At  the  end of a
repeated frame,  this line goes from  one  to   zero, and  then  back  to
one again.  Thus setting Timer  A  into  event countdown  mode allows you
to generate an interrupt when  a  frame  has  been played a set number of
times.

     Frame repetition is seamless -  there  is  no time delay between the
end of a sample,   and  the  start  of  its   replay,  because  the frame
start  and  end  registers  are  double   buffered.   Writing   to  these
registers actually places data into a  holding area  and the contents  of
the holding area actually go into the true  registers when  the  chip  is
idle (at the end of the frame, if one is currently playing).

     Thus,  if you want to play  two consecutive frames,  you would write
the start and end addresses, and  set  the control register to three. The
first frame will start playing, and you can immediately write  the  start
and end addresses of  the   next   frame,   without waiting for the first
frame to finish.  There will be an  interrupt  from Timer A at the end of
the first frame, and you could use that  to load the address of a further
frame, and so on...

     One  further  thing to note is that the  'DMA  sound  active' signal
is also exclusive-ORed with the  'monochrome monitor detect' signal,  and
fed  into the GPIP 17 input of   the  MFP.  This  was provided  to enable
interrupt driven sound without using the  last  free timer of the MFP. It
is a little more difficult to use, since you  will get a different signal
edge depending on whether a  mono or colour monitor is attached,  as well
as an interrupt at the end of every frame.

     Monochrome monitors ground the  'mono  detect'  line  resulting in a
zero when the bit is read from  the MFP. Colour monitors don't ground the
line and the bit reads one. When  DMA  sound is active, this situation is
inverted (because of the XOR  with  the  'DMA  sound active'  line).  TOS
actually looks at this bit   during  vertical  blank time (the time taken
for the electron gun in the monitor  to  adjust  ready to scan the screen
again) to see if the monitor  has been  changed,  but  TOS on any machine
with DMA  sound  has  been modified appropriately to avoid problems.

     Finally, the 'DMA Sound Active' line  goes  from active to idle (one
to zero) after the last sample  has  been fetched.  There is  a four-word
FIFO (First In First Out) buffer inside  the chip,  so it will  be  eight
sample times (in stereo mode)  before  the  sound actually  finishes.  If
you do not reload  the  frame   registers   in  this  time, then the join
between samples will NOT be seamless.

End of extract !

   ------------------------------------------------------------------

     I've  given  a piece of source code  for  this as well - I  DID  NOT
WRITE IT,  but it is fairly well  documented.  It also shows how to check
for the presence of a  DMA  sound  chip  !   When  assembled,  it loads a
sample file called SAMPLE.SAM (which must  be  signed  !) and plays it at
6khz in mono.  You can change  the  bit  which writes the sample rate and
mode fairly easily if you want a different type of sample.  The sample is
played forever and runs in the background  -  so you can have music while
you work <ha ha>.

Thats it anyway - So good luck to those who have a mess !
See ya
MORF (Ian)

   ------------------------------------------------------------------
