void SE_Play()
        {
            //選択しているSEを再生
            if (IsClosing)
            {
                return;
            }
            Bass.BASS_ChannelStop(Stream);
            Bass.BASS_StreamFree(Stream);
            string SE_Count     = SE_Change_Window.Preset_List[SE_Change_Window.Preset_Index][SE_Lists.SelectedIndex + 1];
            int    StreamHandle = Bass.BASS_StreamCreateFile(SE_Count.Split('|')[SE_Play_Index - 1], 0, 0, BASSFlag.BASS_STREAM_DECODE);

            Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE);
            Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1f);
            Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device);
            Bass.BASS_ChannelPlay(Stream, true);
            if (SE_Play_Index < Select_SE_File_Count)
            {
                SE_Play_Index++;
                SE_Play_Number_T.Text = SE_Play_Index + "/" + Select_SE_File_Count;
            }
            else if (Select_SE_File_Count != 1 && SE_Play_Index == Select_SE_File_Count)
            {
                SE_Play_Index         = 1;
                SE_Play_Number_T.Text = SE_Play_Index + "/" + Select_SE_File_Count;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts, pauses or resumes playback of the current song
        /// </summary>
        public void PlayPause()
        {
            if (currentTrack == null)
            {
                throw new Exception("No song loaded.");
            }

            if (playing)
            {
                Bass.BASS_ChannelPause(currentHandle);
                playing = false;
            }
            else
            {
                if (currentHandle == 0)
                {
                    currentHandle = Bass.BASS_StreamCreateFile(currentTrack.Tags.filename, 0, 0, BASSFlag.BASS_DEFAULT);
                    Bass.BASS_ChannelSetDevice(currentHandle, currentDevice);
                    Bass.BASS_ChannelSetSync(currentHandle, BASSSync.BASS_SYNC_END, 0, EndTrackDelegate, IntPtr.Zero);

                    long scrobblePos = Bass.BASS_ChannelGetLength(currentHandle) / 2;
                    Bass.BASS_ChannelSetSync(currentHandle, BASSSync.BASS_SYNC_POS, scrobblePos, ScrobbleTrackDelegate, IntPtr.Zero);
                }
                Bass.BASS_ChannelPlay(currentHandle, false);
                playing = true;
            }
        }
Exemplo n.º 3
0
        public void ChannelSetDevice(byte device, string _name)
        {
            try
            {
                // if you want to change the output of the first stream to the second output
                // you might call this (even during playback)
                bool rez = Bass.BASS_ChannelSetDevice(_Stream, device);
                int  dev = Bass.BASS_GetDevice();
                int  num = Bass.BASS_GetDeviceCount();

                BASS_DEVICEINFO info = new BASS_DEVICEINFO();
                info.name   = string.Empty;
                info.driver = string.Empty;
                info.flags  = 0;
                Bass.BASS_GetDeviceInfo(num, info);

                if (!rez)
                {
                    System.Windows.MessageBox.Show(
                        "Ошибка устройства вывода " + device.ToString() +
                        "\nИмя " + _name + "/" + info.name
                        + "\ndriver= " + info.driver
                        + "\nflags= " + info.flags
                        + "\nТекущее " + dev.ToString()
                        + "\nВсего устр. " + num.ToString()

                        );
                }
            }
            catch (Exception ex) { System.Windows.MessageBox.Show("ошибка " + ex.Message); }
        }
Exemplo n.º 4
0
        private void cbDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            int deviceIndex = cbDevice.SelectedIndex + 1;

            Bass.BASS_Init(deviceIndex, 44100, (BASSInit)0, IntPtr.Zero);
            Bass.BASS_SetDevice(deviceIndex);
            Bass.BASS_ChannelSetDevice(stream, deviceIndex);
        }
