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

0 Members and 1 Guest are viewing this topic.

Offline MusicallyInspired

Set channel properties for Sound resources in Companion?
« on: May 25, 2021, 07:10:16 PM »
I may have brought this up before, I don't remember. I discovered while streaming today that Companion doesn't seem to have the ability to alter channel properties on Sound resources. Mainly the "Initial Voices" value. This is important for Adlib because if it's not set no notes will be played at all. Ravi's SoundBox program can set this but it's only compatible with SCI0 Sound resources, which makes it unhelpful for SCI1+ games.

What the Initial Voices value does is set the polyphony limit for the channel it's set on. I think Adlib has a maximum limit of 8 voices across all Adlib channels total. I think some stereo OPL drivers (sndblast?) ignore this and have a higher polyphony limit but I'd like to be able to to support the original mono adl.drv driver too.

Unless Companion already supports this and I've missed it lol. The source for SoundBox is freely available so I'm going to take a look at it later tonight too.
« Last Edit: October 21, 2021, 01:02:07 AM by MusicallyInspired »


Brass Lantern Prop Competition

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #1 on: May 27, 2021, 07:02:27 PM »
Thankfully, it seems that setting the "initial voices" flag on each channel is handled right in the header of each sound resource (which makes sense) so it is probably easy enough to add this functionality to Companion for SCI0 resources anyway. I'm checking out the source to see how Companion handles SCI1 sound resources to see if I can find where(/if) it sets this flag there...

EDIT: Kawa, I'm trying to open your Companion fork source in Visual Studio but it's giving me errors saying it can't find any DIALOGs. Any idea what's going on there? I don't have much experience working with MFC program stuff...
« Last Edit: May 27, 2021, 10:34:16 PM by MusicallyInspired »
Brass Lantern Prop Competition

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #2 on: May 28, 2021, 08:05:13 AM »
Kawa, I'm trying to open your Companion fork source in Visual Studio but it's giving me errors saying it can't find any DIALOGs. Any idea what's going on there? I don't have much experience working with MFC program stuff...
I got nothing. I open it in 2015 Community and I can build all three variations, regular mild and kawa, with no issues 🤷‍♀️

Offline troflip

Re: Set channel properties for Sound resources in Companion?
« Reply #3 on: May 28, 2021, 07:04:33 PM »
Make sure you have the MFC components installed for your visual studio.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #4 on: May 28, 2021, 11:40:03 PM »
I do. I had to do so to open the SoundBox source. And I can see those Dialogs just fine. But with Companion when I try to open anything it says it can't find any Dialogs and gives me the option to just edit the code instead. I guess I should try and earlier version then.
Brass Lantern Prop Competition

Offline EricOakford

Re: Set channel properties for Sound resources in Companion?
« Reply #5 on: October 21, 2021, 12:44:52 AM »
It would be a good idea to add the ability to set the initial voices. I have managed to export the title and death music for SQ:TLC into MIDI for the purpose of bringing them into the SCI01 remake. I can then import the MIDI files into the game, but the music won't play.

Naturally, Soundbox only supports SCI0, and the sounds need to be in SCI1 format.
My SCI templates
SCI0 SCI0.1 SCI1.0 SCI1.1
SCI2.1 planned

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #6 on: October 21, 2021, 01:03:18 AM »
I gave up trying to edit the Companion source because of the error messages I keep getting and I can't seem to get an earlier version of Visual Studio working either.
Brass Lantern Prop Competition

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #7 on: October 21, 2021, 03:26:33 PM »
I've run into this sound issue several times as well.

I couldn't find a working version of VS 2015 Community, but I was able to get Kawa's SC fork to build without errors from a fresh install of Visual Studio Community 2019. It required adding the MFC Build Tools (see attached pic for reference) and installing the windows 8.1 SDK manually from here: https://go.microsoft.com/fwlink/p/?LinkId=323507 as they removed that SDK in 2019. Then I was able to clone the repo, choose not to upgrade the targets, and build without error.

« Last Edit: October 22, 2021, 02:04:50 AM by doomlazer »

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #8 on: October 21, 2021, 03:55:48 PM »
What I find interesting here is this part:
This is important for Adlib because if it's not set no notes will be played at all.
I know for a fact the music in The Dating Pool works fine on AdLib, which I import from .mid files in SCI Companion. Of course, that's an SCI11 game, not SCI1...

Offline MusicallyInspired

Re: Set channel properties for Sound resources in Companion?
« Reply #9 on: October 22, 2021, 12:22:42 AM »
What I find interesting here is this part:
This is important for Adlib because if it's not set no notes will be played at all.
I know for a fact the music in The Dating Pool works fine on AdLib, which I import from .mid files in SCI Companion. Of course, that's an SCI11 game, not SCI1...

There's a difference in drivers too remember. There is a stereo OPL driver that ignores the initial voices value, but the original ADL.DRV won't play notes without that value set.
Brass Lantern Prop Competition

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #10 on: October 22, 2021, 01:32:47 AM »
I'm checking out the source to see how Companion handles SCI1 sound resources to see if I can find where(/if) it sets this flag there...

I found _onImportMidi(). Would adding all six devices to every imported midi solve the problem?

