Exemple #1
0
        /// <summary>
        /// 読み込み処理を終了する。
        /// </summary>
        /// <returns>Error code</returns>
        public int StreamEnd()
        {
            int rv = 0;

            mMD5SumInMetadata = null;
            mMD5SumOfPcm      = null;

            switch (m_format)
            {
            case Format.FLAC:
                rv = mFlacR.ReadEnd();
                mMD5SumInMetadata = mFlacR.MD5SumInMetadata;
                mMD5SumOfPcm      = mFlacR.MD5SumOfPcm;
                break;

            case Format.AIFF:
                mAiffR.ReadStreamEnd();
                break;

            case Format.WAVE:
                mWaveR.ReadStreamEnd();
                break;

            case Format.DSF:
                mDsfR.ReadStreamEnd();
                break;

            case Format.DSDIFF:
                mDsdiffR.ReadStreamEnd();
                break;

            case Format.MP3:
                mMp3Reader.ReadStreamEnd();
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            if (null != mBr)
            {
                mBr.Close();
                mBr = null;
            }
            mPcmData = null;
            mFlacR   = null;
            mAiffR   = null;
            mWaveR   = null;
            mDsfR    = null;

            return(rv);
        }
        private PcmData FlacScanDopMarker(PcmData pcmData, FlacDecodeIF fdif)
        {
            // 1個PCMデータを読み出す。
            int  ercd = 0;
            var  buff = fdif.ReadStreamReadOne(PcmDataLib.PcmData.DOP_SCAN_FRAMES, out ercd);
            bool bDoP = pcmData.ScanDopMarker(buff);

            if (bDoP)
            {
                pcmData.SampleDataType = PcmData.DataType.DoP;
            }

            return(pcmData);
        }
        private int StreamBeginFlac(string path, long startFrame, long wantFrames, int typicalReadFrames)
        {
            // m_pcmData = new PcmDataLib.PcmData();
            mFlacR         = new FlacDecodeIF();
            mFlacR.CalcMD5 = CalcMD5SumIfAvailable;
            int ercd = mFlacR.ReadStreamBegin(path, startFrame, wantFrames, typicalReadFrames, out mPcmData);

            if (ercd < 0)
            {
                return(ercd);
            }

            NumFrames = mFlacR.NumFrames;
            return(ercd);
        }
        public void StreamAbort()
        {
            switch (m_format)
            {
            case Format.FLAC:
                mFlacR.ReadStreamAbort();
                break;

            case Format.AIFF:
                mAiffR.ReadStreamEnd();
                break;

            case Format.WAVE:
                mWaveR.ReadStreamEnd();
                break;

            case Format.DSF:
                mDsfR.ReadStreamEnd();
                break;

            case Format.DSDIFF:
                mDsdiffR.ReadStreamEnd();
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            if (null != mBr)
            {
                mBr.Close();
                mBr = null;
            }
            mPcmData = null;
            mFlacR   = null;
            mAiffR   = null;
            mWaveR   = null;
            mDsfR    = null;
        }
        /// <summary>
        /// FLACファイルのヘッダ部分を読み込む。
        /// </summary>
        /// <returns>読めたらtrue、失敗false</returns>
        private bool ReadFlacFileHeader(string path, ReadHeaderMode mode)
        {
            PcmDataLib.PcmData pcmData;
            List <WWFlacRWCS.FlacCuesheetTrack> ctiList;

            var fdif     = new FlacDecodeIF();
            int flacErcd = 0;

            flacErcd = fdif.ReadHeader(path, out pcmData, out ctiList);
            if (flacErcd != 0)
            {
                // FLACヘッダ部分読み込み失敗。
                LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + " {2}: {1}{3}",
                                                  "FLAC", path, FlacDecodeIF.ErrorCodeToStr(flacErcd), Environment.NewLine));
                return(false);
            }

            // FLACヘッダ部分読み込み成功。

            // PCMデータにDoPマーカーが付いているか調べ、pcmData.SampleDataTypeを確定する。
            pcmData = FlacScanDopMarker(pcmData, fdif);
            fdif.ReadEnd();

            if (ctiList.Count == 0 || mode == ReadHeaderMode.OnlyConcreteFile)
            {
                // FLAC埋め込みCUEシート情報を読まない。

                CheckAddPcmData(path, pcmData, true);
            }
            else
            {
                // FLAC埋め込みCUEシート情報を読む。

                PcmData pcmTrack = null;
                for (int trackId = 0; trackId < ctiList.Count; ++trackId)
                {
                    var cti = ctiList[trackId];

                    if (cti.indices.Count == 0)
                    {
                        // インデックスが1つもないトラック。lead-outトラックの場合等。
                        if (pcmTrack != null)
                        {
                            pcmTrack.EndTick = (int)((cti.offsetSamples * 75) / pcmTrack.SampleRate);
                            CheckAddPcmData(path, pcmTrack, false);
                            pcmTrack = null;
                        }
                    }
                    else
                    {
                        for (int indexId = 0; indexId < cti.indices.Count; ++indexId)
                        {
                            var indexInfo = cti.indices[indexId];

                            if (pcmTrack != null)
                            {
                                pcmTrack.EndTick = (int)(((cti.offsetSamples + indexInfo.offsetSamples) * 75) / pcmTrack.SampleRate);
                                CheckAddPcmData(path, pcmTrack, false);
                                pcmTrack = null;
                            }

                            pcmTrack = new PcmData();
                            pcmTrack.CopyFrom(pcmData);
                            if (pcmTrack.DisplayName.Length == 0)
                            {
                                pcmTrack.DisplayName = System.IO.Path.GetFileName(path);
                            }
                            pcmTrack.DisplayName = string.Format(CultureInfo.InvariantCulture,
                                                                 "{0} (Track {1}, Index {2})", pcmTrack.DisplayName, cti.trackNr, indexInfo.indexNr);
                            pcmTrack.CueSheetIndex = indexInfo.indexNr;
                            pcmTrack.StartTick     = (int)(((cti.offsetSamples + indexInfo.offsetSamples) * 75) / pcmTrack.SampleRate);
                        }
                    }
                }
            }

            return(true);
        }
