csvorbis.VorbisFile.bitrate C# (CSharp) Method

bitrate() public method

public bitrate ( int i ) : int
i int
return int
        public int bitrate(int i)
        {
            if(i>=links)return(-1);
            if(!skable && i!=0)return(bitrate(0));
            if(i<0)
            {
                long bits=0;
                for(int j=0;j<links;j++)
                {
                    bits+=(offsets[j+1]-dataoffsets[j])*8;
                }
                return((int)Math.Round(bits/time_total(-1)));
            }
            else
            {
                if(skable)
                {
                    // return the actual bitrate
                    return((int)Math.Round((offsets[i+1]-dataoffsets[i])*8/time_total(i)));
                }
                else
                {
                    // return nominal if set
                    if(vi[i].bitrate_nominal>0)
                    {
                        return vi[i].bitrate_nominal;
                    }
                    else
                    {
                        if(vi[i].bitrate_upper>0)
                        {
                            if(vi[i].bitrate_lower>0)
                            {
                                return (vi[i].bitrate_upper+vi[i].bitrate_lower)/2;
                            }
                            else
                            {
                                return vi[i].bitrate_upper;
                            }
                        }
                        return(-1);
                    }
                }
            }
        }

Usage Example

Esempio n. 1
0
        private TagLib.File m_TagLibFile; // TagLibSharp file object

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Filename">
        /// A <see cref="System.String"/> containing the path to the Ogg Vorbis file this instance represents
        /// </param>
        public OggFile(string Filename)
        {
            // Check that the file exists
            if (!(System.IO.File.Exists(Filename))) { throw new OggFileReadException("File not found", Filename); }
            // Load the relevant objects
            m_Filename = Filename;
            try
            {
                m_CSVorbisFile = new VorbisFile(m_Filename);
            }
            catch (Exception ex)
            {
                throw new OggFileReadException("Unable to open file for data reading\n" + ex.Message, Filename);
            }
            try
            {
                m_TagLibFile = TagLib.File.Create(m_Filename);
            }
            catch (TagLib.UnsupportedFormatException ex)
            {
                throw new OggFileReadException("Unsupported format (not an ogg?)\n" + ex.Message, Filename);
            }
            catch (TagLib.CorruptFileException ex)
            {
                throw new OggFileCorruptException(ex.Message, Filename, "Tags");
            }

            // Populate some other info shizzle and do a little bit of sanity checking
            m_Streams = m_CSVorbisFile.streams();
            if (m_Streams<=0) { throw new OggFileReadException("File doesn't contain any logical bitstreams", Filename); }
            // Assuming <0 is for whole file and >=0 is for specific logical bitstreams
            m_Bitrate = m_CSVorbisFile.bitrate(-1);
            m_LengthTime = (int)m_CSVorbisFile.time_total(-1);
            // Figure out the ALFormat of the stream
            m_Info = m_CSVorbisFile.getInfo();	// Get the info of the first stream, assuming all streams are the same? Dunno if this is safe tbh
            if (m_Info[0] == null) { throw new OggFileReadException("Unable to determine Format{FileInfo.Channels} for first bitstream", Filename); }
            if (m_TagLibFile.Properties.AudioBitrate==16) {
                m_Format = (m_Info[0].channels)==1 ? ALFormat.Mono16 : ALFormat.Stereo16; // This looks like a fudge, but I've seen it a couple of times (what about the other formats I wonder?)
            }
            else
            {
                m_Format = (m_Info[0].channels)==1 ? ALFormat.Mono8 : ALFormat.Stereo8;
            }

            // A grab our first instance of the file so we're ready to play
            m_CSVorbisFileInstance = m_CSVorbisFile.makeInstance();
        }