示例#1
0
        private void Initialize()
        {
            if (this.listBeatPositions == null)
            {
                this.listBeatPositions = new List <stBeatPos>();
            }

            #region [ BASS registration ]
            // BASS.NET ユーザ登録(BASSスプラッシュが非表示になる)。

            BassNet.Registration("*****@*****.**", "2X9181017152222");
            #endregion
            #region [ BASS Version Check ]
            // BASS のバージョンチェック。
            int nBASSVersion = Utils.HighWord(Bass.BASS_GetVersion());
            if (nBASSVersion != Bass.BASSVERSION)
            {
                throw new DllNotFoundException(string.Format("bass.dll のバージョンが異なります({0})。このプログラムはバージョン{1}で動作します。", nBASSVersion, Bass.BASSVERSION));
            }

            int nBASSFXVersion = Utils.HighWord(BassFx.BASS_FX_GetVersion());
            if (nBASSFXVersion != BassFx.BASSFXVERSION)
            {
                throw new DllNotFoundException(string.Format("bass_fx.dll のバージョンが異なります({0})。このプログラムはバージョン{1}で動作します。", nBASSFXVersion, BassFx.BASSFXVERSION));
            }
            #endregion

            #region [ BASS の設定。]
            //this.bIsBASSFree = true;
            //Debug.Assert( Bass.BASS_SetConfig( BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0 ),		// 0:BASSストリームの自動更新を行わない。(サウンド出力しないため)
            //    string.Format( "BASS_SetConfig() に失敗しました。[{0}", Bass.BASS_ErrorGetCode() ) );
            #endregion
            #region [ BASS の初期化。]
            int nデバイス = 0;                      // 0:"no sound" … BASS からはデバイスへアクセスさせない。
            int n周波数  = 44100;                  // 仮決め。lデバイス(≠ドライバ)がネイティブに対応している周波数であれば何でもいい?ようだ。いずれにしろBASSMXで自動的にリサンプリングされる。
            if (!Bass.BASS_Init(nデバイス, n周波数, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                throw new Exception(string.Format("BASS の初期化に失敗しました。(BASS_Init)[{0}]", Bass.BASS_ErrorGetCode().ToString()));
            }
            #endregion

            #region [ 指定されたサウンドファイルをBASSでオープンし、必要最小限の情報を取得する。]
            //this.hBassStream = Bass.BASS_StreamCreateFile( this.filename, 0, 0, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE );
            this.hBassStream = Bass.BASS_StreamCreateFile(this.filename, 0, 0, BASSFlag.BASS_STREAM_DECODE);
            if (this.hBassStream == 0)
            {
                throw new Exception(string.Format("{0}: サウンドストリームの生成に失敗しました。(BASS_StreamCreateFile)[{1}]", filename, Bass.BASS_ErrorGetCode().ToString()));
            }

            this.nTotalBytes = Bass.BASS_ChannelGetLength(this.hBassStream);

            this.nTotalSeconds = Bass.BASS_ChannelBytes2Seconds(this.hBassStream, nTotalBytes);
            if (!Bass.BASS_ChannelGetAttribute(this.hBassStream, BASSAttribute.BASS_ATTRIB_FREQ, ref fFreq))
            {
                string errmes = string.Format("サウンドストリームの周波数取得に失敗しました。(BASS_ChannelGetAttribute)[{0}]", Bass.BASS_ErrorGetCode().ToString());
                Bass.BASS_Free();
                throw new Exception(errmes);
            }
            #endregion
        }
示例#2
0
        public static void GetAudioInformation(string filename)
        {
            float lFrequency = 0;
            float lVolume    = 0;
            float lPan       = 0;

            int stream = Bass.BASS_StreamCreateFile(filename, 0L, 0L, BASSFlag.BASS_STREAM_DECODE);

            // the info members will contain most of it...
            BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);

            if (Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, ref lVolume))
            {
                System.Diagnostics.Debug.WriteLine("Volume: " + lVolume);
            }

            if (Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_PAN, ref lPan))
            {
                System.Diagnostics.Debug.WriteLine("Pan: " + lPan);
            }

            if (Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_FREQ, ref lFrequency))
            {
                System.Diagnostics.Debug.WriteLine("Frequency: " + lFrequency);
            }

            int nChannels = info.chans;

            System.Diagnostics.Debug.WriteLine("Channels: " + nChannels);

            int nSamplesPerSec = info.freq;

            System.Diagnostics.Debug.WriteLine("SamplesPerSec: " + nSamplesPerSec);
        }