Exemplo n.º 5
0
 private void CbDevices_SelectedIndexChanged(object sender, EventArgs e)
 {
     deviceIndex = cbDevices.SelectedIndex + 1;
     //int oldDevice = Bass.BASS_GetDevice();
     Bass.BASS_Init(deviceIndex, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
     Bass.BASS_SetDevice(deviceIndex);
     Bass.BASS_ChannelSetDevice(stream, deviceIndex);
     //Bass.BASS_Free();
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 internal void ChangeDevice(int device)
 {
     Bass.BASS_ChannelSetDevice(audioStreamPrefilter, device);
     if (audioStreamPrefilter != audioStreamForwards)
     {
         Bass.BASS_ChannelSetDevice(audioStreamForwards, device);
         Bass.BASS_ChannelSetDevice(audioStreamBackwards, device);
     }
 }
Exemplo n.º 8
0
        void Load_Sound(string File_Name = "")
        {
            Location_S.Value = 0;
            Location_T.Text  = "00:00";
            int StreamHandle = Bass.BASS_StreamCreateFile(File_Name, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP);

            Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE);
            Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100);
            Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device);
            Location_S.Maximum = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream, BASSMode.BASS_POS_BYTES));
        }
        private void Play_B_Click(object sender, RoutedEventArgs e)
        {
            Bass.BASS_ChannelStop(Stream);
            Bass.BASS_StreamFree(Stream);
            int StreamHandle = Bass.BASS_StreamCreateFile(Voice_Set.Special_Path + "/Server/" + Voice_Set.SRTTbacon_Server_Name + "/Voices/" + Server_Voices.Voice_List[(int)Voice_Select_S.Value], 0, 0, BASSFlag.BASS_STREAM_DECODE);

            Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE);
            Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device);
            Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)(Volume_S.Value / 100));
            Bass.BASS_ChannelPlay(Stream, true);
        }
Exemplo n.º 10
0
        public static void AssignChannelToDevice(int channelId, int deviceId)
        {
            if (!Bass.BASS_ChannelSetDevice(channelId, deviceId))
            {
                var error = Bass.BASS_ErrorGetCode();
                if (error != BASSError.BASS_ERROR_ALREADY)
                {
                    throw new Exception("Can't set device " + error);
                }
            }

            Bass.BASS_ChannelPlay(channelId, false);
        }
Exemplo n.º 11
0
        //
        // Methods
        //
        // play sound
        public void PlaySound(Sound sound)
        {
            if (g.vars.DeviceID == -2 || g.vars.DeviceID > Bass.BASS_GetDeviceCount())
            {
                ThrowWarning($"Please choose playback device in Options");
                return;
            }

            if (!currentSound.IsNULL())
            {
                StopSound(true);
            }

            if (!sound.IsSound())
            {
                ThrowError($"Tried to play not valid sound {sound}");
            }
            else
            {
                playSoundThread = new Thread(() =>
                {
                    isOnDelay    = true;
                    currentSound = sound;

                    OnTrackStart?.Invoke(sound, true);

                    if (Key.IsPressing(g.vars.SoundPlayDelayKey))
                    {
                        Thread.Sleep(g.vars.SoundPlayDelay);
                    }

                    OnTrackStart?.Invoke(sound, false);

                    Bass.BASS_Init(g.vars.DeviceID, 192000, BASSInit.BASS_DEVICE_STEREO, IntPtr.Zero);
                    Stream = Bass.BASS_StreamCreateFile(sound.path, 0, 0, BASSFlag.BASS_DEFAULT);

                    if (Stream != 0)
                    {
                        isOnDelay = false;

                        Bass.BASS_ChannelSetDevice(Stream, g.vars.DeviceID);
                        Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, g.vars.Volume);
                        Bass.BASS_ChannelPlay(Stream, false);
                    }
                });

                playSoundThread.Start();
            }
        }
