hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 19, 2020 8:50 pm

Yes .... Just Intonation
I have found now , that actually ,
I can be fairly happy with ' quasi '
just intonation I . E .........

Code: Select all

         FOR jn = 1 TO 1024
        nn(jn)=INT(40 + (48*LOG(jn/20)/LOG(2)))
      NEXT jn
    
I can write the piece algorythmically ( even if notes
are somewhat out of tune ) and it sounds O . K .

Again ( out of curiosity )
Why does the note range not go lower ?

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 19, 2020 10:07 pm

hitsware wrote:
Wed Feb 19, 2020 8:50 pm
Why does the note range not go lower ?
I think it's because Acorn decided to use only a single byte (0-255) to represent the pitch, so with quarter-semitone steps you only get just over 5 octaves total range. As to why they chose ¼-semitone steps (rather than, say, half) again I don't know for sure, but I assume it's because they wanted to achieve fairly smooth glissando effects. Designing a cheap home computer in the early 1980s involved an awful lot of compromises.

User avatar
scruss
Posts: 2892
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 19, 2020 11:18 pm

I think Acorn might have been driving the sound hardware quite close to the metal. The SN76489 chip they used could only accept an 8-bit control input, and the input you gave it was the divisor of the chip clock frequency (4 MHz) to get the output tone (give or take an order of magnitude).

There's more on SOUND on the Beeb, plus a silly diversion Experimenting with an Arduino and a SN76489. They are cheap and immensely fun (loud! beepy!) chips to play with.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Thu Feb 20, 2020 12:20 am

scruss wrote:
Wed Feb 19, 2020 11:18 pm
I think Acorn might have been driving the sound hardware quite close to the metal. The SN76489 chip they used could only accept an 8-bit control input, and the input you gave it was the divisor of the chip clock frequency (4 MHz) to get the output tone (give or take an order of magnitude).

There's more on SOUND on the Beeb, plus a silly diversion Experimenting with an Arduino and a SN76489. They are cheap and immensely fun (loud! beepy!) chips to play with.
Reminds me my first P.C. music.
A Commodore Vic-20.
Had 3 8-bit dividers with outputs.
With Vactrols for envelopes,
it was quite nice.
Quite a ways from there to
Sonic Pi : )

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Thu Feb 20, 2020 9:19 am

scruss wrote:
Wed Feb 19, 2020 11:18 pm
The SN76489 chip they used could only accept an 8-bit control input
Its interface to the CPU may well have been an 8-bit port, but the tone 'divisor' registers which determine the final frequency are 10 bits, so there isn't inherently a limit of 256 different notes. However with a clock frequency of 4 MHz the lowest possible output frequency is 122 Hz.

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Thu Feb 20, 2020 10:40 am

hitsware wrote:
Thu Feb 20, 2020 12:20 am
Reminds me my first P.C. music. A Commodore Vic-20. Had 3 8-bit dividers with outputs.
I find it interesting that my own experience with writing tone-generation software completely skipped the 'programmable divider' phase, which was so popular with chip manufacturers and hardware designers in the early days. Programmable dividers have the disadvantage that the frequency resolution is best at the low end of the output range, where you don't need it, and worst at the top end, where you do!

My earliest foray into computer-generated music was my Z80 Music program, which required no hardware other than an 8-bit DAC (and in practice a resistor ladder network on a standard parallel output port sufficed). It generated 4-voice polyphonic music using Direct Digital Synthesis, just by putting the CPU into a tight loop and using the Z80's rather generous (for the day) set of registers for the phase accumulators and so on. I loved pushing the Z80 to its limits!

Using DDS meant that the best frequency resolution was at the high end of the output range, where it is most needed. Counter-intuitively, however, it only really worked well for early Z80s clocked at 2 MHz or so. The faster Z80s, with clock rates up to 6 MHz or more, didn't work well in this application because the output frequency range was pushed higher and I couldn't generate low notes with enough resolution (I could have tried slowing the loop with NOPs but that would have meant different versions of the code for different CPU clocks).

Jump from the 1970s to 2000 when I next needed to generate music in code (for BBC BASIC for Windows) and again Direct Digital Synthesis was the right solution. Indeed the entirely-register-based 80386 code owed a lot to that old Z80 program from 20+ years before, although the much faster CPU and 16-bit registers meant I had more control.

User avatar
scruss
Posts: 2892
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Introduction to BBC BASIC

Thu Feb 20, 2020 2:59 pm

