English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 09 December 2020, 11:34   #1
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
playing sample with audio irq

Tried to find a simple (and proper one) code for playing sample and stopping it via audio irq and I failed.

Can someone share a code snippet for that. Thanks.
Asman is offline  
Old 09 December 2020, 11:57   #2
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,162
phx ptreplay is the best to play modules & samples. There's source too, but you may not need it since it's so easy to use.

It uses level 6 interrupt only. Maybe it's not what you want. But it's awesome.
jotd is offline  
Old 09 December 2020, 12:11   #3
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Asman View Post
Tried to find a simple (and proper one) code for playing sample and stopping it via audio irq and I failed.

Can someone share a code snippet for that. Thanks.
I have code for doing that but i'm afraid it's not simple enough for a small code snippet.
Perhaps you could post your code and we will tell you why it fails.
meynaf is offline  
Old 09 December 2020, 17:11   #4
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Here you are. Its funny but it almost taken from polish game PrawoKrwiAGA. I am wondering if this is a proper way to play sample.

Comments are welcome.

Code:
	SECTION PLAYSFX,CODE_P
Start:
	;init
		lea	$dff000,a5
		move.w	#$7fff,$9a(a5)	;stop ints
		move.w	#$7fff,$9c(a5)	;clear pending ints

		sub.l	a0,a0		;for tests vbr = 0

		lea	IntLevelFourAudio(pc),a1
		move.l	a1,$70(a0)
		
		move.w	#$c400,$9a(a5)	;allow int aud3

	;start playing sample
		move.w	#$400,$9a(a5)	;disable aud3 int

		move.w	#64,$d8(a5)	;set volume
		move.w	#160,$d6(a5)	;period 22050
		move.w	#sampleLenght,$d4(a5)	;length
		move.l	#sampleBegin,$d0(a5)	;sample

		move.w	#$8008,$96(a5)	;set aud3 dma

		bsr	Wait		;why wait ? and how long I should wait ???

		move.w	#$c400,$9a(a5)	;allow aud3 int
		move.w	#$400,$9c(a5)	;I don't know why but without that not works

.lmb		btst	#6,$bfe001
		bne	.lmb
		rts

IntLevelFourAudio:
		movem.l	d0/a5,-(sp)
		lea	$dff000,a5
		move.w	$1e(a5),d0	;check for aud3 int
		and.w	#$400,d0
		beq	.exit

		move.w	#8,$96(a5)	;disable aud3 dma

.exit		move.w	#$400,$9c(a5)	;clear aud3
		move.w	#$400,$9c(a5)	;twice
		movem.l	(sp)+,d0/a5
		rte


Wait:		moveq	#2-1,d1
.wait1		move.b	$dff006,d0
.wait2		cmp.b	$dff006,d0
		beq.b	.wait2
		dbf	d1,.wait1 
		rts

	SECTION SFX,DATA_C

sampleBegin:	incbin	'sfx.raw'
sampleEnd:
sampleLenght	= (sampleEnd-sampleBegin)/2
Asman is offline  
Old 09 December 2020, 17:36   #5
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Volume has range 0-63 if I recall... 64 may be setting it to 0.
mcgeezer is offline  
Old 09 December 2020, 17:59   #6
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Asman View Post
Here you are. Its funny but it almost taken from polish game PrawoKrwiAGA. I am wondering if this is a proper way to play sample.

Comments are welcome.
Not a proper way to play a sample indeed.
The main problem is that a first irq comes as soon as the sample is started, not only when it is finished. The coder clumsily attempted to avoid this with a wait.
Proper steps are :
- clear intreq
- allow interrupts
- start sample
Then in your interrupt :
- ignore first time interrupt is called (or setup repeat/replen there if you want)
- then at second interrupt, you've reached the end


Quote:
Originally Posted by mcgeezer View Post
Volume has range 0-63 if I recall... 64 may be setting it to 0.
No, range is really 0-64.
meynaf is offline  
Old 09 December 2020, 18:13   #7
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Yeah, that example is not good. Post above is the "official" way. Interrupt is generated when sample starts, not when it ends.

I'd personally set up empty sample in first interrupt, this guarantees no glitches (sample repeating) if second interrupt gets delayed by some higher level interrupt etc.. (or setup next sample if you plan to play >128k sample)


Also never ever enable interrupt first and then clear intreq. This introduces undefined behavior depending on CPU/hardware..
Toni Wilen is offline  
Old 09 December 2020, 21:48   #8
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Thanks a lot for answers. Second attempt.


Code:
	SECTION PLAYSFX,CODE_P
Start:
	;init
		lea	$dff000,a5
		move.w	#$7fff,$9a(a5)	;stop ints
		move.w	#$7fff,$9c(a5)	;clear pending ints

		sub.l	a0,a0		;for tests vbr = 0

		lea	IntLevelFourAudio(pc),a1
		move.l	a1,$70(a0)
		
		move.w	#$c400,$9a(a5)	;allow int aud3

	;start playing sample
		move.w	#$400,$9a(a5)	;disable aud3 int
		move.w	#$400,$9c(a5)	;clear int aud3 request
		move.w	#$c400,$9a(a5)	;allow int aud3

		move.w	#64,$d8(a5)	;set volume
		move.w	#160,$d6(a5)	;period 22050
		move.w	#sampleLenght,$d4(a5)	;length
		move.l	#sampleBegin,$d0(a5)	;sample

		move.w	#$8008,$96(a5)	;start the sample

.lmb		btst	#6,$bfe001
		bne	.lmb
		rts

