Esempio n. 1
0
        private void TryLoadSound(Stream fileData)
        {
            BinaryReader streamReader = new BinaryReader(fileData);

            soundData    = new WaveSoundData(streamReader);
            length       = CacheLengthInSeconds();
            bufferHandle = CreateNativeBuffer();
        }
Esempio n. 2
0
        /// <summary>
        /// Play a WSD entry.
        /// </summary>
        /// <param name="a">Sound archive.</param>
        /// <param name="wsdNumber">WSD entry to play.</param>
        public static void PlayWsd(SoundArchive a, int wsdNumber)
        {
            //Try playing.
            Stop();
            try {
                //WSD.
                WaveSoundData s = a.WaveSoundDatas[wsdNumber].File.File as WaveSoundData;
                var           p = s.Waves[s.DataItems[a.WaveSoundDatas[wsdNumber].WaveIndex].Notes[0].WaveIndex];
                Wave          w = (a.WaveArchives[p.WarIndex].File.File as SoundWaveArchive)[p.WaveIndex];
                if (w.Wav.info.channelInfo.Count > 2)
                {
                    switch (w.Wav.info.encoding)
                    {
                    case 0:
                        w.Wav.data.pcm8 = new sbyte[][] { w.Wav.data.pcm8[0], w.Wav.data.pcm8[1] };
                        break;

                    case 1:
                        w.Wav.data.pcm16 = new short[][] { w.Wav.data.pcm16[0], w.Wav.data.pcm16[1] };
                        break;

                    case 2:
                        w.Wav.data.dspAdpcm = new byte[][] { w.Wav.data.dspAdpcm[0], w.Wav.data.dspAdpcm[1] };
                        break;
                    }
                }
                for (int i = 2; i < w.Wav.info.channelInfo.Count; i++)
                {
                    w.Wav.info.channelInfo.RemoveAt(i);
                }
                var m = new MemoryStream(w.Riff.ToBytes());
                var n = new WaveFileReader(m);
                waveOut.Initialize(n);
                waveOut.Play();
                CurrHash = "WSD_" + wsdNumber;
                Stopped  = false;
                Paused   = false;
            } catch { }
        }
