Skip to content

Commit

Permalink
Added --stretch parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
haerfest committed Mar 15, 2020
1 parent 31529ed commit 9060ca8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ your Acorn.
You can read the [UEF specification](http://electrem.emuunlim.com/UEFSpecs.htm)
one.

There is a `--stretch` command-line parameter by which you can stretch the
duration of carrier tones. The specification states that a carrier tone is one
fast cycle, repeated the number of cycles as specified in the UEF file.

However, for some software this seems to be too short, and you can stretch
the number of cycles by this factor. For instance, `--stretch 2` makes every
carrier tone last for twice as long as specified in the UEF.

### Supported chunks

The following UEF chunks are supported:
Expand Down
33 changes: 28 additions & 5 deletions uef2wave.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

from argparse import ArgumentParser
from functools import reduce
from math import pi, radians, sin
from operator import xor
from struct import pack, unpack
from math import pi, radians, sin
from operator import xor
from struct import pack, unpack

import gzip
import io
Expand All @@ -12,6 +13,21 @@
import zipfile


args = None


def parse_args():
parser = ArgumentParser()
parser.add_argument('-s', '--stretch', metavar='FACTOR', type=int,
help='stretch carrier tone duration (default: 1)',
default=1)
args = parser.parse_args()

args.stretch = max(1, args.stretch)

return args


def open_zip(file):
if not zipfile.is_zipfile(file):
file.seek(0)
Expand Down Expand Up @@ -116,7 +132,7 @@ def wave(x):

elif identifier == 0x110: # Carrier tone.
cycles = unpack('<H', chunk)[0]
data.write(wave(1) * cycles) # Note: spec says wave('FC').
data.write(wave('FC') * cycles * args.stretch)

elif identifier == 0x111: # Carrier tone with dummy byte.
n, m = unpack('<HH', chunk)
Expand Down Expand Up @@ -179,4 +195,11 @@ def write_wav(data, stream):
stream.write(data)


write_wav(read_chunks(sys.stdin.buffer), sys.stdout.buffer)
def main():
global args
args = parse_args()
write_wav(read_chunks(sys.stdin.buffer), sys.stdout.buffer)


if __name__ == '__main__':
main()

0 comments on commit 9060ca8

Please sign in to comment.