Shirus Tracker and PSG file format

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Shirus Tracker and PSG file format

Post by Alex Khan » Mon Feb 08, 2010 6:43 pm

Hello,

I am using Shiru's tracker to compose sound for my game.

The problem is the Tracker does not export in PSG file format.

How do I export in PSG ... since I need my compiler to run the tracks in PSG.

Awaiting A Reply.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Mon Feb 08, 2010 7:02 pm

What is the PSG file format? The only .psg I know is not related to SMD at all.

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Tue Feb 09, 2010 6:31 am

Shiru Hello,

Here I was using the Basi compiler.

And found this sample code for audio.

psgvol 0,15
psg 3,1
psgvol 3,12
while 1
for a=200 to 1000 step 20
psg 0,a
sleep 1
next
for a=800 to 200 step -20
psg 0,a
sleep 1
next
wend

What do you think about the code above ?

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue Feb 09, 2010 7:02 am

This code absolutely not related to my tracker or music. All it does is controlling PSG sound chip in SMD to produce simple sound effect.

mic_
Very interested
Posts: 265
Joined: Tue Aug 12, 2008 12:26 pm
Location: Sweden
Contact:

Post by mic_ » Tue Feb 09, 2010 8:49 am

I've never heard of a "PSG format". You export to .TFD in TFM Music Maker. Then use one of the replayers in \replayers\smd\. If you can't find the necessary assemblers you'll have to ask Shiru about that, because I only ever use GAS and WLA-DX myself for genesis dev.

tinctu
Very interested
Posts: 97
Joined: Tue Oct 30, 2007 8:28 pm

Post by tinctu » Tue Feb 09, 2010 10:26 am

For Sega PSG there is Mod2PSG2 tracker>

http://www.kontechs.de/product?name=mod2psg

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Wed Feb 10, 2010 6:31 am

tinctu:
The Mod2PSG2 tracker I can use the Basi code to play music composed in this Tracker ?

So I can only use Shiru's tracker if I can program in Assembly. Which I obvioulsy can't.

mic_:
I don't understand what you mean it is French to me :(

Shiru:

I want to confirm if I compose music in your tracker I can use it provided I can code Motorolla Assembly or Z80 Assembly to playback music in the game.

By the way I'm using the Basi compiler.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Wed Feb 10, 2010 7:23 am

Alex Khan, please open /replayers/smd/bex/ in the tracker package. You had to do this before asking anything, it will take only few seconds or your time.

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Thu Feb 11, 2010 8:43 am

SHIRU YOU ARE A PROGRAMMING GOD !!!

THANK YOU THANK YOU !!! :)))

I thought I would have to write an engine in Assembly but you already made the engine .

THANK YOU THANK YOU !!! :)))



'Simple replayer for TFD files exported from TFM Music Maker
'Pure BEX version by Shiru, 31.12.07

'How to use:
' Load your music module into editor, File->Export->TFD file for SMD.
' Now you can use resulted file with this replayer. File can be large
' because no compression used, usually it has size from tens up to
' hundreds of KB, depending from music module (more slides and volume
' effects - larger module)



cls
ink 1
locate 1,1
print "TFD music replayer"

reload musicData 'point to music data (needed only once, right before init)
gosub tfdPlayInit 'init replayer
on VBLANK gosub tfdPlayFrame
enable INTERRUPTVBLANK
mainLoop:
sleep 1 'main loop of your program
goto mainLoop



'Replayer init. Set data read pointer to music data (by RELOAD or RESTORE)
'and GOSUB here. It needed once before playing

tfdPlayInit:
DataPtr&=DataPtr&()+4 'skip TFMD signature
for a=1 to 3 'skip three null-terminated text lines
while 1
read b
if b=0 then exit while
wend
next
vTfdDataPtr&=DataPtr&() 'store current read position
vTfdLoopPtr&=vTfdDataPtr& 'default loop position
vTfdCurrentBank=0 'select bank0
vTfdFrameCnt=0 'frame counter
vTfdWaitCnt=0 'wait counter
pokeint &hA11100,&h100 'busreq on
pokeint &hA11200,&h100 'reset Z80 and YM2612
pokeint &hA11200,0
pokeint &hA11100,0 'busreq off

return



'Replayer update. GOSUB here each frame (1/50sec) to play music.
'Note that for NTSC system you must do speed compensation to
'make music play at normal speed. In this example that done
'simply by skipping every 6th frame

