예제 #1
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (btnPlay.Text == "Stop")
            {
                if (sPlayer != null)
                {
                    sPlayer.Stop();
                    sPlayer = null;

                    btnPlay.Text = "Play Loop";
                }
            }
            else
            {
                try
                {
                    int loopStart = rbFromAudioFile.Checked ? int.Parse(lbLoopStartValue.Text) : int.Parse(tbLoopStart.Text);

                    Wave wave;
                    if (cbSourceSound.Checked)
                        wave = new Wave(sourceSound);
                    else
                        wave = new Wave(tbAudioFile.Text);

                    wave.TrimStart(loopStart);
                    MemoryStream waveFile = wave.ToMemoryStream();
                    wave.Dispose();

                    waveFile.Seek(0, SeekOrigin.Begin);

                    sPlayer = new SoundPlayer(waveFile);
                    sPlayer.PlayLooping();

                    btnPlay.Text = "Stop";
                }
                catch (Exception ex)
                {
                    sPlayer = null;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
        void bwGatherInfo_DoWork(object sender, DoWorkEventArgs e)
        {
            EventHandler UpdateValues = new EventHandler(this.UpdateValues);

            try
            {
                Wave wave;
                if (e.Argument is byte[])
                { wave = new Wave((byte[])e.Argument); }
                else
                { wave = new Wave((string)e.Argument); }

                try { this.sampleCount = wave.NumSamples; }
                catch { }

                try { bitDepth = wave.BitDepth; }
                catch { bitDepth = -1; }

                try { sampleRate = wave.SampleRate; }
                catch { sampleRate = -1; }

                try { channelCount = wave.NumChannels; }
                catch { channelCount = -1; }

                try { dataFormat = wave.DataFormat; }
                catch { dataFormat = -1; }

                try { loopCount = wave.NumLoops; }
                catch { loopCount = -1; }

                try { loopStart = wave.LoopStart; }
                catch { loopStart = -1; }

                if (!cancelled)
                    this.Invoke(UpdateValues);
            }
            catch
            {
                error = true;

                if (!cancelled)
                    this.Invoke(UpdateValues);
            }
        }
예제 #3
0
파일: BNS.cs 프로젝트: Chris230291/sma-wii
        public static Wave BnsToWave(byte[] bnsFile)
        {
            BNS b = new BNS();
            byte[] samples;

            using (MemoryStream ms = new MemoryStream(bnsFile))
                samples = b.Read(ms);

            Wave wave = new Wave(b.bnsInfo.ChannelCount, 16, b.bnsInfo.SampleRate, samples);
            if (b.bnsInfo.HasLoop == 1) wave.AddLoop((int)b.bnsInfo.LoopStart);
            return wave;
        }
예제 #4
0
파일: BNS.cs 프로젝트: Chris230291/sma-wii
        private void convert(byte[] waveFile, bool loopFromWave)
        {
            Wave wave = new Wave(waveFile);
            int waveLoopCount = wave.NumLoops;
            int waveLoopStart = wave.LoopStart;

            this.bnsInfo.ChannelCount = (byte)wave.NumChannels;
            this.bnsInfo.SampleRate = (ushort)wave.SampleRate;

            if (this.bnsInfo.ChannelCount > 2 || this.bnsInfo.ChannelCount < 1)
                throw new Exception("Unsupported Amount of Channels!");
            if (wave.BitDepth != 16)
                throw new Exception("Only 16bit Wave files are supported!");
            if (wave.DataFormat != 1)
                throw new Exception("The format of this Wave file is not supported!");

            this.bnsData.Data = Encode(wave.SampleData);

            if (this.bnsInfo.ChannelCount == 1)
            {
                this.bnsHeader.InfoLength = 0x60;
                this.bnsHeader.DataOffset = 0x80;

                this.bnsInfo.Size = 0x60;
                this.bnsInfo.Channel1StartOffset = 0x0000001C;
                this.bnsInfo.Channel2StartOffset = 0x00000000;
                this.bnsInfo.Channel1Start = 0x00000028;
                this.bnsInfo.Coefficients1Offset = 0x00000000;
            }

            this.bnsData.Size = (uint)bnsData.Data.Length + 8;

            this.bnsHeader.DataLength = this.bnsData.Size;
            this.bnsHeader.FileSize = this.bnsHeader.Size + this.bnsInfo.Size + this.bnsData.Size;

            if (loopFromWave)
                if (waveLoopCount == 1)
                    if (waveLoopStart != -1)
                    { this.bnsInfo.LoopStart = (uint)waveLoopStart; this.bnsInfo.HasLoop = 0x01; }

            this.bnsInfo.LoopEnd = (uint)tempSampleCount;

            for (int i = 0; i < 16; i++)
            {
                this.bnsInfo.Coefficients1[i] = this.defTbl[i];

                if (this.bnsInfo.ChannelCount == 2)
                    this.bnsInfo.Coefficients2[i] = this.defTbl[i];
            }

            this.converted = true;
        }
예제 #5
0
파일: BNS.cs 프로젝트: Chris230291/sma-wii
        public static Wave BnsToWave(string pathToFile)
        {
            BNS b = new BNS();
            byte[] samples;

            using (FileStream fs = new FileStream(pathToFile, FileMode.Open))
                samples = b.Read(fs);

            Wave wave = new Wave(b.bnsInfo.ChannelCount, 16, b.bnsInfo.SampleRate, samples);
            if (b.bnsInfo.HasLoop == 1) wave.AddLoop((int)b.bnsInfo.LoopStart);
            return wave;
        }
예제 #6
0
파일: BNS.cs 프로젝트: Chris230291/sma-wii
        /// <summary>
        /// Converts a BNS audio file to Wave format.
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="outputFile"></param>
        /// <returns></returns>
        public static Wave BnsToWave(Stream inputFile)
        {
            BNS b = new BNS();
            byte[] samples = b.Read(inputFile);

            Wave wave = new Wave(b.bnsInfo.ChannelCount, 16, b.bnsInfo.SampleRate, samples);
            if (b.bnsInfo.HasLoop == 1) wave.AddLoop((int)b.bnsInfo.LoopStart);
            return wave;
        }
        private bool securityChecks()
        {
            if (cbSecurityChecksOff.Checked) return true;

            try
            {
                //Check Channel Title Boxes
                if (!(!string.IsNullOrEmpty(tbAllLanguages.Text) ||
                    (!string.IsNullOrEmpty(tbEnglish.Text) &&
                    !string.IsNullOrEmpty(tbJapanese.Text) &&
                    !string.IsNullOrEmpty(tbGerman.Text) &&
                    !string.IsNullOrEmpty(tbFrench.Text) &&
                    !string.IsNullOrEmpty(tbSpanish.Text) &&
                    !string.IsNullOrEmpty(tbItalian.Text) &&
                    !string.IsNullOrEmpty(tbDutch.Text))))
                {
                    errorBox("You must either enter a general Channel Title or one for each language!");
                    return false;
                }

                //Check Title ID Length + Chars
                if (tbTitleID.Text.Length != 4)
                { errorBox("The Title ID must be 4 characters long!"); return false; }

                Regex allowedchars = new Regex("[A-Z0-9]{4}$");
                if (!allowedchars.IsMatch(tbTitleID.Text.ToUpper()))
                { errorBox("Please enter a valid Title ID!"); return false; }

                //Check Startup IOS Box
                int tmp;
                if (!int.TryParse(tbStartupIos.Text, out tmp))
                { errorBox("Please enter a valid Startup IOS! (0 - 255)"); return false; }
                else if (tmp < 0 || tmp > 255)
                { errorBox("Please enter a valid Startup IOS! (0 - 255)"); return false; }

                //Check brlan files
                string[] validBrlans = new string[] { "banner.brlan", "icon.brlan", "banner_loop.brlan", "banner_start.brlan" };
                foreach (string thisBrlan in lbxBrlanBanner.Items)
                {
                    if (!Array.Exists(validBrlans, brlanName => brlanName.ToLower() == thisBrlan.ToLower()))
                    { errorBox(thisBrlan + " is not a valid brlan filename!"); return false; }
                }
                foreach (string thisBrlan in lbxBrlanIcon.Items)
                {
                    if (!Array.Exists(validBrlans, brlanName => brlanName.ToLower() == thisBrlan.ToLower()))
                    { errorBox(thisBrlan + " is not a valid brlan filename!"); return false; }
                }

                //Check TPLs
                string[] bannerRequiredTpls = new string[0];
                string[] iconRequiredTpls = new string[0];
                List<string> bannerTpls = new List<string>();
                List<string> iconTpls = new List<string>();

                if (string.IsNullOrEmpty(replacedBanner))
                {
                    for (int i = 0; i < bannerBin.NumOfNodes; i++)
                    {
                        if (bannerBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                        { bannerRequiredTpls = Shared.MergeStringArrays(bannerRequiredTpls, Brlyt.GetBrlytTpls(bannerBin.Data[i])); }
                        else if (bannerBin.StringTable[i].ToLower().EndsWith(".brlan"))
                        { bannerRequiredTpls = Shared.MergeStringArrays(bannerRequiredTpls, Brlan.GetBrlanTpls(bannerBin.Data[i])); }
                        else if (bannerBin.StringTable[i].ToLower().EndsWith(".tpl"))
                        { bannerTpls.Add(bannerBin.StringTable[i]); }
                    }
                }
                else
                {
                    for (int i = 0; i < newBannerBin.NumOfNodes; i++)
                    {
                        if (newBannerBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                        { bannerRequiredTpls = Shared.MergeStringArrays(bannerRequiredTpls, Brlyt.GetBrlytTpls(newBannerBin.Data[i])); }
                        else if (newBannerBin.StringTable[i].ToLower().EndsWith(".brlan"))
                        { bannerRequiredTpls = Shared.MergeStringArrays(bannerRequiredTpls, Brlan.GetBrlanTpls(newBannerBin.Data[i])); }
                        else if (newBannerBin.StringTable[i].ToLower().EndsWith(".tpl"))
                        { bannerTpls.Add(newBannerBin.StringTable[i]); }
                    }
                }

                if (string.IsNullOrEmpty(replacedIcon))
                {
                    for (int i = 0; i < iconBin.NumOfNodes; i++)
                    {
                        if (iconBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                        { iconRequiredTpls = Shared.MergeStringArrays(iconRequiredTpls, Brlyt.GetBrlytTpls(iconBin.Data[i])); }
                        else if (iconBin.StringTable[i].ToLower().EndsWith(".brlan"))
                        { iconRequiredTpls = Shared.MergeStringArrays(iconRequiredTpls, Brlan.GetBrlanTpls(iconBin.Data[i])); }
                        else if (iconBin.StringTable[i].ToLower().EndsWith(".tpl"))
                        { iconTpls.Add(iconBin.StringTable[i]); }
                    }
                }
                else
                {
                    for (int i = 0; i < newIconBin.NumOfNodes; i++)
                    {
                        if (newIconBin.StringTable[i].ToLower().EndsWith(".brlyt"))
                        { iconRequiredTpls = Shared.MergeStringArrays(iconRequiredTpls, Brlyt.GetBrlytTpls(newIconBin.Data[i])); }
                        else if (newIconBin.StringTable[i].ToLower().EndsWith(".brlan"))
                        { iconRequiredTpls = Shared.MergeStringArrays(iconRequiredTpls, Brlan.GetBrlanTpls(newIconBin.Data[i])); }
                        else if (newIconBin.StringTable[i].ToLower().EndsWith(".tpl"))
                        { iconTpls.Add(newIconBin.StringTable[i]); }
                    }
                }

                //Check for missing TPLs
                List<string> missingTpls = new List<string>();

                for (int i = 0; i < bannerRequiredTpls.Length; i++)
                    if (!Array.Exists(bannerTpls.ToArray(), thisTpl => thisTpl.ToLower() == bannerRequiredTpls[i].ToLower()))
                        missingTpls.Add(bannerRequiredTpls[i]);

                if (missingTpls.Count > 0)
                {
                    errorBox("The following Banner TPLs are required by the banner.brlyt, but missing:\n\n" + string.Join("\n", missingTpls.ToArray()));
                    return false;
                }

                missingTpls.Clear();

                for (int i = 0; i < iconRequiredTpls.Length; i++)
                    if (!Array.Exists(iconTpls.ToArray(), thisTpl => thisTpl.ToLower() == iconRequiredTpls[i].ToLower()))
                        missingTpls.Add(iconRequiredTpls[i]);

                if (missingTpls.Count > 0)
                {
                    errorBox("The following Icon TPLs are required by the icon.brlyt, but missing:\n\n" + string.Join("\n", missingTpls.ToArray()));
                    return false;
                }

                //Check Sound length
                int soundLength = 0;
                if (!string.IsNullOrEmpty(replacedSound))
                {
                    if (!tbSound.Text.ToLower().EndsWith(".bns") && !tbSound.Text.StartsWith("BNS:"))
                    {
                        Wave w = new Wave(Headers.IMD5.RemoveHeader(newSoundBin));
                        soundLength = w.PlayLength;
                        if (soundLength > soundMaxLength)
                        {
                            errorBox(string.Format("Your wave sound is longer than {0} seconds and thus not supported.\nIt is recommended to use a sound shorter than {1} seconds, the maximum length is {0} seconds!\nThis limit doesn't affect BNS sounds!", soundMaxLength, soundWarningLength));
                            return false;
                        }
                    }
                }

                /*Errors till here..
                  From here only Warnings!*/

                if (soundLength > soundWarningLength)
                {
                    if (MessageBox.Show(string.Format("Your Sound is longer than {0} seconds.\nIt is recommended to use Sounds that are shorter than {0} seconds!\nDo you still want to continue?", soundWarningLength), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        return false;
                }

                //Check BNS sound length
                if (tbSound.Text.StartsWith("BNS:") || tbSound.Text.ToLower().EndsWith(".bns"))
                {
                    int bnsLength = BNS.GetBnsLength(Headers.IMD5.RemoveHeader(newSoundBin));
                    if (bnsLength > bnsWarningLength)
                    {
                        if (MessageBox.Show(string.Format("Your BNS Sound is longer than {0} seconds.\nIt is recommended to use Sounds that are shorter than {0} seconds!\nDo you still want to continue?", bnsWarningLength), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                            return false;
                    }
                }

                //Check if brlyt or brlan were changed
                if (brlytChanged && !brlanChanged)
                {
                    if (MessageBox.Show("You have changed the brlyt, but didn't change the brlan.\nAre you sure this is correct?", "brlyt Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        return false;
                }
                else if (brlanChanged && !brlytChanged)
                {
                    if (MessageBox.Show("You have changed the brlan, but didn't change the brlyt.\nAre you sure this is correct?", "brlan Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        return false;
                }

                //Check for unused TPLs
                List<string> unusedTpls = new List<string>();

                for (int i = 0; i < bannerTpls.Count; i++)
                    if (!Array.Exists(bannerRequiredTpls, thisTpl => thisTpl.ToLower() == bannerTpls[i].ToLower()))
                        unusedTpls.Add(bannerTpls[i]);

                if (unusedTpls.Count > 0)
                {
                    DialogResult dlgresult = MessageBox.Show(
                        "The following Banner TPLs are unused by the banner.brlyt:\n\n" +
                        string.Join("\n", unusedTpls.ToArray()) +
                        "\n\nDo you want them to be deleted before the WAD is being created? (Saves space!)",
                        "Delete unused TPLs?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dlgresult == DialogResult.Yes)
                    {
                        if (string.IsNullOrEmpty(replacedBanner))
                        {
                            foreach (string thisTpl in unusedTpls)
                                bannerBin.RemoveFile("/arc/timg/" + thisTpl);
                        }
                        else
                        {
                            foreach (string thisTpl in unusedTpls)
                                newBannerBin.RemoveFile("/arc/timg/" + thisTpl);
                        }

                        addTpls();
                    }
                    else if (dlgresult == DialogResult.Cancel) return false;
                }

                unusedTpls.Clear();

                for (int i = 0; i < iconTpls.Count; i++)
                    if (!Array.Exists(iconRequiredTpls, thisTpl => thisTpl.ToLower() == iconTpls[i].ToLower()))
                        unusedTpls.Add(iconTpls[i]);

                if (unusedTpls.Count > 0)
                {
                    DialogResult dlgresult = MessageBox.Show(
                        "The following Icon TPLs are unused by the icon.brlyt:\n\n" +
                        string.Join("\n", unusedTpls.ToArray()) +
                        "\n\nDo you want them to be deleted before the WAD is being created? (Saves memory!)",
                        "Delete unused TPLs?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dlgresult == DialogResult.Yes)
                    {
                        if (string.IsNullOrEmpty(replacedIcon))
                        {
                            foreach (string thisTpl in unusedTpls)
                                iconBin.RemoveFile("/arc/timg/" + thisTpl);
                        }
                        else
                        {
                            foreach (string thisTpl in unusedTpls)
                                newIconBin.RemoveFile("/arc/timg/" + thisTpl);
                        }

                        addTpls();
                    }
                    else if (dlgresult == DialogResult.Cancel) return false;
                }

                currentProgress.progressState = " ";
                currentProgress.progressValue = 100;
                this.Invoke(ProgressUpdate);

                return true;
            }
            catch (Exception ex)
            {
                errorBox(ex.Message);
                return false;
            }
        }
예제 #8
0
        private void cmMakeSilent_Click(object sender, EventArgs e)
        {
            Wave w = new Wave(1, 8, 500, new byte[] { 0x80, 0x80, 0x80, 0x80, 0x80 });
            newSoundBin = Headers.IMD5.AddHeader(w.ToByteArray());
            w.Dispose();

            replacedSound = "Silence";
            setControlText(tbSound, "Silence");
            btnBrowseSound.Text = "Clear";

            if (cmbReplace.SelectedIndex == 2) setControlText(tbReplace, string.Empty);
        }
        private void convert(byte[] waveFile, bool loopFromWave)
        {
            Wave wave          = new Wave(waveFile);
            int  waveLoopCount = wave.NumLoops;
            int  waveLoopStart = wave.LoopStart;

            this.bnsInfo.ChannelCount = (byte)wave.NumChannels;
            this.bnsInfo.SampleRate   = (ushort)wave.SampleRate;

            if (this.bnsInfo.ChannelCount > 2 || this.bnsInfo.ChannelCount < 1)
            {
                throw new Exception("Unsupported Amount of Channels!");
            }
            if (wave.BitDepth != 16)
            {
                throw new Exception("Only 16bit Wave files are supported!");
            }
            if (wave.DataFormat != 1)
            {
                throw new Exception("The format of this Wave file is not supported!");
            }

            this.bnsData.Data = Encode(wave.SampleData);

            if (this.bnsInfo.ChannelCount == 1)
            {
                this.bnsHeader.InfoLength = 0x60;
                this.bnsHeader.DataOffset = 0x80;

                this.bnsInfo.Size = 0x60;
                this.bnsInfo.Channel1StartOffset = 0x0000001C;
                this.bnsInfo.Channel2StartOffset = 0x00000000;
                this.bnsInfo.Channel1Start       = 0x00000028;
                this.bnsInfo.Coefficients1Offset = 0x00000000;
            }

            this.bnsData.Size = (uint)bnsData.Data.Length + 8;

            this.bnsHeader.DataLength = this.bnsData.Size;
            this.bnsHeader.FileSize   = this.bnsHeader.Size + this.bnsInfo.Size + this.bnsData.Size;

            if (loopFromWave)
            {
                if (waveLoopCount == 1)
                {
                    if (waveLoopStart != -1)
                    {
                        this.bnsInfo.LoopStart = (uint)waveLoopStart; this.bnsInfo.HasLoop = 0x01;
                    }
                }
            }

            this.bnsInfo.LoopEnd = (uint)tempSampleCount;

            for (int i = 0; i < 16; i++)
            {
                this.bnsInfo.Coefficients1[i] = this.defTbl[i];

                if (this.bnsInfo.ChannelCount == 2)
                {
                    this.bnsInfo.Coefficients2[i] = this.defTbl[i];
                }
            }

            this.converted = true;
        }