**
from an article by Philippe Rivaillon (privaillon free.fr)
in "La Voix de Paula" - Amiga News Tech issues
29-30 jan/feb 1992 (translated from french with some little
summaries and omissions but not very important) :
Once upon a time,
"[...]It's Paula and incidentally Agnus for the
transfers DMA which manage the sound. But its capacities
arent only a simple spit of samples. Indeed, this diva
is able to modulate the amplitude and the frequency
of sound of one or more channels in order to produce
the desired effects.[...]
A sound is a vibration, defined by two criteria: its
amplitude and its frequency. The latter will determine
whether a sound is low or high-pitched (the higher the
frequency is, more the sound is high pitched).
The average amplitude defines the power of a sound (its
volume), while the variations of this value define the
sound itself. The data table transmitted to Paula will
be thus a succession of instantaneous amplitudes. this
table is cut out in bytes, for an amplitude from +127
to -128. Paula will of course have needs other information
on the sound before playing it: its address, its length,
its period (corresponding to the frequency of the signal)
and its volume.
registers used :
*=# of channel (0-3)
+=channels 0=$A, 1=$B, 2=$C, 3=$D
AUD*LCH $dff0+0 Address of data in Chip
AUD*LCL $dff0+2
AUD*LEN $dff0+4 lenght of sample in words (16 bits)
. max=128 kb
AUD*VOL $dff0+8 volume. 0-63. in words (16 bits)
only the 6 lower bits used.
AUD*PER $dff0+6 periode. speed of sample play. in cycle
(16 bits)
frequency in bytes : Periode=1/(Freq)/279,365.10^-9
(for a 68000)
moreover than the audio circuit has limits because
of its synchronization with the screen: knowing that
it load a data word per rasterline, we obtains a maximum
theoretical frequency of: 2 bytes*262.5 lines/screen
* 59.94 screen/sec) = 31469 bytes/s
but the real max freq is 28867 bytes/s = periode 124
cycles.
If you put a value lower than 124 in this register,
Agnus will not inevitably have time to charge the audio
data and it's the old one which will be used, then a
deformation of the sound.
First: simple transmission in automatic mode
with Paula
summary:
- setup the registers above for each channel.
- to start the sound, enable DMA channels. (bit 9 and
0-3)
- Paula loop the sample automatically : after having
read the number of words indicated in AUD*LEN, Paula
will replace itself automatically at the beginning of
the data.
- to stop the sound, disable DMA channels. if you give
these channels DMA on the way, Paula will start again
the sound from the beginning, with an exception : if
the interval of time passed between the cut and the
re-starting is lower than 2 times the period, then the
reading will continue where Paula had left it.[...]
a quick example 1 :
start:
lea custom,a6
move.l #data,aud0lch(a6) ; $dff0a0
move.w #1,aud0len(a6) ; len in word - $dff0a4
move.w #5000,aud0per(a6) ; periode - $dff0a6
move.w #50,aud0vol(a6) ; volume - $dff0a8
move.w #D_setclr|D_Master|D_aud0,dmacon(a6) ; start
dma channel 0
wait: btst #6,$bfe001
bne.s wait
move.w #D_aud0,dmacon(a6) ; stop
rts
data: dc.b 120,-120 ; square signal (in chipram)
my Example : 4 channels - 4 diff. period
lea
custom+aud0lch,a0
move.w #3000,d0 ;period
lea Sample,a1
moveq #3,d1
loop:
move.l a1,(a0)+ ad
move.w #13,(a0)+ len
move.w d0,(a0)+ per
move.w #64,(a0) vol
addq.w #4,d0 ; incr period
addq.l #8,a0 ; next channel
dbf d1,loop
move.w #D_setclr|D_Master|D_aud,custom+dmacon
mouse: btst #6,$bfe001
bne mouse
move.w #D_aud,custom+dmacon
rts
Sample
dc.w $808a,$949e,$a8d2,$bcd0
dc.w $daea,$eef8,$d20c,$1c20
dc.w $2a34,$3e48,525c,$6670,$7a40 ; in chip"
to be continued...
Second: effects.
There are two kinds of possible modulations: amplitude
modulation (volume) and frequency modulation (period).
The first could be used to make effects of vibrato or
tremolo type, imitation of distance of a sound...
The second allows simulating chords.
Moreover, it's possible to combine the two modulations.
one problem: to modulate a voice, it's needed to use
two consecutive channels.
the first (low) is used for the envelope and the second
(high) is used for the basic sound.
the registers are initialized normally (except volume
of the modulation channel, not played).
for the modulation channel, the data table is not made
up of bytes but of words either a volume (0-64) or a
period.
If you want to make an amplitude and frequency modulation
at the same time, the table must alternatively contain
a volume and a period, in this order. In this last case,
there will be two readings instead of one so that the
modulations are done simultaneously and not one after
the other. Not need to touch at the period to compensate.
Then it's necessary to link the two channels for the
modulation with register ADKCON (!! it is also used
for the disk drives !!).
ADKCON/R: $dff09e/10
15 set/clr
07 ATPER3 if 1, cut voice 3
06 ATPER2 if 1, voice 2 module voice 3
05 ATPER1 if 1, voice 1 module voice 2
04 ATPER0 if 1, voide 0 module voice 1
03 ATVOL3 idem
02 ATVOL2 ...
01 ATVOL1 ...
00 ATVOL0 ...
bits 7 and 3 are same effect : stop the voice 3, the
higher and so cant modulate an other. But even if no
sound, datas continues to be loaded by Agnus. these
2 bits are useless. we can make use of it to create
a break up of the audio in voice 3, but there are other
less constraining methods to do that (amplitude modulation
with a table made of only 2 values: 0 and 64).
After that, enable DMA channels : the basic sound will
be played on the highest voice of both. It will use
as volume or frequency (or both) the words loaded at
each period with the channel of modulation. These words
are loaded at the address of volume or frequency of
the modulated channel. if you stop the modulation, dont
forget to reset the volume or the frequency of the modified
channels and disable DMA of the modulated channels.
It's possible to use only one channel, by modifying
the volume or the frequency "in one's hand",
but no syncro and cpu fully used!
example2:
lea
custom,a6
; freq modulation
move.l #datamod,aud0lch(a6) ; datamod2 for amplitude
modul. / datamod3 for both
move.w #8,aud0len(a6) ; 16 for both mod
move.w #40000,aud0per(a6) ; periode
; basic sound
move.l #data,aud1lch(a6)
move.w #1,aud1len(a6)
move.w #5000,aud1per(a6)
move.w #50,aud1vol(a6)
move.w
#$8010,adkcon(a6) ; adkcon = 0 + 1 / 8001 for amplitude
/ 8011 for both
move.w
#$8203,dmacon(a6) ; start
mouse: btst #6,$bfe001
bne.s mouse
move.w #$11,adkcon(a6) ; end of modulation
move.w #3,dmacon(a6)
rts
data: dc.b 120,-120 ; square signal
datamod:
dc.w 1000,2000,3000,4000,5000,6000,7000,8000 ; freq
modulation
datamod2:
dc.w 2,8,10,20,30,40,50,60 ; amplitude modulation
datamod3:
dc.w 2,1000,8,2000,10,3000,20,4000 ; both
dc.w 30,5000,40,6000,50,7000,60,8000"
Third: interruption mode
[...]Amiga has 4 audio circuits, one for each voice.
Agnus uses 4 DMA channels to transfer datas.[... ]
After the authorization of DMA transfers, Paula transfer
address and length of the sound in its own registers.
Afterwards, it generates an interruption of level 4
to inform the 68000 that it finished the operation.
The processor can then change the contents of the address
and volume registers without that influencing the audio
in progress. During this time Agnus load a word both
periodes in register AUD*DAT $dff0+A
A cut of DMA channel is without effect if it lasts
less time than twice the period of the played sound,
because the state of DMA channel is checked only before
each transfer of data, time between two transfers is
the double of the period of the sound since the data
are loaded word by word.
When the end of the sample reached, Paula reload audio
registers and causes an interruption, until DMA stopped.
first problem: for example, we want to launch at the
same time the same sound on the 4 channels. if the channels
are not synchronized between them, that will produce
a cacophony. But that will occur however only in one
precise case: if the computer played already a sound
on one or several of the voices. In this case, Paula
will take account of the new sound only after having
finished that which it was playing, from where a shift
compared to the sound which began immediately.
Before any work with Paula, make sure that previous
DMA transfers are finished. For that, it's necessary
to wait time that the longest period lasts twice, 65535
cycles, or 20 ms with a CIA timer, more compatible with
all amiga .
second problem: how to join 2 samples too long to play
in one time ?
launch the first piece normally. After having loaded
the contents of the registers, Paula causes an interruption
of level 4. It's there that the interruption should
be grabed, re-init address and length of the second
piece without modifying DMACON.
During the second reading, these are the lately initialized
registers that Paula will load, and it will be thus
the new piece which will be played. If you have more
than two pieces, the system is the same.
[skip note about interruptions in general]
example:
; save
values
;...
; init
lea custom,a6
move.w #$7fff,intena(a6)
move.l #intlev4,$70.w
move.w #$c080,intena(a6) ; channel 0
; first sample
move.w #500,aud0per(a6)
move.w #50,aud0vol(a6)
move.l #data1,aud0lch(a6)
move.w #50000,aud0len(a6)
move.w #$8201,dmacon(a6)
mouse: btst #6,$bfe001
bne.s mouse
move.w #1,dmacon(a6)
; restore
;...
rts
intlev4: movem.l d0/a0/a6,-(sp)
lea custom,a6
move.w intreqr(a6),d0
btst #7,d0
beq .no
move.l pt,a0
move.l (a0)+,aud0lch(a6)
move.w (a0)+,aud0len(a6)
cmp.l #endtable,a0
bne .skip
lea table,a0
.skip:
move.l a0,pt
move.w #$80,intreq(a6)
.no:
movem.l (sp)+,d0/a0/a6
rte
data1:
dcb.b 384000,0
table:
dc.l data1
dc.w 50000
dc.l data1+100000
dc.w 50000
dc.l data1+200000
dc.w 50000
dc.l data1+300000
dc.w 42000
fin:
pt:
dc.l table+6
note: if the following piece doesnt have the same frequency
or if you want to change his volume, you will have to
wait the beginning of this piece (loading of the registers)
to carry out the changes because volume and frequency
arent safeguarded by Paula, who works directly on.
Fourth: manual mode
no more need to use audlch, audlen, nor to authorize
the DMA.
it's necessary to indicate volume and period.
then you transfer the first data word in auddat, which
will start the process: the word will be read at the
frequency indicated and an interruption of level 4 will
be generated indicating that you can send the following
word. if you dont grab it, the sound transmission will
end, and you will be forced to restart the process.
advantages (summary):
1. makes it possible to use samples of which the length
depends only on the memory size.
2. amplitude and frequency modulation by using only
one channel.
3. easy realization of many effects (inversion of sound,
scratching...)
4. mix in real time several signals: fake 4+ channels!
to mix 2 sounds, it's enough to add the current amplitudes
of the two signals by taking the differences of volume
and frequency into account.
5. data dont need more to be in CHIP since the DMA is
not used.
this mode is needed for the sampling.
last, the filter:
it cuts all the high frequencies, no more risks of aliasing.[...]
it's on bit 1 of port A of the CIA-A ($$bfe001). On
old Amiga, it on/off the power-led.
ex.: eor.w
#2,$bfe001
advices:
try echo effect by desynchronizing slightly two voices
playing the same sound (and it's better if on the same
stereo channel)
for good quality: use all the band of amplitude (+127
to -128), frequency not too low (min 7000), and for
the loop, same value for the beginning and the end of
the sample."
The End
credits: Philippe Rivaillon in "La Voix
de Paula" - ANT issues 29/30 jan/feb 1992
|