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


C# IWaveProvider.Read方法代码示例

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


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

示例1: LoadNextChunk

 public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
 {
     int sourceBytesRequired = samplePairsRequired * 6;
     sourceBuffer = GetSourceBuffer(sourceBytesRequired);
     sourceBytes = source.Read(sourceBuffer, 0, sourceBytesRequired);
     offset = 0;
 }
开发者ID:jayfar,项目名称:NAudio_1.5_Updates,代码行数:7,代码来源:Stereo24SampleChunkConverter.cs

示例2: LoadNextChunk

 public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
 {
     int sourceBytesRequired = samplePairsRequired;
     sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired);
     sourceBytes = source.Read(sourceBuffer, 0, sourceBytesRequired);
     offset = 0;
 }
开发者ID:aljordan,项目名称:NAJAudio,代码行数:7,代码来源:Mono8SampleChunkConverter.cs

示例3: LoadNextChunk

 public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
 {
     int sourceBytesRequired = samplePairsRequired * 2;
     sourceSample = 0;
     sourceBuffer = BufferHelpers.Ensure(sourceBuffer, sourceBytesRequired);
     sourceWaveBuffer = new WaveBuffer(sourceBuffer);
     sourceSamples = source.Read(sourceBuffer, 0, sourceBytesRequired) / 2;
 }
开发者ID:aljordan,项目名称:NAJAudio,代码行数:8,代码来源:Mono16SampleChunkConverter.cs

示例4: LoadNextChunk

 public void LoadNextChunk(IWaveProvider source, int samplePairsRequired)
 {
     int sourceBytesRequired = samplePairsRequired * 4;
     sourceBuffer = GetSourceBuffer(sourceBytesRequired);
     sourceWaveBuffer = new WaveBuffer(sourceBuffer);
     sourceSamples = source.Read(sourceBuffer, 0, sourceBytesRequired) / 2;
     sourceSample = 0;
 }
开发者ID:jayfar,项目名称:NAudio_1.5_Updates,代码行数:8,代码来源:Stereo16SampleChunkConverter.cs

示例5: CreateWaveFile

 /// <summary>
 /// Creates a Wave 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 Wave File will grow indefinitely.
 /// </summary>
 /// <param name="filename">The filename to use</param>
 /// <param name="sourceProvider">The source WaveProvider</param>
 public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
 {
     using (WaveFileWriter writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
     {
         byte[] buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
         while (true)
         {
             int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
                 break;
             writer.Write(buffer, 0, bytesRead);
         }
     }
 }
开发者ID:jayfar,项目名称:NAudio_1.5_Updates,代码行数:21,代码来源:WaveFileWriter.cs

示例6: CreateWaveFile

 /// <summary>
 /// Creates a Wave 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 Wave File will grow indefinitely.
 /// </summary>
 /// <param name="filename">The filename to use</param>
 /// <param name="sourceProvider">The source WaveProvider</param>
 public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
 {
     using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
     {
         var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
         while (true)
         {
             int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 // end of source provider
                 break;
             }
             // Write will throw exception if WAV file becomes too large
             writer.Write(buffer, 0, bytesRead);
         }
     }
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:WaveFileWriter.cs

示例7: AppendWaveFile

 public static void AppendWaveFile(string filename, IWaveProvider sourceProvider)
 {
     using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat, FileMode.Append))
     {
         long outputLength = 0;
         var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
         while (true)
         {
             int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 // end of source provider
                 break;
             }
             outputLength += bytesRead;
             if (outputLength > Int32.MaxValue)
             {
                 throw new InvalidOperationException("WAV File cannot be greater than 2GB. Check that sourceProvider is not an endless stream.");
             }
             writer.Write(buffer, 0, bytesRead);
         }
     }
 }
开发者ID:step4u,项目名称:MiniCRM,代码行数:23,代码来源:WaveFileWriter.cs

示例8: CreateWaveFileAsync

        /// <summary>
        /// Creates a Wave 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 Wave File will grow indefinitely.
        /// </summary>
        /// <param name="filename">The filename to use</param>
        /// <param name="sourceProvider">The source WaveProvider</param>
        public static async Task CreateWaveFileAsync(string filename, IWaveProvider sourceProvider)
        {
            StorageFile fileOperation = await StorageFile.GetFileFromPathAsync(filename);
            Stream fileStream = await fileOperation.OpenStreamForWriteAsync();

            using (var writer = new WaveFileWriterRT(fileStream, sourceProvider.WaveFormat))
            {
                writer.filename = filename;
                long outputLength = 0;
                var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
                while (true)
                {
                    int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        // end of source provider
                        break;
                    }
                    outputLength += bytesRead;
                    // Write will throw exception if WAV file becomes too large
                    writer.Write(buffer, 0, bytesRead);
                }
            }
        }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:31,代码来源:WaveFileWriterRT.cs