示例#3
0
        public void LoadStartFlightChannel(string fileName)
        {
            StartFlightChannelHandle = ChannelFactory.Create(fileName);

            if (!StartFlightChannelHandle.Valid)
            {
                throw new Exception("Failed to load start boost channel.");
            }

            Bass.BASS_ChannelSetAttribute(StartFlightChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, 0f);

            StartFlightChannelSyncs.Add(
                new Sync(
                    StartFlightChannelHandle,
                    BASSSync.BASS_SYNC_END,
                    (handle, channel, data, user) =>
            {
                if (FlightChannelHandle != null)
                {
                    var volume = 0.0f;
                    Bass.BASS_ChannelGetAttribute(StartFlightChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, ref volume);

                    if (volume > 0.0f)
                    {
                        Bass.BASS_ChannelSetAttribute(FlightChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, MaximumVolume);
                    }

                    Bass.BASS_ChannelPlay(FlightChannelHandle.Handle, true);
                }
            }
                    )
                );
        }
示例#4
0
        public void LoadJumpChannel(string fileName)
        {
            JumpChannelHandle = ChannelFactory.Create(fileName, BASSFlag.BASS_MUSIC_LOOP);

            if (!JumpChannelHandle.Valid)
            {
                throw new Exception("Failed to load the jump channel.");
            }

            Bass.BASS_ChannelSetAttribute(JumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, 0f);

            JumpChannelSyncs.Add(
                new Sync(
                    JumpChannelHandle,
                    BASSSync.BASS_SYNC_SLIDE | BASSSync.BASS_SYNC_MIXTIME,
                    (handle, channel, data, user) =>
            {
                var volume = 0.0f;
                Bass.BASS_ChannelGetAttribute(JumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, ref volume);

                if (volume >= MaximumVolume * 0.45f)
                {
                    Console.WriteLine("Will fade next frame.");
                    _fadeJumpNextFrame = true;
                }
            }
                    )
                );
        }
        /// <summary>
        ///		This function makes sure your default device is being used, if not, reload Bass and the song back and continue as if nothing happened.
        /// </summary>
        private void CheckDevice()
        {
            if (!BassManager.CheckDevice(streamID))
            {
                var pos  = Bass.BASS_ChannelGetPosition(streamID, BASSMode.BASS_POS_BYTES);
                var secs = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(streamID, pos));

                var state  = Bass.BASS_ChannelIsActive(streamID);
                var volume = 0.3f;

                Bass.BASS_ChannelGetAttribute(streamID, BASSAttribute.BASS_ATTRIB_VOL, ref volume);

                BassManager.Reload();

                Load(lastFile);

                Volume      = volume;
                CurrentTime = secs;

                switch (state)
                {
                case BASSActive.BASS_ACTIVE_PAUSED:
                case BASSActive.BASS_ACTIVE_STOPPED:
                    Bass.BASS_ChannelPause(streamID);
                    Bass.BASS_ChannelSetPosition(streamID, pos, BASSMode.BASS_POS_BYTES);
                    break;

                case BASSActive.BASS_ACTIVE_STALLED:
                case BASSActive.BASS_ACTIVE_PLAYING:
                    Bass.BASS_ChannelPlay(streamID, false);
                    break;
                }
            }
        }
示例#6
0
    public static float GetAttribute(TempoStream audioStream, TempoAudioAttributes attribute)
    {
        float value = 0;

        Bass.BASS_ChannelGetAttribute(audioStream.audioHandle, (BASSAttribute)attribute, ref value);
        return(value);
    }
