Playing a sample on the F030 (in assembler)

This code is basically the same as the C equivelent... I have not actually tested this code - I'm typing it in from memory, so dont blame me if it doesn't work - just email me at jacquesa@zetnet.co.uk and tell me what it does. I have got working code, but thats embedded in 7000 lines of code, so copying it from that is equally untested...


To initialise the audio sub-system do this :-

	move.w	#128,-(sp)		(Locksound)
	trap	#14
	addq.l	#2,sp	
	cmpi	#1,d0
	bne	sound_locked

	move.w	#0,-(sp)		set output to first track
	move.w	#134,-(sp)
	trap	#14
	addq.l	#4,sp			(Setmontrack)

	move.w	#1,-(sp)		set number of tracks to 1 playback
	move.w	#0.-(sp)
	move.w	#133,-(sp)
	trap	#14
	addq.l	#6,sp			(Settrack)

	move.w	res,-(sp)		res: 0=8bit stereo, 1=16bit stereo, 2=8bit mono
	move.w	#132,-(sp)
	trap	#14
	addq.l	#4,sp			(Setmode)	

The following will then play the actual sample...

	move.w	#6,-(sp)
	move.w	value,-(sp)		value : determines frequency (see below)
	move.w	#130,-(sp)
	trap	#14
	addq.l	#6,sp			Soundcmd               

	move.l	#samend,-(sp)
	move.l	#sambegin,-(sp)
	move.w	0,-(sp)			0=play, 1=record.
	move.w	#131,-(sp)
	trap	#14
	lea	12(sp),sp		Setbuffer

	move.w	#0,-(sp)		connect DMA play to DAC.
	move.w	scale,-(sp) 		scale  determines frequency
	move.w	#0,-(sp)
	move.w	#8,-(sp)
	move.w	#0,-(sp)
	move.w	#139,-(sp)
	trap	#14
	lea	12(sp),sp		Devconnect

	move.w	mode,-(sp)		mode: 0=stop, 1=play, 3=play with loop
	move.w	#136
	trap	#14
	addq.l	#4,sp			Buffoper

In your data area, you are going to want to declare some space for the various values etc (although you may want to store some in registers etc.)


scale	dc.w	1
mode	dc.w	0
value	dc.w	0

sambegin
	incbin "mysound.sam"
samend
The frequency is determined by the prescale value. Below is a table which gives the frequency for each value. Any value not listed will give a mute condition.

scale    freq (Hz)   value passed in Soundcmd(value,6);

11        8195              -
 9        9834              -
 7       12292              -
 5       16390              -
 4       19668              -
 3       24585              -
 2       32780              -
 1       49170              -
 0       125??              1
 0       25???              2
 0       50???              3

( - means no effect.)
At the end of the code, dont forget to unlock the sound-system, as there is nothing worse than this for stopping other applications from running when they are perfectly entitled to:

	move.w	#129,-(sp)
	trap	#14
	addq.l	#2,sp
And thats about it!


Back to programmers page.
Back to Atari Pages.
Anthony Jacques : jacquesa@zetnet.co.uk