當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。