626

(20 replies, posted in Sinclair)

Ah, yes, I made a last minute change and probably forgot to update main.asm in the repo. Thanks for reporting, will fix asap. Edit: done.

The "-is" suffix is indeed for sharps, forgot to mention that as well. (German notation, hehe) Using an actual # char would break pasmo, so we'll have to live with "-is" I guess. Originally I had "h" instead of "b" as well yikes

Anyway, thanks for the cheers wink

Btw fancy website for MDAL: https://utz82.github.io/MDAL
Not much content in the wiki yet, will be filling that in in the coming days.

627

(20 replies, posted in Sinclair)

Good news everyone, BetaPhase is the first engine to get Music Data Abstraction Language (MDAL) support! (If you missed the discussion about MDAL, read up on it here.

I haven't written much documentation yet, but usage should be pretty straightforward. Check out docs/betaphase.txt and examples/betaphase-demo.mdal. Some general notes:

- Unlike standard music markup languages like MML or ABC, the notation in MDAL is row-based, just like you would do it in a tracker.
- If you don't want to change anything in a given row, you can use the dot command (.) to specify just that.
- Pattern names must be lowercase.
- Specifying a loop point in the sequence is optional (will be set to sequence start if not specified).

MDAL is still in very early beta stage, I'm expecting it'll have tons of bugs at this stage. Let me know if you find any.
Most notably, there are two problems at the moment:
1) Mixing of strings and bit flags is not yet supported. In case of BetaPhase, that means that upward slides cannot be used in conjunction with note names, so you'd have to supply a note divider instead (see pattern1b in betaphase-demo.mdal)
2) There's no support for global constants yet, so MDAL will fall back to internal defaults in some cases (for example, speed is reset at the beginning of every pattern)

source:

git clone https://github.com/utz82/MDAL.git

win32 build


In the meantime, I've found a way to generate noise in BetaPhase, but I haven't updated the engine yet. Stay tuned. Meanwhile, a new, crappy demo tune, produced by the MDAL converter:

Yippee, FloppusMaximus has fixed tilem2! Latest version is available via

svn checkout https://tilem.svn.sourceforge.net/svnroot/tilem/trunk tilem

Edit: win32 version: http://tilem.sourceforge.net/beta/tilem … 161022.exe

Hehehe, yes.
Anyway, let's continue this discussion here, if you like.

630

(20 replies, posted in Sinclair)

In continuation of this discussion, I wrote a new experimental engine based on Shiru's concepts. It's called BetaPhase because, uh, it's unfinished and probably will be in eternal beta status. It's intended more as a test-case rather than something you'd actually use for music production.

The engine may not sound all that impressive, it's more about the magic that's happening code-wise. Anyway, on the front end we've got 2 "simplified" Phaser channels, and one regular square wave channel with fixed 50% duty that can do slides. Phase offset is used to change the duty of the Phaser channels.

