//--Properties //--Methods public WaveFileReader(string fileName) { if (!Path.GetExtension(fileName).ToLower().Equals(".wav") || !CrossPlatformHelper.ResourceExists(fileName)) { throw new InvalidDataException("Invalid wave file : " + fileName); } reader = new BinaryReader(CrossPlatformHelper.OpenResource(fileName)); }
private static string GetTemporaryFileName(string path) { int x = 0; string baseName = path + "Raw_Wave_Data_"; while (CrossPlatformHelper.ResourceExists(baseName + x + ".dat")) { x++; } return(baseName + x + ".dat"); }
public void LoadSampleAsset(string assetName, string patchName, string directory) { string assetNameWithoutExtension; string extension; if (Path.HasExtension(assetName)) { assetNameWithoutExtension = Path.GetFileNameWithoutExtension(assetName); extension = Path.GetExtension(assetName).ToLower(); } else { assetNameWithoutExtension = assetName; assetName += ".wav"; //assume .wav extension = ".wav"; } if (FindSample(assetNameWithoutExtension) == null) { string waveAssetPath; if (CrossPlatformHelper.ResourceExists(assetName)) { waveAssetPath = assetName; //ex. "asset.wav" } else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + assetName)) { waveAssetPath = directory + Path.DirectorySeparatorChar + assetName; //ex. "C:\asset.wav" } else if (CrossPlatformHelper.ResourceExists(directory + "/SAMPLES/" + assetName)) { waveAssetPath = directory + "/SAMPLES/" + assetName; //ex. "C:\SAMPLES\asset.wav" } else if (CrossPlatformHelper.ResourceExists(directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName)) { waveAssetPath = directory + Path.DirectorySeparatorChar + patchName + Path.DirectorySeparatorChar + assetName; //ex. "C:\Piano\asset.wav" } else { throw new IOException("Could not find sample asset: (" + assetName + ") required for patch: " + patchName); } using (BinaryReader reader = new BinaryReader(CrossPlatformHelper.OpenResource(waveAssetPath))) { switch (extension) { case ".wav": sampleAssets.Add(new SampleDataAsset(assetNameWithoutExtension, WaveFileReader.ReadWaveFile(reader))); break; } } } }