示例#7
0
        public float GetVOL()
        {
            float value = 0;

            Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, ref value);
            return(value);
        }
示例#8
0
        public float GetSpeed()
        {
            float value = 0;

            Bass.BASS_ChannelGetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO, ref value);
            return(value);
        }
示例#9
0
        private void GetInfoFromStream_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                while (true)
                {
                    if (chan != 0)
                    {
                        normalpos = Bass.BASS_ChannelGetPosition(chan);
                        normallen = Bass.BASS_ChannelGetLength(chan);
                        tick      = Bass.BASS_ChannelGetPosition(chan, BASSMode.BASS_POS_MIDI_TICK);                       // get position in ticks
                        lentick   = Bass.BASS_ChannelGetLength(chan, BASSMode.BASS_POS_MIDI_TICK);                         // get length in ticks
                        Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_MIDI_VOICES, maxvoices);             // apply to current MIDI file too
                        Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_MIDI_CPU, Convert.ToSingle(maxcpu)); // apply to current MIDI file too
                        Bass.BASS_ChannelGetAttribute(chan, BASSAttribute.BASS_ATTRIB_MIDI_VOICES_ACTIVE, ref active);     // get active voices
                        Bass.BASS_ChannelGetAttribute(chan, BASSAttribute.BASS_ATTRIB_CPU, ref cpu);                       // get cpu usage
                        PassedTime = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(chan, normalpos));
                        LengthTime = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(chan, normallen));
                    }

                    BASS_MIDI_FONTINFO i = new BASS_MIDI_FONTINFO();
                    BassMidi.BASS_MIDI_FontGetInfo(font, i);
                    sfinfolabel = String.Format("Name: {0}\nLoaded: {1} / {2}", i.name, i.samload, i.samsize);

                    System.Threading.Thread.Sleep(1);
                }
            }
            catch { }
        }
        private async void Adaptation_B_Click(object sender, RoutedEventArgs e)
        {
            if (IsClosing)
            {
                return;
            }
            MessageBoxResult result = MessageBox.Show("Mod内に追加されるSEは、現在選択しているプリセットから使用されます。適応する前に必ずプリセットの保存を行ってください。\n" +
                                                      "現在選択中のプリセット:" + Preset_List[Preset_Index][0] + "   続行しますか?", "確認",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No);

            if (result == MessageBoxResult.Yes)
            {
                IsClosing = true;
                Preset_Save_File();
                float Volume_Now = 1f;
                Bass.BASS_ChannelGetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, ref Volume_Now);
                float Volume_Minus = Volume_Now / 15f;
                while (Opacity > 0)
                {
                    Volume_Now -= Volume_Minus;
                    if (Volume_Now < 0f)
                    {
                        Volume_Now = 0f;
                    }
                    Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, Volume_Now);
                    Opacity -= Sub_Code.Window_Feed_Time;
                    await Task.Delay(1000 / 60);
                }
                Bass.BASS_ChannelStop(Stream);
                Bass.BASS_StreamFree(Stream);
                Visibility = Visibility.Hidden;
                IsClosing  = false;
            }
        }
示例#11
0
        internal void ToggleMutePlayback()
        {
            float currentVolume = 0;

            Bass.BASS_ChannelGetAttribute(m_SoundStream, BASSAttribute.BASS_ATTRIB_VOL, ref currentVolume);
            Bass.BASS_ChannelSetAttribute(m_SoundStream, BASSAttribute.BASS_ATTRIB_VOL, currentVolume == 0.0f ? 1.0f : 0.0f);
        }