tfdPlayFrame:
vTfdFrameCnt++ 'increment frame counter
if TvType()=0 then 'speed compensation for NTSC
if vTfdFrameCnt%6=0 then return
endif
if vTfdWaitCnt then 'skip frames if needed
vTfdWaitCnt--
else
vTfdDataTemp&=DataPtr&() 'store current read position
DataPtr&=vTfdDataPtr& 'set read position of music data
while 1
read vTag
if vTag<&hFA then 'write to YM2612 register
read vData 'read data
if vTag<&h30 then
curBank=0 'writes below 0x30 always goes to bank0
else
curBank=vTfdCurrentBank
endif
adrReg&=&hA04000+curBank
adrVal&=&hA04001+curBank
if vTag=&h28 then 'correction for bank1 Key On/Off event
if vTfdCurrentBank then
vData=vData+4
endif
endif
'pokeint &hA11100,&h0100 'busreq on
while peek(&hA04000).7 'wait for busy
wend
poke adrReg&,vTag 'write YM2612 register number
while peek(&hA04000).7 'wait for busy
wend
poke adrVal&,vData 'write YM2612 register data
'pokeint &hA11100,&h0000 'busreq off
elseif vTag=&hFF then 'single frame
vTfdCurrentBank=0
exit while
elseif vTag=&hFE then 'few frames
vTfdCurrentBank=0
read vTfdWaitCnt
vTfdWaitCnt=vTfdWaitCnt+2
exit while
elseif vTag=&hFD then 'select bank1
vTfdCurrentBank=2
elseif vTag=&hFC then 'select bank0
vTfdCurrentBank=0
elseif vTag=&hFB then 'end of data
DataPtr&=vTfdLoopPtr& 'jump to loop position
elseif vTag=&hFA then 'loop position
vTfdLoopPtr&=DataPtr&() 'remember read position
endif
wend
vTfdDataPtr&=DataPtr&() 'store read position of music data
DataPtr&=vTfdDataTemp& 'restore current read position
endif
return



musicData:
datafile music.tfd,BIN

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Thu Feb 11, 2010 9:17 am

Shiru one last question for Sound FX.

If I take a wave file like a "Womans Scream" can I convert it to PSG and play it back using this:

psgvol 0,15
psg 3,1
psgvol 3,12
while 1
for a=200 to 1000 step 20
psg 0,a
sleep 1
next
for a=800 to 200 step -20
psg 0,a
sleep 1
next
wend

Or can I play the wav sound directly ?

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Thu Feb 11, 2010 9:39 am

You can't convert WAV to PSG or FM. WAV is digitized sample, PSG and FM are synthesizers. You'd better to learn the basics before thinking about sound or making a game.

To play sample, you have to stream it at constant rate to DAC, in case with SMD it is one of channels of YM2612 (DAC mode replaces one of FM channels). If you want to play FM music at the same time, you should make special driver for this.

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Thu Feb 11, 2010 4:40 pm

Shiru I am not doing the programming alone it is a group of programmers wanting to do a project for the game.

Shiru can I just play raw wave samples for character sound effects with Basi ?

Waiting your reply.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Thu Feb 11, 2010 4:51 pm

I don't know if BEX has built-in driver for sample playing, but even if it has, it can't work with music player, because they both should have access to YM2612, and they will conflict. Thus you need custom sample player.

Simplest (and surely not the best) solution is to have sample player on Z80 side, and music player on M68K side, and when music player should access to YM2612, it should stop Z80 first, and before re-enabling Z80 it should select DAC register of YM2612.

Alex Khan
Very interested
Posts: 77
Joined: Thu Jan 07, 2010 9:51 am

Post by Alex Khan » Mon Feb 15, 2010 8:53 am

Yes Shiru !

You are right like Golden Axe.

In Golden Axe the music plays and when the sample has to play the M68K sound goes silent and then the Z80 plays a sample.

I see what you mean.

But what I don't understand is why have not all these great programmers who have produced all these excellent tools for Sega game programming not made a tool for playing samples ?

This confuses me!

Why Shiru Why ?

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Mon Feb 15, 2010 10:04 am

I haven't meant Golden Axe. In the method I've described, the music will not interrupted while sample playing.

There are ton of sample players. As I said, the problem is to share YM2612 between sample and music player.

Post Reply