Example #1
0
        XSample ConvertSample(int count, SSampleHeader sh, byte [] sample, Zone izone)
        {
            // Indices in sf2 are numbers of samples, not byte length. So double them.
            var xs = new XSample();

            xs.Extension = ".wav";
            xs.LoopStart = sh.StartLoop - sh.Start;
            xs.LoopEnd   = sh.EndLoop - sh.Start;
            int sampleModes = izone.SampleModes();

            xs.LoopMode = sampleModes == 0 ? InstrumentSampleLoopMode.Off : InstrumentSampleLoopMode.Forward;
            xs.Name     = String.Format("Sample{0:D02} ({1})", count, sh.SampleName);
            xs.BaseNote = (sbyte)izone.OverridingRootKey();
//			xs.Volume = (izone.VelocityRange () & 0xFF00 >> 8); // low range
            if (xs.BaseNote == 0)
            {
                xs.BaseNote = (sbyte)sh.OriginalPitch;
            }
//Console.WriteLine ("{0} ({1}/{2}/{3}/{4}) {5}:{6}:{7}:{8}", xs.Name, sh.Start, sh.StartLoop, sh.EndLoop, sh.End, sh.SampleRate != 0xAC44 ? sh.SampleRate.ToString () : "", sh.OriginalPitch != 60 ? sh.OriginalPitch.ToString () : "", sh.PitchCorrection != 0 ? sh.PitchCorrection.ToString () : "", sampleModes);
            xs.FileName = xs.Name + ".wav";
            var ms  = new MemoryStream();
            var wfw = new WaveFileWriter(ms, new WaveFormat((int)sh.SampleRate, 16, 1));

            wfw.WriteData(sample, 2 * (int)sh.Start, 2 * (int)(sh.End - sh.Start));
            wfw.Close();
            xs.Buffer = ms.ToArray();

            return(xs);
        }
Example #2
0
 public SampleMap(ushort keyRange, ushort velocityRange, XSample sample, SampleHeader sh)
 {
     KeyRange      = keyRange;
     VelocityRange = velocityRange;
     Sample        = sample;
     SampleHeader  = sh;
 }
Example #3
0
        XSample ConvertSample(int count, SSampleHeader sh, byte [] sample, Zone izone)
        {
            // Indices in sf2 are numbers of samples, not byte length. So double them.
            var xs = new XSample ();
            xs.Extension = ".wav";
            xs.LoopStart =(sh.StartLoop - sh.Start);
            xs.LoopEnd = (sh.EndLoop - sh.Start);
            int sampleModes = izone.SampleModes ();
            xs.LoopMode = sampleModes == 0 ? InstrumentSampleLoopMode.Off : InstrumentSampleLoopMode.Forward;
            xs.Name = String.Format ("Sample{0:D02} ({1})", count, sh.SampleName);
            xs.BaseNote = (sbyte) izone.OverridingRootKey ();
            //			xs.Volume = (izone.VelocityRange () & 0xFF00 >> 8); // low range
            if (xs.BaseNote == 0)
                xs.BaseNote = (sbyte) sh.OriginalPitch;
            //Console.WriteLine ("{0} ({1}/{2}/{3}/{4}) {5}:{6}:{7}:{8}", xs.Name, sh.Start, sh.StartLoop, sh.EndLoop, sh.End, sh.SampleRate != 0xAC44 ? sh.SampleRate.ToString () : "", sh.OriginalPitch != 60 ? sh.OriginalPitch.ToString () : "", sh.PitchCorrection != 0 ? sh.PitchCorrection.ToString () : "", sampleModes);
            xs.FileName = xs.Name + ".wav";
            var ms = new MemoryStream ();
            var wfw = new WaveFileWriter (ms, new WaveFormat ((int) sh.SampleRate, 16, 1));
            wfw.WriteData (sample, 2 * (int) sh.Start, 2 * (int) (sh.End - sh.Start));
            wfw.Close ();
            xs.Buffer = ms.ToArray ();

            return xs;
        }
Example #4
0
 public SampleMap(ushort keyRange, ushort velocityRange, XSample sample, SampleHeader sh)
 {
     KeyRange = keyRange;
     VelocityRange = velocityRange;
     Sample = sample;
     SampleHeader = sh;
 }