Example #1
0
        /// <summary>
        /// Make a standard RIFF Wave.
        /// </summary>
        /// <param name="sampleRate">Sample rate.</param>
        /// <param name="bytesPerSample">Number of bytes per sample.</param>
        /// <param name="samples">Array of samples, can be byte[][] or Int16[][]. First index is channel number.</param>
        /// <returns></returns>
        public static RiffWave CreateRiffWave(UInt32 sampleRate, UInt16 bytesPerSample, object samples)
        {
            RiffWave r = new RiffWave();

            byte[][]  pcm8;
            Int16[][] pcm16;

            UInt16 numChannels = 1;

            if (bytesPerSample == 1)
            {
                pcm8        = (samples as byte[][]);
                numChannels = (UInt16)pcm8.Length;
            }
            else
            {
                pcm16       = (samples as Int16[][]);
                numChannels = (UInt16)pcm16.Length;
            }

            r.fmt  = new RiffWave.FmtChunk(numChannels, sampleRate, bytesPerSample);
            r.data = new RiffWave.DataChunk(samples, r.fmt);
            r.smpl = null;

            return(r);
        }
Example #2
0
        /// <summary>
        /// Make a looping RIFF Wave.
        /// </summary>
        /// <param name="sampleRate">Sample rate.</param>
        /// <param name="bytesPerSample">Number of bytes per sample.</param>
        /// <param name="samples">Array of samples, can be byte[][] or Int16[][]. First index is channel number.</param>
        /// <param name="loopStart">Loop start in samples.</param>
        /// <param name="loopEnd">Loop end in samples.</param>
        /// <returns></returns>
        public static RiffWave CreateRiffWave(UInt32 sampleRate, UInt16 bytesPerSample, object samples, UInt32 loopStart, UInt32 loopEnd)
        {
            RiffWave r = CreateRiffWave(sampleRate, bytesPerSample, samples);

            r.smpl = new RiffWave.SmplChunk(loopStart, loopEnd);

            return(r);
        }
Example #3
0
        /// <summary>
        /// Create a RIFF wave from a vibration.
        /// </summary>
        /// <param name="v">Vibration file.</param>
        /// <returns>The RIFF wave as a vibration.</returns>
        public static RiffWave CreateRiffWave(Vibration v)
        {
            //New wave.
            RiffWave r = new RiffWave();

            //Not looped.
            if (!v.Loops)
            {
                r = RiffWaveFactory.CreateRiffWave(200, 1, EncoderFactory.SignedPcm8ToPcm8(new sbyte[][] { v.pcm8 }));
            }

            //Looped.
            else
            {
                r = RiffWaveFactory.CreateRiffWave(200, 1, EncoderFactory.SignedPcm8ToPcm8(new sbyte[][] { v.pcm8 }), v.LoopStart, v.LoopEnd);
            }

            return(r);
        }
Example #4
0
        /// <summary>
        /// Make a RIFF Wave from a FISP.
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public static RiffWave CreateRiffWave(FISP f)
        {
            //New wave.
            RiffWave r = new RiffWave();

            //Not looped.
            if (!f.stream.isLoop)
            {
                r = RiffWaveFactory.CreateRiffWave(f.stream.sampleRate, 2, f.data.data.ToArray());
            }

            //Looped.
            else
            {
                r = RiffWaveFactory.CreateRiffWave(f.stream.sampleRate, 2, f.data.data.ToArray(), f.stream.loopStart, f.stream.loopEnd);
            }

            return(r);
        }
Example #5
0
        /// <summary>
        /// Create a RIFF wave from a binary wave.
        /// </summary>
        /// <param name="b">Binary wave.</param>
        /// <returns>The binary wave.</returns>
        public static RiffWave CreateRiffWave(BinaryWave b)
        {
            RiffWave r = new RiffWave();
            UInt16   bytesPerSample = 2;

            //Non-looping.
            if (!b.Loops)
            {
                r = CreateRiffWave(b.SampleRate, bytesPerSample, b.Data.GetDataWAV(b.DspAdpcmInfo, b.LoopEndSample));
            }

            //Looping.
            else
            {
                r = CreateRiffWave(b.SampleRate, bytesPerSample, b.Data.GetDataWAV(b.DspAdpcmInfo, b.LoopEndSample), b.LoopStartSample, b.LoopEndSample);
            }

            return(r);
        }