Exemple #6
0
        private int StreamBeginFlac(string path, long startFrame, long wantFrames, int typicalReadFrames)
        {
            // m_pcmData = new PcmDataLib.PcmData();
            mFlacR = new FlacDecodeIF();
            mFlacR.CalcMD5 = CalcMD5SumIfAvailable;
            int ercd = mFlacR.ReadStreamBegin(path, startFrame, wantFrames, typicalReadFrames, out mPcmData);
            if (ercd < 0) {
                return ercd;
            }

            NumFrames = mFlacR.NumFrames;
            return ercd;
        }
Exemple #7
0
        /// <summary>
        /// 読み込み処理を通常終了する。
        /// </summary>
        /// <returns>Error code</returns>
        public int StreamEnd()
        {
            int rv = 0;

            mMD5SumInMetadata = null;
            mMD5SumOfPcm = null;

            switch (m_format) {
            case Format.FLAC:
                rv = mFlacR.ReadStreamEnd();
                mMD5SumInMetadata = mFlacR.MD5SumInMetadata;
                mMD5SumOfPcm = mFlacR.MD5SumOfPcm;
                break;
            case Format.AIFF:
                mAiffR.ReadStreamEnd();
                break;
            case Format.WAVE:
                mWaveR.ReadStreamEnd();
                break;
            case Format.DSF:
                mDsfR.ReadStreamEnd();
                break;
            case Format.DSDIFF:
                mDsdiffR.ReadStreamEnd();
                break;
            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            if (null != mBr) {
                mBr.Close();
                mBr = null;
            }
            mPcmData = null;
            mFlacR = null;
            mAiffR = null;
            mWaveR = null;
            mDsfR = null;

            return rv;
        }
Exemple #8
0
        public void StreamAbort()
        {
            switch (m_format) {
            case Format.FLAC:
                mFlacR.ReadStreamAbort();
                break;
            case Format.AIFF:
                mAiffR.ReadStreamEnd();
                break;
            case Format.WAVE:
                mWaveR.ReadStreamEnd();
                break;
            case Format.DSF:
                mDsfR.ReadStreamEnd();
                break;
            case Format.DSDIFF:
                mDsdiffR.ReadStreamEnd();
                break;
            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            if (null != mBr) {
                mBr.Close();
                mBr = null;
            }
            mPcmData = null;
            mFlacR = null;
            mAiffR = null;
            mWaveR = null;
            mDsfR = null;
        }
Exemple #9
0
        /// <summary>
        /// FLACファイルのヘッダ部分を読み込む。
        /// </summary>
        /// <returns>読めたらtrue、失敗false</returns>
        private bool ReadFlacFileHeader(string path, ReadHeaderMode mode)
        {
            PcmDataLib.PcmData pcmData;
            List<FlacDecodeIF.FlacCuesheetTrackInfo> ctiList;

            var fdif = new FlacDecodeIF();
            int flacErcd = 0;
            flacErcd = fdif.ReadHeader(path, out pcmData, out ctiList);
            if (flacErcd != 0) {
                // FLACヘッダ部分読み込み失敗。
                LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + " {2}: {1}{3}",
                        "FLAC", path, FlacDecodeIF.ErrorCodeToStr(flacErcd), Environment.NewLine));
                return false;
            }

            // FLACヘッダ部分読み込み成功。
            if (ctiList.Count == 0 || mode == ReadHeaderMode.OnlyConcreteFile) {
                // FLAC埋め込みCUEシート情報を読まない。

                CheckAddPcmData(path, pcmData, true);
            } else {
                // FLAC埋め込みCUEシート情報を読む。

                PcmData pcmTrack = null;
                for (int trackId=0; trackId < ctiList.Count; ++trackId) {
                    var cti = ctiList[trackId];

                    if (cti.indices.Count == 0) {
                        // インデックスが1つもないトラック。lead-outトラックの場合等。
                        if (pcmTrack != null) {
                            pcmTrack.EndTick = (int)((cti.offsetSamples * 75) / pcmTrack.SampleRate);
                            CheckAddPcmData(path, pcmTrack, false);
                            pcmTrack = null;
                        }
                    } else {
                        for (int indexId=0; indexId < cti.indices.Count; ++indexId) {
                            var indexInfo = cti.indices[indexId];

                            if (pcmTrack != null) {
                                pcmTrack.EndTick = (int)(((cti.offsetSamples + indexInfo.offsetSamples) * 75) / pcmTrack.SampleRate);
                                CheckAddPcmData(path, pcmTrack, false);
                                pcmTrack = null;
                            }

                            pcmTrack = new PcmData();
                            pcmTrack.CopyFrom(pcmData);
                            if (pcmTrack.DisplayName.Length == 0) {
                                pcmTrack.DisplayName = System.IO.Path.GetFileName(path);
                            }
                            pcmTrack.DisplayName = string.Format(CultureInfo.InvariantCulture,
                                    "{0} (Track {1}, Index {2})", pcmTrack.DisplayName, cti.trackNr, indexInfo.indexNr);
                            pcmTrack.CueSheetIndex = indexInfo.indexNr;
                            pcmTrack.StartTick = (int)(((cti.offsetSamples + indexInfo.offsetSamples) * 75) / pcmTrack.SampleRate);
                        }
                    }
                }
            }

            return true;
        }