示例#12
0
        private void CheckPosition()
        {
            Int64 MIDILengthRAW     = Bass.BASS_ChannelGetLength(Data.StreamHandle);
            Int64 MIDICurrentPosRAW = Bass.BASS_ChannelGetPosition(Data.StreamHandle);

            RAWTotal     = ((float)MIDILengthRAW) / 1048576f;
            RAWConverted = ((float)MIDICurrentPosRAW) / 1048576f;
            Double LenRAWToDouble = Bass.BASS_ChannelBytes2Seconds(Data.StreamHandle, MIDILengthRAW);
            Double CurRAWToDouble = Bass.BASS_ChannelBytes2Seconds(Data.StreamHandle, MIDICurrentPosRAW);

            Data.TotalTime   = TimeSpan.FromSeconds(LenRAWToDouble);
            Data.CurrentTime = TimeSpan.FromSeconds(CurRAWToDouble);
            Bass.BASS_ChannelGetAttribute(Data.StreamHandle, BASSAttribute.BASS_ATTRIB_MIDI_PPQN, ref Data.PPQN);
            Data.TotalTicks = Convert.ToUInt32(Bass.BASS_ChannelGetLength(Data.StreamHandle, BASSMode.BASS_POS_MIDI_TICK));
            Data.Tick       = Convert.ToUInt32(Bass.BASS_ChannelGetPosition(Data.StreamHandle, BASSMode.BASS_POS_MIDI_TICK));
            Int32 Tempo = 60000000 / BassMidi.BASS_MIDI_StreamGetEvent(Data.StreamHandle, 0, BASSMIDIEvent.MIDI_EVENT_TEMPO);

            Data.Tempo = Convert.ToUInt32(Tempo.LimitIntegerToRange(0, 999));

            try
            {
                Data.Bar               = Convert.ToUInt32(((Int64)(Data.Tick / (Data.PPQN / (8 / 4) * 4))).LimitLongToRange(0, 9223372036854775807));
                Data.TotalBars         = Convert.ToUInt32(((Int64)(Data.TotalTicks / (Data.PPQN / (8 / 4) * 4))).LimitLongToRange(0, 9223372036854775807));
                Data.HowManyZeroesBars = String.Concat(Enumerable.Repeat("0", Data.TotalBars.ToString().Length));
            }
            catch
            {
                Data.Bar       = 0;
                Data.TotalBars = 0;
            }
        }
示例#13
0
 public static void GIWWork(object sender, DoWorkEventArgs e)
 {
     while (true)
     {
         try
         {
             if (MainWindow.KMCStatus.IsKMCBusy || MainWindow.KMCStatus.IsKMCNowExporting)
             {
                 RTF.TotalTicks        = Bass.BASS_ChannelGetLength(MainWindow.KMCGlobals._recHandle, BASSMode.BASS_POS_MIDI_TICK);
                 RTF.CurrentTicks      = Bass.BASS_ChannelGetPosition(MainWindow.KMCGlobals._recHandle, BASSMode.BASS_POS_MIDI_TICK);
                 RTF.MIDILengthRAW     = Bass.BASS_ChannelGetLength(MainWindow.KMCGlobals._recHandle);
                 RTF.MIDICurrentPosRAW = Bass.BASS_ChannelGetPosition(MainWindow.KMCGlobals._recHandle);
                 RTF.RAWTotal          = ((float)RTF.MIDILengthRAW) / 1048576f;
                 RTF.RAWConverted      = ((float)RTF.MIDICurrentPosRAW) / 1048576f;
                 RTF.LenRAWToDouble    = Bass.BASS_ChannelBytes2Seconds(MainWindow.KMCGlobals._recHandle, RTF.MIDILengthRAW);
                 RTF.CurRAWToDouble    = Bass.BASS_ChannelBytes2Seconds(MainWindow.KMCGlobals._recHandle, RTF.MIDICurrentPosRAW);
                 RTF.LenDoubleToSpan   = TimeSpan.FromSeconds(RTF.LenRAWToDouble * MainWindow.KMCGlobals.TempoScale);
                 RTF.CurDoubleToSpan   = TimeSpan.FromSeconds(RTF.CurRAWToDouble * MainWindow.KMCGlobals.TempoScale);
                 Bass.BASS_ChannelGetAttribute((MainWindow.VSTs.VSTInfo[0].isInstrument ? MainWindow.VSTs._VSTiHandle : MainWindow.KMCGlobals._recHandle), BASSAttribute.BASS_ATTRIB_CPU, ref RTF.CPUUsage);
                 Bass.BASS_ChannelGetAttribute(MainWindow.KMCGlobals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_VOICES_ACTIVE, ref RTF.ActiveVoices);
                 RTF.GetVoices();
             }
             System.Threading.Thread.Sleep(1);
         }
         catch { }
     }
 }
        public override void Play()
        {
            if ((Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PAUSED) || (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_STOPPED))
            {
                Bass.BASS_StreamFree(_stream);

                _stream = Bass.BASS_StreamCreateFile(_source, 0, 0, BASSFlag.BASS_DEFAULT);
                //_stream = Bass.BASS_StreamCreateFile(_source, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                if (_stream != 0)
                {
                    //костыли
                    Bass.BASS_ChannelGetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, ref vol);
                    //костыли
                    Volume = vol * 100F;
                    //костыли
                    Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, (float)_volume);
                    Bass.BASS_ChannelPlay(_stream, false); //2й параметр это луп (рестарт)
                    //   MessageBox.Show(vol.ToString());
                }
                else
                {
                    MessageBox.Show("Error= " + Bass.BASS_ErrorGetCode().ToString());
                }
            }
            else
            {
                Bass.BASS_ChannelPlay(_stream, false);
            }

            //       MessageBox.Show(Duration.ToString());
