コード例 #1
0
 public static byte[] ReadStream(OggVorbisFileStream stream)
 {
     byte[] readBuffer = new byte[4096];
     if (stream.Read(readBuffer, 0, 4096) > 0)
     {
         return(readBuffer);
     }
     return(null);
 }
コード例 #2
0
        public static byte[] ReadWholeArray(OggVorbisFileStream stream, byte[] buffer)
        {
            List <byte> data = new List <byte>();

            byte[] readBuffer = null;
            while ((readBuffer = ReadStream(stream)) != null)
            {
                data.AddRange(readBuffer);
            }
            return(data.ToArray());
        }
コード例 #3
0
        public static OggVorbisMemoryStream LoadFromFile(string filename)
        {
            //load from file
            OggVorbisFileStream fileStream = new OggVorbisFileStream(filename);
            VorbisInfo          ninfo      = fileStream.Info;

            //read to memory
            byte[] nbuffer = new byte[fileStream.Length];
            //fileStream.Read(nbuffer, 0, nbuffer.Length);
            nbuffer = ReadWholeArray(fileStream, nbuffer);

            OggVorbisMemoryStream memoryStream = new OggVorbisMemoryStream(nbuffer, ninfo, fileStream.RawLength, fileStream.Duration);

            //clean up
            fileStream.Close();

            return(memoryStream);
        }
コード例 #4
0
        public static OggVorbisMemoryStream LoadFromFile(string filename)
        {
            //load from file
            OggVorbisFileStream fileStream = new OggVorbisFileStream(filename);
            VorbisInfo ninfo = fileStream.Info;

            //read to memory
            byte[] nbuffer = new byte[fileStream.Length];
            //fileStream.Read(nbuffer, 0, nbuffer.Length);
            nbuffer = ReadWholeArray(fileStream, nbuffer);

            OggVorbisMemoryStream memoryStream = new OggVorbisMemoryStream(nbuffer, ninfo, fileStream.RawLength, fileStream.Duration);

            //clean up
            fileStream.Close();

            return memoryStream;
        }
コード例 #5
0
 public static byte[] ReadWholeArray(OggVorbisFileStream stream, byte[] buffer)
 {
     List<byte> data = new List<byte>();
     byte[] readBuffer = null;
     while ((readBuffer = ReadStream(stream)) != null)
     {
         data.AddRange(readBuffer);
     }
     return data.ToArray();
 }
コード例 #6
0
 public static byte[] ReadStream(OggVorbisFileStream stream)
 {
     byte[] readBuffer = new byte[4096];
     if (stream.Read(readBuffer, 0, 4096) > 0)
     {
         return readBuffer;
     }
     return null;
 }
コード例 #7
0
        public Sound LoadOgg(string fileName)
        {
            var stream = new OggVorbisFileStream(fileName);
            VorbisInfo vInfo = stream.Info;
            WaveFormatExtensible wfe = new WaveFormatExtensible
            {
                // cbSize
                BitsPerSample = 16,
                Channels = (short)vInfo.Channels,
                SamplesPerSecond = vInfo.Rate,      // ogg vorbis always uses 16 bits
                AverageBytesPerSecond = vInfo.Rate * vInfo.Channels * 2,
                BlockAlignment = (short)(2 * vInfo.Channels),
                FormatTag = WaveFormatTag.Pcm
            };

            AudioBuffer buffer = new AudioBuffer();
            buffer.AudioData = stream;
            buffer.AudioBytes = (int)stream.Length;
            buffer.Flags = BufferFlags.EndOfStream;

            return new Sound { Buffer = buffer, Stream = stream, Format = wfe, Program = this };
        }