Example #1
0
        private void LoadOggFile(IOggFileSource source)
        {
            m_Source       = source;
            m_CSVorbisFile = source.VorbisFile;
            m_TagLibFile   = source.TagLibFile;

            // 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", source.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", source.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();
        }
Example #2
0
        /// <summary>Supports opening an Ogg Vorbis file</summary>
        public OggFileReader(string oggFileName)
        {
            m_vorbisFile = new VorbisFile(oggFileName);
            Info[] info = m_vorbisFile.getInfo();
            // TODO: 8 is hard coded!! need to change it dynamically by reading tags
            waveFormat = new WaveFormat(info[0].rate, 8, info[0].channels);

            float t = m_vorbisFile.time_total(-1); // Timespan in seconds
        }
Example #3
0
        /// <summary>Constructor - Supports opening an Ogg Vorbis file</summary>
        public OggVorbisFileReader(string oggFileName)
        {
            m_vorbisFile = new VorbisFile(oggFileName);
            Info[] info = m_vorbisFile.getInfo();

            // TODO: 8 bit is hard coded!! need to figure out how to calculate it, Ogg tags do not seem to contain it
            int bitsPerSample = 8;

            m_waveFormat = new WaveFormat(info[0].rate, bitsPerSample, info[0].channels);
        }
Example #4
0
        /// <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;
            }
        }