//
            // Position = TimeSpan.Parse("00:01:00");// 40000;
        }
示例#15
0
 //戻る
 private async void Back_B_Click(object sender, RoutedEventArgs e)
 {
     if (!IsClosing && !IsBusy)
     {
         IsClosing = true;
         IsPaused  = true;
         float Volume_Now = 1f;
         Bass.BASS_ChannelGetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, ref Volume_Now);
         float Volume_Minus = Volume_Now / 30f;
         while (Opacity > 0)
         {
             Opacity    -= Sub_Code.Window_Feed_Time;
             Volume_Now -= Volume_Minus;
             if (Volume_Now < 0f)
             {
                 Volume_Now = 0f;
             }
             Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, Volume_Now);
             await Task.Delay(1000 / 60);
         }
         Bass.BASS_ChannelStop(Stream);
         Bass.BASS_StreamFree(Stream);
         Location_S.Value           = 0;
         Location_S.Maximum         = 0;
         Voices_L.SelectedIndex     = -1;
         Voice_Type_L.SelectedIndex = -1;
         BGM_Add_List.SelectedIndex = -1;
         Visibility = Visibility.Hidden;
         IsClosing  = false;
     }
 }
示例#16
0
        public int GetBitrate()
        {
            float bitRate = 0;

            Bass.BASS_ChannelGetAttribute(_stream, BASSAttribute.BASS_ATTRIB_BITRATE, ref bitRate);

            return((int)bitRate);
        }
