Пример #1
0
        static void Main(string[] args)
        {
            if (args[0] == "-g") {
                GenTables();
                return;
            }

            // Get source

            ArrayList alsFiles = new ArrayList();
            for (int n = 0; n < args.Length; n++) {
                string strFileT = Path.GetFileName(args[n]);
                string strDirT = Path.GetDirectoryName(args[n]);
                if (strDirT == "")
                    strDirT = ".";
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            foreach (string strFileWav in alsFiles) {
                // Read in wav

                Pcm pcm = new Pcm(strFileWav);

                // Write out .snd file

                string strFileSnd = Path.ChangeExtension(strFileWav, ".snd");
                Console.WriteLine(Path.GetFileName(strFileWav) + " -> " + Path.GetFileName(strFileSnd));
                BinaryWriter bwtr = new BinaryWriter(new FileStream(strFileSnd, FileMode.Create, FileAccess.Write, FileShare.None));
                bwtr.Write(pcm.GetSndEncoding());
                bwtr.Close();

            }
        }
Пример #2
0
 void SetSoundsDir(string strDir)
 {
     m_fFillingListBox = true;
     try {
         textBoxSoundsDir.Text = strDir;
         ArrayList alsFiles = new ArrayList();
         alsFiles.AddRange(Directory.GetFiles(strDir, "*.wav"));
         alsFiles.AddRange(Directory.GetFiles(strDir, "*.snd"));
         ArrayList alsItems = new ArrayList();
         string strPath = Path.GetFullPath(textBoxSoundsDir.Text);
         foreach (string strFileFull in alsFiles) {
             string strFile = Path.GetFileName(strFileFull);
             Pcm pcm = new Pcm(strPath + "\\" + strFile);
             pcm.ConvertTo8Bit();
             alsItems.Add(strFile + ", " + pcm.Data8Bit.Length / 2 + " bytes");
         }
         listBoxSounds.DataSource = (string[])alsItems.ToArray(typeof(string));
     } catch {
         MessageBox.Show("Invalid directory!");
     }
     m_fFillingListBox = false;
 }
Пример #3
0
 void PlaySound(string strFile)
 {
     try {
         if (!m_fFillingListBox && m_fPlaySound) {
             string strPath = Path.GetFullPath(textBoxSoundsDir.Text);
             Pcm pcm = new Pcm(strPath + "\\" + strFile);
             pcm.Play();
         }
     } catch {
     }
 }
Пример #4
0
        void SavePdb(string strPdbFile)
        {
            // Make a list of unique sound files

            PdbPacker pdbp = new PdbPacker();
            int cSfx = m_alsNames.Count;
            StringCollection strcUniqueSounds = new StringCollection();
            ArrayList alsPcm = new ArrayList();
            for (int iSfx = 0; iSfx < cSfx; iSfx++) {
                if (!listViewSfx.Items[iSfx].Checked)
                    continue;
                if (!(bool)m_alsSfxEnabled[iSfx])
                    continue;
                string strFile = listViewSfx.Items[iSfx].SubItems[1].Text;
                if (strFile == null)
                    continue;
                strFile.Trim();
                if (strFile.Length == 0)
                    continue;
                int istr = strcUniqueSounds.IndexOf(strFile);
                if (istr == -1)
                    istr = strcUniqueSounds.Add(strFile);
            }

            // Serialize names out

            ArrayList alsStringOffsets = new ArrayList();
            BinaryWriter bwtr = new BinaryWriter(new MemoryStream());
            bwtr.Write(Misc.SwapUShort((ushort)strcUniqueSounds.Count));
            for (int iSound = 0; iSound < strcUniqueSounds.Count; iSound++) {
                alsStringOffsets.Add(bwtr.BaseStream.Position);
                string strFile = Path.ChangeExtension(strcUniqueSounds[iSound], ".snd");
                char[] sz = strFile.ToCharArray();
                bwtr.Write(sz);
                bwtr.Write((byte)0);
            }
            byte[] abSoundFiles = new byte[bwtr.BaseStream.Length];
            bwtr.BaseStream.Seek(0, SeekOrigin.Begin);
            bwtr.BaseStream.Read(abSoundFiles, 0, (int)bwtr.BaseStream.Length);
            bwtr.Close();

            // soundfiles file

            PdbPacker.File fileSounds = new PdbPacker.File("soundfiles", abSoundFiles);
            pdbp.Add(fileSounds);

            // Now serialize the sfx entries in the order of the names

            bwtr = new BinaryWriter(new MemoryStream());
            for (int iName = 0; iName < m_alsNames.Count; iName++) {
                // Need to find the entry in listViewSfx for this name since the persist
                // order needs to match soundeffects.h.

                string strName = ((StringCollection)m_alsNames[iName])[0];
                int iSfx;
                bool fFound = false;
                for (iSfx = 0; iSfx < cSfx; iSfx++) {
                    if (strName == listViewSfx.Items[iSfx].SubItems[0].Text) {
                        fFound = true;
                        break;
                    }
                }
                if (!fFound)
                    throw new Exception("Internal error");

                string strFile = listViewSfx.Items[iSfx].SubItems[1].Text;
                if (!listViewSfx.Items[iSfx].Checked)
                    strFile = null;
                if (!(bool)m_alsSfxEnabled[iSfx])
                    strFile = null;
                if (strFile == null) {
                    bwtr.Write((byte)0xff);
                } else {
                    strFile.Trim();
                    if (strFile.Length == 0) {
                        bwtr.Write((byte)0xff);
                    } else {
                        bwtr.Write((byte)strcUniqueSounds.IndexOf(strFile));
                    }
                }
                bwtr.Write((byte)0); // bwtr.Write(byte.Parse(listViewSfx.Items[iSfx].SubItems[2].Text));
                int nPriority = m_strcPriorities.IndexOf(listViewSfx.Items[iSfx].SubItems[3].Text);
                if (nPriority < 0) {
                    MessageBox.Show("Warning: " + listViewSfx.Items[iSfx].SubItems[0].Text + " has an unfamiliar priority.");
                }
                bwtr.Write((byte)nPriority);
            }
            byte[] abSfxEntries = new byte[bwtr.BaseStream.Length];
            bwtr.BaseStream.Seek(0, SeekOrigin.Begin);
            bwtr.BaseStream.Read(abSfxEntries, 0, (int)bwtr.BaseStream.Length);
            bwtr.Close();

            PdbPacker.File fileSfxEntries = new PdbPacker.File("SfxEntries", abSfxEntries);
            pdbp.Add(fileSfxEntries);

            // Now add in all the sounds

            for (int istrFile = 0; istrFile < strcUniqueSounds.Count; istrFile++) {
                string strFile = Path.GetFullPath(textBoxSoundsDir.Text) + "\\" + strcUniqueSounds[istrFile];
                Pcm pcm = new Pcm(strFile);
                PdbPacker.File fileT = new PdbPacker.File();
                fileT.str = Path.ChangeExtension(strcUniqueSounds[istrFile], ".snd");
                fileT.ab = pcm.GetSndEncoding();
                fileT.fCompress = false;
                pdbp.Add(fileT);
            }

            // Ready to save pdb

            pdbp.Save(strPdbFile, "WARI");
        }
Пример #5
0
 private void menuItemPlayOnPalm_Click(object sender, System.EventArgs e)
 {
     int iItem = listBoxSounds.SelectedIndex;
     if (iItem == -1)
         return;
     string strFile = GetListboxItemFileName(iItem);
     try {
         string strPath = Path.GetFullPath(textBoxSoundsDir.Text);
         Pcm pcm = new Pcm(strPath + "\\" + strFile);
         PlayOnPalm(strFile, pcm.GetSndEncoding());
     } catch {
         MessageBox.Show("Couldn't load " + strFile);
     }
 }