Special code features used:
- no use of duty threshold comparison trick (which was my self-set challenge for this engine), phase determines duty
- fast counter updates with 13-bit frequency resolution (bit 12 of the counter determines output state)
- and a little addition to the code discussed earlier: scalers. (zilogat0r proposed those a while back, but I think that's not quite what he meant big_smile)

   add hl,bc
   ex de,hl
   nop            ;swap with adc hl,bc for duty modulation
   add hl,bc
   ex de,hl
   ld a,h
   nop          ;pre-scaler, modified with rlca/rrca
   xor d
   nop          ;post-scaler, as above
   out (#fe),a

The prescaler can be heard on the bassline in test.tap, and briefly on the arpeggios as well. The post-scaler actually seems unnecessary, 12-bit frequency resolution is sufficient to reach low notes without detuning too much. So it might be more interesting to have two pre-scalers instead.
Also, duty modulation with adc hl,bc is very ineffective, so I might consider removing it. However, modifying it with inc bc is too fast and sounds unpleasant. Still need to find a solution for this. Also, some way to create noise would be nice. So, as I said, the engine is currently quite unfinished.

Anyway, source for the engine is here, feel free to play around with it.

Edit: Counting bits... it's hard, lol. Of course bit 12 of the counter determines the output state, not bit 11. Hence, we've actually got 13-bit frequency resolution. Better than AY wink

Cheers garvalf, take your time. I'll probably be working some more on ht2 in the coming days, so there'll be more crap betas wink
The 5xx/7xx bug turned out to be a phantom bug, caused by faulty z80 emulation. Everything works as intended on hardware, and also the new pitch slides work indeed much better (slower) than tilem2 suggests.

   ld hl,0
   ld de,#8000
   ld bc,#7
    
loop
   add hl,bc
   ex de,hl
   adc hl,bc    ;nice switch for toggling duty mod on/off
   ex de,hl
   ld a,h
   xor d
   out (#fe),a
   jr loop

19 byte 48K Spectrum intro xD

Hmm... so it basically does the "SID sound" thing, but at a different rate. Very interesting idea, looks unassuming but has a lot of potential.
Would be an interesting challenge to write a pulse interleaving engine that doesn't use the "compare counter hi-byte against duty threshold" method.

- 9xx is back (sounds slightly different and no longer disables 3xx)
- 6xx has a new additional parameter: enable ch3 grind effect when xx > 0x80
- Axx is now ch3 phase offset (can be used as primitive volume control in conjunction with a second channel playing the same note)
- old A0x is removed (A01 was redundant anyway since it can be set via 4xx, A02 might come back later)
- note tables are tuned correctly again
- channel volumes are rebalanced

EDIT: Seems I've broken the 5xx duty sweep and 7xx effects somehow. Stay tuned for updates.

Reworked the ch3 pitch slides today. The new systems runs slower (updates synced to main osc), so slides should be slightly more useful now. It doesn't make a huge difference, but it was quite a piece of work. Didn't think I would ever make such drastic changes to the player code at this point, but here we are. Some new possibilities have opened up as well, not sure yet what I'm going to do with all those free t-states that suddenly appeared tongue

Anyway, for the time being, the note table is out of tune again, sorry. Also, 9xx is disabled for the time being, and channel volume balance is pretty awful right now.

If anyone is feeling adventurous, there's a new beta on github.
New stuff in this version:

- Note table is now tuned to 440 Hz. (This means note A is no longer suited for ch1 noise mode, but there are a couple of other viable options instead.)
- Duty Sweep (5xx, xx > 0x80) is now configurable, ie. xx acts as a speed parameter (581 to get the old behaviour)
- Auto Chord (7xx) now has a "sync" mode (set xx > 0x80), enhances octave harmonics
- a minor drawback, 5xx and 7xx now share a common parameter, meaning they will impact each other in some circumstances

Beware that since this is a beta build, stuff may change without notice, and there's no ht2util support.

Good point. I still haven't found a useful application for this, though.
What I came up with some time ago was this:

   ld bc,DIVIDER     ;DIVIDER < #1000
   ld hl,0
   ld de,!0
loop
   add hl,bc
   ex de,hl
   add hl,bc
   ex de,hl
   ld a,h
   xor d
   out (#fe),a
   ...

It's obviously pretty fast, and 12-bit resolution more or less does the job. But as such, it's still seems quite a waste. I wonder if something more useful can be derived from it.

Part 11: Sound Tricks - Noise, Phasing, SID Sound, Earth Shaker, Duty Modulation

Digital/PCM sound is a powerful and flexible tool, but unfortunately it tends to consume a lot of RAM. So in this part of the tutorial, let's go back to the good old Pulse Interleaving technique, and talk about various tricks that can be used to spice up its sound.


Noise

Historically speaking, 1-bit routines have always been lacking in terms of percussive effects. However, converting a tone generator into a simple noise generator is surprisingly simple, and costs a mere 8 cycles on Z80-based systems. Consider the usual way we generate square wave tones:

   add hl,de           ;add base frequency divider (DE) to channel accumulator (HL)
   ld a,h              ;grab hi-byte of channel accumulator
   cp DUTY             ;compare against duty threshold value
   sbc a,a             ;set A to 0 or 0xFF depending on result
   out (#fe),a         ;output A to beeper port

Now, in order to generate noise instead of tones, one would obviously need to randomize the value held by the channel accumulator. But pseudo-random number generators are slow, so how do we do it? The answer is to simply reduce the quality of the PRNG as much as possible. Believe it or not, adding a single

   rlc h

after the add hl,de operation will provide enough entropy to create a convincing illusion of white noise. But it will do so only if it is fed a suitable
frequency divider as a seed. I usually use a fixed value of 0x2174 in my routines. Other values are possible of course, and may give slightly different results, though most values will just generate nasty glitch sounds instead of noise.

There's a nice side effect that you get for free - you can create the illusion of controlling the volume of the noise by changing the duty threshold. Changing the pitch of the noise however is much more difficult, and requires the use of additional counters. I'm still looking for an efficient way of doing it, if you have any ideas please let me know.

Last note, you can of course also rotate the hi-byte of frequency divider instead of the accu. The result of that however is almost guaranteed to be a glitch sound rather than noise.


Phasing

The Phasing technique was developed by Shiru, and is used to generate the signature sound of his Phaser1-3 engines. It comes at a rather heavy cost in terms of cycle count and register usage, but it's power and flexibility undoubtedly outweigh those drawbacks.

For regular tone generation, we use a single oscillator to generate the square wave (represented by the add hl,de operation). The main idea of Phasing, on the other hand, is to use two oscillators, and mix their outputs into a single signal. The mixing can be done via a binary XOR of the two oscillator outputs (the method used in Phaser1), or via a binary OR or AND (added in Phaser2/3).

   add hl,de           ;OSC 1: add base freq divider (DE) to channel accu (HL) as usual
   ld a,h              ;grab hi-byte of channel accumulator
   cp DUTY1            ;compare against duty threshold value
   sbc a,a             ;set A to 0 or 0xFF depending on result
   ld b,a              ;preserve result in B
   
   exx                 ;shadow register set, yay
   add hl,de           ;OSC 2: exactly the same operation as above
   ld a,h              ;grab hi-byte of channel accumulator
   cp DUTY2            ;compare against duty threshold value
   sbc a,a             ;set A to 0 or 0xFF depending on result
   exx                 ;back to primary register set
   
   xor b               ;combine output of OSC 1 and 2. (xor|or|and)
   out (#fe),a         ;output A to beeper port

As you can see, this method offers a wide range of parameters that affect timbre. The most important one, from which the technique derives its name, is the phase offset between the two oscillators. To make use of this feature, simply initialize the OSC1 accu to another value than the initial value of the OSC2 accu, eg. initialize HL to 0 and HL' to a non-zero value. Especially in conjunction with a slight offset between the OSC1 and OSC2 base dividers, some surprisingly complex timbres can be produced.

Side note: By using a binary OR to mix the signal and keeping the duty thresholds down to a reasonable level, the two oscillators can be used as independant tone generators. This method is used to mix channels in Squeeker and derived engines.


SID Sound

This effect, which derives its name from the key sound that can be heard in many of the early SID tunes, is formed by a simple duty cycle sweep. The velocity of the sweep is in sync with the frequency of the tone generator. Basically, every time the channel accumulator overflows, the duty threshold is increased or decreased. As with noise, this is trivial to pull off and costs only a few cycles. Using the standard tone generation procedure, we can implement it as follows

   add hl,de           ;add base frequency divider (DE) to channel accumulator (HL)
   sbc a,a             ;set A to 0 or 0xFF depending on result
   add a,c             ;add duty threshold (C)
   ld c,a              ;update duty threshold value (C = C - 1 if add hl,de carried)
   cp h                ;compare duty threshold value against hi-byte of channel accu
   sbc a,a             ;set A to 0 or 0xFF depending on result
   out (#fe),a         ;output A

As you can see, this operation costs a mere 4 cycles compared to the standard procedure without duty cycle sweep.


Earth Shaker

This effect is named after the game Earth Shaker, which used a rather unusual sound routine with two semi-independant tone channels, written by Michael Batty. As an actual method of generating multi-channel sound, it is of limited practicality, but it can be applied as an effect to regular Pulse Interleaving at a minimal cost. The core concept here is to continually modulate the duty threshold within the sound loop. Depending on the ratio of the duty cycle change vs the oscillator speed, the result can be a nice chord, phatness, or - in most cases - gruesome disharmony that will strike fear in the hearts of even the most accustomed 1-bit connaisseurs. A simple implementation, as used in HoustonTracker 2 for example, looks like this:

   add hl,de           ;add base frequency divider (DE) to channel accumulator (HL)
   ld a,c              ;load duty threshold (C)
   add a,DUTY_MOD      ;add duty threshold modifier
   ld c,a              ;store new duty threshold
   cp h                ;compare duty threshold value against hi-byte of channel accu
   sbc a,a             ;set A to 0 or 0xFF depending on result
   out (#fe),a         ;output A to beeper port

Duty Modulation

The aforementioned SID sound and Earth Shaker effects are actually basic implementations of a family of effects that may best be described as "Duty Modulation". As a first step into the world of Duty Modulation, let's take the Earth Shaker effect and modify it to change the duty threshold in sync with the main oscillator.

   add hl,de           ;add base frequency divider (DE) to channel accumulator (HL)
   sbc a,a             ;set A to 0 or 0xFF depending on result
   and DUTY_MOD        ;set A to 0 or DUTY_MOD
   xor c               ;XOR with current duty threshold (C)
   ld c,a              ;store new duty threshold
   cp h                ;compare duty threshold value against hi-byte of channel accu
   sbc a,a             ;set A to 0 or 0xFF depending on result
   out (#fe),a         ;output A to beeper port

By syncing the modulation in this way, the nasty glitches of the Earth Shaker effect can be avoided entirely (but also, no chords will be produced). Instead, we can now control harmonic components that share an octave relation with the base note. In other words, we can amplify over- and undertones at will, as long as they are a multiple of 12 half-tones away from the main note.


Things can be pushed even further by decoupling the sync and using a second oscillator to time the duty threshold updates.

   exx
   add hl,de           ;independant oscillator for timed duty threshold updates
   exx
   sbc a,a             ;set A to 0 or 0xFF depending on result
   and DUTY_MOD        ;set A to 0 or DUTY_MOD
   xor c               ;XOR with current duty threshold (C)
   ld c,a              ;store new duty threshold
   
   add hl,de           ;add base frequency divider (DE) to channel accumulator (HL)
   cp h                ;compare duty threshold value against hi-byte of channel accu
   sbc a,a             ;set A to 0 or 0xFF depending on result
   out (#fe),a         ;output A to beeper port

This way, we can create the octave effects from the previous example (by setting the "duty" oscillator to the same value as the main tone oscillator), as well as Earth Shaker style chords, while also gaining better control over the latter. Additionally, some interesting slow-running timbre changes can be achieved by setting the duty oscillator to a frequency near (but not equal to) the main oscillator.

The usefulness of this approach might seem a bit questionable considering the hefty cost in CPU cycles and register usage. However, the required code is almost the same as the one used for the Phasing technique, so with a tiny amount of self-modifying code, it can be implemented in a Phaser style engine at virtually no extra cost.

There's also an added bonus when combining this technique with the noise generator explained above. By setting the duty threshold to the same value as the duty modifier, the duty oscillator can be used as a tone generator, meaning you can actually mix noise and tone on the same channel!

That's all for this time. If you know of any other cool tricks please post them here!

The master of Savage engine strikes again! Thanks for digging this up, Tufty.

xxl, demo itself appears to be one-file, so it should be possible to rip .bin from emulator.

640

(5 replies, posted in Sinclair)

Cheers wink The demo doesn't really show the flexibility of this thing, I just picked one setting for the phaser channel that I really liked, and ch1 is running in standard SID mode. But actually, you can do all kinds of weird shit with it big_smile Hmm, I wonder how it would sound with some filters and volume envelopes on top... well, another time, maybe.

641

(5 replies, posted in Sinclair)

Surprise! Was a bit bored today...

PhaserX is an experimental 2-channel beeper engine for the ZX Spectrum. It uses
a new type of effect called "duty modulation". As the name suggests, this effect
modulates the duty cycle setting over time. Its operating speed is synced to the
affected tone generator, so despite the similarities with the tone generation in
engines like Earth Shaker, it does not affect pitch.

Each of the two tone channels has a different set of effects. Channel 1 produces
a simple square wave. In addition to the aforementioned duty modulation, it
features a SID-like duty cycle sweep effect, and can generate pseudo-white noise
instead of square waves.

Channel 2 uses two oscillators to produce Phaser-style sound. Each of the 
oscillators can have it's own duty modulation settings. This allows for very
complex timbres. Oscillator frequencies can of course be configured 
independantly, and can run at different phases. The channel mixer supports XOR
(Phaser1 standard), OR, and AND mixing methods. When using the OR method, the
oscillators can be decoupled and used as 2 independant channels, Squeeker style.

Credits go to Shiru for inventing the original Phaser effect.

No XM converter obviously, and no mp3 render either for the time being.
Source is on my github, as usual.

I also made a 3-channel core with this effect (Tritone style, no phaser fx), but I don't have time/motivation to finish it atm. Might try to squeeze a few more cycles from that one so I can add it to beepertoy. Or maybe I'll add it to this engine, got an unused flag bit which could be used for switching cores on the fly. Not sure yet.

642

(21 replies, posted in Sinclair)

A quick update on this: Just got the parser to output it's first blob of correct asm data. Unfortunately today is the last day I can work on it for the forseeable future, but I'm glad I got this far. There's still tons of functionality missing, and the code would probably give any self-respecting programmer a heart attack at this point. So long story short, there probably won't be any public release till beginning of 2017.

In the meantime, here's a little preview, to give you an idea how the thing works (it has a name now, too, btw - MDAL aka Music Data Abstraction Language).

The input music file looks like this:

CONFIG=PhaseSqueek

:SEQUENCE
    intro
    pattern0
    [loop]
    pattern0
    pattern2
    
:intro
    A=a1, B=c3, C=e3, GMIX=or, MIXAB=or, MIXCD=or, SPD=$8
    .
    A=a2
    .
    A=a3
    .
    A=a2, C=0
    .

:pattern0
    .

:pattern2
    .

which gives us this:

    dw intro
    dw pattern0
loop
    dw pattern0
    dw pattern2
    dw 0

intro

    dw #b000, fx0, #b000, a1, c3, #4040, #c6, #c6, #0, #b000, e3, #0, #4040, #0, #800
    dw #b085, #800
    dw #b001, #b0c4, a2, #0, #800
    dw #b085, #800
    dw #b001, #b0c4, a3, #0, #800
    dw #b085, #800
    dw #b001, #b0c4, a2, #0, #b0c0, #0, #0, #800
    dw #b085, #800
    db #40

pattern0

    dw #b085, #800
    db #40

pattern2

    dw #b085, #800
    db #40

based on this config:

MDAL_VERSION(0)
USE_SEQUENCE;
USE_PATTERNS;

WORD_DIRECTIVE("dw");
BYTE_DIRECTIVE("db");
HEX_PREFIX("#");


CFG_SEQUENCE {
    USE_END("dw 0");
    USE_LOOP(LABEL, "loop");
    USE_TRACKS(1);
}

CFG_PATTERNS {
    USE_END("db #40");
}
    
CFG_COMMANDS {
                
    WORD("FX","fx0");    
    WORD("A", 0, USE_LAST_SET|USE_RESTS(0));
    WORD("B", 0, USE_LAST_SET|USE_RESTS(0));
    BYTE("DA", $40, USE_LAST_SET);    
    BYTE("DB", $40, USE_LAST_SET);    
    BYTE("SIDA", $c6, USE_LAST_SET|FORCE_SUBSTITUTION("off"=$c6, "on"=$ce));
    BYTE("SIDB", $c6, USE_LAST_SET|FORCE_SUBSTITUTION("off "=$c6, "on"=$ce));
    BYTE("ESA", 0, USE_LAST_SET);
    BYTE("ESB", 0, USE_LAST_SET);
    WORD("PAB", 0, USE_LAST_SET);
    WORD("C", 0, USE_LAST_SET|USE_RESTS(0));
    WORD("D", 0, USE_LAST_SET|USE_RESTS(0));
    BYTE("DC", $40, USE_LAST_SET);
    BYTE("DD", $40, USE_LAST_SET);
    BOOL("NC", false, USE_LAST_SET|FORCE_SUBSTITUTION("off"=false, "on"=true));
    WORD("PCD", 0, USE_LAST_SET);
    
    BYTE("DRUM", 0, FORCE_SUBSTITUTION("kick"=$40, "hat"=$80));
    BYTE("GMIX", $b0, FORCE_REPEAT|FORCE_SUBSTITUTION("or"=$b0, "xor"=$a8, "and"=$a0));
    BYTE("MIXAB", $b0, USE_LAST_SET|FORCE_SUBSTITUTION("or"=$b0, "xor"=$a8, "and"=$a0));
    BYTE("MIXCD", $b0, USE_LAST_SET|FORCE_SUBSTITUTION("or"=$b0, "xor"=$a8, "and"=$a0));
    BYTE("GSPD", $10, GLOBAL_CONST);
    BYTE("SPD", $10, FORCE_REPEAT);
}
    
    
CFG_FIELDS {
    WORD(0, REQUIRED(), SET_IF(!(FX&A&B&DA&DB&SIDA&SIDB&ESA&ESB&PAB&C&D&DC&DD&NC&PCD&MIXAB&MIXCD), 4), SET_IF(!FX, 1), SET_IF(!(A&B&DA&DB&SIDA&SIDB&ESA&ESB&PAB&MIXAB), $80), SET_HI(GMIX));
    WORD("fx0", SET(FX));
    WORD(0, REQUIRED(A|B|DA|DB|SIDA|SIDB|ESA|ESB|PAB|MIXAB), SET_IF(!(A&B), 1), SET_IF(!(SIDA&SIDB&ESA&ESB), 4), SET_IF(!DA&DB, $40), SET_IF(!PAB, $80), SET_HI(MIXAB));
    WORD(1, REQUIRED(B), SET(A));
    WORD(2, REQUIRED(A), SET(B));
    WORD($4040, SET_HI(DA), SET_LO(DB));
    WORD($00c6, SET_HI(ESA), SET_LO(SIDA));
    WORD($00c6, SET_HI(ESB), SET_LO(SIDB));
    WORD(3, SET(PAB));
    WORD(4, REQUIRED(C|D|DC|DD|NC|PCD|MIXCD), SET_IF(!(C&D), 1), SET_IF(!(DC&DD), $40), SET_IF(!PCD, $80), SET_HI(MIXCD));
    WORD(5, REQUIRED(D), SET(C));
    WORD(6, REQUIRED(C), SET(D));
    WORD($4040, SET_HI(DC), SET_LO(DD));
    WORD(7, SET(PCD));    
    WORD($1000, REQUIRED(), SET_HI(SPD), SET_LO(DRUM));

    REQUIRE_SEQ_BEGIN();    
}

Guess what, it's time for a new version! HT2.20 comes with new effects, improved speed control, and a savestate manager utility for importing tracks from older versions. Full list of changes can be found in the OP.

Tutorial vid demonstrating some of the new fx: https://www.youtube.com/watch?v=bBXjOJTFe5k
New demo track: https://soundcloud.com/irrlicht-project/hrd-4-da-money

download HT2.20

644

(130 replies, posted in Sinclair)

Cheers guys, I also think all the tracks were pretty damn good. Also, great to see a new face in the compo.

To my shame I have to admit I didn't recognize the engine used for Road Song yikes Modded Tritone, you say? Interesting, I presume you had a hand in this, introspec?

645

(20 replies, posted in Sinclair)

Reverted the fix and applied another one, which seems to be working. Latest fix is on github now.

646

(3 replies, posted in Sinclair)

Horray, it's officially out! And my copy of the CD is sitting proudly on top of the stereo smile

647

(20 replies, posted in Sinclair)

Ok, found it. It's a bug in Squeeker Plus itself, rather than the converter.
What's happening is that in order to prevent ch4 from being left in a permanent "high" state after applying the slide effect (ie. counter hi byte + duty > 0xff, which would cause channel overload), the channel counter is reset on every tick. That's fine for higher notes, but it's deadly for bass notes.
I've applied a little temp fix for this, but I'm not entirely happy with that solution yet. I've pushed the changes to github for now, though.

Btw, something I forgot to mention regarding detune - contrary to standard XM behaviour, it is only effective in conjunction with a note trigger, and will live till the end of a note rather than the end of a row.

648

(20 replies, posted in Sinclair)

Seems I've introduced another bug with the latest changes. Under some circumstances ch4 appears to not generate the correct note frequencies. It only happens sometimes, haven't quite figured out why. Let me know if you encounter this bug as well.

649

(20 replies, posted in Sinclair)

I agree, the other way around would be more logical. But it would also be much more complicated to detect in the converter, so for the time being I can't be arsed. I've (hopefully) fixed the detune though.

650

(20 replies, posted in Sinclair)

Thanks mate. I've made a new commit, hopefully this should fix the issue. There might be more horrors lurking in the abyss of xmkit though.