RichardRussell wrote:
Thu Feb 20, 2020 10:40 am
The faster Z80s, with clock rates up to 6 MHz or more, didn't work well in this application …
It would do very badly with my latest acquisition, then: a 36.8 MHz Z180 (it multiplies! it has an MMU!) in a tiny box with micro-sd storage. I have it hanging off a Raspberry Pi as a highly unnecessary CP/M Z80 Second Processor.

The resistor DAC was good enough for the Covox Speech thing and many cheap PC parallel port sound card clones. DDS is the big thing for software radios (SDR): the AD9851 can give you a stable 5 Hz - 30 MHz sine wave for not much money.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Thu Feb 20, 2020 5:24 pm

RichardRussell wrote:
Thu Feb 20, 2020 10:40 am
Programmable dividers have the disadvantage that the frequency resolution is best at the low end of the output range, where you don't need it, and worst at the top end, where you do!
Not such a problem with just intonation ( everything in integers)
AND
You don't care what key you're in .....

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Fri Feb 21, 2020 6:07 pm

Code: Select all

      REM: .... Down on the Island .............

      DIM nn(1024),c(3),m(7),o(3), e(7) ,p(7)
      FOR jn = 1 TO 1024
        nn(jn)=INT(40 + (48*LOG(jn/20)/LOG(2)))
      NEXT jn

      ENVELOPE 1,0,0,0,0,0,0,0,127,-40,0,0,127,0
      ENVELOPE 2,0,0,0,0,0,0,0,090,-40,0,0,090,0
      ENVELOPE 3,0,0,0,0,0,0,0,080,-40,0,0,080,0
      ENVELOPE 4,0,0,0,0,0,0,0,100,-01,0,0,100,0
      ENVELOPE 5,0,0,0,0,0,0,0,080,-10,0,0,080,0
      ENVELOPE 6,0,0,0,0,0,0,0,050,-02,0,0,050,0

      FOR x=0 TO 3: READ o(x): NEXT x
      FOR x=0 TO 3: READ c(x): NEXT x
      FOR x=0 TO 3: READ m(x): NEXT x
      FOR x=0 TO 7: READ e(x): NEXT x
      FOR x=0 TO 3: READ p(x): NEXT x

      REPEAT
        FOR x = 0 TO 3
          SOUND 2,-5,nn(2*c(x)),24
          SOUND 3,-5,nn(3*c(x)),24
          FOR y = 0  TO 3: r=RND(3)
            SOUND 1,p(r),nn(c(x)*m(y)*o(r)),6
            FOR z = 0 TO 1: t = (2*y)+z
              SOUND 0,e(t),4,3
            NEXT z: NEXT y: NEXT x: UNTIL FALSE

      DATA 0,1,2,4
      DATA 8,6,9,6
      DATA 2,4,3,4
      DATA 2,0,3,3,1,0,3,3
      DATA 0,4,5,6


hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 3:38 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      z=1
      FOR x=0 TO 3
        REM:BPUT#A,z
        BPUT#A,x
      NEXT x
      CLOSE#A
      END
The above will write the value of z to the file, but not x ????

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 4:36 pm

hitsware wrote:
Wed Feb 26, 2020 3:38 pm
The above will write the value of z to the file, but not x ????
Sorry, I don't understand. The code you listed creates a file exactly 4 bytes long, with those bytes having the values 0, 1, 2, and 3 respectively; that's precisely what it should do. The only thing about the program that I would consider 'questionable' is that you create a file with a .txt extension, which implies a 'plain text' file, but then you write binary, non-text, data to it! But it's doing what you asked it to do.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 5:49 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR x=0 TO 3
        BPUT#A,x
      NEXT x
      CLOSE#A
      END
This write's nothing to the file
(unless it's something I can't see)

ejolson
Posts: 4465
Joined: Tue Mar 18, 2014 11:47 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 6:19 pm

hitsware wrote:
Wed Feb 26, 2020 5:49 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR x=0 TO 3
        BPUT#A,x
      NEXT x
      CLOSE#A
      END
This write's nothing to the file
(unless it's something I can't see)
That's right. Using binary mode means you can't see it. That's why naming the file bbc.txt seems like a bad idea.

Do you want to write the numbers to the file in a way that you can see them?

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 6:45 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR x=0 TO 3
        z=1
        BPUT#A,z
      NEXT x
      CLOSE#A
      END
This writes to the file
symbols.jpg
symbols.jpg (42.01 KiB) Viewed 520 times
(not the numbers, but symbols (which before has denoted what I want))

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 7:28 pm

hitsware wrote:
Wed Feb 26, 2020 5:49 pm
This write's nothing to the file
What length is the file you created? If it's 4 bytes the program has worked.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 7:59 pm

Code: Select all

z=1
means a variable named z with a value of 1 .... right ?

Code: Select all

