TriOS-alt/flash/administra/admflash-wav.spin

165 lines
4.9 KiB
Plaintext
Raw Normal View History

2010-03-18 19:59:13 +01:00
' ASM WAV Player Ver. 1b (Plays only stereo, 16-bit PCM WAV files from SD card)
' Copyright 2007 Raymond Allen See end of file for terms of use.
' Settings for Demo Board Audio Output: Right Pin# = 10, Left Pin# = 11 , VGA base=Pin16, TV base=Pin12
' Rev.B: 21Dec07 Fixed pin assignment bug.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 '80 MHz
buffSize = 100
VAR long parameter1 'to pass @buff1 to ASM
long parameter2 'to pass @buff2 to ASM
long parameter3 'to pass sample rate to ASM
long parameter4 'to pass #samples to ASM
long buff1[buffSize]
long buff2[buffSize]
long cog
byte Header[44]
PUB start(para_ptr) 'startet eine cog als wav-player
'' para_ptr - zeiger auf vier long-parameter
stop
'Start ASM player in a new cog
cog := COGNEW(@ASMWAV,para_ptr) + 1
PUB stop
if cog
cogstop(cog~ - 1)
DAT
ORG 0
ASMWAV
'load input parameters from hub to cog given address in par
mov y, par
rdlong pData1, y
add y, #4
rdlong pData2, y
add y, #4
rdlong dRate, y
add y, #4
rdlong nSamples, y
setup
'setup output pins
MOV DMaskR,#1
ROL DMaskR,OPinR
OR DIRA, DMaskR
MOV DMaskL,#1
ROL DMaskL,OPinL
OR DIRA, DMaskL
'setup counters
OR CountModeR,OPinR
MOV CTRA,CountModeR
OR CountModeL,OPinL
MOV CTRB,CountModeL
'Wait for SPIN to fill table
MOV WaitCount, CNT
ADD WaitCount,BigWait
WAITCNT WaitCount,#0
'setup loop table
MOV LoopCount,SizeBuff
'ROR LoopCount,#1 'for stereo
MOV pData,pData1
MOV nTable,#1
'setup loop counter
MOV WaitCount, CNT
ADD WaitCount,dRate
MainLoop
SUB nSamples,#1
CMP nSamples,#0 wz
IF_Z JMP #Done
waitcnt WaitCount,dRate
RDLONG Right,pData
ADD Right,twos 'Going to cheat a bit with the LSBs here... Probably shoud fix this!
MOV FRQA,Right
ROL Right,#16 '16 LSBs are left channel...
MOV FRQB,Right
WRLONG Zero,pData
ADD pData,#4
'loop
DJNZ LoopCount,#MainLoop
MOV LoopCount,SizeBuff
'switch table ?
CMP nTable,#1 wz
IF_Z JMP #SwitchToTable2
SwitchToTable1
MOV nTable,#1
MOV pData,pData1
JMP #MainLoop
SwitchToTable2
MOV nTable,#2
MOV pData,pData2
JMP #MainLoop
Done
'now stop
COGID thisCog
COGSTOP thisCog
'Working variables
thisCog long 0
x long 0
y long 0
dlsb long 1 << 9
BigWait long 100000
twos long $8000_8000
'Loop parameters
nTable long 0
WaitCount long 0
pData long 0
LoopCount long 0
SizeBuff long buffsize
'Left long 0
Right long 0
Zero long 0
'setup parameters
DMaskR long 0 'right output mask
OPinR long 8 'right channel output pin # ' <--------- Change Right pin# here !!!!!!!!!!!!!!
DMaskL long 0 'left output mask
OPinL long 9 'left channel output pin # ' <--------- Change Left pin# here !!!!!!!!!!!!!!
CountModeR long %00011000_00000000_00000000_00000000
CountModeL long %00011000_00000000_00000000_00000000
'input parameters
pData1 long 0 'Address of first data table
pData2 long 0 'Address of second data table
dRate long 5000 'clocks between samples
nSamples long 2000
{{
TERMS OF USE: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
}}