Waveform Generator

Here you can link to screenshots and demos etc. of programs made using BBC BASIC
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Waveform Generator

Post by Richard Russell »

DDRM wrote: Tue 28 Jan 2025, 09:57 Hmm. My version of arraylib doesn't include a PROC_arrayslice! Is it out of date (says version 2.2, 2019)?
PROC_arrayslice was added to arraylib in BBCSDL version 1.39a, release details are here. The current version is 1.40a.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Waveform Generator

Post by Richard Russell »

Richard Russell wrote: Tue 28 Jan 2025, 10:07 PROC_arrayslice was added to arraylib in BBCSDL version 1.39a
In case it's of interest, here's a version of the sawtooth program which uses PROC_pcopy instead of PROC_arrayslice; this may improve its compatibility (PROC_pcopy was added in BBCSDL 1.37a), but at the cost of running a little more slowly:

Code: Select all

      REM Synthesise a sawtooth waveform from its Fourier series
      REM By Richard Russell, inspired by a program by MrHiggins

      MODE 8
      INSTALL @lib$ + "arraylib"
      DIM a(320 * 640), s(639), t(639)

      REM Construct harmonics up to Nyquist limit:
      P% = 0
      FOR H% = 0 TO 319
        FOR I% = -320 TO 319
          a(P%) = SIN(2 * PI * H% * I% / 640)
          P% += 1
        NEXT
      NEXT H%

      REM Build sawtooth from Fourier series:
      *REFRESH OFF
      FOR H% = 1 TO 319
        CLS
        PROC_pcopy(a(), t(), 0, H% * 640, 640)
        a = (-1) ^ H%
        t() *= a / H%
        s() += t()
        FOR I% = 0 TO 639
          GCOL 15
          PLOT I% * 2, t(I%) * 300 + 512
          GCOL 9
          PLOT I% * 2, s(I%) * 300 + 512
        NEXT
        *REFRESH
      NEXT H%
      *REFRESH ON
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Waveform Generator

Post by Richard Russell »

Richard Russell wrote: Tue 28 Jan 2025, 15:01 at the cost of running a little more slowly:
I did a speed comparison (with the 'wait for vsync' removed):

PROC_arrayslice (BBCSDL): 0.73 seconds
PROC_pcopy (BBCSDL): 0.73 seconds
PROC_pcopy (BB4W): 12.5 seconds

Plotting dominates the time, so PROC_pcopy being slower than PROC_arrayslice made no significant difference to the overall duration. However, BB4W was about 17-times slower than BBCSDL! 8-)

(Incidentally neither Repton nor DDRM seems to have seen my replies. I'm guessing this is probably because they have both added me to their Foes list, which blocks notifications and hides messages).
DDRM
Posts: 14
Joined: Mon 17 Jun 2024, 08:02

Re: Waveform Generator

Post by DDRM »

Hi Richard,

Of course I haven't added you to a foes list! And I have seen your response, and noted that I need to update my version of BBC-SDL. Is an updated library available for BB4W, and/or will the updated SDL version work in BB4W?

Currently mainly working in R... :-(

Best wishes,

D
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Waveform Generator

Post by Richard Russell »

DDRM wrote: Fri 31 Jan 2025, 09:05 will the updated SDL version work in BB4W?
No, it depends on changes to the core interpreter. You could copy PROC_pcopy() into your BB4W program, but what would be the point? I've already noted that the code runs about 17-times more slowly in BB4W so it makes much more sense to run it in BBCSDL.

Although I have no plans to discontinue, or to remove support for, BB4W it is reliant on Windows continuing to run 32-bit apps (and updates not breaking it). Windows is just about the only major OS which hasn't fully migrated to 64-bits.

I've discussed extensively what would be involved in accessing the Windows GUI (native dialogue boxes etc.) from BBCSDL, and have suggested that libraries to support this be developed so that there's an alternative if BB4W does stop working. It's not my fault that nobody has (yet) done so!