|
|
replaying soundsamples via a mere YM2149
in this document i'll try to describe an old fashioned technique that's able to produce quite astonishing results,
although it is old and has been used for many times yet. if you're trying to output tunes or sound effects during
your demo, game or whatever it seems like you'd be limited to outputing more or less boring chip-sounds as long as
you're using the ST's and Mega ST's crappy old YM2149 sound device :).
wouldn't it be much nicer to be able to replay sampled instruments, voices or sound effects like it is possible
with a dma soundsystem that got introduced with the STE and was present on all its descendant machines ? for sure,
if you ask me.
now, what's so striking about this dma sound system ? well, first of all like the abbreviation 'dma' implies it
works completely cpu-independent and thus provides performance. it is able to replay so called pcm-samples that
can be seen as stream of da values (so called 'samples'), which get thrown out through a speaker at a certain
frequency to reproduce a voice or tune encoded that way (da = digital to analog). the STE is able to replay stereo
streams at frequencies up to 50Khz accomplishing quite good results that way - the only disadvantage: the better
your sample's quality, the more diskspace and/or ram you will have to spend.
so on the STE and all newer Atari machines all you must do in order to play such a sound sample is setting up
its start-, its end-address and its frequency to start it playing, afterwards. then you can let the dma system loop
your sound buffer or invoke a timer-a interrupt at the end of the sample to set up a next one - everything without
losing any cpu cycles.
back to the topic, i.e. replaying those samples via the old YM-chip on STs and Mega STs. as this soundchip provides
3 independent channels that can replay noise-waves and frequencies at 16 different voulumes it is possible to
emulate an 8bit digital to analog converter like present on the STE at almost the same sound-quality by using the
apropiate values according to the current sample-value to be replayed, using a lookup table.
the player then gets synced using a timer-a interrupt that fits best here because you might be going to use timer-b
for other purposes like palette-splits etc.
of course, you can't output stereo streams and i'd recommend you to limit the sample rate to a maximum of lets say
15Khz as replaying is done by the cpu and uses more cycles the higher the sample rate gets.
this is how a looping player can be implemented (adapting it to a routine that plays multiple samples one after
another should be easy enough, though):
sample_length
player
.play
.da_table |
section text
dc.l sample_end-sample
movem.l d0-d1/a6,-(sp)
move.l usp,a6
moveq.l #0,d0
move.b (a6)+,d0
lsl.w #3,d0
subq.l #1,position
bne.s .play
lea.l sample,a6
move.l sample_length(pc),position
move.l a6,usp
lea.l $ffff8800.w,a6
movem.l .da_table(pc,d0.l),d0/d1
movep.l d0,(a6)
move.l d1,(a6)
movem.l (sp)+,d0-d1/a6
rte
include 'da_table.s'
|
; Get pointer to current sample
; Get sample byte
; *8
; Decrement counter
; Loop sample if it we reached the end
; Store address to the next sample
; YM2149
; Output volume data to YM-register,
; this is how the DA is emulated
|
all you have to do to start it playing is setting this up as a timer-a routine (vector $0134.w) with timer-a running
at a frequency equal or as close as possible to the one of your sample. the long variable 'position' has to be filled
with the length of your sample as stored in 'sample_length' as well as the usp register, which isn't used in supervisor
mode anyway, has to be loaded with the starting address of your sample, initially. please note that this player is
intended to replay *unsigned 8bit pcm samples* only whereas the STE's dma soundsystem uses signed samples, instead.
furthermore this technique doesn't work on the Falcon because of a missing shadow address, but you can directly use
dma replay there, anyway.
the player can be optimized by preshifting your samples up by 3 bits which saves the movep.l and the lsl.w but expands
your sample space by a factor of two. you can even skip the table lookup by saving your samples as raw YM-register pokes
in the first place - however, this isn't recommended as it doesn't result in an obvious speedup
and because it inflates your sample record from one to eight (!) bytes.
various da-tables holding the proper YM-register values have yet been created, i've experienced best results with this one.
this whole text is based on the documentation of AN-COOL's TCB Tracker which
provides a comprehensive source and additional information such as 4 channel mixing - credits have to go out to him at
this place.
- 2002 ray//.tscc. -
|
|
|