Author Topic: HuSound  (Read 3722 times)

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: HuSound
« Reply #75 on: November 10, 2015, 11:39:23 AM »
I was reading the manual.. how do you do volume and vibrato envelopes?

TailChao

  • Full Member
  • ***
  • Posts: 156
Re: HuSound
« Reply #76 on: November 10, 2015, 01:34:39 PM »
I was reading the manual.. how do you do volume and vibrato envelopes?
All control over an instrument's envelope is done through its macro script. If you look at ./HuListen/SASS/Instruments.txt in the library download or ./Instruments.txt in the Secret SASS download you can see the basic instrument set I've used for most of the test songs and covers.

The big learning curve is that everything in SASS is a script, there are no predefined envelopes. So you're free to do ADSRAR or whatever you want instead of just ADSR.

The first instrument is actually a good example of a volume envelope among other things.
Let's walk through it :
Code: [Select]
CasioTrumpet
; Approximation of Earthbound / Mother's Trumpets.
; Uses the same waveform as the CasioTone instrument, but has
; a much slower attack phase giving it a brass / wind quality.
;-----------------------
{
wave 0,4,12,24,28,29,28,24,12,8,4,3,2,2,1,1 0,2,6,12,14,15,14,12,6,4,2,2,1,1,0,0
frequency 6 -1
volume 20 2
tuning 16.0
{
rest 4
volume 30 -1
rest 2
frequency 0
volume 28 -2
rest 2
volume 22 0.113
loop -1
wait 9
volume 26 -0.113
wait 9
volume 22 0.113
endloop
noteoff
volume 24 -1
wait 18
end
}
}

The parameters inside the first set of curlybraces right after the instrument name are the initial settings. I set the waveform and initial envelope operations here. We're interested in the latter, which are :
Code: [Select]
frequency 6 -1
volume 20 2
...
The first line (frequency 6 -1) sets the instrument's frequency offset, and how that will change over time. When an instrument is played, its final frequency is the sum of its current note, any active pitch bends, and this offset value. We're setting this to 6, which increases the divider value and gives us a lower frequency. The second parameter of -1 indicates how the frequency offset will change over time. In this case it decreases by 1 per tick. So the pitch of the instrument is increasing.
The next line (volume 20 2) does the same, except for amplitude. We set an initial volume of 20 (out of 31), and will add 2 to it each driver tick. So we're getting louder.

That's our attack phase.

Continuing onward :
Code: [Select]
{
rest 4
volume 30 -1
...
We've hit a rest command, whose argument indicates we're not going to advance our script for 4 frames. Note that rest and wait are interchangeable in instrument scripts, but have different meaning in music scripts. I use both here.
Meanwhile, the frequency and volume envelopes are still calculating in the background. So by the time four frames expires :

Volume = 20 + (2 * (4 + 1)) = 30
Frequency / Divider Offset = 6 + (-1 * (4 + 1)) = 1
Some drivers I wrote pre-add these values on any change, so you need to bias the frame count by one. I think HuSound is one of these. Yay, standards.

Anyway, our next command is volume 30 -1. The volume is getting quieter, and we're starting our decay phase.

Let's skip ahead, since you've likely picked up what's going on by now. A little further down is our first loop :
Code: [Select]
...
volume 22 0.113
loop -1
wait 9
volume 26 -0.113
wait 9
volume 22 0.113
endloop
...
We set the volume to increase and then enter the loop body with a loop count of -1. This is an infinite loop, and it will continue until either the song hits a note off command, is manually stopped, or the channel is taken over by a sound effect.
Looking at the body of the loop, I'm just delaying for a bit, then reversing the direction of the volume envelope, effectively doing this : /\/\/\/\/ ... during the instrument's sustain period.
Replacing this with a frequency command will effectively give you vibrato. You can make the differentials very large and the delays very small to get arpeggios.


Now about note off commands -
We're effective looping in the sustain period above, and will stay there until we hit a rest / note off command in the music script. Once we hit one of those, the instrument script will JMP to the tagged note off area of its script (if the instrument still has control of the channel).

If we look right below the loop body, you'll see :
Code: [Select]
...
endloop
noteoff
volume 24 -1
wait 18
end
}

The noteoff tag is where the instrument will jump. If you look right after it, I'm setting the volume to decrease and then telling the instrument to terminate.


Hopefully all this is clear! SASS can be a little difficult.
« Last Edit: November 10, 2015, 01:37:09 PM by TailChao »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: HuSound
« Reply #77 on: November 10, 2015, 02:05:21 PM »
Ahh I see. That makes sense.

Heh - I thought some of my engines were too mechanical in nature (I always worried that other people would be put off by the complexity). I can visualize that, though, having created music engines and fussing over ticks and divisors/counters.


TailChao

  • Full Member
  • ***
  • Posts: 156
Re: HuSound
« Reply #78 on: November 10, 2015, 03:55:04 PM »
Heh - I thought some of my engines were too mechanical in nature (I always worried that other people would be put off by the complexity). I can visualize that, though, having created music engines and fussing over ticks and divisors/counters.
Yeah, it's difficult to get a good balance for a scripting language. I'm still not completely happy with some the choices I made in SASS (especially with how 16.8 or 16.16 values are entered). Graphical editors will knock down most of the learning curve, especially for creating instruments.

