public MusicPcm(RiffWaveRiff aRiffFile) { Name = aRiffFile.name; Waveform = new WaveformReaderPcm(aRiffFile, false); Length = new SoundTime(Waveform.format.sampleRate, Waveform.format.samples); RiffWaveSmpl lRiffWaveSmpl = ( RiffWaveSmpl )aRiffFile.GetChunk(RiffWaveSmpl.ID); if (lRiffWaveSmpl != null) { loopList = new List <List <LoopInformation> >(); int lIndex = -1; int lLoopLength = -1; for (int i = 0; i < lRiffWaveSmpl.sampleLoops; i++) { SampleLoop lLoop = lRiffWaveSmpl.sampleLoopList[i]; if (( int )(lLoop.end - lLoop.start) == lLoopLength) { } else { loopList.Add(new List <LoopInformation>()); lLoopLength = ( int )(lLoop.end - lLoop.start); lIndex++; } loopList[lIndex].Add(new LoopInformation(Length.sampleRate, ( int )lLoop.start, ( int )lLoop.end)); } } else { loopList = new List <List <LoopInformation> >(); loopList.Add(new List <LoopInformation>()); loopList[0].Add(new LoopInformation(Length.sampleRate, -1, -1)); } Loop = GetLoop(0, 0); }
//--Methods public SamplerChunk(string id, int size, BinaryReader reader) : base(id, size) { smplManufacturer = reader.ReadInt32(); smplProduct = reader.ReadInt32(); smplSamplePeriod = reader.ReadInt32(); smplMidiUnityNote = reader.ReadInt32(); smplMidiPitchFraction = reader.ReadUInt32(); smplSmpteFormat = reader.ReadInt32(); smplSmpteOffset = reader.ReadInt32(); int smplSampleLoops = reader.ReadInt32(); int smplSamplerData = reader.ReadInt32(); smplLoops = new SampleLoop[smplSampleLoops]; for (int x = 0; x < smplLoops.Length; x++) { smplLoops[x] = new SampleLoop(reader); } smplData = reader.ReadBytes(smplSamplerData); if (size % 2 == 1 && reader.PeekChar() == 0) reader.ReadByte(); }
public RiffSubchunk_smpl(byte[] data) { this.data = data; tag = "smpl"; BinaryReader br = new BinaryReader(new MemoryStream(data)); br.BaseStream.Position += 7 * 4; //skip unusued fields int numLoops = br.ReadInt32(); br.BaseStream.Position += 4; //skip sampler data for (int i = 0; i < numLoops; i++) { var sl = new SampleLoop(); sl.CuePointId = br.ReadInt32(); sl.Type = br.ReadInt32(); sl.Start = br.ReadInt32(); sl.End = br.ReadInt32(); sl.Fraction = br.ReadInt32(); sl.PlayCount = br.ReadInt32(); SampleLoops.Add(sl); } }
//--Methods public SamplerChunk(string id, int size, BinaryReader reader) : base(id, size) { smplManufacturer = reader.ReadInt32(); smplProduct = reader.ReadInt32(); smplSamplePeriod = reader.ReadInt32(); smplMidiUnityNote = reader.ReadInt32(); smplMidiPitchFraction = reader.ReadUInt32(); smplSmpteFormat = reader.ReadInt32(); smplSmpteOffset = reader.ReadInt32(); int smplSampleLoops = reader.ReadInt32(); int smplSamplerData = reader.ReadInt32(); smplLoops = new SampleLoop[smplSampleLoops]; for (int x = 0; x < smplLoops.Length; x++) { smplLoops[x] = new SampleLoop(reader); } smplData = reader.ReadBytes(smplSamplerData); if (size % 2 == 1 && reader.PeekChar() == 0) { reader.ReadByte(); } }
private string CreateSfzList(string aDirectory) { Dictionary <int, string> lFileNameDictionary = new Dictionary <int, string>(); Dictionary <int, int> lToneDictionary = new Dictionary <int, int>(); string lDirectoryName = Path.GetFileName(aDirectory); string[] lFilePathArray = Directory.GetFiles(aDirectory, "*.wav", SearchOption.TopDirectoryOnly); Dictionary <string, int> lLoopStartDictionary = new Dictionary <string, int>(); Dictionary <string, int> lLoopEndDictionary = new Dictionary <string, int>(); for (int i = 0; i < lFilePathArray.Length; i++) { string lFileName = Path.GetFileName(lFilePathArray[i]); string[] separatedStringArrayDot = lFileName.Split('.'); int separatedNumDot = separatedStringArrayDot.Length; lLoopStartDictionary.Add(lFileName, 0); lLoopEndDictionary.Add(lFileName, 0); if (separatedNumDot >= 3) { string pitchNotation = separatedStringArrayDot[separatedNumDot - 2]; string[] separateStringArrayAtmark = pitchNotation.Split('@'); int separatedNumAtmark = separateStringArrayAtmark.Length; if (separatedNumAtmark >= 1) { int keycenterActual = GetPitchNotation(separateStringArrayAtmark[0]); int keycenterDestination = keycenterActual; if (separatedNumAtmark == 2) { keycenterDestination = GetPitchNotation(separateStringArrayAtmark[1]); } if (lFileNameDictionary.ContainsKey(keycenterDestination) == false) { lFileNameDictionary.Add(keycenterDestination, Path.GetFileName(lFilePathArray[i])); } if (lToneDictionary.ContainsKey(keycenterDestination) == false) { lToneDictionary.Add(keycenterDestination, (keycenterActual - keycenterDestination) * 100); } } } RiffWaveRiff lRiffWaveRiff = new RiffWaveRiff(lFilePathArray[i]); RiffWaveSmpl lRiffWaveSmpl = ( RiffWaveSmpl )lRiffWaveRiff.GetChunk(RiffWaveSmpl.ID); if (lRiffWaveSmpl != null) { if (lRiffWaveSmpl.sampleLoopList[0] != null) { SampleLoop lLoop = lRiffWaveSmpl.sampleLoopList[0]; lLoopStartDictionary[lFileName] = ( int )lLoop.start; lLoopEndDictionary[lFileName] = ( int )lLoop.end; } } } string lSfz = ""; lSfz += "<group>\n"; lSfz += "loop_mode=no_loop\n"; //sfz += "loop_mode=loop_continuous\n"; lSfz += "ampeg_release=0.250\n"; lSfz += "\n"; int lokey = 0; int hikey = 127; for (int i = 0; i < 128; i++) { if (lFileNameDictionary.ContainsKey(i) == true) { lSfz += "<region>\n"; lSfz += "sample=" + lDirectoryName + "/" + lFileNameDictionary[i] + "\n"; lSfz += "pitch_keycenter=" + i + "\n"; for (hikey = i + 1; hikey < 127; hikey++) { if (lFileNameDictionary.ContainsKey(hikey) == true) { hikey--; break; } } lSfz += "lokey=" + lokey + "\n"; lSfz += "hikey=" + hikey + "\n"; if (lLoopStartDictionary[lFileNameDictionary[i]] != 0 || lLoopEndDictionary[lFileNameDictionary[i]] != 0) { lSfz += "loop_start=" + lLoopStartDictionary[lFileNameDictionary[i]] + "\n"; lSfz += "loop_end=" + lLoopEndDictionary[lFileNameDictionary[i]] + "\n"; } if (lToneDictionary.ContainsKey(i) == true) { lSfz += "tune=" + lToneDictionary[i] + "\n"; } else { lSfz += "tune=0\n"; } lSfz += "\n"; lokey = hikey + 1; } } return(lSfz); }
public MusicWave(RiffFile aRiffFile) { RiffChunkListWave lWaveRiff = ( RiffChunkListWave )aRiffFile.riffChunkList; nameFile = aRiffFile.name; bytePosition = ( int )lWaveRiff.dataChunk.position; byteSize = ( int )lWaveRiff.dataChunk.size; Channels = lWaveRiff.fmt_Chunk.channels; SampleRate = ( int )lWaveRiff.fmt_Chunk.samplesPerSec; sampleBits = lWaveRiff.fmt_Chunk.bitsPerSample; SampleLength = ( int )(byteSize / (sampleBits / 8) / Channels); sampleArray = new float[Channels][]; if (LENGTH_BUFFER == 0) { lengthBuffer = SampleLength; } else { lengthBuffer = LENGTH_BUFFER; } for (int i = 0; i < Channels; i++) { sampleArray[i] = new float[lengthBuffer]; } startPosition = 0x7FFFFFFF; if (lWaveRiff.smplChunk != null) { Loop = new List <List <LoopInformation> >(); int lIndex = -1; int lLoopLength = -1; for (int i = 0; i < lWaveRiff.smplChunk.sampleLoops; i++) { SampleLoop lLoop = lWaveRiff.smplChunk.sampleLoopList[i]; if (( int )(lLoop.end - lLoop.start) == lLoopLength) { } else { Loop.Add(new List <LoopInformation>()); lLoopLength = ( int )(lLoop.end - lLoop.start); lIndex++; } Loop[lIndex].Add(new LoopInformation(SampleRate, ( int )lLoop.start, ( int )lLoop.end)); } } else { Loop = new List <List <LoopInformation> >(); Loop.Add(new List <LoopInformation>()); Loop[0].Add(new LoopInformation(SampleRate, 0, 0)); } }