Better music capabilities

Page 8/11
1 | 2 | 3 | 4 | 5 | 6 | 7 | | 9 | 10 | 11

By DarkSchneider

Paladin (944)

DarkSchneider's picture

31-05-2018, 09:04

@Timmy it can be used by regular interrupts. I think you are talking about digital version.

As @yzi says it can produce other kind of sounds. And with a constant sound yes it can be annoying, but what it needs is a melody, combine and vary them. On Atari ST they are part of the trackers intrumentation, they call them "buzzing effect".
Do not underestimate it.


The envelope generator is used to create bass sounds in a variety of ways.

That is the perfect for support in music, right?

Let's do some easy exercise, open BASIC and write:

SOUND 8,15
SOUND 7,254

Now we have a regular PSG sound. Write:

SOUND 7,255
SOUND 11,16
SOUND 12,0
SOUND 13,14
SOUND 8,16

Now the same sound with traingle waveform. Remember that for envelope is /256 instead /16.

SOUND 13,12

Saw form.
Now we can combine them with the square one, in multiple relationship. See that actually they are the same (because the /16 and /256 proportion). So 1:1.

SOUND 13,14
SOUND 7,254

Combined triangle with square 1:1.

SOUND 0,128

Combined triangle with square 1:2 (2 squared inside the triangle period).


Another ratio.

SOUND 13,14

Now combined square with saw...
You can try by your own, here the manual for registers and shapes.

Can even combine in a non-integer ratio, in that case we have some kind of sinusoidal sounds, ascending and descending. Irregular ones. But in this case cannot define "instrument" because the combinations are infinite, so we can only try (unless you have much clear what you are looking for).

Then (stop the sound or you will get mad), simply get the idea that many kind of regular (and even irregular) periodic waveforms can be used as instruments, not only the base square one, in one of the channels.

So, instead the drum (noise) one, plus 2 the same squared ones, we can have instead the melodic one (square) and the support one (envelope). This could allow to add much variety to PSG music composing, and is plenty of possibilities.
And this is for free, it can be used in the regular ISR, no advanced technique required. There is nothing really stopping to use it.

By ro

Scribe (4696)

ro's picture

31-05-2018, 10:20

for the record: I love this topic. Not only because I'm a huge ATARI-ST music addict, I love PSG on MSX as well as programming it Smile

By DarkSchneider

Paladin (944)

DarkSchneider's picture

31-05-2018, 11:20

@Grauw look at this:


The so-called SID effect requires use of a programmable timer interrupt, e.g. like the MFP Timers A,B,C, or D on the Atari ST. Here we use the native squarewave oscillator and additionally program the timer to trigger an interrupt at close to the same frequency of the oscillator. The interrupt service routine then toggles the volume register between zero and the current volume (whatever the volume value in the music player's ADSR envelope). The slight offset between the frequencies causes an effective pulse-width modulation of the square wave, which gives the pleasant movement in the harmonics known as the SID sound.

That means on Atari there is also no phase sync? It could mean that is not required to achieve the desired effect. Is there much difference if simply applying the level variations on the line interrupts at 300Hz not looking for exact phase match? It probably will sound similar to what is wanted, simply an harmonic variation.

I.e. the MusicMon works at 200Hz, and it gives good results.

I think it could be more about the ON/OFF variations (at 300Hz there are many possible) than exact phase match related.

Remember that the patterns no need to be VBLANK sized (5 for 60Hz). You can apply patterns ON/OFF of any size, as a regular note usually last more than 16ms. Take the FM modulation as example, set the piano, its modulation is very long, with all its attack, sustain and decay. The same for WPM patterns. You can have something like 1100 0011 1111 1111 0101 1010 to be applied at 300Hz.

You have the VGMPlay so can try some. Can define some patterns of different sizes, and apply to different notes of a music score (a channel), and watch if they sound similar, being different frequencies and at different timmings, so the phase sync is not the same on each note, as you apply the patterns line interrupt based, it should be slighty different on each case.

Note: look at the MusicMon
I'd say the the number at right of the note is the modulation pattern used of the defined ones.

By Metalion

Paragon (1509)

Metalion's picture

31-05-2018, 12:54

DarkSchneider wrote:

Now the same sound with traingle waveform

This is a common misconception : the PSG does NOT generate different waveforms.
It can only generate one type of sound waveform : square.

What everybody is refering to are envelope generators, which are modulating the volume and only the volume. This is completely different than generating a waveform.

By DarkSchneider

Paladin (944)

DarkSchneider's picture

31-05-2018, 13:18

If you disable tone and put volume to 16 (envelope one), it only sounds the envelope. Try it.
Set R0 and 1 to 0. Set R7 to 255 (tone disabled). Set R11 = 32; R12 = 0; R13 = 14 (triangle).
Now let it play: R8 = 16.

You can think, that is combining with the squareform set by R0 and R1 to max freq that is the nearest to constant. Try to set R7 = 254 to enable the tone, it sounds different.

Setting tone to OFF, it is like the square part would be always multiplied by 1 (this is, it does not affect), so it full depends on the envelope, that is like generating that waveform.

Try with the saw too (R13 = 12; remember to disable tone R7 = 255) and tell me that it does not sounds just like here:

By syn

Prophet (2096)

syn's picture

31-05-2018, 13:53

it still generates a squarewave that, due to the hardware envelopes, sounds more like a sawtooth but underneath it all its still a squarewave.

It is not like a SID where you can freely choose the waveform or the nes that has triangle and pwm channels.

By PingPong

Prophet (3887)

PingPong's picture

31-05-2018, 14:23

No . You are wrong. Metallion said the the square wave period is set to infinite. Because the frequency is zero.
In those situations without envelope enabled , the output is a continuos signal .
The role of the envelope is to drive some attenuation cirquit inside the psg.
When you enable envelope the output signal is the result of thd continuos signal MODULATED by the envelope function so the output is a continuos signal modulated by the function signal of the envelope
From the theory of modulation the output is the envelope waveform

By DarkSchneider

Paladin (944)

DarkSchneider's picture

31-05-2018, 16:05

In other words, 2 +2 = 4.

Also remember that the resulting waveform can not match exactly with a pure analog one. The chip works in digital with its internal limitations, so probably the level attenuation steps are limited (could be 16 the same that can be set manually). So we are hearing really something like a 4-bit digitized representation of the waveform.
This is more clear for the triangle one, as it is a perfectly linear ascending and descending, it is more noticeable the lack of precision in the waveform generation. So don't compare directly with pure signals (analog or high precision digital ones). But it is usually this way for all chips.


By hit9918

Prophet (2923)

hit9918's picture

31-05-2018, 16:08

DarkSchneider, on the one hand you say 200hz timer, on the other hand the atari text talks of a variable interrupt
"program the timer to trigger an interrupt at close to the same frequency of the oscillator"
you cannot do this with the MSX line interrupt
aside the atari stuff has been untidy

ok and this is tidy PWM with fixed rate interrupt:

milliseconds            0       5       10      15      20      25      30

200hz interrupt         +       +       +       +       +       +       +
frequency register write        +6.25   +12.5                   +6.25

AY sound                 +---------+___________________+---------+___________________
                           6.25ms        12.5ms          6.25ms        12.5ms

the poke to frequency register can be late
                ;interrupt makes an AY counters simulation to know when another poke is due

interrupt:      ld hl,(counter)
                ld bc,amount of AY counting in the time between two interrupts
                add hl,bc
                ld (counter),hl
                ld bc,(comparator)      ;frequency register
                and a
                sbc hl,bc
                call nc,AYtoneflip       ;no carry: it got >= comparator

AYtoneflip:     ld (counter),hl         ;not resetting to 0 but store back the modolo
                ;load new comparator ld (comparator),hl
                ;and poke it to AY comparator (frequency register)

By syn

Prophet (2096)

syn's picture

31-05-2018, 22:20

I think you guys misunderstand me

PingPong wrote:

In those situations without envelope enabled , the output is a continuos signal .

in this case a continuous signal can only be square wave (or noise but thats not the point).
While nes or sid have more choices BEFORE hardware envelopes are applied.

So yes, the PSG is only a square wave or noise GENERATOR. However, what it can actually do with this simple square wave is, as we all know, far beyond its initial specification Wink

Page 8/11
1 | 2 | 3 | 4 | 5 | 6 | 7 | | 9 | 10 | 11