Esempio n. 1
0
		public void LoadZones(Zone[] zones)
		{
			// don't do the last preset, which is simply EOP
			for(int instrument = 0; instrument < data.Count - 1; instrument++)
			{
				Instrument i = (Instrument) data[instrument];
				i.Zones = new Zone[i.endInstrumentZoneIndex - i.startInstrumentZoneIndex + 1];
				Array.Copy(zones,i.startInstrumentZoneIndex,i.Zones,0,i.Zones.Length);
			}
			// we can get rid of the EOP record now
			data.RemoveAt(data.Count - 1);
		}
Esempio n. 2
0
		public void LoadZones(Zone[] presetZones)
		{
			// don't do the last preset, which is simply EOP
			for(int preset = 0; preset < data.Count - 1; preset++)
			{
				Preset p = (Preset) data[preset];
				p.Zones = new Zone[p.endPresetZoneIndex - p.startPresetZoneIndex + 1];
				Array.Copy(presetZones,p.startPresetZoneIndex,p.Zones,0,p.Zones.Length);
			}
			// we can get rid of the EOP record now
			data.RemoveAt(data.Count - 1);
		}
Esempio n. 3
0
		public override object Read(BinaryReader br) 
        {
			Zone z = new Zone();
			z.generatorIndex = br.ReadUInt16();
			z.modulatorIndex = br.ReadUInt16();
			if(lastZone != null)
			{
				lastZone.generatorCount = (ushort) (z.generatorIndex - lastZone.generatorIndex);
				lastZone.modulatorCount = (ushort) (z.modulatorIndex - lastZone.modulatorIndex);
			}
			data.Add(z);
			lastZone = z;
			return z;
		}
Esempio n. 4
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;
        }