//SND archive as used in many Apogee-published games
// Contains PC speaker sounds

file-format sound-PC-APOGEE
{
	compressed[file.size] "PC-Speaker"
	{
		sound
		{
			channels: 1
            samples-per-second: 44100
            bits-per-sample: 16
            volume: 255
		}
	}
}

file-format sound-PC-APOGEE-AUDIOT
{
	unsigned32 length
	unsigned16 priority
	compressed[file.size - 7] "PC-Speaker-AudioT"
	{
		sound
		{
			channels: 1
            samples-per-second: 44100
            bits-per-sample: 16
            volume: 255
		}
	}
}

function PC-Speaker
{
	loop
	{
		unsigned16 frequency-sample

		if (frequency-sample != 0xFFFF)
		{
			//344 <---- 44100 / 128
			write frequency 344 frequency-sample 1193180 255
		}
	} while (frequency-sample != 0xFFFF)
}

function PC-Speaker-AudioT
{
	loop (file.remaining-bytes)
	{
		unsigned8 frequency-sample
		write frequency 344 (frequency-sample * 60) 1193180 255
	}
}

file-format archive-SND_DOS
{
    fixed-string(4) ID //always "SND\0"
    unsigned16 fileLength
    unsigned16 soundCount

    if (ID == "SPK")
    {
	soundCount = 63
    }
    unsigned16 unknown
    data(6) padding

    file [soundCount]
    {
        unsigned16 offset
        unsigned8 priority
        unsigned8 does-exist
        fixed-string(12) name
	interpret-as "sound-PC-APOGEE"

	skip-if does-exist == 0
	skip-if name == "->UNUSED<-"
	skip-if name == "__UnNamed__"
    }
}