//--Public Methods
 public WaveFileReader(string filename)
 {
     if (Path.GetExtension(filename).ToLower() != ".wav" || PlatformHelper.FileExists(filename) == false)
     {
         throw new IOException("Invalid wave file!");
     }
     BR = new System.IO.BinaryReader(PlatformHelper.StreamLoad(filename));
 }
 public void loadBank(byte[] Programs, byte[] DrumPrograms)
 {
     if (PlatformHelper.FileExists(lastbankpath) == false)
     {
         return;
     }
     Clear();
     Bank.Capacity     = BankManager.DEFAULT_BANK_SIZE;
     DrumBank.Capacity = BankManager.DEFAULT_DRUMBANK_SIZE;
     for (int x = 0; x < BankManager.DEFAULT_BANK_SIZE; x++)
     {
         Bank.Add(null);
     }
     for (int x = 0; x < BankManager.DEFAULT_DRUMBANK_SIZE; x++)
     {
         DrumBank.Add(null);
     }
     loadStream(PlatformHelper.StreamLoad(lastbankpath), Path.GetDirectoryName(lastbankpath) + "/", Programs, DrumPrograms);
 }
Exemple #3
0
        //--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);
        }