Beispiel #1
0
        void WriteSdta()
        {
            mWriter.WriteString("LIST");
            mWriter.WriteS32(CalculateSmplSize() + 12);

            mWriter.WriteString("sdta");

            mWriter.WriteString("smpl");
            mWriter.WriteS32(CalculateSmplSize());

            foreach (var waveGroup in mWaveBank)
            {
                var archiveFileName = Path.Combine(mInputDirectory, waveGroup.ArchiveFileName);

                using (var instream = mareep.OpenFile(archiveFileName)) {
                    var reader = new aBinaryReader(instream, Endianness.Big);

                    mareep.WriteSeparator('-');
                    mareep.WriteMessage("{0} ({1} wave(s))\n", waveGroup.ArchiveFileName, waveGroup.Count);

                    foreach (var wave in waveGroup)
                    {
                        reader.Goto(wave.WaveStart);
                        var data  = reader.Read8s(wave.WaveSize);
                        var mixer = new RawWaveMixer(new MemoryStream(data), wave.Format);
                        mixer.Write(WaveFormat.Pcm16, mWriter);

                        for (var i = 0; i < 92; i++)
                        {
                            mWriter.WriteS8(0);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        void ExtractWav(Wave wave, byte[] data, Stream stream)
        {
            var writer     = new aBinaryWriter(stream, Endianness.Little);
            var mixer      = new RawWaveMixer(new MemoryStream(data), wave.Format);
            var dataSize   = (wave.SampleCount * 2);
            var sampleRate = (int)wave.SampleRate;
            var numLoops   = wave.Loop ? 1 : 0;

            writer.WriteString("RIFF");
            writer.WriteS32(36 + dataSize + ((wave.Loop || wave.RootKey != 60) ? (36 + (numLoops * 24)) : 0));
            writer.WriteString("WAVE");
            writer.WriteString("fmt ");
            writer.WriteS32(16);
            writer.WriteS16(1);              // format
            writer.Write16(1);               // channel count
            writer.WriteS32(sampleRate);
            writer.WriteS32(sampleRate * 2); // byte rate
            writer.Write16(2);               // block align
            writer.Write16(16);              // bit depth
            if (wave.Loop || wave.RootKey != 60)
            {
                writer.WriteString("smpl");
                writer.WriteS32(36 + (numLoops * 24));
                writer.WriteS32(0);                       // manufacturer
                writer.WriteS32(0);                       // product
                writer.WriteS32(1000000000 / sampleRate); // sample period
                writer.WriteS32(wave.RootKey);            // unity note
                writer.WriteS32(0);                       // pitch fraction
                writer.WriteS32(0);                       // SMPTE format
                writer.WriteS32(0);                       // SMPTE offset
                writer.WriteS32(numLoops);
                writer.WriteS32(0);                       // sampler data
                if (wave.Loop)
                {
                    writer.WriteS32(0);                     // cue point ID
                    writer.WriteS32(0);                     // type
                    writer.WriteS32(wave.LoopStart);
                    writer.WriteS32(wave.LoopEnd - 1);
                    writer.WriteS32(0);                     // fraction
                    writer.WriteS32(0);                     // play count
                }
            }
            writer.WriteString("data");
            writer.WriteS32(dataSize);
            mixer.Write(WaveFormat.Pcm16, writer);
        }
Beispiel #3
0
        void ExtractWav(Wave wave, byte[] data, Stream stream)
        {
            var writer     = new aBinaryWriter(stream, Endianness.Little);
            var mixer      = new RawWaveMixer(new MemoryStream(data), wave.Format);
            var dataSize   = (wave.SampleCount * 2);
            var sampleRate = (int)wave.SampleRate;

            writer.WriteString("RIFF");
            writer.WriteS32(36 + dataSize);
            writer.WriteString("WAVE");
            writer.WriteString("fmt ");
            writer.WriteS32(16);
            writer.WriteS16(1);              // format
            writer.Write16(1);               // channel count
            writer.WriteS32(sampleRate);
            writer.WriteS32(sampleRate * 2); // byte rate
            writer.Write16(2);               // block align
            writer.Write16(16);              // bit depth
            writer.WriteString("data");
            writer.WriteS32(dataSize);
            mixer.Write(WaveFormat.Pcm16, writer);
        }
Beispiel #4
0
        protected override WaveBank DoTransform(WaveBank obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var badwaves = 0;

            if (!Directory.Exists(mBankDirectory))
            {
                mareep.WriteMessage("Creating directory '{0}'...\n", mBankDirectory);
                Directory.CreateDirectory(mBankDirectory);
            }

            mareep.WriteMessage("Transferring waves...\n");

            foreach (var waveGroup in obj)
            {
                var archiveFileName = Path.Combine(mBankDirectory, waveGroup.ArchiveFileName);

                mareep.WriteSeparator('-');
                mareep.WriteMessage("{0}\n", waveGroup.ArchiveFileName);

                using (var outstream = mareep.CreateFile(archiveFileName)) {
                    var writer = new aBinaryWriter(outstream, Endianness.Big);

                    foreach (var wave in waveGroup)
                    {
                        var waveFileName = Path.Combine(mWaveDirectory, wave.FileName);
                        var extension    = Path.GetExtension(waveFileName).ToLowerInvariant();

                        if (!File.Exists(waveFileName))
                        {
                            mareep.WriteWarning("XFER: cannot find file '{0}'\n", wave.FileName);
                            ++badwaves;
                            continue;
                        }

                        using (var instream = mareep.OpenFile(waveFileName)) {
                            wave.WaveStart = (int)writer.Position;
                            WaveMixer mixer = null;

                            switch (extension)
                            {
                            case ".wav": mixer = new MicrosoftWaveMixer(instream); break;

                            case ".raw": mixer = new RawWaveMixer(instream, wave.Format); break;
                            }

                            if (mixer == null)
                            {
                                mareep.WriteWarning("XFER: could not create wave mixer (unsupported file extension '{0}')\n", extension);
                                ++badwaves;
                                continue;
                            }

                            mixer.MixerMode = mMixerMode;
                            mixer.CopyWaveInfo(wave);

                            if (wave.Loop && wave.LoopStart > 0)
                            {
                                int last, penult;

                                mixer.CalculateHistory(wave.LoopStart, wave.Format, out last, out penult);

                                wave.HistoryLast   = last;
                                wave.HistoryPenult = penult;
                            }

                            mixer.Write(wave.Format, writer);
                            wave.WaveSize = ((int)writer.Position - wave.WaveStart);
                            writer.WritePadding(32, 0);

                            mareep.WriteMessage(" #{0:X4} '{1,-35}' (0x{2:X6} 0x{3:X6})\n", wave.WaveId, Path.GetFileName(wave.FileName), wave.WaveStart, wave.WaveSize);
                        }
                    }
                }
            }

            if (badwaves > 0)
            {
                mareep.WriteError("Failed to transfer {0} wave(s).", badwaves);
            }

            return(obj);
        }