Exemplo n.º 1
0
        //--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));
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
        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;
                    }
                }
            }
        }