7 include libraries
/ahi_sub
.i
8 include libraries
/toccata
.i
9 include lvo
/toccata_lib
.i
10 include utility
/hooks
.i
14 XDEF _intAHIsub_Disable
15 XDEF _intAHIsub_Enable
16 XDEF _intAHIsub_Update
17 XDEF _intAHIsub_SetVol
18 XDEF _intAHIsub_SetFreq
19 XDEF _intAHIsub_SetSound
20 XDEF _intAHIsub_SetEffect
21 XDEF _intAHIsub_LoadSound
22 XDEF _intAHIsub_UnloadSound
24 XDEF _SlaveProcessEntry
31 XDEF _PlayFuncStereo32
38 *******************************************************************************
41 * a2 struct AHI_AudioCtrl
50 * a2 struct AHI_AudioCtrl
66 _intAHIsub_UnloadSound
:
67 moveq #AHIS_UNKNOWN
,d0
72 *******************************************************************************
79 move
.l TC_Userdata
(a0
),a2
80 move
.l ahiac_DriverData
(a2
),a0
81 move
.l t_AHIsubBase
(a0
),a6
84 *******************************************************************************
92 move
.l ahiac_DriverData
(a2
),a1
94 * Update dd
->t_RecMessage
->ahirm_Length
:
95 move
.l t_RecMessage
(a1
),a3
96 lsr
.l #
2,d0
;bytes
=> samples
97 move
.l d0
,ahirm_Length
(a3
)
100 move
.l t_RecBuffer
(a1
),a3
111 * Call the SamplerFunc Hook
112 move
.l t_RecMessage
(a1
),a1
113 move
.l ahiac_SamplerFunc
(a2
),a0
114 move
.l h_Entry
(a0
),a3
121 *******************************************************************************
123 TocSamplesCnt EQUR d7
127 * These functions fills the Toccata buffer
with the mixed output
. Since
128 * the Toccata buffer
is not the same size as the mixing buffer
, the mixing
129 * routine may have to be called several times each interrupt
. Or if the mixing
130 * buffer
is larger than the Toccata buffer
, it may
not be called
at all.
132 * The routines are
not very well commented
, but they should be pretty stright
-
133 * forward once you know what they actually
do.
145 move
.l a1
,a2
;a2
is later used as Hook object
146 move
.l ahiac_DriverData
(a2
),a5
148 * Swap Toccata buffer buffers
and get pointer to one
of them
.
149 move
.l t_SampBuffer1
(a5
),TocBuffer
150 move
.l t_SampBuffer2
(a5
),t_SampBuffer1
(a5
)
151 move
.l TocBuffer
,t_SampBuffer2
(a5
)
153 * TocSamplesCnt
is number
of samples left
in Toccata buffer to fill
.
154 move
.l t_TocSamples
(a5
),TocSamplesCnt
156 * t_MixSamplesCnt
is uncopied samples left
in mixing buffer
158 tst
.l t_MixSamplesCnt
(a5
)
161 * There are no unplayed samples
in the mixing buffer
. Fill it again
!
163 move
.l ahiac_BuffSamples
(a2
),t_MixSamplesCnt
(a5
)
165 move
.l t_MixBuffer1
(a5
),d0
166 move
.l t_MixBuffer2
(a5
),t_MixBuffer1
(a5
)
167 move
.l t_MixBuffer3
(a5
),t_MixBuffer2
(a5
)
168 move
.l d0
,t_MixBuffer3
(a5
)
170 move
.l t_MixBuffer1
(a5
),t_MixBufferPtr
(a5
)
172 ; Now check
if the mixing routine will mix more samples than are transfered
173 ; each software interrupt
. If so
, signal a
(high
-priority
) task to
do the
174 ; actual mixing
. This
is because one cannot be sure that the mixing routine
175 ; terminates before FIFO
is empty
. If the routine will mix less samples than
176 ; transfered
, there
is no need to
use a
task for it
(in fact that would be a
177 ; pretty stupid idea
, since the mixing hook may have to be called several
178 ; times during the interrupt
.
180 move
.l t_TocSamples
(a5
),d0
181 cmp
.l ahiac_BuffSamples
(a2
),d0
184 ; The mixing buffer
is smaller than the toccata one
=> Mix
in soft interrupt
187 move
.l ahiac_PlayerFunc
(a2
),a0
189 move
.l h_Entry
(a0
),a3
190 jsr
(a3
) ;Call Player Hook
192 *** NOTE
: No protection against CPU overload
when mixing inline
!
193 move
.l ahiac_MixerFunc
(a2
),a0
194 move
.l t_MixBuffer3
(a5
),a1
195 move
.l h_Entry
(a0
),a3
196 jsr
(a3
) ;Call Mixer Hook
200 ; The mixing buffer
is larger than the toccata one
=> Signal
task to mix
.
201 ; But first
, check
if we
're using a hard interrupt
. If so
, we Cause
() a
202 ; SoftInt instead
of signalling a
task.
205 and.w #
%0000011100000000,d0
;Check
if we run as SoftInt
(lev
0)
210 move
.l t_MixSoftInt
(a5
),a1
216 ; If the flag t_NoTask
is TRUE, we mix
in the software interrupt anyway
.
223 move
.l t_SlaveProcess
(a5
),a1
224 move
.b t_MixSignal
(a5
),d1
231 move
.l t_MixSamplesCnt
(a5
),d0
232 sub
.l d0
,TocSamplesCnt
234 add
.l TocSamplesCnt
,d0
235 moveq #
0,TocSamplesCnt
237 * d0
is now how many samples should be copied before either the Toccata buffer
238 * is full
or the mixing
is empty
.
240 sub
.l d0
,t_MixSamplesCnt
(a5
)
242 * t_MixBufferPtr
is the address
(in the mixing buffer
) where the next untouched
244 move
.l t_MixBufferPtr
(a5
),a0
245 lsr
.l #
1,d0
;Just unrolling
...
252 * move
.w
(a0
)+,(TocBuffer
)+
254 * move
.w
(a0
)+,(TocBuffer
)+
258 move
.l a0
,t_MixBufferPtr
(a5
) ;Update pointer till next time
259 tst
.l TocSamplesCnt
;Is Toccata buffer full now?
260 bne
.loop ;Nope
, loop.
273 move
.w
(a0
)+,(TocBuffer
)+
275 move
.w
(a0
)+,(TocBuffer
)+
281 move
.l
(a0
)+,(TocBuffer
)+ ; 2 WORDs
== left
and right data
283 move
.l
(a0
)+,(TocBuffer
)+
288 move
.w
(a0
),(TocBuffer
)+ ; Upper
16 bits
...
291 move
.w
(a0
),(TocBuffer
)+ ; Upper
16 bits
...
297 move
.w
(a0
),(TocBuffer
)+ ; Upper
16 bits
...
298 move
.w
4(a0
),(TocBuffer
)+ ; Upper
16 bits
...
301 move
.w
(a0
),(TocBuffer
)+ ; Upper
16 bits
...
302 move
.w
4(a0
),(TocBuffer
)+ ; Upper
16 bits
...
311 move
.l a1
,a2
;a2
is Hook object
312 move
.l ahiac_DriverData
(a2
),a5
314 move
.l ahiac_PlayerFunc
(a2
),a0
316 move
.l h_Entry
(a0
),a3
317 jsr
(a3
) ;Call Player Hook
319 move
.l ahiac_PreTimer
(a2
),a0
321 bne
.mixed
;Skip mixing
!
322 move
.l ahiac_MixerFunc
(a2
),a0
323 move
.l t_MixBuffer3
(a5
),a1
324 move
.l h_Entry
(a0
),a3
325 jsr
(a3
) ;Call Mixer Hook
327 move
.l ahiac_PostTimer
(a2
),a0