Exemple #1
0
        private void btnImportXma_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "XMA Audio File|*.xma";
            //openFile.InitialDirectory = Directory.GetCurrentDirectory();
            openFile.CheckFileExists  = true;
            openFile.CheckPathExists  = true;
            openFile.RestoreDirectory = true;

            if (openFile.ShowDialog() == true)
            {
                try
                {
                    currentFsbEntry = fsb.ReadXMA(openFile.FileName);
                    fsb.fsbEntries[lstFsb.SelectedIndex].xmaName = Path.GetFileNameWithoutExtension(openFile.FileName);
                    fsb.fsbEntries[lstFsb.SelectedIndex]         = currentFsbEntry;

                    RefreshFields(lstFsb.SelectedIndex, currentFsbEntry);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }

                lblCurrentXma.Content = string.Format("Current XMA file: {0}", currentFsbEntry.xmaName);
            }
        }
Exemple #2
0
        private void lstFsb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lstFsb.SelectedIndex != -1)
            {
                currentFsbEntry = fsb.fsbEntries[lstFsb.SelectedIndex];

                RefreshFields();

                if (currentFsbEntry.xmaName != "")
                {
                    lblCurrentXma.Content = string.Format("Current XMA file: {0}", currentFsbEntry.xmaName);
                }
                else
                {
                    lblCurrentXma.Content = "";
                }
            }

            if (fsb == null)
            {
                btnDel.IsEnabled = false;
            }
            else
            {
                btnDel.IsEnabled = true;
            }
        }
        public void ReadFile(string path)
        {
            var bytes = File.ReadAllBytes(path);

            using (var stream = new BinaryStream(new MemoryStream(bytes)))
            {
                if (stream.ReadString(4) != magic)
                {
                    throw new InvalidDataException("Not an FSB4 file. Please open an FSB4 file and try again.");
                }

                numSounds        = stream.ReadInt32();
                sampleHeaderSize = stream.ReadInt32();

                stream.Position = 0x30;

                fsbEntries.Clear();

                for (int i = 0; i < numSounds; i++)
                {
                    FSBEntry entry = new FSBEntry();

                    entry.size = stream.ReadInt16();

                    entry.name            = stream.ReadString(30).Replace("\0", "");
                    entry.numSamples      = stream.ReadInt32();
                    entry.streamSize      = stream.ReadInt32();
                    entry.loopStartSample = stream.ReadInt32();
                    entry.loopEndSample   = stream.ReadInt32();

                    stream.Position += 0x03;

                    entry.codec      = (byte)stream.ReadByte();
                    entry.sampleRate = stream.ReadInt32();
                    entry.pan        = stream.ReadInt16();
                    entry.defPri     = stream.ReadInt16();

                    stream.Position += 0x02;

                    entry.numChannels = stream.ReadInt16();

                    stream.Position += 0x08;

                    entry.volume      = stream.ReadInt32();
                    entry.unknownData = stream.ReadBytes(entry.size - 80);
                    entry.unknownInt  = stream.ReadInt32();

                    fsbEntries.Add(entry);
                }

                stream.Position = 0x30 + sampleHeaderSize;

                foreach (FSBEntry entry in fsbEntries)
                {
                    entry.audioData = stream.ReadBytes(entry.streamSize);
                }
            }
        }
        public FSBFile()
        {
            fsbEntries  = new List <FSBEntry>();
            entryFields = new List <string>();

            FSBEntry disposableEntry = new FSBEntry();

            foreach (var item in disposableEntry.GetType().GetFields().Where(x => !x.Name.Contains("Data")).ToList())
            {
                entryFields.Add(item.Name);
            }
        }
Exemple #5
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (fsb == null)
            {
                fsb = new FSBFile();
            }

            FSBEntry newFsb = new FSBEntry();

            fsb.fsbEntries.Add(newFsb);
            currentFsbEntry = newFsb;

            lstFsb.Items.Add(string.Format("{0} - {1}", fsb.fsbEntries.Count, newFsb.name));

            ToggleFields(true);

            lstFsb.SelectedIndex = lstFsb.Items.Count - 1;
            btnDel.IsEnabled     = true;
        }
Exemple #6
0
        private void RefreshFields(int indexToUpdate = -1, FSBEntry fsbEntry = null)
        {
            txtName.Text         = currentFsbEntry.name;
            txtFileSizeRO.Text   = currentFsbEntry.streamSize.ToString();
            txtSampleRateRO.Text = currentFsbEntry.sampleRate.ToString();
            txtSamplesRO.Text    = currentFsbEntry.numSamples.ToString();
            txtStartSample.Text  = currentFsbEntry.loopStartSample.ToString();
            txtEndSample.Text    = currentFsbEntry.loopEndSample.ToString();
            txtPan.Text          = currentFsbEntry.pan.ToString();
            txtChannelsRO.Text   = currentFsbEntry.numChannels.ToString();
            txtCodecRO.Text      = currentFsbEntry.codec == 1 ? "XMA" : "Unknown";
            txtVolume.Text       = currentFsbEntry.volume.ToString();

            if (indexToUpdate != -1)
            {
                lstFsb.SelectedIndex        = 0;
                lstFsb.Items[indexToUpdate] = string.Format("{0} - {1}", indexToUpdate + 1, fsbEntry.name);
                lstFsb.SelectedIndex        = indexToUpdate;
            }
        }
        public FSBEntry ReadXMA(string path)
        {
            FSBEntry entry = new FSBEntry();

            var bytes = File.ReadAllBytes(path);

            using (var stream = new BinaryStream(new MemoryStream(bytes)))
            {
                if (stream.ReadString(4) != xmaMagic)
                {
                    throw new InvalidDataException("Not an XMA file. Please open an XMA file and try again.");
                }

                string fileName = Path.GetFileNameWithoutExtension(path);

                entry.name    = fileName.Substring(0, fileName.Length > 32 ? 31 : fileName.Length);
                entry.xmaName = fileName;

                stream.Position = 0x16;

                entry.numChannels = stream.ReadInt16();
                entry.sampleRate  = stream.ReadInt32();

                stream.Position += 0x1C;

                entry.numSamples    = stream.ReadInt32();
                entry.loopEndSample = entry.numSamples - 1;

                stream.Position = FindSequence(bytes, dataHeader) + 4;

                entry.streamSize = stream.ReadInt32();
                entry.audioData  = stream.ReadBytes(entry.streamSize);
            }

            return(entry);
        }