Exemplo n.º 1
0
        private String thePath;                                                         // Path of this file

        // ------------------------------------------------------------------------------------------

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="path">Path of the file to be parsed</param>
        public AudioFileReader(String path)
        {
            thePath    = path;
            theFactory = AudioReaderFactory.GetInstance();
            audioData  = theFactory.GetDataReader(path);
            metaData   = theFactory.GetMetaReader(path, audioData);
        }
Exemplo n.º 2
0
 void CreateReader()
 {
     try
     {
         reader       = new AudioDataReader(Config.DataStream, Config.AudioFormat, Config.PreferredDecoder);
         SamplesCount = (int)(reader.Length / (long)(reader.WaveFormat.BitsPerSample / 8));
         Channels     = reader.WaveFormat.Channels;
         SampleRate   = reader.WaveFormat.SampleRate;
         UsedDecoder  = reader.UsedDecoder;
     }
     catch (Exception exception)
     {
         MyOnLoadingFailed(exception);
     }
 }
Exemplo n.º 3
0
 void DataWillNoLongerBeNeeded()
 {
     if (isDisposed)
     {
         return;
     }
     isDisposed = true;
     if (reader != null)
     {
         reader.Dispose();
         reader = null;
     }
     if (Config.DisposeDataStreamIfNotNeeded && Config.DataStream != null)
     {
         Config.DataStream.Dispose();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the appropriate metadata reader for a given file / physical data reader
        /// </summary>
        /// <param name="path">Path of the file</param>
        /// <param name="theDataReader">AudioDataReader produced for this file</param>
        /// <returns>Metadata reader able to give metadata info for this file (or the dummy reader if the format is unknown)</returns>
        public MetaDataReader GetMetaReader(String path, AudioDataReader theDataReader)
        {
            MetaDataReader theMetaReader = null;

            // Step 1 : The physical reader may have already parsed the metadata
            for (int i = 0; i < TAG_TYPE_COUNT; i++)
            {
                if ((TAG_ID3V1 == tagPriority[i]) && (theDataReader.ID3v1.Exists))
                {
                    theMetaReader = theDataReader.ID3v1; break;
                }
                if ((TAG_ID3V2 == tagPriority[i]) && (theDataReader.ID3v2.Exists))
                {
                    theMetaReader = theDataReader.ID3v2; break;
                }
                if ((TAG_APE == tagPriority[i]) && (theDataReader.APEtag.Exists))
                {
                    theMetaReader = theDataReader.APEtag; break;
                }
            }

            // Step 2 : Nothing found in step 1 -> considerate specific tagging (data+meta file formats)
            if (null == theMetaReader)
            {
                //# improve something here

                /*
                 * if (theDataReader is BinaryLogic.TOggVorbis)
                 * {
                 *      BinaryLogic.TOggVorbis theVorbis = new BinaryLogic.TOggVorbis();
                 *      theVorbis.ReadFromFile(path);
                 *      theMetaReader = theVorbis;
                 * }
                 *
                 * if (theDataReader is BinaryLogic.TWMAfile)
                 * {
                 *      BinaryLogic.TWMAfile theWMA = new BinaryLogic.TWMAfile();
                 *      theWMA.ReadFromFile(path);
                 *      theMetaReader = theWMA;
                 * }
                 *
                 * if (theDataReader is BinaryLogic.TFLACFile)
                 * {
                 *      BinaryLogic.TFLACFile theFLAC = new BinaryLogic.TFLACFile();
                 *      theFLAC.ReadFromFile(path);
                 *      theMetaReader = theFLAC;
                 * }
                 *
                 * if (theDataReader is BinaryLogic.TPSFFile)
                 * {
                 *      BinaryLogic.TPSFFile thePSF = new BinaryLogic.TPSFFile();
                 *      thePSF.ReadFromFile(path);
                 *      theMetaReader = thePSF;
                 * }
                 *
                 * if (theDataReader is BinaryLogic.TSPCFile)
                 * {
                 *      BinaryLogic.TSPCFile theSPC = new BinaryLogic.TSPCFile();
                 *      theSPC.ReadFromFile(path);
                 *      theMetaReader = theSPC;
                 * }*/
                if ((theDataReader is BinaryLogic.TOggVorbis) ||
                    (theDataReader is BinaryLogic.TWMAfile) ||
                    (theDataReader is BinaryLogic.TFLACFile) ||
                    (theDataReader is BinaryLogic.TPSFFile) ||
                    (theDataReader is BinaryLogic.TSPCFile))
                {
                    theMetaReader = (MetaDataReader)theDataReader;                     // Boorish but correct cast
                }
            }

            // Step 3 : default (no tagging at all - provides the dummy reader)
            if (null == theMetaReader)
            {
                theMetaReader = new BinaryLogic.DummyTag();
            }

            return(theMetaReader);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the appropriate physical data reader for a given file
        /// </summary>
        /// <param name="formatId">ID of the format</param>
        /// <param name="path">Path of the file</param>
        /// <returns>AudioDataReader able to give info about the file's contents (or the dummy reader if the format is unknown)</returns>
        public AudioDataReader GetDataReader(String path, int formatId)
        {
            AudioDataReader theDataReader = null;

            switch (formatId)
            {
            case CID_MP3:
                theDataReader = new BinaryLogic.TMPEGaudio();
                break;

            case CID_OGG:
                theDataReader = new BinaryLogic.TOggVorbis();
                break;

            case CID_MPC:
                theDataReader = new BinaryLogic.TMPEGplus();
                break;

            case CID_FLAC:
                theDataReader = new BinaryLogic.TFLACFile();
                break;

            case CID_APE:
                theDataReader = new BinaryLogic.TMonkey();
                break;

            case CID_WMA:
                theDataReader = new BinaryLogic.TWMAfile();
                break;

            case CID_MIDI:
                theDataReader = new BinaryLogic.Midi();
                break;

            case CID_AAC:
                theDataReader = new BinaryLogic.TAACfile();
                break;

            case CID_AC3:
                theDataReader = new BinaryLogic.TAC3();
                break;

            case CID_OFR:
                theDataReader = new BinaryLogic.TOptimFrog();
                break;

            case CID_WAVPACK:
                theDataReader = new BinaryLogic.TWAVPackfile();
                break;

            case CID_WAV:
                theDataReader = new BinaryLogic.TWAVfile();
                break;

            case CID_PSF:
                theDataReader = new BinaryLogic.TPSFFile();
                break;

            case CID_SPC:
                theDataReader = new BinaryLogic.TSPCFile();
                break;

            default:
                theDataReader = new BinaryLogic.DummyReader();
                break;
            }

            theDataReader.ReadFromFile(path);

            return(theDataReader);
        }