Example #6
0
        /// <summary>
        /// Make a RIFF Wave from a b_stm.
        /// </summary>
        /// <param name="b">The b_stm.</param>
        /// <returns></returns>
        public static RiffWave CreateRiffWave(b_stm b)
        {
            RiffWave r = new RiffWave();
            UInt16   bytesPerSample = 2;

            if (b.info.streamSoundInfo.encoding == EncodingTypes.PCM8)
            {
                bytesPerSample = 1;
            }

            //Non-looping.
            if (!b.info.streamSoundInfo.isLoop)
            {
                r = CreateRiffWave(b.info.streamSoundInfo.sampleRate, bytesPerSample, b.data.GetDataSTM(b.info.streamSoundInfo, b.info));
            }

            //Looping.
            else
            {
                r = CreateRiffWave(b.info.streamSoundInfo.sampleRate, bytesPerSample, b.data.GetDataSTM(b.info.streamSoundInfo, b.info), b.info.streamSoundInfo.loopStart, b.info.streamSoundInfo.sampleCount);
            }

            return(r);
        }
Example #7
0
 /// <summary>
 /// Create a binary wave.
 /// </summary>
 /// <param name="r">Riff wave.</param>
 public static BinaryWave FromRiff(RiffWave r)
 {
     return(new BinaryWave(StreamFactory.CreateStream(r, true, 4, 0, 0)));
 }
Example #8
0
        /// <summary>
        /// Create a new b_stm from a RIFF Wave.
        /// </summary>
        /// <param name="r">The RIFF Wave.</param>
        /// <param name="encode">Whether or not to encode PCM16 data.</param>
        /// <param name="version">Version of the file.</param>
        /// <returns></returns>
        public static b_stm CreateStream(RiffWave r, bool encode, byte vMajor, byte vMinor, byte vRevision)
        {
            b_stm s     = new b_stm();
            bool  loops = false;

            if (r.smpl != null)
            {
                loops = true; if (r.smpl.numLoops < 1)
                {
                    loops = false;
                }
            }
            if (r.fmt.bitsPerSample == RiffWave.FmtChunk.BitsPerSample.PCM8)
            {
                List <byte[]> pcm8      = new List <byte[]>();
                int           count     = 0;
                UInt32        endSample = (UInt32)r.data.channels[0].pcm8.Count();
                if (loops)
                {
                    endSample = r.smpl.loops[0].endSample;
                }
                foreach (RiffWave.DataChunk.DataSamples d in r.data.channels)
                {
                    if (count <= endSample)
                    {
                        pcm8.Add(d.pcm8.ToArray());
                    }
                    count += 1;
                }
                if (!loops)
                {
                    s = CreateStream(r.fmt.sampleRate, endSample, pcm8.ToArray(), EncodingTypes.PCM8, vMajor, vMinor, vRevision);
                }
                else
                {
                    s = CreateStream(r.fmt.sampleRate, endSample, pcm8.ToArray(), EncodingTypes.PCM8, vMajor, vMinor, vRevision, r.smpl.loops[0].startSample);
                }
            }
            else
            {
                List <Int16[]> pcm16      = new List <Int16[]>();
                int            count2     = 0;
                UInt32         endSample2 = (UInt32)r.data.channels[0].pcm16.Count();
                if (loops)
                {
                    endSample2 = r.smpl.loops[0].endSample;
                }
                foreach (RiffWave.DataChunk.DataSamples d in r.data.channels)
                {
                    if (count2 <= endSample2)
                    {
                        pcm16.Add(d.pcm16.ToArray());
                    }
                    count2 += 1;
                }
                byte encoding = EncodingTypes.PCM16;;
                if (encode)
                {
                    encoding = EncodingTypes.DSP_ADPCM;
                }
                if (!loops)
                {
                    s = CreateStream(r.fmt.sampleRate, (UInt32)r.data.channels[0].pcm16.Count(), pcm16.ToArray(), encoding, vMajor, vMinor, vRevision);
                }
                else
                {
                    s = CreateStream(r.fmt.sampleRate, (UInt32)r.data.channels[0].pcm16.Count(), pcm16.ToArray(), encoding, vMajor, vMinor, vRevision, r.smpl.loops[0].startSample);
                }
            }

            return(s);
        }