コード例 #1
0
 public void Dispose()
 {
     m_TagLibFile.Dispose();
     m_TagLibFile = null;
     m_CSVorbisFile.Dispose();
     m_CSVorbisFile = null;
 }
コード例 #2
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();
        }
コード例 #3
0
ファイル: OggFileReader.cs プロジェクト: Damian666/blasters
        /// <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
        }
コード例 #4
0
ファイル: VorbisFileReader.cs プロジェクト: whztt07/SDK
		public bool OpenVorbisFile( VorbisFile.File vorbisFile )
		{
			IntPtr datasource = GCHandle.ToIntPtr( streamGCHandle );

			if( vorbisFile.open_callbacks( datasource, IntPtr.Zero, 0, callbacks ) != 0 )
				return false;

			return true;
		}
コード例 #5
0
 public MusicVorbis(VorbisFile aVorbisFile)
 {
     sampleArray  = aVorbisFile.GetSampleArray();
     Channels     = aVorbisFile.GetChannelLength();
     SampleLength = aVorbisFile.GetSampleLength();
     SampleRate   = aVorbisFile.GetSampleRate();
     Loop         = new List <List <LoopInformation> >();
     Loop.Add(new List <LoopInformation>());
     Loop[0].Add(new LoopInformation(SampleRate, aVorbisFile.GetSampleLoopStart(), aVorbisFile.GetSampleLoopEnd()));
 }
コード例 #6
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);
        }
コード例 #7
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;
            }
        }
コード例 #8
0
 /// <summary>
 /// Disposes this WaveStream
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (m_vorbisFile != null)
         {
             m_vorbisFile.Dispose();
             m_vorbisFile = null;
         }
     }
     base.Dispose(disposing);
 }
コード例 #9
0
        public LocalOggFile(string path)
        {
            FileName = path;

            try
            {
                VorbisFile = new VorbisFile(path);
            }
            catch (Exception ex)
            {
                throw new OggFileReadException("Unable to open file for data reading\n" + ex.Message, path);
            }
        }