Int:
IntLevelFourAudio:
		movem.l	d0/a5,-(sp)
		lea	$dff000,a5
		move.w	$1e(a5),d0	;check for aud3 int
		and.w	#$400,d0
		beq	.exit

		lea	cnt(pc),a0
		subq.w	#1,(a0)
		beq.b	.setEmpty

	;	move.w	#8,$96(a5)	;should I disable aud3 as well ?
		move.w	#$400,$9a(a5)	;is it mandatory to stop this int ?
		bra	.exit
		
.setEmpty	move.w	#sampleEmptyLen,$d4(a5)	;length
		move.l	#sampleEmptyBeg,$d0(a5)	;sample

.exit		move.w	#$400,$9c(a5)	;clear aud3
		move.w	#$400,$9c(a5)	;twice
		movem.l	(sp)+,d0/a5
		rte

cnt:		dc.w	1



	SECTION SFX,DATA_C

sampleBegin:	incbin	'sfx.raw'
sampleEnd:
sampleLenght	= (sampleEnd-sampleBegin)/2

sampleEmptyBeg:	dc.l	0
sampleEmptyEnd:
sampleEmptyLen	= (sampleEmptyEnd-sampleEmptyBeg)/2
Asman is offline  
Old 10 December 2020, 08:24   #9
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
This one can work from first sight but it does a few unneeded things.

1. Clear pending ints + allow int aud3 + disable aud3 int + clear int aud3 request + allow int aud3 can be replaced by simpler clear pending ints + allow int aud3.

2. Instead of clearing aud3 twice at the end of the interrupt, clear it once but at start, right after checking it.
meynaf is offline  
Old 11 December 2020, 12:28   #10
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
@meynaf - Thanks a lot. I removed unneeded things and it works nice.
Asman is offline  
Old 17 December 2020, 16:02   #11
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,801
So post it for other to use
kamelito is offline  
Old 17 December 2020, 20:50   #12
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
@kamelito - Here you are.

Code:
	SECTION PLAYSFX,CODE_P
Start:
	;init
		lea	$dff000,a5
		move.w	#$7fff,$9a(a5)	;stop ints

		sub.l	a0,a0		;for tests vbr = 0
		lea	IntLevelFourAudio(pc),a1
		move.l	a1,$70(a0)

	;start playing sample
		move.w	#$400,$9c(a5)	;clear int aud3 request
		move.w	#$c400,$9a(a5)	;allow int aud3

		move.w	#64,$d8(a5)	;set volume
		move.w	#160,$d6(a5)	;period 22050
		move.w	#sampleLenght,$d4(a5)	;length
		move.l	#sampleBegin,$d0(a5)	;sample

		move.w	#$8008,$96(a5)	;start the sample

.lmb		btst	#6,$bfe001
		bne	.lmb
		rts

IntLevelFourAudio:
		movem.l	d0/a0/a5,-(sp)
		lea	$dff000,a5
		
		move.w	$1e(a5),d0	;check for aud3 int
		and.w	#$400,d0
		beq.b	.exit
		move.w	#$400,$9c(a5)	;clear aud3

		lea	cnt(pc),a0
		subq.w	#1,(a0)
		beq.b	.setEmpty

		move.w	#$400,$9a(a5)
		move.w	#8,$96(a5)
		
.setEmpty	move.w	#sampleEmptyLen,$d4(a5)	;length
		move.l	#sampleEmptyBeg,$d0(a5)	;sample

.exit		movem.l	(sp)+,d0/a0/a5
		rte

cnt:		dc.w	1

	SECTION SFX,DATA_C

sampleBegin:	incbin	'sfx.raw'
sampleEnd:
sampleLenght	= (sampleEnd-sampleBegin)/2

sampleEmptyBeg:	dc.l	0
sampleEmptyEnd:
sampleEmptyLen	= (sampleEmptyEnd-sampleEmptyBeg)/2
Asman is offline  
Old 17 December 2020, 21:03   #13
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Code:
---

IntLevelFourAudio:
		movem.l	d0/a0/a5,-(sp)
		lea	$dff000,a5
		move.w	#$400,d0
		
		and.w	$1e(a5),d0	;check for aud3 int
		beq.b	.exit
		move.w	d0,$9c(a5)	;clear aud3

		lea	cnt(pc),a0
		subq.w	#1,(a0)
		beq.b	.setEmpty

		move.w	d0,$9a(a5)
		move.w	#8,$96(a5)
		
.setEmpty	move.w	#sampleEmptyLen,$d4(a5)	;length
		move.l	#sampleEmptyBeg,$d0(a5)	;sample

.exit		movem.l	(sp)+,d0/a0/a5
		rte

---
ross is offline  
Old 17 December 2020, 21:08   #14
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
@ross - Thanks.
Asman is offline  
Old 17 December 2020, 21:22   #15
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
In any case I don't think that the check over INTREQR is useful in any way, since the IRQs handling is done directly by Paula (spurious level 4 IRQs cannot externally reach the chip lines).
Sure they could actually arrive directly on the IPLs, but usually in that case are triggered for a change on the lines that are not in phase.
We should ask Toni if in fact there can be a level 4 spurious IRQ... (probably yes in very special and unlucky cases)

Well, is a simple check, not many cycles lost
ross is offline  
Old 18 December 2020, 18:50   #16
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,801
@Asman
Thanks for sharing.
kamelito is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing a long running sample... mcgeezer Coders. Asm / Hardware 13 18 January 2020 11:16
Cannot use AUDX-INT (Level 4 IRQ) to stop sample. Herpes Coders. Asm / Hardware 18 16 January 2020 22:37
Using two voices for 56K sample/second audio output rate -- OCS -- No CPU or Copper mc6809e Coders. Asm / Hardware 2 28 January 2012 00:29
AHI uae.audio with up to 192KHz sample freq. amiga request.UAE Wishlist 4 18 March 2010 01:35

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:55.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10172 seconds with 15 queries