Exemplo n.º 12
0
        private void comboBoxOutputDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (m_outputDev)
                {
                    if (Player.IsAsioInitialized)
                    {
                        BassAsioDevice.outputDevice = comboBoxOutputDevice.SelectedIndex;
                        //groupMicrophoneEffects.Visible = false;
                        BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(false, comboBoxOutputDevice.SelectedIndex * 2);
                        BassAsioDevice.Stop();
                        BassAsioDevice.SetDevice(comboBoxInputDevice.SelectedIndex * 2, comboBoxOutputDevice.SelectedIndex * 2);
                        BassAsioDevice.Start();
                        Effects.GetorSetFx = Effects.Load.CHANNETSTRIP;
                        RefreshEffects();
                        // groupMicrophoneEffects.Visible = true;
                    }
                    if (Player.IsWasapiInitialized)
                    {
                        //Get the device index from the selected device
                        DeviceInfo info = (DeviceInfo)comboBoxOutputDevice.Items[comboBoxOutputDevice.SelectedIndex];
                        if (info == null)
                        {
                            return;
                        }

                        WasapiDevice.Stop();

                        WasapiDevice.SetDevice(WasapiDevice.InputDevice, info.WasapiDeviceNum);
                        WasapiDevice.Start();
                    }
                    if (Player.IsBassInitialized)
                    {
                        Player.DefaultDevice = comboBoxOutputDevice.SelectedIndex;
                        Bass.BASS_ChannelSetDevice(Player.Mixer, comboBoxOutputDevice.SelectedIndex);
                    }

                    m_outputDev = false;
                    m_inputDev  = false;
                }
            }
            catch (Exception ex)
            {
                Logger.LogFile(ex.Message, "", "comboBoxOutputDevice_SelectedIndexChanged", ex.LineNumber(), this.Name);
            }
        }
Exemplo n.º 13
0
        public void PlaySound(string filename)
        {
            Bass.BASS_StreamFree(stream);
            syncCallback = new SYNCPROC(OnSongFinished);
            BASSActive isActive = default(BASSActive);

            isActive = Bass.BASS_ChannelIsActive(stream);
            if (isActive == BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelStop(stream);
            }
            stream = Bass.BASS_StreamCreateURL(filename, 0, 0, null, IntPtr.Zero);
            Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, tbVolume.Value / 100F);
            Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END, 0, syncCallback, IntPtr.Zero);
            //Bass.BASS_Init(deviceIndex, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            Bass.BASS_SetDevice(deviceIndex);
            Bass.BASS_ChannelSetDevice(stream, deviceIndex);
            Bass.BASS_ChannelPlay(stream, false);
        }
        private void SE_Play_B_Click(object sender, RoutedEventArgs e)
        {
            if (IsClosing || SE_List.SelectedIndex == -1 || SE_Sound_List.SelectedIndex == -1)
            {
                Message_Feed_Out("ファイルが選択されていません。");
                return;
            }
            if (!File.Exists(SE_Files[SE_List.SelectedIndex][SE_Sound_List.SelectedIndex]))
            {
                Message_Feed_Out("音声ファイルが存在しません。削除された可能性があります。");
                return;
            }
            Bass.BASS_ChannelStop(Stream);
            Bass.BASS_StreamFree(Stream);
            int StreamHandle = Bass.BASS_StreamCreateFile(SE_Files[SE_List.SelectedIndex][SE_Sound_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);
            Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device);
            Bass.BASS_ChannelPlay(Stream, false);
            Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100);
        }
Exemplo n.º 15
0
        public void ChangeDevice(BASS_DEVICEINFO device)
        {
            var deviceNO    = FindDevice(device);
            var oldDeviceNO = Bass.BASS_GetDevice();

            if (oldDeviceNO != deviceNO)
            {
                if (!Bass.BASS_GetDeviceInfo(deviceNO).IsInitialized)
                {
                    var handle = IntPtr.Zero;
                    if (!Bass.BASS_Init(-1, sampleFrequency, BASSInit.BASS_DEVICE_SPEAKERS, handle))
                    {
                        Debug.WriteLine("Bass Initialize error!");
                        throw new Exception(Bass.BASS_ErrorGetCode().ToString());
                    }
                }
                if (_activeStreamHandle != 0)
                {
                    if (!Bass.BASS_ChannelSetDevice(_activeStreamHandle, deviceNO))
                    {
                        throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString());
                    }
                }
                if (!Un4seen.Bass.Bass.BASS_SetDevice(oldDeviceNO))
                {
                    throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString());
                }
                if (!Un4seen.Bass.Bass.BASS_Free())
                {
                    throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString());
                }
                if (!Un4seen.Bass.Bass.BASS_SetDevice(deviceNO))
                {
                    throw new Exception(Un4seen.Bass.Bass.BASS_ErrorGetCode().ToString());
                }
            }
            Device = device;
        }