示例#17
0
 private void Play_B_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     if (IsClosing)
     {
         return;
     }
     if (Sound_List.SelectedIndex == -1 && Change_List.SelectedIndex == -1)
     {
         return;
     }
     else if (Sound_List.SelectedIndex != -1 && !File.Exists(Voice_Set.Special_Path + "/Wwise/Temp_01.ogg"))
     {
         Message_Feed_Out("サウンドファイルが変換されませんでした。");
         return;
     }
     else if (Change_List.SelectedIndex != -1 && !File.Exists(Change_Sound_Full_Name[Change_List.SelectedIndex]))
     {
         Message_Feed_Out("選択されたファイルが存在しません。");
         return;
     }
     if (SelectIndex == Sound_List.SelectedIndex || SelectIndex == Change_List.SelectedIndex)
     {
         Bass.BASS_ChannelPlay(Stream, false);
     }
     else
     {
         Bass.BASS_ChannelStop(Stream);
         Location_S.Value = 0;
         Bass.BASS_StreamFree(Stream);
         if (Sound_List.SelectedIndex != -1)
         {
             int StreamHandle = Bass.BASS_StreamCreateFile(Voice_Set.Special_Path + "/Wwise/Temp_01.ogg", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP);
             Stream      = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE);
             SelectIndex = Sound_List.SelectedIndex;
         }
         else if (Change_List.SelectedIndex != -1)
         {
             int StreamHandle = Bass.BASS_StreamCreateFile(Change_Sound_Full_Name[Change_List.SelectedIndex], 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP);
             Stream      = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE);
             SelectIndex = Change_List.SelectedIndex;
         }
         else
         {
             Message_Feed_Out("エラーが発生しました。");
             return;
         }
         IsMusicEnd = new SYNCPROC(EndSync);
         Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device);
         Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, IsMusicEnd, IntPtr.Zero);
         Bass.BASS_ChannelPlay(Stream, true);
         Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100);
         Bass.BASS_ChannelGetAttribute(Stream, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, ref SetFirstFreq);
         Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, SetFirstFreq + (float)Speed_S.Value);
         Location_S.Maximum = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream, BASSMode.BASS_POS_BYTES));
     }
     IsPaused = false;
 }
示例#18
0
        /// <summary>
        /// 获取播放声道特性值
        /// </summary>
        /// <param name="attri">要获取的特性</param>
        /// <returns>值</returns>
        public float GetChannelAttribute(BASSAttribute attri)
        {
            if (this._handle == -1)
            {
                return(0f);
            }

            return(Bass.BASS_ChannelGetAttribute(this._handle, attri));
        }
示例#19
0
        private static void FadeMusic(object source, EventArgs e)
        {
            Bass.BASS_ChannelGetAttribute(_music, BASSAttribute.BASS_ATTRIB_VOL, ref _volume);
            Bass.BASS_ChannelSetAttribute(_music, BASSAttribute.BASS_ATTRIB_VOL, _volume - 0.01f);

            if (_volume <= 0.01f)
            {
                Bass.BASS_ChannelSetAttribute(_music, BASSAttribute.BASS_ATTRIB_VOL, 0);
                _timer.Elapsed -= FadeMusic;
            }
        }
示例#20
0
        /// <summary>
        /// Gets the current volume level.
        /// </summary>
        /// <returns>Current volume level.</returns>
        private Double GetVolume()
        {
            Single volume = 0f;

            if (Bass.BASS_ChannelGetAttribute(handle, BASSAttribute.BASS_ATTRIB_VOL, ref volume))
            {
                volume *= 100;
            }

            return(volume);
        }
示例#21
0
        /// <summary>
        /// Gets the current stream volume.
        /// </summary>
        /// <returns>Volume of the channel of this stream. 0 = silent, 1 = full.</returns>
        private float GetVolume()
        {
            float value = 0.0f;

            if (!Bass.BASS_ChannelGetAttribute(_handle, BASSAttribute.BASS_ATTRIB_VOL, ref value))
            {
                CheckException("BASS_ChannelGetAttribute");
            }

            return(value);
        }
示例#22
0
        public void LoadStartJumpChannel(string fileName)
        {
            StartJumpChannelHandle = ChannelFactory.Create(fileName);

            if (!StartJumpChannelHandle.Valid)
            {
                throw new Exception("Failed to load start boost channel.");
            }

            Bass.BASS_ChannelSetAttribute(StartJumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, 0f);

            StartJumpChannelSyncs.Add(
                new Sync(
                    StartJumpChannelHandle,
                    BASSSync.BASS_SYNC_END,
                    (handle, channel, data, user) =>
            {
                if (JumpChannelHandle != null)
                {
                    var volume = 0.0f;
                    Bass.BASS_ChannelGetAttribute(StartJumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, ref volume);

                    if (volume > 0.0f)
                    {
                        Bass.BASS_ChannelSetAttribute(JumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, MaximumVolume);
                    }

                    Bass.BASS_ChannelPlay(JumpChannelHandle.Handle, true);
                }
            }
                    )
                );

            StartJumpChannelSyncs.Add(
                new Sync(
                    StartJumpChannelHandle,
                    BASSSync.BASS_SYNC_SLIDE | BASSSync.BASS_SYNC_MIXTIME,
                    (handle, channel, data, user) =>
            {
                var volume = 0.0f;
                Bass.BASS_ChannelGetAttribute(StartJumpChannelHandle.Handle, BASSAttribute.BASS_ATTRIB_VOL, ref volume);

                if (volume >= MaximumVolume * 0.5f)
                {
                    Console.WriteLine($"Will fade. Volume {volume} hit.");
                    _fadeJumpNextFrame = true;
                }
            }
                    )
                );
        }
