Beeb ENVELOPE documentation

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
ctr
Posts: 183
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

Beeb ENVELOPE documentation

Post by ctr » Fri Aug 03, 2018 4:02 pm

I was trying to create a simple envelope that alternated between two pitches but it was more trouble than I expected because there are a couple of errors in the BBC User Guide. I ended up using Audacity to look at the sound output to see exactly what was going on. To save anyone else the bother...

The pitch envelope is defined in three sections. For each section you define how many ticks the section lasts and how much the pitch changes on each tick.

According to the user guide, the pitch changes at the end of each tick and the minimum section length is zero.

In reality, the pitch changes at the start of each tick and a section of length zero is treated as a section of length one in which the pitch doesn't change. In particular, if the first section has length zero then the pitch isn't reset at the end of a cycle.

So the alternating pitch envelope is:

Code: Select all

REM Alternate between pitches A% and B%
ENVELOPE2,1,0,B%-A%,0,2,1,1,0,0,0,0,126,126
SOUND2,2,A%,20
It does nothing for two ticks; changes the pitch and waits a tick; and does nothing for the final tick. Then the cycle restarts which resets the pitch.

Alternatively, this can be improved by starting at a pitch below A%, which is never output because the first tick moves the pitch up to A%. (This description assumes A%<B% but it works either way.)

Code: Select all

ENVELOPE2,1,B%-A%,A%-B%,B%-A%,2,1,1,0,0,0,0,126,126
SOUND2,2,2*A%-B%,20
So each of the two pitches only lasts for a single tick.

User avatar
Richard Russell
Posts: 526
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Beeb ENVELOPE documentation

Post by Richard Russell » Fri Aug 03, 2018 5:36 pm

ctr wrote:
Fri Aug 03, 2018 4:02 pm
there are a couple of errors in the BBC User Guide.
I certainly wasn't aware of that, and should anybody care neither BBC BASIC for Windows nor BBC BASIC for SDL 2.0 emulates the behaviour described here. In fact using them it isn't possible to generate, using ENVELOPE, an alternating tone with equal durations. Because the pitch envelope has an odd number of sections you always end up with one tone having twice the duration of the other.

User avatar
ctr
Posts: 183
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

Re: Beeb ENVELOPE documentation

Post by ctr » Fri Aug 03, 2018 5:46 pm

Richard Russell wrote:
Fri Aug 03, 2018 5:36 pm
I certainly wasn't aware of that, and should anybody care neither BBC BASIC for Windows nor BBC BASIC for SDL 2.0 emulates the behaviour described here. In fact using them it isn't possible to generate, using ENVELOPE, an alternating tone with equal durations. Because the pitch envelope has an odd number of sections you always end up with one tone having twice the duration of the other.
Can't you set the length of one of the sections to zero so you effectively have only two sections? It's difficult on a beeb because, contrary to the user guide, the OS doesn't respect a section length of zero.

User avatar
jgharston
Posts: 3246
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Beeb ENVELOPE documentation

Post by jgharston » Fri Aug 03, 2018 7:51 pm

The diagram in the user guide is telling me that you can have two equal sections by making two of the three sections the same length and one of them twice as long, so you get, eg: 1+1+2 which gives you 2+2. It gives an example of a police siren, presumably going WEE wah WEE wah WEE wah.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
Richard Russell
Posts: 526
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Beeb ENVELOPE documentation

Post by Richard Russell » Fri Aug 03, 2018 9:27 pm

ctr wrote:
Fri Aug 03, 2018 5:46 pm
Can't you set the length of one of the sections to zero so you effectively have only two sections? It's difficult on a beeb because, contrary to the user guide, the OS doesn't respect a section length of zero.
The feature whereby a value of zero is treated as one is shared by my BASICs, so no. I thought it was documented somewhere, but even if not it's easy to see from a software perspective why all the implementations have that limitation.
jgharston wrote:
Fri Aug 03, 2018 7:51 pm
The diagram in the user guide is telling me that you can have two equal sections by making two of the three sections the same length and one of them twice as long, so you get, eg: 1+1+2 which gives you 2+2. It gives an example of a police siren, presumably going WEE wah WEE wah WEE wah.
Yes, I can do that in just the same way, but it's not 'alternating between two frequencies' as the OP described.

Richard.

Post Reply