コード例 #10
0
        public void WriteFile(PCM16Audio lwav, string output_dir, string original_filename_no_ext)
        {
            string output_filename = Path.Combine(output_dir, original_filename_no_ext + ".ogg");

            // Don't re-encode if the original input file was also Ogg Vorbis
            if (lwav.OriginalPath != null && new string[] { ".ogg", ".logg" }.Contains(Path.GetExtension(lwav.OriginalPath), StringComparer.InvariantCultureIgnoreCase))
            {
                File.Copy(lwav.OriginalPath, output_filename, true);
            }
            else
            {
                sox.WriteFile(lwav, output_filename, encodingParameters);
            }

            using (VorbisFile file = new VorbisFile(File.ReadAllBytes(output_filename))) {
                var commentHeader = file.GetPageHeaders().Select(p => p.GetCommentHeader()).Where(h => h != null).FirstOrDefault();
                var comments      = commentHeader?.ExtractComments() ?? new VorbisComments();
                if (lwav.Looping)
                {
                    if (commentHeader == null)
                    {
                        throw new Exception("No comment header found in Ogg Vorbis file - cannot edit it to make it loop.");
                    }

                    string loopStart  = null;
                    string loopLength = null;
                    comments.Comments.TryGetValue("LOOPSTART", out loopStart);
                    comments.Comments.TryGetValue("LOOPLENGTH", out loopLength);

                    if (loopStart != lwav.LoopStart.ToString() || loopLength != lwav.LoopLength.ToString())
                    {
                        comments.Comments["LOOPSTART"]  = lwav.LoopStart.ToString();
                        comments.Comments["LOOPLENGTH"] = lwav.LoopLength.ToString();
                        using (VorbisFile newFile = new VorbisFile(file, comments)) {
                            File.WriteAllBytes(output_filename, newFile.ToByteArray());
                        }
                    }
                }
                else
                {
                    if (comments.Comments.ContainsKey("LOOPSTART") || comments.Comments.ContainsKey("LOOPLENGTH"))
                    {
                        comments.Comments.Remove("LOOPSTART");
                        comments.Comments.Remove("LOOPLENGTH");
                        using (VorbisFile newFile = new VorbisFile(file, comments)) {
                            File.WriteAllBytes(output_filename, newFile.ToByteArray());
                        }
                    }
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Reset the OggFile (reload from disk).
 /// Useful if tags have changed externally, or to reset the internal position pointer to replay the file from the beginning
 /// SeekToTime(0) is the prefered method of moving the internal pointer to the beginning however however
 /// </summary>
 public void ResetFile()
 {
     try
     {
         m_CSVorbisFile = null;
         m_CSVorbisFile = new VorbisFile(m_Filename);                    // No point reloading anything else 'cos it shouldn't have changed
         m_TagLibFile   = null;
         m_TagLibFile   = TagLib.File.Create(m_Filename);
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to reload OggFile [" + m_Filename + "]", ex);
     }
 }
コード例 #12
0
ファイル: ChainingExample.cs プロジェクト: hermitdave/nvorbis
        public static void main(String[] arg)
        {
            VorbisFile ov = null;

            try
            {
                if (arg.Length > 0)
                {
                    ov = new VorbisFile(File.OpenRead(arg[0]));
                }
                else
                {
                    throw (new NotImplementedException());
                    //ov=new VorbisFile(Console.In, null, -1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                return;
            }

            if (ov.seekable())
            {
                Console.WriteLine("Input bitstream contained " + ov.streams()
                     + " logical bitstream section(s).");
                Console.WriteLine("Total bitstream playing time: " + ov.time_total(-1)
                     + " seconds\n");
            }
            else
            {
                Console.WriteLine("Standard input was not seekable.");
                Console.WriteLine("First logical bitstream information:\n");
            }

            for (int i = 0; i < ov.streams(); i++)
            {
                Info vi = ov.getInfo(i);
                Console.WriteLine("\tlogical bitstream section " + (i + 1) + " information:");
                Console.WriteLine("\t\t" + vi.rate + "Hz " + vi.channels + " channels bitrate "
                     + (ov.bitrate(i) / 1000) + "kbps serial number=" + ov.serialnumber(i));
                Console.Write("\t\tcompressed length: " + ov.raw_total(i) + " bytes ");
                Console.WriteLine(" play time: " + ov.time_total(i) + "s");
                Comment vc = ov.getComment(i);
                Console.WriteLine(vc);
            }
            //ov.clear();
        }
コード例 #13
0
        public static void main(String[] arg)
        {
            VorbisFile ov = null;

            try
            {
                if (arg.Length > 0)
                {
                    ov = new VorbisFile(File.OpenRead(arg[0]));
                }
                else
                {
                    throw (new NotImplementedException());
                    //ov=new VorbisFile(Console.In, null, -1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                return;
            }

            if (ov.seekable())
            {
                Console.WriteLine("Input bitstream contained " + ov.streams()
                                  + " logical bitstream section(s).");
                Console.WriteLine("Total bitstream playing time: " + ov.time_total(-1)
                                  + " seconds\n");
            }
            else
            {
                Console.WriteLine("Standard input was not seekable.");
                Console.WriteLine("First logical bitstream information:\n");
            }

            for (int i = 0; i < ov.streams(); i++)
            {
                Info vi = ov.getInfo(i);
                Console.WriteLine("\tlogical bitstream section " + (i + 1) + " information:");
                Console.WriteLine("\t\t" + vi.rate + "Hz " + vi.channels + " channels bitrate "
                                  + (ov.bitrate(i) / 1000) + "kbps serial number=" + ov.serialnumber(i));
                Console.Write("\t\tcompressed length: " + ov.raw_total(i) + " bytes ");
                Console.WriteLine(" play time: " + ov.time_total(i) + "s");
                Comment vc = ov.getComment(i);
                Console.WriteLine(vc);
            }
            //ov.clear();
        }
コード例 #14
0
        static public void NewTest()
        {
            VorbisFile.OggVorbis_File vf = new VorbisFile.OggVorbis_File();

            Console.WriteLine(VorbisFile.ov_fopen("stop.ogg", ref vf));

            Vorbis.vorbis_info vi = VorbisFile.ov_info(ref vf, -1);

            int   buffersize = 44100;
            byte *buffer     = stackalloc byte [buffersize];

            FileStream stream = File.Create
                                (
                "C:\\" + Guid.NewGuid().ToString() + ".wav"
                                );

            // while (true)
            try
            {
                int bitstream = 0;
                int ret       = 0;

                while (true)
                {
                    ret = VorbisFile.ov_read(ref vf, buffer, buffersize, 0, 2, 1, ref bitstream);

                    if (ret <= 0)
                    {
                        return;
                    }

                    Console.WriteLine(ret);

                    byte[] buffer_managed = new byte [ret];
                    Marshal.Copy((IntPtr)buffer, buffer_managed, 0, buffer_managed.Length);

                    stream.Write(buffer_managed, 0, buffer_managed.Length);
                }
            }
            finally
            {
                stream.Close();
                stream.Dispose();
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            byte[] b = File.ReadAllBytes(@"test.ogg");

            using (VorbisFile file = new VorbisFile(b)) {
                List <OggPage> pageHeaders = file.GetPageHeaders();

                VorbisHeader commentHeader = null;
                foreach (var pageHeader in pageHeaders)
                {
                    commentHeader = pageHeader.GetCommentHeader();
                    if (commentHeader != null)
                    {
                        break;
                    }
                }

                if (commentHeader == null)
                {
                    throw new Exception("comment header not found");
                }

                if (commentHeader.PacketType == 3)
                {
                    var c = commentHeader.ExtractComments();

                    Console.WriteLine(c.Vendor);
                    Console.WriteLine(string.Join(", ", c.Comments.Select(p => p.Key + ": " + p.Value)));

                    c.Comments["LOOPSTART"]  = "100000";
                    c.Comments["LOOPLENGTH"] = "150000";

                    using (VorbisFile newFile = new VorbisFile(file, c)) {
                        File.WriteAllBytes("out.ogg", newFile.ToByteArray());
                    }
                }
            }
        }
コード例 #16
0
 /// <summary>
 /// Reads an audio clip from the given stream.
 /// </summary>
 /// <param name="inputStream">The stream to read from.</param>
 public AudioClip(Stream inputStream)
 {
     rawClip = new VorbisFile(inputStream);
     Cache(64 * 1024);
 }
コード例 #17
0
 /// <summary>
 /// Constructs an audio clip from the given file.
 /// </summary>
 /// <param name="fileName">The file which to read from.</param>
 public AudioClip(string fileName)
 {
     rawClip = new VorbisFile(fileName);
     Cache(64 * 1024);
 }