示例#23
0
文件: Player.cs 项目: yarwelp/tooll
        private void KeyUpHandler(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
            {
                if (Bass.BASS_ChannelIsActive(_soundStream) == Un4seen.Bass.BASSActive.BASS_ACTIVE_PLAYING)
                {
                    Bass.BASS_ChannelPause(_soundStream);
                    _globalTime.Stop();
                }
                else
                {
                    Bass.BASS_ChannelPlay(_soundStream, false);
                    _globalTime.Start();
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                if (D3DDevice.SwapChain != null)
                {
                    D3DDevice.SwapChain.SetFullscreenState(false, null);
                }

                _form.Close();
            }
            else if (e.KeyCode == Keys.S)
            {
                // Mute sound
                float currentVolume = 0;
                Bass.BASS_ChannelGetAttribute(_soundStream, BASSAttribute.BASS_ATTRIB_VOL, ref currentVolume);
                Bass.BASS_ChannelSetAttribute(_soundStream, BASSAttribute.BASS_ATTRIB_VOL, currentVolume == 0.0f ? 1.0f : 0.0f);
            }
            // Jump positions for Square-show
            else if (e.KeyCode == Keys.D0)
            {
                float time = 0;
                Bass.BASS_ChannelSetPosition(_soundStream, time);
            }
            else if (e.KeyCode == Keys.D1)
            {
                float time = 3 * 60 + 10;
                Bass.BASS_ChannelSetPosition(_soundStream, time);
            }
            else if (e.KeyCode == Keys.D2)
            {
                float time = 4 * 60 + 1;
                Bass.BASS_ChannelSetPosition(_soundStream, time);
            }
            e.Handled = true;
        }
示例#24
0
        public void Open(string path)
        {
            _timer = new BASSTimer(Interval);
            Bass.BASS_StreamFree(_channel);
            _channel  = Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE);
            _channel  = Un4seen.Bass.AddOn.Fx.BassFx.BASS_FX_TempoCreate(_channel, 0);
            _isopened = true;

            if (_channel == 0)
            {
                //throw (new FormatException(Bass.BASS_ErrorGetCode().ToString()));
                _isopened = false;
            }
            Bass.BASS_ChannelGetAttribute(_channel, BASSAttribute.BASS_ATTRIB_FREQ, ref _freq);
        }
        /// <summary>
        ///     Gets the audio stream sample rate.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns>
        ///     The audio stream sample rate
        /// </returns>
        public static int GetSampleRate(int channel)
        {
            if (channel == int.MinValue)
            {
                return(0);
            }

            float trackSampleRate = DefaultSampleRate;

            //lock (Lock)
            {
                Bass.BASS_ChannelGetAttribute(channel, BASSAttribute.BASS_ATTRIB_FREQ, ref trackSampleRate);
                Thread.Sleep(1);
            }
            return((int)trackSampleRate);
        }
