public SampleMap(ushort keyRange, ushort velocityRange, XSample sample, SampleHeader sh) { KeyRange = keyRange; VelocityRange = velocityRange; Sample = sample; SampleHeader = sh; }
public SamplesData(SampleHeader p_header, KaitaiStream p__io, FasttrackerXmModule.Instrument p__parent = null, FasttrackerXmModule p__root = null) : base(p__io) { m_parent = p__parent; m_root = p__root; _header = p_header; _read(); }
protected override bool ReadFile(BinaryReader r) { var length = (int)r.BaseStream.Length; if (length < IDXHeader.ByteSize) { return false; } if (!Header.ReadFile(r)) { return false; } if (Header.SampleCount > 0) { var oldVersion = Header.Version == 1; var offs = IDXHeader.ByteSize; int sampleSize = oldVersion ? 32 : 36; var dataSize = Header.SampleCount * sampleSize; if (offs + dataSize > length) { return false; } var data = r.ReadBytes(dataSize); for (var i = 0; i < Header.SampleCount; ++i) { var S = new SampleHeader(); var seg = new ArraySegment<byte>(data, i * sampleSize, sampleSize); S.ReadFile(seg, !oldVersion); Samples.Add(S.Name, S); } } return true; }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { this.assetName = sample.Name; this.sampleRate = sample.SampleRate; this.rootKey = sample.RootKey; this.tune = sample.Tune; this.start = sample.Start; this.end = sample.End; this.loopStart = sample.StartLoop; this.loopEnd = sample.EndLoop; this.sampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); }
public SampleHeaderChunk(string id, int size, BinaryReader reader) : base(id, size) { if (size % 46 != 0) throw new Exception("Invalid SoundFont. The sample header chunk was invalid."); sampleHeaders = new SampleHeader[(size / 46) - 1]; for (int x = 0; x < sampleHeaders.Length; x++) { sampleHeaders[x] = new SampleHeader(reader); } new SampleHeader(reader); //read terminal record }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { this.assetName = sample.Name; this.sampleRate = sample.SampleRate; this.rootKey = sample.RootKey; this.tune = sample.Tune; this.start = sample.Start; this.end = sample.End; this.loopStart = sample.StartLoop; this.loopEnd = sample.EndLoop; this.sampleData = sampleData.SampleData; }
private static SampleSoundGenerator GetSampleRemainder(SampleHeader sh, Zone izone, byte[] sample, SampleGeneratingArgs args) { // Indices in sf2 are numbers of samples, not byte length. So double them int start = (int)sh.Start + izone.FullStartAddressOffset(); int end = (int)sh.End + izone.FullEndAddressOffset(); int startLoop = (int)sh.StartLoop + izone.FullStartLoopAddressOffset(); int endLoop = (int)sh.EndLoop + izone.FullEndLoopAddressOffset(); int length = end - start; int loopLength = endLoop - startLoop; int loopLengthBytes = loopLength * 2; int lengthFirstHalf = startLoop - start; int lengthFirstHalfBytes = lengthFirstHalf * 2; int lengthSecondHalf = end - endLoop; int lengthSecondHalfBytes = lengthSecondHalf * 2; double lengthInSeconds = args.Length != -1 ? (args.Length / 1000) : length / (double)sh.SampleRate; // Sample rate key correction int keyCorrection = args.Key != -1 ? args.Key - izone.Key() : 0; double factor = Math.Pow(2, keyCorrection / 12d); lengthInSeconds *= factor; int numberOfSamples = (int)Math.Ceiling(lengthInSeconds * sh.SampleRate); numberOfSamples += lengthSecondHalf; int numberOfLoopSamples = numberOfSamples - lengthFirstHalf - lengthSecondHalf; if (numberOfLoopSamples < loopLength) { return(GetSampleWithoutLoop(sh, izone, sample, args)); } int numberOfBytes = numberOfSamples * 2; int numberOfLoopBytes = numberOfLoopSamples * 2; byte[] buffer = new byte[numberOfBytes]; byte[] bufferLoop = new byte[numberOfLoopBytes]; Array.Copy(sample, start * 2, buffer, 0, lengthFirstHalfBytes); for (int i = 0; i < (numberOfLoopSamples + loopLength - 1) / loopLength; i++) { Array.Copy(sample, startLoop * 2, bufferLoop, i * loopLengthBytes, Math.Min(loopLengthBytes, numberOfLoopBytes - i * loopLengthBytes)); } bufferLoop.CopyTo(buffer, lengthFirstHalfBytes); Array.Copy(sample, start * 2, buffer, lengthFirstHalfBytes + numberOfLoopBytes, lengthSecondHalfBytes); return(new SampleSoundGenerator(BufferToWaveStream(buffer, (uint)(sh.SampleRate * factor)))); }
public SampleHeaderChunk(string id, int size, IReadable input) : base(id, size) { if (size % 46 != 0) throw new Exception("Invalid SoundFont. The sample header chunk was invalid."); SampleHeaders = new SampleHeader[(int)((size / 46.0) - 1)]; for (int x = 0; x < SampleHeaders.Length; x++) { SampleHeaders[x] = new SampleHeader(input); } new SampleHeader(input); //read terminal record }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { Channels = 1; Name = sample.Name; SampleRate = sample.SampleRate; RootKey = sample.RootKey; Tune = sample.Tune; Start = sample.Start; End = sample.End; LoopStart = sample.StartLoop; LoopEnd = sample.EndLoop; SampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); }
public SampleHeaderChunk(string id, int size, BinaryReader reader) : base(id, size) { if (size % 46 != 0) { throw new InvalidDataException("Invalid SoundFont. The sample header chunk was invalid."); } sampleHeaders = new SampleHeader[(size / 46) - 1]; for (int x = 0; x < sampleHeaders.Length; x++) { sampleHeaders[x] = new SampleHeader(reader); } new SampleHeader(reader); //read terminal record }
public SampleHeaderChunk(string id, int size, IReadable input) : base(id, size) { if (size % 46 != 0) { throw new Exception("Invalid SoundFont. The sample header chunk was invalid."); } SampleHeaders = new SampleHeader[(int)((size / 46.0) - 1)]; for (int x = 0; x < SampleHeaders.Length; x++) { SampleHeaders[x] = new SampleHeader(input); } new SampleHeader(input); //read terminal record }
private static SampleSoundGenerator GetSampleWithLength(SampleHeader sh, Zone izone, int sampleMode, byte[] sample, SampleGeneratingArgs args) { if (sampleMode == 0 || sampleMode == 2) { // Don't loop return(GetSampleWithoutLoop(sh, izone, sample, args)); } else if (sampleMode == 1) { // Loop continuously return(GetSampleContinuous(sh, izone, sample, args)); } else { // Loops for the duration of key depression then proceed to play the remainder of the sample return(GetSampleRemainder(sh, izone, sample, args)); } }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { Channels = 1; Name = sample.Name; SampleRate = sample.SampleRate; RootKey = sample.RootKey; Tune = sample.Tune; Start = sample.Start; End = sample.End; LoopStart = sample.StartLoop; LoopEnd = sample.EndLoop; if ((sample.SoundFontSampleLink & SFSampleLink.OggVobis) != 0) { throw new Exception("Ogg Vobis encoded soundfonts not supported"); } else { SampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); } }
protected override bool ReadFile(BinaryReader r) { var length = (int)r.BaseStream.Length; if (length < IDXHeader.ByteSize) { return(false); } if (!Header.ReadFile(r)) { return(false); } if (Header.SampleCount > 0) { var oldVersion = Header.Version == 1; var offs = IDXHeader.ByteSize; int sampleSize = oldVersion ? 32 : 36; var dataSize = Header.SampleCount * sampleSize; if (offs + dataSize > length) { return(false); } var data = r.ReadBytes(dataSize); for (var i = 0; i < Header.SampleCount; ++i) { var S = new SampleHeader(); var seg = new ArraySegment <byte>(data, i * sampleSize, sampleSize); S.ReadFile(seg, !oldVersion); Samples.Add(S.Name, S); } } return(true); }
private static SampleSoundGenerator GetSampleWithoutLoop(SampleHeader sh, Zone izone, byte[] sample, SampleGeneratingArgs args) { // Indices in sf2 are numbers of samples, not byte length. So double them int start = (int)sh.Start + izone.FullStartAddressOffset(); int end = (int)sh.End + izone.FullEndAddressOffset(); int length = end - start; double lengthInSeconds = args.Length != -1 ? (args.Length / 1000) + 0.4 : length / (double)sh.SampleRate; // Sample rate key correction int keyCorrection = args.Key != -1 ? args.Key - izone.Key() : 0; double factor = Math.Pow(2, keyCorrection / 12d); lengthInSeconds *= factor; lengthInSeconds = Math.Min(lengthInSeconds, length / (double)sh.SampleRate); int numberOfSamples = (int)Math.Ceiling(lengthInSeconds * sh.SampleRate); int numberOfBytes = numberOfSamples * 2; byte[] buffer = new byte[numberOfBytes]; Array.Copy(sample, start * 2, buffer, 0, numberOfBytes); var output = new SampleSoundGenerator(BufferToWaveStream(buffer, (uint)(sh.SampleRate * factor))); if (lengthInSeconds <= 0.4) { output.FadeStart = lengthInSeconds * 0.7; output.FadeLength = lengthInSeconds * 0.2; } else { output.FadeStart = lengthInSeconds - 0.4; output.FadeLength = 0.3; } return(output); }
public ADPCMHeader(SampleHeader S) : base(S) { FileHeaderSize = HeaderSize; FmtExtraSize = 4; Format = 0x11; }
public PCMHeader(SampleHeader S) : base(S) { Format = 1; FileHeaderSize = HeaderSize; }
public PCMHeader(SampleHeader S) : base(S) { Format = 1; FileHeaderSize = HeaderSize; }
public WAVHeader(SampleHeader S) { IDXSample = S; }
public WAVHeader(SampleHeader S) { IDXSample = S; }
public ADPCMHeader(SampleHeader S) : base(S) { FileHeaderSize = HeaderSize; FmtExtraSize = 4; Format = 0x11; }