Ejemplo n.º 1
0
        public static PcmData ReadWav(BinaryReader br)
        {
            var reader = new WavReader();
            if (!reader.ReadHeaderAndSamples(br, 0, -1)) {
                return null;
            }

            var pcm = new PcmData();
            pcm.AlbumTitle = reader.AlbumName;
            pcm.ArtistName = reader.ArtistName;
            pcm.DisplayName = reader.Title;

            pcm.SetFormat(reader.NumChannels, reader.BitsPerSample,
                reader.ValidBitsPerSample, reader.SampleRate,
                reader.SampleValueRepresentationType, reader.NumFrames);

            pcm.SetSampleArray(reader.GetSampleArray());

            return pcm;
        }
Ejemplo n.º 2
0
        private int StreamBeginWave(string path, long startFrame)
        {
            int ercd = -1;

            mWaveR = new WavReader();
            mBr = new BinaryReader(
                File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));

            bool readSuccess = mWaveR.ReadStreamBegin(mBr, out mPcmData);
            if (readSuccess) {

                NumFrames = mWaveR.NumFrames;

                if (mWaveR.ReadStreamSkip(mBr, startFrame)) {
                    ercd = 0;
                }
            }
            return ercd;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
        private PcmData ReadWavFile(string path)
        {
            PcmData pcmData = new PcmData();

            using (BinaryReader br = new BinaryReader(
                    File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                var wavR = new WavReader();
                bool readSuccess = wavR.ReadHeaderAndSamples(br, 0, -1);
                if (!readSuccess) {
                    return null;
                }
                pcmData.SetFormat(wavR.NumChannels, wavR.BitsPerSample, wavR.BitsPerSample,
                    wavR.SampleRate, wavR.SampleValueRepresentationType, wavR.NumFrames);
                pcmData.SetSampleArray(wavR.GetSampleArray());
            }

            return pcmData;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// WAVファイルのヘッダ部分を読み込む。
        /// </summary>
        /// <returns>読めたらtrue</returns>
        private bool ReadWavFileHeader(string path)
        {
            bool result = false;
            var pd = new PcmDataLib.PcmData();

            var wavR = new WavReader();
            using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                if (wavR.ReadHeader(br)) {
                    // WAVヘッダ読み込み成功。PcmDataを作って再生リストに足す。

                    pd.SetFormat(wavR.NumChannels, wavR.BitsPerSample, wavR.ValidBitsPerSample,
                            (int)wavR.SampleRate, wavR.SampleValueRepresentationType, wavR.NumFrames);
                    if ("RIFFINFO_INAM".Equals(wavR.Title) &&
                            "RIFFINFO_IART".Equals(wavR.ArtistName)) {
                        // Issue 79 workaround
                    } else {
                        if (wavR.Title != null) {
                            pd.DisplayName = wavR.Title;
                        }
                        if (wavR.AlbumName != null) {
                            pd.AlbumTitle = wavR.AlbumName;
                        }
                        if (wavR.ArtistName != null) {
                            pd.ArtistName = wavR.ArtistName;
                        }
                    }
                    pd.SetPicture(wavR.PictureBytes, wavR.PictureData);
                    result = CheckAddPcmData(path, pd, true);
                } else {
                    LoadErrorMessageAdd(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ReadFileFailed + ": {1} : {2}{3}",
                            "WAV", path, wavR.ErrorReason, Environment.NewLine));
                }
            }

            return result;
        }