One nice thing about SASS is that once your very complex macro is written, all of that functionality is reduced to one "using" statement in your music script :
Code: [Select]
using CasioTrumpet
...
c.4 14
rest 1
c.4 14
rest 1
e.4 24
rest 5
b.4 25
rest 5
...

You can also use abbreviated commands, i.e. "f" for "frequency" or "l" for "loop" when you get more comfortable with the language.

In any case, all of this is still easier than creating patches for very ancient analog synths  :wink:
But I would like to write a proper graphical editor at some point.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: HuSound
« Reply #79 on: November 10, 2015, 05:41:17 PM »
You could always use blargg's sound engine (hes player) source code and interface it with some specific gui/code for your pce sound engine.

 Do you buffer your reg changes, so that they all happen near the same time? So pairing channels for phase effects, the channels get updated near synchronously?

TailChao

  • Full Member
  • ***
  • Posts: 156
Re: HuSound
« Reply #80 on: November 10, 2015, 06:30:04 PM »
You could always use blargg's sound engine (hes player) source code and interface it with some specific gui/code for your pce sound engine.
Huh, I didn't think of that approach. That could definitely work.
It's nice that so many tools are being made available  :)

Long term I definitely need a SASS graphical suite, since it's being used on more targets than just the PCE. Being able to just draw notes on a staff is great.

Do you buffer your reg changes, so that they all happen near the same time? So pairing channels for phase effects, the channels get updated near synchronously?
Yeah, that's actually one of the reasons the memory consumption is a little high. My Lynx driver doesn't do this since the resources are so constrained, but it definitely helps with the macro setup.

So for HuSound updates you do two calls : one right at the beginning of your VBL IRQ (HuSound_WriteBack) which dumps all of the register updates calculated on the last frame, then one at the end of the IRQ (HuSound_Main) which calculates the next register update set and is interruptable.

elmer

  • Hero Member
  • *****
  • Posts: 2153
Re: HuSound
« Reply #81 on: November 11, 2015, 04:59:22 AM »
So for HuSound updates you do two calls : one right at the beginning of your VBL IRQ (HuSound_WriteBack) which dumps all of the register updates calculated on the last frame, then one at the end of the IRQ (HuSound_Main) which calculates the next register update set and is interruptable.

Nice, clean design.  :)

Gredler

  • Guest
Re: HuSound
« Reply #82 on: January 27, 2016, 01:15:23 PM »
support the commercial Renoise editor

My friend who is trying to make PCE tunes with renoise is having trouble getting it to export midi's that contain the intended channel information, and also linking the sounds he has access to in squirrel to what he has in renoise.

I have 0% musical knowledge, and about 5% coding knowledge, so troubleshooting for him is so hard hahaha.

Is it a fools errand for him to continue trying to use renoise, or is it possible and cockpit trouble preventing his renoise>midi>3ml>squirrel>huc workflow?

elmer

  • Hero Member
  • *****
  • Posts: 2153
Re: HuSound
« Reply #83 on: November 23, 2016, 07:01:15 AM »
OK, switching from the MML back to this one ...

It'd be great if that SASS thing from TailChao had a midi--->SASS conversion.

It has one here, which is also under zlib.

Cool, thanks!  :D

BTW ... I've read the HuSound documentation and I have a question for you ...

How do you add arpeggios, vibrato, tremolo, note-transposition, and *musical* sweeps and slides to the tracks in HuSound (the hard-coded add-a-frequency-step isn't *musical*, the step size needs to depend upon the note that was played)?

TailChao

  • Full Member
  • ***
  • Posts: 156
Re: HuSound
« Reply #84 on: November 23, 2016, 07:38:52 AM »
How do you add arpeggios, vibrato, tremolo, note-transposition, and *musical* sweeps and slides to the tracks in HuSound (the hard-coded add-a-frequency-step isn't *musical*, the step size needs to depend upon the note that was played)?
I usually accomplish this by making two or three instruments with manually tuned hard steps to cover a wider frequency range, kind of like how you'd have multiple source instrument samples at different octaves for a sampler.

This is one thing I'm not really happy about, but usually one instrument won't wander around a huge octave range anyway (and to be honest many games don't even bother with this). If that kind of precision is needed you could probably build it into the SASS compiler side to autogenerate more instruments or shove some tables into ROM and let the driver deal with it.

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: HuSound
« Reply #85 on: November 23, 2016, 07:47:02 AM »
support the commercial Renoise editor

My friend who is trying to make PCE tunes with renoise is having trouble getting it to export midi's that contain the intended channel information, and also linking the sounds he has access to in squirrel to what he has in renoise.

I have 0% musical knowledge, and about 5% coding knowledge, so troubleshooting for him is so hard hahaha.

Is it a fools errand for him to continue trying to use renoise, or is it possible and cockpit trouble preventing his renoise>midi>3ml>squirrel>huc workflow?


Renoise pissed me off, so I blame Renoise.

I had the best luck with MODPlug for Windows, years ago.
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.