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


C# StreamState.Clear方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........

                                    // **pcm is a multichannel float vector.  In stereo, for
                                    // example, pcm[0] is left, and pcm[1] is right.  samples is
                                    // the size of each channel.  Convert the float values
                                    // (-1.<=range<=1.) to whatever PCM format and write it out

                                    while ((samples = DspState.synthesis_pcmout(_pcm, _index)) > 0)
                                    {
                                        float[][] pcm = _pcm[0];
                                        int bout = (samples < convsize ? samples : convsize);

                                        // convert floats to 16 bit signed ints (host order) and
                                        // interleave
                                        for (i = 0; i < Info.channels; i++)
                                        {
                                            int ptr = i * 2;
                                            //int ptr=i;
                                            int mono = _index[i];
                                            for (int j = 0; j < bout; j++)
                                            {
                                                int val = (int)(pcm[i][mono + j] * 32767.0);
                                                //		      short val=(short)(pcm[i][mono+j]*32767.);
                                                //		      int val=(int)Math.round(pcm[i][mono+j]*32767.);
                                                // might as well guard against clipping
                                                if (val > 32767)
                                                {
                                                    val = 32767;
                                                }
                                                if (val < -32768)
                                                {
                                                    val = -32768;
                                                }
                                                if (val < 0)
                                                    val = val | 0x8000;
                                                convbuffer[ptr] = (byte)(val);
                                                convbuffer[ptr + 1] = (byte)(((uint)val) >> 8);
                                                ptr += 2 * (Info.channels);
                                            }
                                        }

                                        //                  System.out.write(convbuffer, 0, 2*vi.channels*bout);
                                        //throw(new NotImplementedException("ccccccccc"));
                                        OutputBuffer.Write(convbuffer, 0, 2 * Info.channels * bout);

                                        // tell libvorbis how
                                        // many samples we
                                        // actually consumed
                                        DspState.synthesis_read(bout);
                                    }
                                }
                            }
                            if (Page.eos() != 0)
                                eos = 1;
                        }
                    }
                    if (eos == 0)
                    {
                        index = SyncState.Buffer(4096);
                        buffer = SyncState.Data;
                        try
                        {
                            bytes = input.Read(buffer, index, 4096);
                        }
                        catch (Exception e)
                        {
                            throw(new Exception("Exception", e));
                        }
                        SyncState.wrote(bytes);
                        if (bytes == 0) eos = 1;
                    }
                }

                // clean up this logical bitstream; before exit we see if we're
                // followed by another [chained]

                StreamState.Clear();

                // ogg_page and ogg_packet structs always point to storage in
                // libvorbis.  They're never freed or manipulated directly

                Block.clear();
                DspState.clear();
                Info.Clear(); // must be called last
            }

            // OK, clean up the framer
            SyncState.Clear();

            var WaveStream = new WaveStream();
            using (var WaveOutputStream = File.OpenWrite(Name + ".wav"))
            {
                OutputBuffer.Position = 0;
                WaveStream.WriteWave(WaveOutputStream, () =>
                {
                    OutputBuffer.CopyTo(WaveOutputStream);
                }, NumberOfChannels: 1, SampleRate: 44100);
            }

            Console.Error.WriteLine("Done.");
        }
开发者ID:hermitdave,项目名称:nvorbis,代码行数:101,代码来源:DecodeExample.cs


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