Skip to content

Commit ed333f8

Browse files
committed
rudimentary framework for BEEP audio
1 parent 1c8d259 commit ed333f8

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

CTBASIC.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414

1515
from CTBASIC.rule110 import rule110
16+
from CTBASIC import audio
1617
from CTBASIC import graphics
1718
from CTBASIC.graphics import Graphics
1819

@@ -176,6 +177,8 @@ def compile_(self):
176177
append = parse_fill(line, 0)
177178
elif line.startswith('CLS'):
178179
append += print_(STX + graphics.CLS + ETX)
180+
elif audio.match(line):
181+
append = print_(audio.parse(line))
179182
elif line.startswith('ENDIF'):
180183
pass
181184
elif line.startswith('END'):

CTBASIC/audio.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Very experimental attempt to emulate ZX Spectrum audio
3+
via BEEP and piping terminal output to aplay...
4+
"""
5+
import re
6+
7+
8+
ARGS = re.compile(r'(\.?\d+)\s*,\s*(-?\d+)')
9+
10+
11+
def match(line):
12+
return line.startswith('BEEP')
13+
14+
15+
def parse(line):
16+
duration, pitch = ARGS.search(line[4:]).groups()
17+
duration = float(duration)
18+
pitch = int(pitch)
19+
#print('DEBUG:', duration, pitch)
20+
return 'ccccc\n'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM Taken from Steven Vickers, SINCLAIR ZX SPECTRUM: BASIC Programming.
2+
REM Chapter 19, BEEP example code.
3+
4+
PRINT "Frere Gustav"
5+
BEEP 1,0: BEEP 1,2: BEEP .5,3: BEEP.5,2: BEEP 1,0
6+
BEEP 1,0: BEEP 1,2: BEEP .5,3: BEEP.5,2: BEEP 1,0
7+
BEEP 1,3: BEEP 1,5: BEEP 2,7
8+
BEEP 1,3: BEEP 1,5: BEEP 2,7
9+
BEEP .75,7: BEEP .25,8: BEEP .5,7: BEEP .5,5:BEEP .5,3:
10+
BEEP.5,2: BEEP 1,0
11+
BEEP .75,7: BEEP .25,8: BEEP .5,7: BEEP .5,5: BEEP .5,3: BEEP .5,2:
12+
BEEP 1,0
13+
BEEP 1,0: BEEP 1,-5: BEEP 2,0
14+
BEEP 1,0: BEEP 1,-5: BEEP 2,0
15+
16+
BIN 1
17+
CLEAR 941
18+

0 commit comments

Comments
 (0)