Code: [Select]
void CSoundDoc::_OnImportMidi()
{
std::unique_ptr<ResourceEntity> pSound = GetResource()->Clone();

// Import to devices (tracks) that are standard by default.
std::vector<DeviceType> devices;
if (appState->GetVersion().SoundFormat == SoundFormat::SCI1)
{
// REVIEW: Sounds appear not to play properly if these three devices don't appear in the sound resource.
devices.insert(devices.end(), { DeviceType::SCI1_Adlib, DeviceType::SCI1_GM, DeviceType::SCI1_RolandGM });
}
else
{
devices.insert(devices.end(), { DeviceType::Adlib, DeviceType::NewGM, DeviceType::RolandMT32 });
}
« Last Edit: October 22, 2021, 02:01:20 AM by doomlazer »

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #11 on: October 22, 2021, 05:58:36 AM »
In Resources\Sound.cpp there's this part at line 1214:
Code: [Select]
// Channel information:
for (size_t i = 0; i < SCI0ChannelCount; i++)
{
// Each word tells us which devices use this channel.
// We can leave the lower byte blank (it should be ignored), and the upper 8 bits indicate which devices.
uint16_t channelMask = 0;
for (const auto &trackInfo : soundCopy._tracks)
{
for (int channelId : trackInfo.ChannelIds)
{
if (soundCopy._allChannels[channelId].Number == i)
{
// This channel is used for this device.
channelMask |= (trackInfo.Type << 8);
}
}
}
byteStream.WriteWord(channelMask);
}
byteStream.WriteWord(0); // Digital sample offset - we don't care about this for SCI0.

And on the ScummVM wiki, on a page originally written by Ravi no less:
Quote
The upper 4 bits of that byte specify how many voices each logical MIDI channel will be playing. The lower 4 bits specify which drivers should react on that channel. Bit 0 set means AdLib shall react. Bit 1 set means PCjr shall react. MT32 will react on all channels. Bit 3 signals the control channel.

Now look at that first part of the code again.

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #12 on: October 22, 2021, 11:42:00 AM »
What I'm taking from your reply is that adding more DeviceTypes to the array isn't going to affect the bit 0, so that's not the answer.

I really haven't spent much time with C++ and even less with bitwise operations, so I think I might be missing some subtlety of this operation:

Code: [Select]
channelMask |= (trackInfo.Type << 8);
I looked at the DeviceType enum and there only seems to be two relevant adlib types, SCI1_Adlib and Adlib. Is that << shift messing things up when SCI1_Adlib is used? I'll read up on the bitwise stuff to see if I can better understand what's happening there.
« Last Edit: October 22, 2021, 11:52:46 AM by doomlazer »

Offline Kawa

Re: Set channel properties for Sound resources in Companion?
« Reply #13 on: October 22, 2021, 12:11:17 PM »
Okay so channel mask starts out as zero, which is where the fun relevant to this thread's entire purpose begins.

Device types are listed in Sound.h, line 31-56:
Code: [Select]
enum class DeviceType
{
// SCI0 - these can be OR'd together
RolandMT32 = 0x01,
YamahaFB01 = 0x02,
Adlib = 0x04,
Casio = 0x08,
Tandy1000 = 0x10,
PCSpeaker = 0x20,
AmigaMac = 0x40,
NewGM = 0x80,

// SCI1 - these cannot.
SCI1_Adlib = 0x00,
SCI1_GM = 0x07,
SCI1_GameBlaster = 0x09,
SCI1_RolandGM = 0x0c,
SCI1_PCSpeaker = 0x12,
SCI1_Tandy = 0x13,
SCI1_AmigaMac = 0x06,
SCI1_Unknown08 = 0x08,
SCI1_Unkonwn0b = 0x0b,

// Not really a device
Digital = 0xff
};

So if you have a track in the song set to play only on AdLib, that's device type 0x04. Channel mask starts as zero, which is then bitwise-OR'd to include that 4, but shifted over one byte, to make 0x0400. Should a track be set to play on multiple devices, like the MT-32 and PC Speaker, it'll get 0x04000 (AdLib) OR 0x0100 (MT-32) OR 0x2000 (PC Speaker) = 0x2500.

I looked at the DeviceType enum and there only seems to be two relevant adlib types, SCI1_Adlib and Adlib. Is that << shift messing things up when SCI1_Adlib is used?
That's where you read it wrong. SCI0 and SCI1 have different functions to save, load, and handle music, and the SCI0 paths will only use RolandMT32 through NewGM, plus Digital even though we can't do much with that one. The SCI1 functions only use the SCI1_ devicetypes.

So it's not so much mistakenly mixing SCI1_Adlib (0x00) and SCI0 Adlib (0x04). It just doesn't completely fill in the channel mask, leaving the part where it says how many voices to use zero, which the original ADL.DRV takes at face value.

Offline doomlazer

Re: Set channel properties for Sound resources in Companion?
« Reply #14 on: October 22, 2021, 12:34:41 PM »
Hmm, understanding this a little bit more, but still not quite getting it.

Is the solution to check if it's SCI1_Adlib when it's setting the channel mask and insert 0x04 instead of 0x00?


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

Page created in 0.033 seconds with 22 queries.