Esempio n. 3
0
        public static SoundFile <ISoundFile> GetInfo(SoundArchive a, SoundArchive.NewFileEntryType type, int lastEntry, string filePath)
        {
            //File wizard.
            FileWizard w = new FileWizard();

            w.type = type;

            //Add existing files.
            foreach (var f in a.Files)
            {
                w.existingFiles.Items.Add(f.FileName + "." + f.FileExtension);
            }

            //Prepare info.
            w.referenceFileExternally.Enabled = false;
            w.referenceFileExternally.Checked = type == SoundArchive.NewFileEntryType.Stream;
            w.blankFile.Enabled       = type != SoundArchive.NewFileEntryType.Stream && type != SoundArchive.NewFileEntryType.Prefetch;
            w.useExistingFile.Checked = true;
            w.useExistingFile.Enabled = w.newFile.Checked = a.Files.Count == 0;
            w.useExistingFile.Enabled = !w.useExistingFile.Enabled;
            w.okButton.Enabled        = false;

            //Stream specifics.
            if (type == SoundArchive.NewFileEntryType.Stream)
            {
                w.blankFile.Enabled = false;
            }

            //Show.
            w.ShowDialog();

            //Return data.
            if (w.cancel)
            {
                return(new SoundFile <ISoundFile>()
                {
                    FileId = -1
                });
            }
            else
            {
                //Get versions.
                byte maj = 1;
                byte min = 0;
                byte rev = 0;

                //Use existing file.
                if (w.useExistingFile.Checked)
                {
                    return(new SoundFile <ISoundFile>()
                    {
                        Reference = a.Files[w.existingFiles.SelectedIndex]
                    });
                }

                //Use new file.
                else if (w.newFile.Checked)
                {
                    if (w.referenceFileExternally.Checked)
                    {
                        return(new SoundFile <ISoundFile>()
                        {
                            Reference = a.AddNewFile(type, lastEntry, null, false, GetRelativePath(w.newFilePath.Text, Path.GetDirectoryName(filePath)))
                        });
                    }
                    else
                    {
                        return(new SoundFile <ISoundFile>()
                        {
                            Reference = a.AddNewFile(type, lastEntry, SoundArchiveReader.ReadFile(File.ReadAllBytes(w.newFilePath.Text)))
                        });
                    }
                }

                //Blank file.
                else if (w.blankFile.Checked)
                {
                    ISoundFile f = null;
                    switch (type)
                    {
                    case SoundArchive.NewFileEntryType.Bank:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundBank;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundBank()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.Group:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as Group;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new Group()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.Sequence:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundSequence;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundSequence()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.WaveArchive:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundWaveArchive;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundWaveArchive()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.WaveSoundData:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as WaveSoundData;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new WaveSoundData()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;
                    }
                    return(new SoundFile <ISoundFile>()
                    {
                        Reference = a.AddNewFile(type, lastEntry, f)
                    });
                }

                //Null file.
                else
                {
                    return(new SoundFile <ISoundFile>()
                    {
                        FileId = -2
                    });
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Update nodes.
        /// </summary>
        public override void UpdateNodes()
        {
            //Begin update.
            BeginUpdateNodes();

            //Load needed wave files for WSD.
            if (MainWindow != null)
            {
            }

            //Add entries if doesn't exist.
            if (tree.Nodes.Count < 2)
            {
                tree.Nodes.Add("entries", "Entries", 7, 7);
            }

            //Add references if doesn't exist.
            if (tree.Nodes.Count < 3)
            {
                tree.Nodes.Add("references", "References", 6, 6);
            }

            //File open and not null.
            if (FileOpen && File != null)
            {
                //Root context menu.
                tree.Nodes["entries"].ContextMenuStrip    = rootMenu;
                tree.Nodes["references"].ContextMenuStrip = rootMenu;

                //Add references.
                WaveSoundData d = File as WaveSoundData;
                for (int i = 0; i < d.Waves.Count(); i++)
                {
                    //Null entry.
                    if (d == null)
                    {
                        //Add null entry.
                        tree.Nodes["references"].Nodes.Add("reference" + i, "[" + i + "] { Null Reference }", 0, 0);
                    }

                    //Valid entry.
                    else
                    {
                        //Get wave archive name.
                        string warName = "{ Null Wave Archive Name (" + d.Waves[i].WarIndex + ") }";
                        if (MainWindow != null)
                        {
                            //If there is a B_SAR open.
                            if (MainWindow.File != null)
                            {
                                try {
                                    if ((MainWindow.File as SoundArchive).WaveArchives[d.Waves[i].WarIndex].Name != null)
                                    {
                                        warName = (MainWindow.File as SoundArchive).WaveArchives[d.Waves[i].WarIndex].Name;
                                    }
                                } catch { }
                            }
                        }

                        //Add entry.
                        tree.Nodes["references"].Nodes.Add("reference" + i, "[" + i + "] " + warName + " - Wave " + d.Waves[i].WaveIndex, 2, 2);
                    }
                }

                //Add entries.
                for (int i = 0; i < d.DataItems.Count(); i++)
                {
                    //Null.
                    if (d.DataItems[i] == null)
                    {
                        //Null entry.
                        tree.Nodes["entries"].Nodes.Add("entries" + i, "Null Entry (" + i + ")");
                    }

                    //Valid.
                    else
                    {
                        //Valid.
                        tree.Nodes["entries"].Nodes.Add("entries" + i, "Entry " + i);

                        //Add tracks.
                        for (int j = 0; j < d.DataItems[i].NoteEvents.Count; j++)
                        {
                            //Null.
                            if (d.DataItems[i].NoteEvents[j] == null)
                            {
                            }

                            //Valid.
                            else
                            {
                                //Add note events.
                            }
                        }

                        //Add notes.
                        for (int j = 0; j < d.DataItems[i].Notes.Count; j++)
                        {
                            //Null.
                            if (d.DataItems[i].Notes[j] == null)
                            {
                            }

                            //Valid.
                            else
                            {
                            }
                        }
                    }
                }
            }
            else
            {
                //Remove context menus.
                tree.Nodes["entries"].ContextMenuStrip    = null;
                tree.Nodes["references"].ContextMenuStrip = null;
            }

            //End update.
            EndUpdateNodes();
        }