示例9: CreateWaveFile

        internal static void CreateWaveFile(string filename, IWaveProvider sourceProvider, Action<long> progressCallback)
        {
            Debug.Assert(progressCallback != null);

            using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
            {
                long outputLength = 0;
                var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
                while (true)
                {
                    int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        // end of source provider
                        break;
                    }
                    outputLength += bytesRead;
                    // Write will throw exception if WAV file becomes too large
                    writer.Write(buffer, 0, bytesRead);

                    progressCallback(bytesRead);
                }
            }
        }
开发者ID:olathunberg,项目名称:RecordToMP3,代码行数:24,代码来源:FileCreator.cs

示例10: FillBuffer

 private void FillBuffer(IWaveProvider playbackProvider, int frameCount)
 {
     IntPtr buffer = renderClient.GetBuffer(frameCount);
     int readLength = frameCount*bytesPerFrame;
     int read = playbackProvider.Read(readBuffer, 0, readLength);
     if (read == 0)
     {
         playbackState = PlaybackState.Stopped;
     }
     Marshal.Copy(readBuffer, 0, buffer, read);
     int actualFrameCount = read/bytesPerFrame;
     /*if (actualFrameCount != frameCount)
     {
         Debug.WriteLine(String.Format("WASAPI wanted {0} frames, supplied {1}", frameCount, actualFrameCount ));
     }*/
     renderClient.ReleaseBuffer(actualFrameCount, AudioClientBufferFlags.None);
 }
开发者ID:KarimLUCCIN,项目名称:NAudioCustom,代码行数:17,代码来源:WasapiOutRT.cs

示例11: ConvertOneBuffer

        private long ConvertOneBuffer(IMFSinkWriter writer, int streamIndex, IWaveProvider inputProvider, long position, byte[] managedBuffer)
        {
            long durationConverted = 0;
            int maxLength;
            IMFMediaBuffer buffer = MediaFoundationApi.CreateMemoryBuffer(managedBuffer.Length);
            buffer.GetMaxLength(out maxLength);

            IMFSample sample = MediaFoundationApi.CreateSample();
            sample.AddBuffer(buffer);

            IntPtr ptr;
            int currentLength;
            buffer.Lock(out ptr, out maxLength, out currentLength);
            int read = inputProvider.Read(managedBuffer, 0, maxLength);
            if (read > 0)
            {
                durationConverted = BytesToNsPosition(read, inputProvider.WaveFormat);
                Marshal.Copy(managedBuffer, 0, ptr, read);
                buffer.SetCurrentLength(read);
                buffer.Unlock();
                sample.SetSampleTime(position);
                sample.SetSampleDuration(durationConverted);
                writer.WriteSample(streamIndex, sample);
                //writer.Flush(streamIndex);
            }
            else
            {
                buffer.Unlock();
            }

            Marshal.ReleaseComObject(sample);
            Marshal.ReleaseComObject(buffer);
            return durationConverted;
        }
开发者ID:yancai,项目名称:AudioPlayerDemo,代码行数:34,代码来源:MediaFoundationEncoder.cs

示例12: CreateRepositionTestFile

 private void CreateRepositionTestFile(string saveFile, IWaveProvider source, Action reposition)
 {
     using (var writer = new WaveFileWriter(saveFile, source.WaveFormat))
     {
         // half-second buffer
         var buffer = new byte[writer.WaveFormat.AverageBytesPerSecond / 2];
         // read three and a half seconds (half a second is to ensure Resampler has some leftovers to drain)
         for (int n = 0; n < 7; n++)
         {
             var read = source.Read(buffer, 0, buffer.Length);
             writer.Write(buffer, 0, read);
         }
         Array.Clear(buffer, 0, buffer.Length);
         // two seconds of absolute silence
         for (int n = 0; n < 4; n++)
         {
             writer.Write(buffer, 0, buffer.Length);
         }
         // do the reposition
         reposition();
         // now read some more out
         for (int n = 0; n < 6; n++)
         {
             var read = source.Read(buffer, 0, buffer.Length);
             writer.Write(buffer, 0, read);
         }
     }
 }
开发者ID:EraYaN,项目名称:Moonstone,代码行数:28,代码来源:MediaFoundationResampleViewModel.cs


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