Example #1
0
 private int dump_comments(Xiph.vorbis_info vi, Xiph.vorbis_comment vc)
 {
     Debug.Log("Encoded by " + vc.vendor);
     if (vc.user_comments != null)
     {
         Debug.Log("vorbis comment header:");
         for (int i = 0; i < vc.user_comments.Length; i++)
         {
             Debug.Log("\t" + vc.user_comments[i]);
         }
     }
     Debug.Log(string.Concat(new object[]
     {
         "\nBitstream is ",
         vi.channels,
         " channel, ",
         vi.rate,
         "Hz\n"
     }));
     return(0);
 }
Example #2
0
 private bool LoadAudio()
 {
     this.oy              = new Xiph.ogg_sync_state();
     this.os              = new Xiph.ogg_stream_state();
     this.og              = new Xiph.ogg_page();
     this.op              = new Xiph.ogg_packet();
     this.vi              = new Xiph.vorbis_info();
     this.vc              = new Xiph.vorbis_comment();
     this.vd              = new Xiph.vorbis_dsp_state();
     this.vb              = new Xiph.vorbis_block();
     this.instream_pos    = 0L;
     this.eos             = false;
     this.last_buf        = false;
     this.need_more_data  = false;
     this.need_next_pcm   = true;
     this.vorbis_p        = false;
     this.stateflag       = false;
     this.comments_header = false;
     this.instream_pos    = 0L;
     this.curPcmOffset    = 0;
     this.Pcm             = null;
     this.PcmSampleCount  = 0L;
     this.PcmSampleOffset = 0L;
     this.readspeed       = (double)this.control_.Scale + 44.1;
     this.lastReadIdx     = -1;
     Xiph.ogg_sync_init(this.oy);
     Xiph.vorbis_info_init(this.vi);
     Xiph.vorbis_comment_init(this.vc);
     while (!this.stateflag)
     {
         if (this.buffer_data(this.instream, this.oy) == 0)
         {
             break;
         }
         while (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             Xiph.ogg_stream_state ogg_stream_state = new Xiph.ogg_stream_state();
             if (Xiph.ogg_page_bos(this.og) == 0)
             {
                 this.stateflag = true;
                 break;
             }
             Xiph.ogg_stream_init(ogg_stream_state, Xiph.ogg_page_serialno(this.og));
             Xiph.ogg_stream_pagein(ogg_stream_state, this.og);
             int num = Xiph.ogg_stream_packetpeek(ogg_stream_state, this.op);
             if (num == 1 && !this.vorbis_p && Xiph.vorbis_synthesis_headerin(this.vi, this.vc, this.op) >= 0)
             {
                 this.os       = Xiph.ogg_stream_clone(ogg_stream_state);
                 this.vorbis_p = true;
                 Xiph.ogg_stream_packetout(this.os, null);
             }
             else
             {
                 Xiph.ogg_stream_clear(ogg_stream_state);
             }
         }
     }
     while (this.vorbis_p && !this.comments_header)
     {
         int num2;
         while ((num2 = Xiph.ogg_stream_packetpeek(this.os, this.op)) != 0)
         {
             if (num2 >= 0)
             {
                 if (Xiph.vorbis_synthesis_headerin(this.vi, this.vc, this.op) < 0)
                 {
                     this.error = "Error parsing Theora stream vorbis; corrupt stream?\n";
                     return(false);
                 }
                 Xiph.ogg_stream_packetout(this.os, null);
                 this.comments_header = true;
             }
         }
         if (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             Xiph.ogg_stream_pagein(this.os, this.og);
         }
         else if (this.buffer_data(this.instream, this.oy) == 0)
         {
             this.error = "End of file while searching for codec headers.\n";
             return(false);
         }
     }
     if (this.vorbis_p)
     {
         if (this.buffer_data(this.instream, this.oy) == 0)
         {
             this.error = "End of file before finding all Vorbis headers!\n";
             return(false);
         }
         this.PcmRate                        = this.vi.rate;
         this.PcmChannels                    = this.vi.channels;
         this.PcmSampleOffset                = (long)(-176400 / this.PcmChannels);
         this.PcmSampleCount                 = (long)(88200 / this.PcmChannels);
         this.curPcmOffset                   = 88200;
         this.control_.PcmChannels           = this.PcmChannels;
         this.control_.PcmRate               = this.PcmRate;
         this.control_.SamplesPerMillisecond = (double)this.control_.Scale * 44.1;
         this.dump_comments(this.vi, this.vc);
         if (Xiph.vorbis_synthesis_init(this.vd, this.vi) != 0)
         {
             this.error = "Wrong Vorbis stream!\n";
             return(false);
         }
         Xiph.vorbis_block_init(this.vd, this.vb);
     }
     return(this.vorbis_p);
 }