예제 #1
0
        public TimingAnalyzeData AnalyzeSong(string songPath, double blockLength)
        {
            _channel = Bass.CreateStream(songPath, 0, 0, BassFlags.Decode);
            if (_channel == 0)
            {
                _channel = Bass.MusicLoad(songPath, 0, 0, BassFlags.Decode | BassFlags.Prescan, 0);
            }

            var songLength = Bass.ChannelBytes2Seconds(_channel, Bass.ChannelGetLength(_channel));
            var ret        = new TimingAnalyzeData();

            for (var p = 0.0; (p + blockLength) < songLength; p += blockLength)
            {
                var bpm = AnalyzeBpm(p, p + blockLength);
                while (bpm > 360 | bpm < 60)
                {
                    if (bpm > 360)
                    {
                        bpm /= 2;
                    }
                    else if (bpm < 60)
                    {
                        bpm *= 2;
                    }
                }
                ret.AddBpm(new TimingPoint(p, bpm));
            }
            BassFx.BPMFree(_channel);
            Bass.MusicFree(_channel);
            Bass.StreamFree(_channel);

            return(ret);
        }
예제 #2
0
        void OpenFile()
        {
            if (!_ofd.ShowDialog().Value)
            {
                return;
            }

            // free decode bpm stream and resources
            BassFx.BPMFree(_bpmchan);

            // free tempo, stream, music & bpm/beat callbacks
            Bass.StreamFree(_chan);
            Bass.MusicFree(_chan);

            // create decode channel
            _chan = Bass.CreateStream(_ofd.FileName, 0, 0, BassFlags.Decode);

            if (_chan == 0)
            {
                _chan = Bass.MusicLoad(_ofd.FileName, 0, 0, BassFlags.MusicRamp | BassFlags.Prescan | BassFlags.Decode, 0);
            }

            if (_chan == 0)
            {
                // not a WAV/MP3 or MOD
                Status = "Click Here to Open and Play a File...";
                MessageBox.Show("Selected file couldn't be loaded!");
                return;
            }

            // get channel info
            Bass.ChannelGetInfo(_chan, out _info);

            // create a new stream - decoded & resampled :)
            if ((_chan = BassFx.TempoCreate(_chan, BassFlags.Loop | BassFlags.FxFreeSource)) == 0)
            {
                Status = "Click Here to Open and Play a File...";
                MessageBox.Show("Couldn't create a resampled stream!");
                Bass.StreamFree(_chan);
                Bass.MusicFree(_chan);
                return;
            }

            // update the button to show the loaded file name (without path)
            Status = Path.GetFileName(_ofd.FileName);

            SampleRate = _info.Frequency;
            OnPropertyChanged(nameof(MinSampleRate));
            OnPropertyChanged(nameof(MaxSampleRate));

            // update tempo view
            Tempo = 0;

            // set the callback bpm and beat
            IsBpmPeriod = _isBpmPeriod;

            IsBeatPosition = _isBeatPosition;

            // play new created stream
            Bass.ChannelPlay(_chan);

            // create bpmChan stream and get bpm value for BpmPeriod seconds from current position
            var pos    = Bass.ChannelBytes2Seconds(_chan, Bass.ChannelGetPosition(_chan));
            var maxpos = Bass.ChannelBytes2Seconds(_chan, Bass.ChannelGetLength(_chan));

            DecodingBPM(true, pos, pos + BpmPeriod >= maxpos ? maxpos - 1 : pos + BpmPeriod, _ofd.FileName);
        }