Thread: Paula ROCKS!
View Single Post
Old 10 July 2020, 13:19   #92
Defendit numerus

ross's Avatar
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 50
Posts: 3,124
Ok, code time:
	section	pwmvolumetest,code_c

pwmcenter	equ	14+28+1
volume1		equ	15
volume2		equ	63

	lea	$dff000,a6
	move.w	#$7fff,$9a(a6)
	move.w	#$005f,$96(a6)
	move.w	#$00ff,$9e(a6)
	lea	c0(pc),a0
	move.l	a0,$80(a6)

	lea	wave(pc),a0
	move.l	a0,$a0(a6)
	move.w	#16,$a4(a6)
	move.w	#128,$a6(a6)
	move.w	#volume2,$a8(a6)

	lea	copperlist1(pc),a0
	lea	copperlist2(pc),a1
	lea	cl+8(pc),a5
	move.l	a1,-(a5)
	move.l	a0,-(a5)

	moveq	#pwmcenter,d7	; h
	bsr.b	genlist

	move.w	#311,d0			; penultimate line
	move.w	6(a6),d1
	swap	d1
	move.w	4(a6),d1
	rol.l	#8,d1
	andi.w	#$1ff,d1
	cmp.w	d1,d0
	bne.b	waitl
.ll	cmpi.w	#$3840,6(a6)
	blo.b	.ll
	move.l	(a5),$80(a6)
	move.w	#$0120,$96(a6)
	move.w	#$8001,$96(a6)
	move.w	#$7fff,$9c(a6)

.go	moveq	#$20,d0
	and.w	$1e(a6),d0
	beq.b	.go
	move.w	d0,$9c(a6)

	movem.l	(a5),a0/a1
	exg	a0,a1
	movem.l	a0/a1,(a5)
	bsr.b	genlist
	move.l	(a5),$80(a6)
	bra.b	.go

	move.w	#227,d6			; 227
	moveq	#$40,d5
	lsl.w	#2,d5			; #$00000100
	moveq	#1,d4
	swap	d4			; #$00010000
	moveq	#-2,d3
	moveq	#64,d2
	moveq	#0,d0			; line

.nl	moveq	#1,d1
	or.w	d0,d1
	or.b	d7,d1
	move.w	d1,(a0)+
	move.w	d3,(a0)+
	move.l	#$00a8<<16|volume1,(a0)+
	move.l	#$00a8<<16|volume2,(a0)+
	add.w	d2,d7
	cmp.w	d6,d7
	blo.b	.nl
	sub.w	d6,d7
	add.l	d5,d0
	cmp.l	d4,d0
	bne.b	.nl

	cmpi.w	#$ffd3,d1		; copper y-roll fix
	bne.b	.n2
	moveq	#2,d4
.n2	bhi.b	.n3
	move.l	#$ffe1fffe,(a0)+
.n3	cmpi.w	#$ffe3,d1
	bne.b	.nf
	moveq	#-2,d4

.nf	add.w	d4,-12(a0)
	move.l	#313<<8,d4
	bchg	d3,d3
	bne.b	.nl

	cnop	0,4
c0	dc.l	-2

	dcb.b	16,127
	dcb.b	16,-128

cl	dx.l	2

	dx.b	12*(227*313/64)+12+4*2

	cnop	0,4
	dx.b	12*(227*313/64)+12+4*2
Volume change in perfect synchronization with pwm frequency thanks to the copper (hopefully centered in the midpoint of the cycle, in any case it can be modified by simply changing a parameter).
The code can be used as a basis for further synchronized audio experiments.

The double buffered generated copper list(s) has no problems at copper roll of line 0 and 256 and continues to remain in phase with a defined cck.

I assembled two executable: first one that keeps the volume constant, the other one that set volume at 15 then quickly flip to the default 63.
In theory, the two output wave should be identical if the volume is copied into the pwm counter only at the end of the count.

I used a simple square wave with 50% duty cycle (32 samples, period 128), therefore can be annoying to the ears

Work on any Amiga.

Yes this is too much off-topic, all these technical messages should really be moved to the Coders.Asm/Hardware section

Attached Files
File Type: s pwmvolumetest.s (1.6 KB, 28 views)
File Type: 68k pwmvolumetest_63.68k (328 Bytes, 25 views)
File Type: 68k pwmvolumetest_1563.68k (328 Bytes, 26 views)
ross is offline  
Page generated in 0.04130 seconds with 11 queries