FOR x = 0 TO 3
means a variable named x with the values 0,1,2,3 .... right?

BPUT z writes the symbols as above to the file
BPUT x leaves file blank (visually anyways)
likewise

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR i=0 TO 3
        READ z
        BPUT#A,z
      NEXT i
      CLOSE#A
      END
      DATA 0,1,2,3
writes ???? appears blank

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 8:28 pm

hitsware wrote:
Wed Feb 26, 2020 7:59 pm
BPUT x leaves file blank (visually anyways)
We've explained to you that the file contains binary numbers that do not correspond to visible characters. I ask again: what is the length of the file? If it's 4 bytes you can be confident that your program has worked. Don't attempt to view the contents of a binary file, unless you have a utility to show it in hexadecimal or something.

User avatar
scruss
Posts: 2892
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 8:49 pm

xxd is the standard binary file viewer. I just ran this on BBC BASIC for Windows, and then in WSL I can do:

Code: Select all

$ xxd bbc.txt
00000000: 0001 0203                                ....
and it's outputting exactly what you are asking it to do.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 9:18 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR i=0 TO 7
        z=z+1
        FOR i=0 TO 7
          BPUT#A,i
        NEXT i
        CLOSE#A
        END
ONE MORE TIME !
Call me Stupid : (
If I change the ' i ' to ' z ' in the BPUT statement it shows in the file .
As is above , it shows nothing .
I cannot fathom the difference between the i and the z
( RPi version ( if that is germane ) )

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 9:33 pm

hitsware wrote:
Wed Feb 26, 2020 9:18 pm
I cannot fathom the difference between the i and the z
i runs from 0 to 7 whereas z runs from 1 to 8. Bearing in mind that 0 (NUL) is often used as a string terminator I am not at all surprised that one displays something and the other doesn't when you view the file's contents in an inappropriate way.

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 9:38 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR i=0 TO 7
        o=1
        BPUT#A,o
      NEXT i
      CLOSE#A
      END
    
Perhaps ( or not ) more telling :
As above prints ( visually ) to file
IF I change " o=1" to " o=i "
it does not ......

hitsware
Posts: 198
Joined: Sat Mar 26, 2016 10:12 pm
Location: sacramento , california , usa
Contact: Website

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 9:50 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR i=0 TO 3
        READ o
        BPUT#A,o
      NEXT i
      CLOSE#A
      END
      DATA 1,2,3,4   REM: data 1
      DATA 0,1,2,3   REM: data 2
      
O . K ........ data 1 writes ( visually ) ..... data 2 does not

ZXDunny
Posts: 118
Joined: Sun Jul 08, 2012 7:57 pm

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 11:29 pm

hitsware wrote:
Wed Feb 26, 2020 9:50 pm

Code: Select all

      A=OPENOUT"/home/pi/Desktop/bbc.txt"
      FOR i=0 TO 3
        READ o
        BPUT#A,o
      NEXT i
      CLOSE#A
      END
      DATA 1,2,3,4   REM: data 1
      DATA 0,1,2,3   REM: data 2
      
O . K ........ data 1 writes ( visually ) ..... data 2 does not
Well yes, that's exactly what you told the program to do.

FOR i=0 to 3 ; is four loops round. data 1 contains four values. After the four values are READ and written, the program ends. Data 2 is never used.

User avatar
RichardRussell
Posts: 619
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed Feb 26, 2020 11:56 pm

hitsware wrote:
Wed Feb 26, 2020 9:50 pm
O . K ........ data 1 writes ( visually ) ..... data 2 does not
The characters you are writing to the file are, according to their traditional ASCII mnemonics, NUL, SOH, STX, ETX and EOT. They are 'control characters', they do not have a "visual" representation. Your insistence on 'viewing' the contents of the file using an inappropriate tool is the fault here, not BBC BASIC.

There are a number of ways in which you could have easily verified the contents of the file. You could have checked its length, you could have used a binary file viewer, you could have written a simple program to read the file and print its contents. But you didn't. :roll:

User avatar
rpdom
Posts: 16338
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Introduction to BBC BASIC

Thu Feb 27, 2020 6:11 am

RichardRussell wrote:
Wed Feb 26, 2020 11:56 pm
you could have used a binary file viewer
I tend to use hexdump, which is included in Raspbian. With the "-C" option it produces output similar to the various Dump utilities on the BBC Micro :)

Code: Select all

[email protected]:/tmp $ hexdump -C file1
00000000  01 02 03 04                                       |....|
00000004
[email protected]:/tmp $ hexdump -C file2
00000000  00 01 02 03                                       |....|
00000004

Return to “Other programming languages”