BEEP

Anything QL Software or Programming Related.
Post Reply
User avatar
Andrew
Aurora
Posts: 796
Joined: Tue Jul 17, 2018 9:10 pm

BEEP

Post by Andrew »

Is there a simple way to convert ZX Spectrum BEEP to QL BEEP?
length is easy to calculate (ZX Spectrum is in seconds, QL's in 72 microseconds increments) but how to convert pitch?


User avatar
Mark Swift
ROM Dongle
Posts: 31
Joined: Fri Jul 18, 2014 9:13 am
Location: Blackpool, Lancs, UK
Contact:

Re: BEEP

Post by Mark Swift »

An interesting problem.
I haven't got a way of testing if the below is right, but here goes...

On the QL:
BEEP <pitch>,<duration>
Gives a frequency approximately equal to 11447/(10.6+<pitch>) Hz and a duration of <duration>*72/1000000 seconds

So: QL_pitch=(11447/freq)-10.6

A quick google shows that on the Spectrum, pitch is given in semitones above middle C (261.63Hz) using negative numbers for notes below middle C.
So Spectrum_pitch 0 = QL_pitch (11447/261.63)-10.6 = 33.15

With each spectrum pitch increment, you multiply the frequency produced by EXP(LN(2)/12)

This means that
QL_pitch = (11447/( 261.63*EXP(LN(2)/12)^Spectrum_pitch ))-10.6
I assume you would have to round the result up or down


User avatar
Andrew
Aurora
Posts: 796
Joined: Tue Jul 17, 2018 9:10 pm

Re: BEEP

Post by Andrew »

Thank you Mark!

I will write a short program to convert a Spectrum Beep melody to Ql and see how it sounds!


User avatar
janbredenbeek
Super Gold Card
Posts: 633
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: BEEP

Post by janbredenbeek »

No easy way, the QL's pitch range is rather limited compared to the Spectrum's.
I've once written a BCSOUND procedure for implementing sound in BASICODE, which uses parameters similar to the Spectrum's, though the pitch is offset by 60 (which is middle-C). The QL's hardware limits the pitch range from 29 to 88 (-31 to 28 in Spectrum pitch) and because of the granularity in pitch steps the sound produced may be slightly out of tune.

Source code is here, it starts at line 999. If you want to try it, LRESPR BCRAM_BIN from the main page.


Exile
ROM Dongle
Posts: 38
Joined: Sat Jan 15, 2022 8:55 pm

Re: BEEP

Post by Exile »

Hi,

When adding the sound code for sQLux I realised that, despite what it says in the manual, the length of sound for a QL is not in units of 72 microseconds, for "simple" Beeps it is about 43.64 microseconds, although the time base can get longer if several of the optional Beep parameters are used. This time is related to 8049 clock rate (22917). I did confirm this by recording and timing Beeps from a BBQL.

https://github.com/SinclairQL/sQLux/blo ... d#56-sound


Post Reply