Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveBank"/> class from a file for async reading.
        /// </summary>
        /// <param name="audioEngine">The engine.</param>
        /// <param name="fileName">Name of the file to load the wavebank from.</param>
        /// <param name="offset">The offset into the stream.</param>
        /// <param name="packetSize">Packet size used to load the stream.</param>
        public WaveBank(AudioEngine audioEngine, string fileName, int offset, short packetSize)
        {
            this.audioEngine = audioEngine;
            isAudioEngineReadonly = true;

            var handle = NativeFile.Create(fileName, NativeFileAccess.Read, NativeFileShare.Read | NativeFileShare.Write,
                                  IntPtr.Zero, NativeFileMode.Open,
                                  NativeFileOptions.Normal | NativeFileOptions.NoBuffering |
                                  NativeFileOptions.Overlapped | NativeFileOptions.SequentialScan, IntPtr.Zero);


            if (handle == IntPtr.Zero || handle.ToInt32() == -1)
                throw new FileNotFoundException("Unable to open the specified file.", fileName);


            var streamingParameters = new StreamingParameters {File = handle, Flags = 0, Offset = offset, PacketSize = packetSize};

            audioEngine.CreateStreamingWaveBank(streamingParameters, this);
            FileStreamHandle = new SafeFileHandle(handle, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveBank"/> class from a file for async reading.
        /// </summary>
        /// <param name="audioEngine">The engine.</param>
        /// <param name="fileName">Name of the file to load the wavebank from.</param>
        /// <param name="offset">The offset into the stream.</param>
        /// <param name="packetSize">Packet size used to load the stream.</param>
        public WaveBank(AudioEngine audioEngine, string fileName, int offset, short packetSize)
        {
            this.audioEngine      = audioEngine;
            isAudioEngineReadonly = true;

            var handle = NativeFile.Create(fileName, NativeFileAccess.Read, NativeFileShare.Read | NativeFileShare.Write,
                                           IntPtr.Zero, NativeFileMode.Open,
                                           NativeFileOptions.Normal | NativeFileOptions.NoBuffering |
                                           NativeFileOptions.Overlapped | NativeFileOptions.SequentialScan, IntPtr.Zero);


            if (handle == IntPtr.Zero || handle.ToInt32() == -1)
            {
                throw new FileNotFoundException("Unable to open the specified file.", fileName);
            }


            var streamingParameters = new StreamingParameters {
                File = handle, Flags = 0, Offset = offset, PacketSize = packetSize
            };

            audioEngine.CreateStreamingWaveBank(streamingParameters, this);
            FileStreamHandle = new SafeFileHandle(handle, true);
        }