Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="stream">Stream to access in-memory data to be parsed</param>
        /// <param name="mimeType">the file's mime type.</param>
        /// <param name="readEmbeddedPictures">Embedded pictures will be read if true; ignored if false</param>
        /// <param name="readAllMetaFrames">All metadata frames (including unmapped ones) will be read if true; ignored if false</param>
        public AudioFileIo(Stream stream, String mimeType, Boolean readEmbeddedPictures, Boolean readAllMetaFrames = false)
        {
            Byte alternate = 0;
            var  found     = false;

            _audioData = AudioDataIoFactory.GetInstance().GetFromMimeType(mimeType, "In-memory", alternate);

            _audioManager = new AudioDataManager(_audioData, stream);
            found         = _audioManager.ReadFromFile(readEmbeddedPictures, readAllMetaFrames);

            while (!found && alternate < AudioDataIoFactory.MaxAlternates)
            {
                alternate++;
                _audioData    = AudioDataIoFactory.GetInstance().GetFromMimeType(mimeType, "In-memory", alternate);
                _audioManager = new AudioDataManager(_audioData, stream);
                found         = _audioManager.ReadFromFile(readEmbeddedPictures, readAllMetaFrames);
            }

            _metaData = MetaDataIOFactory.GetInstance().GetMetaReader(_audioManager);

            if (_metaData is DummyTag && (0 == _audioManager.getAvailableMetas().Count))
            {
                LogDelegator.GetLogDelegate()(Log.LV_WARNING, "Could not find any metadata");
            }
        }
        // ------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the instance of this factory (Singleton pattern)
        /// </summary>
        /// <returns>Instance of the AudioReaderFactory of the application</returns>
        public static AudioDataIoFactory GetInstance()
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new PlatformNotSupportedException("Big-endian based platforms are not supported by ModifiedAtl");
            }

            if (null != _theFactory)
            {
                return(_theFactory);
            }
            _theFactory = new AudioDataIoFactory
            {
                formatListByExt  = new Dictionary <String, IList <Format> >(),
                formatListByMime = new Dictionary <String, IList <Format> >()
            };


            var tempFmt = new Format("MPEG Audio Layer")
            {
                ID = CidMp3
            };

            tempFmt.AddMimeType("audio/mp3");
            tempFmt.AddMimeType("audio/mpeg");
            tempFmt.AddMimeType("audio/x-mpeg");
            tempFmt.AddExtension(".mp1");
            tempFmt.AddExtension(".mp2");
            tempFmt.AddExtension(".mp3");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("OGG : Vorbis, Opus")
            {
                ID = CidOgg
            };
            tempFmt.AddMimeType("audio/ogg");
            tempFmt.AddMimeType("audio/vorbis");
            tempFmt.AddMimeType("audio/opus");
            tempFmt.AddMimeType("audio/ogg;codecs=opus");
            tempFmt.AddExtension(".ogg");
            tempFmt.AddExtension(".opus");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Musepack / MPEGplus")
            {
                ID = CidMpc
            };
            tempFmt.AddMimeType("audio/x-musepack");
            tempFmt.AddMimeType("audio/musepack");
            tempFmt.AddExtension(".mp+");
            tempFmt.AddExtension(".mpc");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Windows Media Audio")
            {
                ID = CidWma
            };
            tempFmt.AddMimeType("audio/x-ms-wma");
            tempFmt.AddMimeType("video/x-ms-asf");
            tempFmt.AddExtension(".asf");
            tempFmt.AddExtension(".wma");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Advanced Audio Coding")
            {
                ID = CidAac
            };
            tempFmt.AddMimeType("audio/mp4");
            tempFmt.AddMimeType("audio/aac");
            tempFmt.AddMimeType("audio/mp4a-latm");
            tempFmt.AddExtension(".aac");
            tempFmt.AddExtension(".mp4");
            tempFmt.AddExtension(".m4a");
            tempFmt.AddExtension(".m4v");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Dolby Digital")
            {
                ID = CidAc3
            };
            tempFmt.AddMimeType("audio/ac3");
            tempFmt.AddExtension(".ac3");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Digital Theatre System")
            {
                ID = CidDts
            };
            tempFmt.AddMimeType("audio/vnd.dts");
            tempFmt.AddMimeType("audio/vnd.dts.hd");
            tempFmt.AddExtension(".dts");
            tempFmt.Readable = false;
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("TwinVQ")
            {
                ID = CidVqf
            };
            tempFmt.AddExtension(".vqf");
            tempFmt.AddMimeType("audio/x-twinvq");
            tempFmt.Readable = false;
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Free Lossless Audio Codec")
            {
                ID = CidFlac
            };
            tempFmt.AddMimeType("audio/x-flac");
            tempFmt.AddExtension(".flac");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Monkey's Audio")
            {
                ID = CidApe
            };
            tempFmt.AddMimeType("audio/ape");
            tempFmt.AddMimeType("audio/x-ape");
            tempFmt.AddExtension(".ape");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("OptimFROG")
            {
                ID = CidOfr
            };
            tempFmt.AddMimeType("audio/ofr");
            tempFmt.AddMimeType("audio/x-ofr");
            tempFmt.AddExtension(".ofr");
            tempFmt.AddExtension(".ofs");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("WAVPack")
            {
                ID = CidWavpack
            };
            tempFmt.AddMimeType("audio/x-wavpack");
            tempFmt.AddMimeType("audio/wavpack");
            tempFmt.AddExtension(".wv");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("PCM (uncompressed audio)")
            {
                ID = CidWav
            };
            tempFmt.AddMimeType("audio/x-wav");
            tempFmt.AddMimeType("audio/wav");
            tempFmt.AddExtension(".wav");
            tempFmt.AddExtension(".bwf");
            tempFmt.AddExtension(".bwav");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Musical Instruments Digital Interface")
            {
                ID = CidMidi
            };
            tempFmt.AddMimeType("audio/mid");
            tempFmt.AddExtension(".mid");
            tempFmt.AddExtension(".midi");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Direct Stream Digital")
            {
                ID = CidDsf
            };
            tempFmt.AddMimeType("audio/dsf");
            tempFmt.AddMimeType("audio/x-dsf");
            tempFmt.AddMimeType("audio/dsd");
            tempFmt.AddMimeType("audio/x-dsd");
            tempFmt.AddExtension(".dsf");
            tempFmt.AddExtension(".dsd");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Portable Sound Format")
            {
                ID = CidPsf
            };
            tempFmt.AddMimeType("audio/psf");   // Unofficial
            tempFmt.AddMimeType("audio/x-psf"); // Unofficial
            tempFmt.AddExtension(".psf");
            tempFmt.AddExtension(".psf1");
            tempFmt.AddExtension(".minipsf");
            tempFmt.AddExtension(".minipsf1");
            tempFmt.AddExtension(".psf2");
            tempFmt.AddExtension(".minipsf2");
            tempFmt.AddExtension(".ssf");
            tempFmt.AddExtension(".minissf");
            tempFmt.AddExtension(".dsf");
            tempFmt.AddExtension(".minidsf");
            tempFmt.AddExtension(".gsf");
            tempFmt.AddExtension(".minigsf");
            tempFmt.AddExtension(".qsf");
            tempFmt.AddExtension(".miniqsf");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("SPC700 Sound Files")
            {
                ID = CidSpc
            };
            tempFmt.AddMimeType("audio/spc");   // Unofficial
            tempFmt.AddMimeType("audio/x-spc"); // Unofficial
            tempFmt.AddExtension(".spc");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("True Audio")
            {
                ID = CidTta
            };
            tempFmt.AddMimeType("audio/tta");
            tempFmt.AddMimeType("audio/x-tta");
            tempFmt.AddExtension(".tta");
            _theFactory.addFormat(tempFmt);

            tempFmt = new Format("Tom's lossless Audio Kompressor (TAK)")
            {
                ID = CidTak
            };
            tempFmt.AddMimeType("audio/tak");   // Unofficial
            tempFmt.AddMimeType("audio/x-tak"); // Unofficial
            tempFmt.AddExtension(".tak");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Noisetracker/Soundtracker/Protracker Module");
            tempFmt.ID = CidMod;
            tempFmt.AddMimeType("audio/x-mod");
            tempFmt.AddExtension(".mod");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("ScreamTracker Module");
            tempFmt.ID = CidS3M;
            tempFmt.AddMimeType("audio/s3m");
            tempFmt.AddMimeType("audio/x-s3m");
            tempFmt.AddExtension(".s3m");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Extended Module");
            tempFmt.ID = CidXm;
            tempFmt.AddMimeType("audio/xm");
            tempFmt.AddMimeType("audio/x-xm");
            tempFmt.AddExtension(".xm");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Impulse Tracker");
            tempFmt.ID = CidIt;
            tempFmt.AddMimeType("audio/it");
            tempFmt.AddExtension(".it");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Audio Interchange File Format: (Audio IFF)");
            tempFmt.ID = CidAiff;
            tempFmt.AddMimeType("audio/x-aiff");
            tempFmt.AddExtension(".aif");
            tempFmt.AddExtension(".aiff");
            tempFmt.AddExtension(".aifc");
            tempFmt.AddExtension(".snd");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Video Game Music");
            tempFmt.ID = CidVgm;
            tempFmt.AddMimeType("audio/vgm");   // Unofficial
            tempFmt.AddMimeType("audio/x-vgm"); // Unofficial
            tempFmt.AddExtension(".vgm");
            tempFmt.AddExtension(".vgz");
            _theFactory.addFormat(tempFmt);

            tempFmt    = new Format("Genesis YM2612");
            tempFmt.ID = CidGym;
            tempFmt.AddMimeType("audio/gym");   // Unofficial
            tempFmt.AddMimeType("audio/x-gym"); // Unofficial
            tempFmt.AddExtension(".gym");
            _theFactory.addFormat(tempFmt);

            return(_theFactory);
        }