//--Public Methods public Sample(string filename) { //UnitySynth - remove non Unity file path check //if (System.IO.File.Exists(filename) == false) // throw new System.IO.FileNotFoundException("Sample not found: " + Path.GetFileNameWithoutExtension(filename)); name = Path.GetFileNameWithoutExtension(filename); if (CSharpSynth.Unity.EditorConfiguration.DEBUG_SAMPLE_LOAD_VERBOSE) Debug.Log("filename: " + filename + " name " + name); WaveFileReader WaveReader = new WaveFileReader(filename); IChunk[] chunks = WaveReader.ReadAllChunks(); WaveReader.Close(); //Close the reader and the underlying stream. DataChunk dChunk = null; FormatChunk fChunk = null; for (int x = 0; x < chunks.Length; x++) { if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Format) fChunk = (FormatChunk)chunks[x]; else if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Data) dChunk = (DataChunk)chunks[x]; } if (fChunk == null || dChunk == null) throw new ArgumentException("Wave file is in unrecognized format!"); if (fChunk.wBitsPerSample != 16) WaveHelper.ChangeBitsPerSample(fChunk, dChunk, 16); //currently unused: //int channels = fChunk.nChannels; sampleRate = fChunk.nSamplesPerSec; originalRate = sampleRate; data = WaveHelper.GetSampleData(fChunk, dChunk); }
//--Public Methods public Sample(string filename) { if (PlatformHelper.FileExists(filename) == false) throw new System.IO.FileNotFoundException("Sample not found: " + Path.GetFileNameWithoutExtension(filename)); name = Path.GetFileNameWithoutExtension(filename); WaveFileReader WaveReader = new WaveFileReader(filename); IChunk[] chunks = WaveReader.ReadAllChunks(); WaveReader.Close(); //Close the reader and the underlying stream. DataChunk dChunk = null; FormatChunk fChunk = null; for (int x = 0; x < chunks.Length; x++) { if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Format) fChunk = (FormatChunk)chunks[x]; else if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Data) dChunk = (DataChunk)chunks[x]; } if (fChunk == null || dChunk == null) throw new ArgumentException("Wave file is in unrecognized format!"); if (fChunk.wBitsPerSample != 16) WaveHelper.ChangeBitsPerSample(fChunk, dChunk, 16); int channels = fChunk.nChannels; sampleRate = fChunk.nSamplesPerSec; originalRate = sampleRate; data = WaveHelper.GetSampleData(fChunk, dChunk); }