示例#26
0
        public SoundEffectInstance(int bassHandle, bool loop, int loopstart, int loopend)
        {
            handle = bassHandle;                                                                  // Store the handle
            Bass.BASS_ChannelGetAttribute(handle, BASSAttribute.BASS_ATTRIB_FREQ, ref baseSRate); // Store the original sample rate (for pitch bending)
            var sz = Bass.BASS_ChannelGetLength(handle);

            if (loopend > sz | (loopend - loopstart) < 3000) // Hax until i figure out wtf is going on with looping.
            {
                loopend = (int)sz;
            }
            //Console.WriteLine("{0} {1}", loopstart, loopend);
            if (loop)                                                                                                                                                      // If we loop
            {
                syncHandle = Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME, loopend, Engine.globalLoopProc, new IntPtr(loopstart)); // Set the global loop proc to take place at the loop end position, then return to the start.
            }
            looping = loop;                                                                                                                                                // Loopyes
        }
示例#27
0
        internal AudioTrackBass(Stream data, bool quick = false, bool loop = false)
        {
            procs = new BASS_FILEPROCS(ac_Close, ac_Length, ac_Read, ac_Seek);

            Preview = quick;
            Looping = loop;

            BASSFlag flags = Preview ? 0 : (BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);

            if (data == null)
            {
                throw new AudioNotLoadedException();
            }
            else
            {
                //encapsulate incoming stream with async buffer if it isn't already.
                DataStream = data as AsyncBufferStream;
                if (DataStream == null)
                {
                    DataStream = new AsyncBufferStream(data, quick ? 8 : -1);
                }

                audioStreamPrefilter = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, flags, procs, IntPtr.Zero);
            }

            if (Preview)
            {
                audioStream = audioStreamForwards = audioStreamPrefilter;
            }
            else
            {
                audioStream          = audioStreamForwards = BassFx.BASS_FX_TempoCreate(audioStreamPrefilter, loop ? BASSFlag.BASS_MUSIC_LOOP : BASSFlag.BASS_DEFAULT);
                audioStreamBackwards = BassFx.BASS_FX_ReverseCreate(audioStreamPrefilter, 5f, BASSFlag.BASS_DEFAULT);

                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_USE_QUICKALGO, Bass.TRUE);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 4);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 30);
            }

            Length = (Bass.BASS_ChannelBytes2Seconds(audioStream, Bass.BASS_ChannelGetLength(audioStream)) * 1000);
            Bass.BASS_ChannelGetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_FREQ, ref initialAudioFrequency);
            currentAudioFrequency = initialAudioFrequency;

            AudioEngine.RegisterTrack(this);
        }
示例#28
0
 private void StopSync(int handle, int channel, int data, IntPtr user)
 {
     if (user.ToInt32() == channel)
     {
         if (data == 2) // BASS_SLIDE_VOL
         {
             float val = 1.0f;
             if (Bass.BASS_ChannelGetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, ref val))
             {
                 if (val < 0.001)
                 {
                     Bass.BASS_ChannelStop(channel);
                     FileFinished(channel, true);
                 }
             }
         }
     }
 }
        /// <summary>
        ///     Gets the volume of a channel as a value between 0 and 100.
        /// </summary>
        /// <returns>A value between 0 and 100</returns>
        public static decimal GetVolume(int channel)
        {
            if (channel == int.MinValue)
            {
                return(0);
            }

            float volume = 0;

            // DebugHelper.WriteLine($"GetChannelVolume {channel}...");
            //lock (Lock)
            {
                Bass.BASS_ChannelGetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, ref volume);
                Thread.Sleep(1);
            }
            // DebugHelper.WriteLine("done");
            return(Convert.ToDecimal(volume * 100));
        }
示例#30
0
        internal static int PlaySample(int sample, int volume, int freqDiff)
        {
            int chan = Bass.BASS_SampleGetChannel(sample, false);

            if (freqDiff != 0)
            {
                float freq = 44100;
                Bass.BASS_ChannelGetAttribute(chan, BASSAttribute.BASS_ATTRIB_FREQ, ref freq);
                Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_FREQ, freq + freqDiff);
            }
            Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_VOL, (float)volume / 100);

            //Bass.BASS_ChannelSetPosition(chan, FindSilence(sample));

            Bass.BASS_ChannelPlay(chan, false);

            return(chan);
        }