Exemplo n.º 16
0
        public void Evaluate(int SpreadMax)
        {
            #region Pin Device Changed
            if (this.FPinInDevice.PinIsChanged)
            {
                double dbldevice;
                this.FPinInDevice.GetValue(0, out dbldevice);
                int devid = Convert.ToInt32(dbldevice);

                //0 is for no sound device, so redirect to default
                if (devid <= 0)
                {
                    devid = -1;
                }

                IntPtr ptr = IntPtr.Zero;
                Bass.BASS_Init(devid, 44100, BASSInit.BASS_DEVICE_DEFAULT, ptr, null);
                this.FDevice = devid;

                foreach (ChannelInfo channel in this.FChannels)
                {
                    if (channel.BassHandle.HasValue)
                    {
                        //Update all channels in the device
                        int chandevid = Bass.BASS_ChannelGetDevice(channel.BassHandle.Value);
                        if (this.FDevice != chandevid)
                        {
                            Bass.BASS_ChannelSetDevice(channel.BassHandle.Value, chandevid);
                        }
                    }
                }
            }
            #endregion

            if (this.FPinInBuffer.PinIsChanged)
            {
                double db;
                this.FPinInBuffer.GetValue(0, out db);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, Convert.ToInt32(db));
            }
            if (this.FPInInLoop.PinIsChanged)
            {
                double db;
                this.FPInInLoop.GetValue(0, out db);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, Convert.ToInt32(db));
            }

            #region Handle Pin Changed
            if (this.FPinInHandle.PinIsChanged)
            {
                //Make sure we use the proper device
                Bass.BASS_SetDevice(this.FDevice);

                ChannelList oldchannels = new ChannelList();
                oldchannels.AddRange(this.FChannels);

                this.FChannels.Clear();

                for (int i = 0; i < this.FPinInHandle.SliceCount; i++)
                {
                    double dblhandle;
                    this.FPinInHandle.GetValue(0, out dblhandle);
                    int hid = Convert.ToInt32(dblhandle);

                    if (this.manager.Exists(hid))
                    {
                        //Get the channel in the list
                        ChannelInfo channel = this.manager.GetChannel(hid);

                        if (channel.BassHandle == null)
                        {
                            //Initialize channel
                            channel.Initialize(this.FDevice);
                        }
                        else
                        {
                            //Check if wrong device, if yes, update it
                            int chandevid = Bass.BASS_ChannelGetDevice(channel.BassHandle.Value);
                            if (this.FDevice != chandevid)
                            {
                                Bass.BASS_ChannelSetDevice(channel.BassHandle.Value, chandevid);
                            }
                        }
                        this.FChannels.Add(channel);
                        //Little trick to refresh
                        channel.Play = channel.Play;
                    }
                }


                //Pause the old channels not in it anymore
                foreach (ChannelInfo info in oldchannels)
                {
                    if (this.FChannels.GetByID(info.InternalHandle) == null)
                    {
                        if (info.BassHandle.HasValue)
                        {
                            Bass.BASS_ChannelPause(info.BassHandle.Value);
                        }
                    }
                }
            }
            #endregion

            #region Updated if pin connected
            if (this.FHandleConnected != this.FPinInHandle.IsConnected)
            {
                if (this.FPinInHandle.IsConnected)
                {
                    this.FChannels.RefreshPlay();
                }
                else
                {
                    this.FChannels.PauseAll();
                }
                this.FHandleConnected = this.FPinInHandle.IsConnected;
            }
            #endregion
        }
Exemplo n.º 17
0
 /// <summary>
 /// Sets the current audio device
 /// </summary>
 /// <param name="index">Audio device index</param>
 public static bool SetAudioDevice(int index)
 {
     _deviceIndex = index;
     return(Bass.BASS_ChannelSetDevice(channel, index));
 }