Sound Editor

Joel I'm thinking about working on a staff-based sound editor. Actually, I'm thinking more along the lines of a full-fledged AGI Sound Studio kind of thing that will probably not only allow direct editing of AGI Sound resources but also provide menu items to run the converters.

I've sort of already started. I've got code that can correctly print out the names of the notes (in text format, I'm going to hold off on graphical representations until I work out all the math) for a sound resource, along with the correct durations of those notes in 60ths of a second.

I'm not going for excessive objectives. Unlike my other utilities I've released, I'm writing this one with straight Windows API instead of MFC so it will be easier to release the source code so other people can add to it. If I get anywhere with this, I'll let you guys know. At the moment, I think I'm going to work on getting it so that it can print out musical notation for existing sound resources, then I'll worry about editing (or let somebody else worry about it).
sonneveld Good luck with the editor.  The start of the sound scripting tools I released has the source code with it if you need some help.

- Nick
Joel Thanks, Nick. I think I've got the format down ok (although I don't know that for sure) -- the trouble comes with converting it to musical notation, particularly with long notes. At the moment, I'm going with just "good" approximations, but there's a trade-off there with the ability to adjust tempo. At a tempo of 120 beats per minute, long notes are pretty easy to deal with (because they're actually fairly short), but at that tempo the AGI format doesn't have a timer resolution high enough to deal with 64th note triplets (they figure to very close to 0/60 sec. per note), but at a tempo of 40 if you have a half-note tied to a sixteenth-note you will lose that and it will either become a half note or a dotted half note. Obviously, I intend to work on that, but I don't want this thing to get out of hand, so I'm not going to worry about it right now.

By the way, does anybody have any idea what the minimum duration is for a note to actually make a sound on the PC speaker?
sonneveld I think that's the problem with using AGI as the format.  MIDI's a great format because it doesn't have many commands (note up, down.. program changes, stuff that fiddles with the pitch and a whole bunch of meta-commands) so you can store the song you want and easily convert to agi later.

The only thing I could suggest is using sort of intermediate format before going straight to the agi sound.  AGI Studio doesn't edit the logic files completely, it saves them to text files and compiles to logic later.

- Nick
sonneveld Are you talking about the duration for a pc speaker in AGI (which would be 1/60 of a second) or the quickest you can turn it on and off (which i thought was as fast as the code could do it)?

Interestingly, I was looking as the Leisure Suit Larry theme and you never see notes that are at the exact same duration. It always varies between 7-8 or 20-22 (for example).  I'm guessing it's because they used another format (perhaps midi or a script) that used a higher-res counter and then tried to interpolate when converting to AGI.

- Nick
Joel I have some ideas for going to AGI sound from the editor. Where the resolution problem occurs is actually going from AGI sound into the editor, and I think it's mostly because right now I've got a very dumb algorithm that just calculates the 1/60 sec. durations of each basic note type and then finds the closest basic note type match for the duration of each note in the AGI file (that algorithm works pretty good for calculating the note names from the frequency value, but it's not so good for getting the musical notation from a duration value). A slightly smarter algorithm will probably do away with this problem. Also, I'm thinking about maybe saving a small data file to go with each AGI sound file that is edited so that the editor can remember things like tempo, whether the user was editing in treble/bass clef, etc. I'm not worried about the resolution loss in terms of being unable to handle really, really short notes at tempos 120 and above, because I don't think the interpreter can handle them, anyway, and I sort of want an editor that's as limited as the AGI Sound format. That way you can know immediately that what you're trying to do won't work.

As for the minimum time, I was asking what's the minimum amount of time that AGI can sound a note, not that the PC speaker can. I could also use information about what the minimum and the maximum frequencies are that AGI sound can play.

Slight variations in the time for each note should be ok, although the resulting notation when the sound file is loaded might be ugly to look at (it is when you convert the Sierra AGI sounds to midi, incidentally), but the sound files that my program will produce should be very constant about what the note durations are.
eidolon I was thinking a little about the loss of precision;
Using a staff notation means losing some accuracy of tone duration and pitch. For music this should not be an issue, but perhaps for other sound effects?

I seem to remember that the alarm sound in the beginning of SQ1 was using a finer scale.
Joel If I decide to keep going with this, I'll probably have to create a fairly flexible format that, while approximating the note names and durations on the staff, keeps the actual frequency and duration stored.

I've run into another seems Sierra had their frequencies wrong (or they weren't really worried about what the actual notes were) in earlier games like Space Quest 1 and the christmas card. In my text files, I'm getting back note values that create a really horrible sounding song -- the problem is that the frequency divisors used in those older games for the notes often produce frequencies that are very close to dead center between two actual note frequencies, and that's confusing my algorithm (which determines the note value for a given frequency by choosing the closest note to that frequency). There's probably a better way to figure out the note values. After all, when the sound files are converted to midi, they sound like they're supposed to and have the pitches that were apparently intended by the people creating the sound resources at Sierra. Any ideas on that?
sonneveld If we're going to have a more flexible format, we might as well try and make it compatible across tools.

And I've noticed the problem with in-between notes too.  I've tried adjusting the freq, but then it differs for another note.  I think it's because we're using a wrong freq and also because of the inprecision.  it's probably missing a small fraction which would make it exact.

- Nick
Joel I'm not sure what inprecision you mean, exactly. I'm using a look-up table of precalculated frequencies. Although they only go out to two decimal places, the error in the Sierra frequencies is much larger than that. The 111860 / freq.count calculation yields numbers that can be about 50 Hz away from any chromatic scale pitch. The frequency I calculate just happens to land slightly closer (sometimes less than 1 Hz) to the frequency for the wrong note than to the frequency for the right note, so my program is choosing the wrong note.

By a "more flexible format", I didn't really mean a file format. I just meant the way the editor works. I definitely don't want to create a flexible format that will be converted to AGI Sound...there's already midi, etc. for that.

Also, for the noise channel, staff-based editing doesn't really make much sense, it seems to me. It might be a good idea to have script-based editing as well as staff-based editing.
sonneveld What I mean is that 111860 is a number made up for the AGI specs we made.  I don't know what number Sierra used for compiling their own sounds.

- Nick
Joakim To me it seems quite a waste to reinvent the wheel anytime we're doing anything AGI-wise. I've got a pretty solid AGI Resource to sound pattern converter, perhaps you all could benefit something from that one.

If you're still interested on my proceedings, I've got a miraculous interest in .NET at the moment, and have converted around 40% of my old code to C#. The reason that I do not post more about my work is that I do not want to create false hopes on you all about when I'll be finished. ;)

But, here's a small snippet of my code;

        // Discovered that the note 118 (A#9) is frequently
        // used as an OFF note together with attenuation 15 (silent)
        // Therefore, set those notes as OFF-notes.
        // Note 118 equals to frequency 15.
        if( frequency <= 15 )
           iNote = AGI_SOUND_NOTE_OFF;
           double dNote = ( 12.0 / log( 2.0 ) ) * log( (111860.0 * 32.0) / ((double)frequency * 440.0) ) + 9.0 - 0.46;

           if( (dNote - floor(dNote)) > 0.5 )
              dNote += 0.5;

           iNote = (UINT)floor( dNote );
Joel What exactly does that big calculation do?

Anything that can make this easier is welcome, because if this thing starts taking too much of my time I'm likely to just give up. Anything I do with this thing drains time away from my other projects like Jen's Quest, and without progress I might get tired of it.
What exactly does that big calculation do?

That calculation converts to an index based MIDI note. (with 0 as C-0)

I haven't tried all sound resources with it, but as far as I know it will translate all frequencies to notes correctly.

/ Joakim
Joel Ok. I have a question -- is there a different index in MIDI, for example, for Ab and G#, or do MIDI editors determine which of the two to draw on a staff by other means? Basically, what I want to know is, after C0 with an index of 0, how do the rest of the notes proceed? Is it


or is it
sonneveld I think it's the later:
Summary of MIDI Note Numbers

I would have assumed that all notes would get converted to their nearest equivilant.  It wouldn't matter when playing MIDI, only when editing.

- Nick
sonneveld How is your editor going by the way?  You haven't posted in a while :)

- Nick
Joel I haven't really been working on it. I was on Spring Break, and what computer work I did do was primarily on Jen's Quest. I've been meaning to ask about those index numbers for a while now. I think there are some design decisions I should make before attempting to write any more code than I already have. If Joakim's conversion is more accurate than just picking the nearest note value, then I will probably use that calculation instead, in which case there are some changes that need to be made to a few of the things I've already written.
Joel It looks like that conversion is pretty accurate, so I will probably be changing my code to make use of it.
Joel I need an algorithm that will let me determine the position of a note on the staff given its MIDI index. Any ideas?