当前位置: 首页>>代码示例>>C#>>正文


C# WaveStream.Read方法代码示例

本文整理汇总了C#中NAudio.Wave.WaveStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# WaveStream.Read方法的具体用法?C# WaveStream.Read怎么用?C# WaveStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NAudio.Wave.WaveStream的用法示例。


在下文中一共展示了WaveStream.Read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Extract

        private static void Extract(Stream output, WaveStream waveStream, byte[] buffer)
        {
            if (waveStream == null)
                return;

            using (WaveFileWriter writer = new WaveFileWriter(output, waveStream.WaveFormat))
            {
                int count;
                while ((count = waveStream.Read(buffer, 0, buffer.Length)) != 0)
                    writer.Write(buffer, 0, count);
            }
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:12,代码来源:ScdToWaveArchiveEntryExtractor.cs

示例2: CreateWaveFile

 /// <summary>
 /// Creates a Wave file by reading all the data from a WaveStream
 /// </summary>
 /// <param name="filename">The filename to use</param>
 /// <param name="stream">The source WaveStream</param>
 public static void CreateWaveFile(string filename, WaveStream stream)
 {
     using (WaveFileWriter writer = new WaveFileWriter(filename, stream.WaveFormat))
     {
         byte[] buffer = new byte[stream.GetReadSize(4000)];
         while (true)
         {
             int bytesRead = stream.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
                 break;
             writer.WriteData(buffer, 0, bytesRead);
         }
     }
 }
开发者ID:Punloeu,项目名称:karaoke,代码行数:19,代码来源:WaveFileWriter.cs

示例3: CreateAiffFile

        /// <summary>
        /// Creates an Aiff file by reading all the data from a WaveProvider
        /// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
        /// or the Aiff File will grow indefinitely.
        /// </summary>
        /// <param name="filename">The filename to use</param>
        /// <param name="sourceProvider">The source WaveProvider</param>
        public static void CreateAiffFile(string filename, WaveStream sourceProvider)
        {
            using (var writer = new AiffFileWriter(filename, sourceProvider.WaveFormat))
            {
                byte[] buffer = new byte[16384];

                while (sourceProvider.Position < sourceProvider.Length)
                {
                    int count = Math.Min((int)(sourceProvider.Length - sourceProvider.Position), buffer.Length);
                    int bytesRead = sourceProvider.Read(buffer, 0, count);

                    if (bytesRead == 0)
                    {
                        // end of source provider
                        break;
                    }

                    writer.Write(buffer, 0, bytesRead);
                }
            }
        }
开发者ID:Shadetheartist,项目名称:Numboard-2.0,代码行数:28,代码来源:AiffFileWriter.cs

示例4: Read

        /// <summary>
        /// Read an audio file.
        /// </summary>
        void Read()
        {
#if WINDOWS
            reader = new MediaFoundationReader(fileName);
            duration = reader.TotalTime;
            format = new AudioFormat(reader.WaveFormat);

            var bytes = new byte[reader.Length];
            var read = reader.Read(bytes, 0, bytes.Length);
            data = new List<byte>(bytes);
#else
            throw new NotImplementedException();
#endif
        }
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:17,代码来源:AudioContent.cs

示例5: LoadStream

        private int LoadStream(WaveStream waveStream) {
            if (!isInitialized) {
                Error("Trying to Load Stream format for uninitialized sound manager");
            }

            int channels, bits_per_sample, sample_rate;
            byte[] sound_data = null;

            for (int i = 0; i < managedSounds.Count; ++i) {
                if (managedSounds[i].refCount <= 0) {
                    StopSound(managedSounds[i].bufferHandle);
                    AL.DeleteBuffer(managedSounds[i].bufferHandle);
                    managedSounds[i].bufferHandle = AL.GenBuffer();
                    managedSounds[i].refCount = 1;

                    sound_data = new byte[waveStream.Length];
                    waveStream.Read(sound_data, 0, (int)waveStream.Length);
                    channels = waveStream.WaveFormat.Channels;
                    bits_per_sample = waveStream.WaveFormat.BitsPerSample;
                    sample_rate = waveStream.WaveFormat.SampleRate;
                    AL.BufferData(managedSounds[i].bufferHandle, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
                    AL.Source(managedSounds[i].soundSource, ALSourcei.Buffer, managedSounds[i].bufferHandle);

                    return i;
                }
            }

            SoundInstance newSound = new SoundInstance();
            newSound.refCount = 1;
            newSound.bufferHandle = AL.GenBuffer();
            newSound.soundSource = AL.GenSource();

            sound_data = new byte[waveStream.Length];
            waveStream.Read(sound_data, 0, (int)waveStream.Length);
            channels = waveStream.WaveFormat.Channels;
            bits_per_sample = waveStream.WaveFormat.BitsPerSample;
            sample_rate = waveStream.WaveFormat.SampleRate;
            AL.BufferData(newSound.bufferHandle, GetSoundFormat(channels, bits_per_sample), sound_data, sound_data.Length, sample_rate);
            AL.Source(newSound.soundSource, ALSourcei.Buffer, newSound.bufferHandle);

            managedSounds.Add(newSound);
            return managedSounds.Count - 1;
        }
开发者ID:gdbooks,项目名称:gdbooks.github.io,代码行数:43,代码来源:SoundManager.cs

示例6: LoadAudio

        public void LoadAudio(String filename)
        {
            try
            {
                waveStream = new NAudio.Wave.WaveFileReader(filename);
            }
            catch (Exception)
            {
                MessageBox.Show("Could not load Audio! WAV files only.");
                return;
            }
            if (waveStream != null)
            {
                bytesPerSample = (waveStream.WaveFormat.BitsPerSample / 8) * waveStream.WaveFormat.Channels;
                if (bytesPerSample == 0)
                    bytesPerSample = 1;

                totalSamples = (int)(waveStream.Length / bytesPerSample);

                // create a memory based copy so we can access internal data without moving position
                MemoryStream ms = new MemoryStream((int)waveStream.Length);
                ms.Position = 0;

                byte[] waveData = new byte[samplesPerPixel * bytesPerSample];
                while (waveStream.Position < waveStream.Length)
                {
                    int bytesRead = waveStream.Read(waveData, 0, samplesPerPixel * bytesPerSample);
                    ms.Write(waveData, 0, bytesRead);
                }

                memoryStream = ms;
                waveStream = new RawSourceWaveStream(memoryStream, waveStream.WaveFormat);

                FitToScreen();
            }
            else
                Reset();

            //Zoom(0, 100000);
        }
开发者ID:runtime1point0,项目名称:Fritz-robot-only,代码行数:40,代码来源:Recorder.cs

示例7: Read

        /// <summary>
        /// Read an audio file.
        /// </summary>
        void Read()
        {

            reader = new MediaFoundationReader(fileName);
            duration = reader.TotalTime;
            format = new AudioFormat(reader.WaveFormat);

            var bytes = new byte[reader.Length];
            var read = reader.Read(bytes, 0, bytes.Length);
            data = new List<byte>(bytes);
        }
开发者ID:Breadmouth,项目名称:Gravitas,代码行数:14,代码来源:AudioContent.cs

示例8: TryReadFloat

        // Read Mono
        public static bool TryReadFloat(WaveStream waveStream, out float sampleValue)
        {
            // 16 bit PCM data
            sampleValue = 0f;
            if (waveStream.WaveFormat.BitsPerSample == 16)
            {
                byte[] buffer = new byte[2];
                int read = waveStream.Read(buffer, 0, buffer.Length);
                if (read < buffer.Length)
                    return false;

                sampleValue = (float)BitConverter.ToInt16(buffer, 0) / 32768f;
                return true;
            }
            return false;
        }
开发者ID:remy22,项目名称:AudioVSTToolbox,代码行数:17,代码来源:AudioUtilsNAudio.cs

示例9: ProcessFile

 private void ProcessFile(WaveStream reader)
 {
     int fileLength = (int)reader.Length;
     byte[] buffer = new byte[fileLength];
     reader.Read(buffer, 0, fileLength);
     ProcessData(buffer, fileLength);
 }
开发者ID:frankw92,项目名称:MultimediaRetrieval,代码行数:7,代码来源:DataTrainingManager.cs


注:本文中的NAudio.Wave.WaveStream.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。