Author Topic: Set channel properties for Sound resources in Companion?  (Read 9078 times)

0 Members and 1 Guest are viewing this topic.

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #15 on: October 22, 2021, 01:09:48 PM »
No, because you can't set SCI1_Adlib on an SCI0 sound resource to begin with. The solution is to put the correct information (the initial voice count) in the other eight bits of channelMask.

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #16 on: October 22, 2021, 01:35:38 PM »
I think my lack of bitwise experience is really hurting me here. I'll need to do a deep dive on that stuff to fill some big holes in my understanding.

In the meantime, would you mind showing me what the correct solution looks like?




Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #17 on: October 22, 2021, 02:23:46 PM »
Okay, check this shit.

You have two bits, A and B. They can be 0 or 1, as bits are wont to do. You can combine them in various ways to get another bit value.
  • With an AND operation, the result is 1 only if A and B are both 1. 0 AND 1 is still 0.
  • With an OR operation, the result is 1 if A or B is 1. If both A and B are 1, that's fine too.
  • With an XOR operation, the result is 1 if A and only A, or B and only B is 1. An exclusive OR.
A byte is just eight bits in a row, and a short is 16 of them. Here endeth that lesson.

channelMask is considered in the SCI Companion source code to be a short (uint16_t, or "unsigned integer, 16 bits", where unsigned means it can't go below zero so you get a 0-65535 range), but from what I understand it's actually two separate bytes, one of them being the channel mask and the other the initial voices count. The << 8 bit is only there so the values from enum DeviceType end up in the channel mask byte, not the initial voices byte.

What the |= means is "take the channel mask value so far, and OR-combine this new value with it." This is done bit-by-bit.

And these are the bits:

MT-320x010000.0001
FB-010x020000.0010
AdLib0x040000.0100
Casio0x080000.1000
Tandy0x100001.0000
PC Spkr0x200010.0000
Ami/Mac0x400100.0000
GM0x801000.0000

Notice how each of them has a different bit set? That means a channel meant to play on MT-32 and AdLib both would have the bits 0000.0101 set, which is 0x05 in hexadecimal.

<THEORY>

But because apparently (and this is entirely my conjecture here) the channel mask isn't a 16-bit value but only 8-bit, and the other eight are the initial voice value, that means they have to be shifted up eight spaces.

Code: [Select]
0x05 0x03
  |    |____ Initial voices value: we'll play at most three notes at once on this track.
  |_________ Channel mask: this is for MT-32 and AdLib.

And that would thus be packed into a single 16-bit value, 0x0503.

</THEORY>

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #18 on: October 22, 2021, 03:56:18 PM »
So, if this loop is setting the DeviceType in to the channelMask,

Code: [Select]
if (soundCopy._allChannels[channelId].Number == i)
{
// This channel is used for this device.
channelMask |= (trackInfo.Type << 8);
}


Where is the Initial voices value coming from? I'm still not seeing how that getting applied to the mask.

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #19 on: October 22, 2021, 05:36:21 PM »
You don't see it getting applied because

... hold onto your butt, this is gonna blow your mind.

Ready?

Because it's not getting applied at all, anywhere. The entire thing about initial voice counts is missing! That's why the channel mask is mistakenly 16-bits in the first place!

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #20 on: October 22, 2021, 06:32:36 PM »
I apologize if I'm being annoying. One final question and I'll just drop it.

Is there not a way to easily determine the initial voice count for each channelID? I'm struggling to find any information about that in any online midi programming tutorials.
« Last Edit: October 22, 2021, 06:45:59 PM by doomlazer »

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #21 on: October 22, 2021, 07:20:34 PM »
That's what I'd like to know myself. And whether or not my hypothesis about where that value should go is correct.

Offline gumby

Re: Set channel properties for Sound resources in Companion?
« Reply #22 on: October 22, 2021, 07:53:36 PM »
What about just be empirical about this?  Can we just take an existing sound resource (as a patch file) that doesn't currently work with AdLib, use a hex editor and just modify the header byte in question?  Muck with it till it works (or doesn't)?
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #23 on: October 22, 2021, 08:43:44 PM »
Excellent idea! I'd also suggest studying a contemporary sound resource already known to work. That would at the very least tell us exactly where the value goes.

If nothing else I can try to add a field to the UI so you can manually set the damn thing.

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #24 on: October 22, 2021, 08:51:37 PM »
Is there not a way to easily determine the initial voice count for each channelID? I'm struggling to find any information about that in any online midi programming tutorials.

The initial voice count must be set manually by the composer. This is easily done in Ravi's SoundBox tool for SCI0 sound resources. But this is of no help for SCI1.0. Adlib has a max of 8 voices across all channels that are flagged as Adlib channels. If you have more than that you're going to get missing/dropped notes. The composer also has to ensure that no more than the max number voices (notes) are playing at the same time in an Adlib channel at once when composing. It's all part of that process pre-game implementation. You do not want this to be generated automatically. At least, not unless you already have the max number of notes playing at a time while you're composing the MIDI so that setting it automatically will be safe. But you have to be sure. I'd just like to have the ability to set it manually. That was my whole idea.
« Last Edit: October 22, 2021, 08:55:31 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #25 on: October 22, 2021, 09:01:11 PM »
Extra field in the side bar, then?

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #26 on: October 22, 2021, 09:13:48 PM »
That makes the most sense.
Brass Lantern Prop Competition

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #27 on: October 22, 2021, 09:14:24 PM »
Just gotta confirm where the value goes, then.

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #28 on: October 22, 2021, 09:31:26 PM »
Yeah. Maybe I'll spend more time on this figuring it out over the weekend.
Brass Lantern Prop Competition

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #29 on: October 22, 2021, 09:33:27 PM »
Not sure if this confirms anything, but the pic below compares an SCI0 patch edited in Soundbox - the only change was setting channel 2 initial voices from 0 to 3. Looks like that 4th byte is all that changes, which lines up with your theory, right or no?


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.032 seconds with 25 queries.