Short beeper routines in assembly

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
R-Tape
Site Admin
Posts: 257
Joined: Thu Nov 09, 2017 11:46 am

Re: Short beeper routines in assembly

Post by R-Tape » Tue Dec 05, 2017 7:49 am

I don't suppose anyone can improve on my naff page turning sound?

It's for use on the tape magazine, would be credited natch.
0 x

Hikaru
Dizzy
Posts: 51
Joined: Mon Nov 13, 2017 1:42 pm
Location: Russia
Contact:

Re: Short beeper routines in assembly

Post by Hikaru » Tue Dec 05, 2017 8:00 am

Well, I gave it a go previously, but decided not to post it in the end as I didn't really like the result. Seems like it was auto-saved as a draft, sooo here

Code: Select all

SFX
	ld hl,0
	ld de,#0710
	ld bc,2
	ld lx,#18
	call .loop
	ld c,24
	ld lx,#06
.loop
	ld a,(hl)
	inc hl
	cp c
	sbc a
	and e
	or d
	out (#FE),a
	djnz .loop
	dec lx
	jr nz,.loop
	ret
0 x

User avatar
R-Tape
Site Admin
Posts: 257
Joined: Thu Nov 09, 2017 11:46 am

Re: Short beeper routines in assembly

Post by R-Tape » Tue Dec 05, 2017 10:44 am

Much better than mine, thanks.

Are you still okay to be credited as 'owner' of the noise if I go with this? I'm using IX as a string pointer, so while it would be easy enough to PUSH it I'm trying to minimise having to do so.

Also, do you think changing ld d,6 to 24 makes it better or too close to masticating crisps?

Why did you use ixl? Timing reasons, or just because you used every other register?

Code: Select all

org 32768
SFX
	ld hl,0
	ld bc,2
	ld d,24
	call .loop
	ld c,24
	ld d,64
.loop
	ld a,(hl)
	inc hl
	cp c
	sbc a,a
	and 24
	or 7
	out (254),a
	djnz .loop
	dec d
	jr nz,.loop
	ret
0 x

Hikaru
Dizzy
Posts: 51
Joined: Mon Nov 13, 2017 1:42 pm
Location: Russia
Contact:

Re: Short beeper routines in assembly

Post by Hikaru » Tue Dec 05, 2017 1:50 pm

I don't think something like this needs a credit at all, so any option is fine of course. For the record, at the core of it is a fairly old trick used in the Tritone engine (and IIRC one more from the 80's), i.e. CP N: SBC A: AND #10. In other words, any values less than N give #10, while values equal to or more than N give 0. Tritone uses it as a kind of hybrid 'timbre/volume control' for square waves, so I thought I might be able to get something similar with the noise, but apparently the result is far less pronounced.

LX, no point really, it's more due to my subconscious habit to speed up innermost loops (use up all registers first, ask questions later). Well, this time it affects the noise pitch. Try both versions, maybe tweak the constants a bit to see which is better. There's no right or wrong about it other than if it sounds good to you.
0 x

Joefish
Dizzy
Posts: 52
Joined: Tue Nov 14, 2017 10:26 am

Re: Short beeper routines in assembly

Post by Joefish » Tue Dec 05, 2017 3:13 pm

If it's any help, the way I generate the combined noise and tone that gives the saws in Buzzsaw+ their 'whine' was to create a high/low square wave, then have a random number generator that whenever it produces a number over a certain threshold, I temporarily invert a bit of the square wave for a small number of cycles.

Now to control the rough 'pitch' of the whine, that's the original square wave. To make it more or less noisy, I move the threshold above which the random number inverts the output, or have it so it can only insert '1s' into the square wave, rather than invert it (so it only affects the low half of the wave). And to adjust the pitch of the noise, I make the random inversion stick around for more or less cycles of my sound function.

But these are prepared in advance and replayed from a buffer, which repeats once it's set up. To make the 'noise' sound more random, the buffer is longer than it needs to be and each time it replays the start position is randomised.
0 x

User avatar
R-Tape
Site Admin
Posts: 257
Joined: Thu Nov 09, 2017 11:46 am

Re: Short beeper routines in assembly

Post by R-Tape » Tue Dec 05, 2017 7:36 pm

Joefish wrote:
Tue Dec 05, 2017 3:13 pm
If it's any help
Aye it is, in the long term. I don't have enough time to refine a sound routine right now but it's something I started to make progress with then forgot during a 6 month coding lacuna. I tend to avoid doing music/sound as I don't feel I have an affinity for audio anyway, but it's probably similar to when people say 'I can't draw' and I never believe them.

There are some amazing sound support packages out there but spot effects and music are IMO the most neglected area in ZX Software these days (and I'm at least as guilty as anyone).
0 x

Post Reply