20 May '13 - 15:47 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: WPF : DSP_PeakLevelMeter with BassAsioHandler (Error Thread)  (Read 471 times)
Kmaa
Posts: 20


« on: 14 Aug '12 - 21:25 »
Reply with quoteQuote

Hello

I have an error when I use DSP_PeakLevelMeter with bassAsioHandler.InputChannel in an WPF application
in a WinForm App, I Havent this problem, and can use my progressbar

WPF App : fail
        BassAsioHandler bassAsioHandler;
        DSP_PeakLevelMeter DspLevelMeter;
        private BASS_ASIO_DEVICEINFO[] bassAsioDeviceinfo;
        private BASS_DEVICEINFO[] bassDeviceinfo;
        private void Load(object sender, RoutedEventArgs e)
        {
            //////////////////////////////////////////////////////
            // Load Bass Asio Device
            //////////////////////////////////////////////////////
            Console.WriteLine("[BASSMotor] BassAsio Init Asio Devices", 5);

            // Get Asio Devices
            bassAsioDeviceinfo = BassAsio.BASS_ASIO_GetDeviceInfos();
            Console.WriteLine("[BASSMotor] BassAsio Fond " + bassAsioDeviceinfo.Length + " Devices " + BassAsio.BASS_ASIO_ErrorGetCode(), 3);

            // Init Asio Devices
            for (int i = 0; i < bassAsioDeviceinfo.Length; i++)
            {
                Console.WriteLine("[BASSMotor] BassAsio Init Device id:" + i + " - " + bassAsioDeviceinfo[i].name, 5);
                if (!BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_DEFAULT))
                {
                    bassAsioDeviceinfo[i].name = "Error " + bassAsioDeviceinfo[i].name;
                    Console.WriteLine("[BASSMotor] BassAsio can't Init Device id:" + i + " - " + bassAsioDeviceinfo[i].name + " : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                    //sBassError = BassAsio.BASS_ASIO_ErrorGetCode().ToString();
                }
                else
                {
                    Console.WriteLine("[BASSMotor] BassAsio Device id:" + i + " - " + bassAsioDeviceinfo[i].name + " : Init Sucess", 3);

                    if (BassAsio.BASS_ASIO_GetDevice() == i || BassAsio.BASS_ASIO_SetDevice(i))
                    {
                        Console.WriteLine("[BASSMotor] BassAsio Get Channels info from Device id:" + i + " - " + bassAsioDeviceinfo[i].name, 5);

                        // Get all Information of Device
                        BASS_ASIO_INFO bassAsioInfo = BassAsio.BASS_ASIO_GetInfo();
                        if (bassAsioInfo == null)
                            Console.WriteLine("[BASSMotor] BassAsio Get Channels info from Device id:" + i + " - " + bassAsioInfo.name + " Error : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                        else
                        {
                            Console.WriteLine("[BASSMotor] BassAsio Fond " + bassAsioInfo.inputs + " Input Channel from Devices id:" + i + " - " + bassAsioInfo.name, 0);
                            for (int ii = 0; ii < bassAsioInfo.inputs; ii++)
                            {
                                Console.WriteLine("[BASSMotor] BassAsio Get Info of from Input Channel id:" + ii + " - " + BassAsio.BASS_ASIO_ChannelGetInfo(true, ii).name + " ", 5);
                            }
                        }
                    }
                    else
                        Console.WriteLine("[BASSMotor] BassAsio can't set Devices id:" + i + " - " + bassAsioDeviceinfo[i].name + "Error : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                }

            }

            //////////////////////////////////////////////////////
            // Load Bass Device
            //////////////////////////////////////////////////////
            Console.WriteLine("[BASSMotor] BassAsio Init WDM Devices", 5);

            // Get WDM Devices
            bassDeviceinfo = Bass.BASS_GetDeviceInfos();
            Console.WriteLine("[BASSMotor] Bass Fond " + bassDeviceinfo.Length + " Devices " + Bass.BASS_ErrorGetCode(), 3);

            // Init WDM Devices
            for (int i = 0; i < bassDeviceinfo.Length; i++)
            {
                if (!Bass.BASS_Init(i, 48000, BASSInit.BASS_DEVICE_DEFAULT,  new WindowInteropHelper(Application.Current.MainWindow).Handle))
                {
                    bassDeviceinfo[i].name = "Error " + bassDeviceinfo[i].name;
                    Console.WriteLine("[BASSMotor] Bass can't Init Device id:" + i + " - " + bassDeviceinfo[i].name + " : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                    //sBassError = Bass.BASS_ErrorGetCode().ToString();
                }
                else
                    Console.WriteLine("[BASSMotor] Bass Device id:" + i + " - " + bassDeviceinfo[i].name + " : Init Sucess", 3);
            }


            bassAsioHandler = new BassAsioHandler(true, 0, 3, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000d);
            if (!bassAsioHandler.Start(512))
            {
                Console.WriteLine("[SoundcardMOTOR] Could not start AsioHandler from Device:0 (id:0) - Channel:5 (id:5) : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                bassAsioHandler.Dispose();
                bassAsioHandler = null;
            }
            else
            {
                Console.WriteLine("[SoundcardMOTOR] Start AsioHandler from Device:" +0+ " (id:" + 0 + ") - Channel:" + 5 + " (id:" + 5 + ") : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                DspLevelMeter = new DSP_PeakLevelMeter(bassAsioHandler.InputChannel, 0);
                DspLevelMeter.Notification += new EventHandler(_plm_Rec_Notification);
            }

        }

        public void _plm_Rec_Notification(object sender, EventArgs e)
        {
            //Console.WriteLine(Tools.SoundcardDSP_PeakLevelMeter[iId].LevelL);
            Console.WriteLine(DspLevelMeter.LevelL.ToString());
            progressBar1.Value = 32768d;//DspLevelMeter.LevelL;
        }
    }
Logged
Kmaa
Posts: 20


« Reply #1 on: 14 Aug '12 - 21:26 »
Reply with quoteQuote

WinForm : Good
       private BASS_ASIO_DEVICEINFO[] bassAsioDeviceinfo;
        private BASS_DEVICEINFO[] bassDeviceinfo;
        public BassAsioHandler bassAsioHandler;
        DSP_PeakLevelMeter DspLevelMeter;
        private void Loaded(object sender, EventArgs e)
        {
            //////////////////////////////////////////////////////
            // Load Bass Asio Device
            //////////////////////////////////////////////////////
            Console.WriteLine("[BASSMotor] BassAsio Init Asio Devices", 5);


            // Get Asio Devices
            bassAsioDeviceinfo = BassAsio.BASS_ASIO_GetDeviceInfos();
            //bassAsioInfo = new BASS_ASIO_INFO[bassAsioDeviceinfo.Length]; // Full Info (Buffer, Driver, ...)
            //bassAsioChannelInfo = new Dictionary<int, BASS_ASIO_CHANNELINFO>[bassAsioDeviceinfo.Length]; //
            Console.WriteLine("[BASSMotor] BassAsio Fond " + bassAsioDeviceinfo.Length + " Devices " + BassAsio.BASS_ASIO_ErrorGetCode(), 3);


            // Init Asio Devices
            for (int i = 0; i < bassAsioDeviceinfo.Length; i++)
            {
                Console.WriteLine("[BASSMotor] BassAsio Init Device id:" + i + " - " + bassAsioDeviceinfo[i].name, 5);
                if (!BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_DEFAULT))
                {
                    bassAsioDeviceinfo[i].name = "Error " + bassAsioDeviceinfo[i].name;
                    Console.WriteLine("[BASSMotor] BassAsio can't Init Device id:" + i + " - " + bassAsioDeviceinfo[i].name + " : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                    //sBassError = BassAsio.BASS_ASIO_ErrorGetCode().ToString();
                }
                else
                {
                    Console.WriteLine("[BASSMotor] BassAsio Device id:" + i + " - " + bassAsioDeviceinfo[i].name + " : Init Sucess", 3);


                    // Get Channels Info
                    //bassAsioChannelInfo[i] = new Dictionary<int, BASS_ASIO_CHANNELINFO>();



                    if (BassAsio.BASS_ASIO_GetDevice() == i || BassAsio.BASS_ASIO_SetDevice(i))
                    {
                        Console.WriteLine("[BASSMotor] BassAsio Get Channels info from Device id:" + i + " - " + bassAsioDeviceinfo[i].name, 5);

                        // Get all Information of Device
                        BASS_ASIO_INFO bassAsioInfo = BassAsio.BASS_ASIO_GetInfo();
                        if (bassAsioInfo == null)
                            Console.WriteLine("[BASSMotor] BassAsio Get Channels info from Device id:" + i + " - " + bassAsioInfo.name + " Error : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                        else
                        {
                            Console.WriteLine("[BASSMotor] BassAsio Fond " + bassAsioInfo.inputs + " Input Channel from Devices id:" + i + " - " + bassAsioInfo.name, 0);


                                for (int ii = 0; ii < bassAsioInfo.inputs; ii++)
                                {
                                    Console.WriteLine("[BASSMotor] BassAsio Get Info of from Input Channel id:" + ii + " - " + BassAsio.BASS_ASIO_ChannelGetInfo(true, ii).name + " ", 5);
                                }
                        }
                    }
                    else
                        Console.WriteLine("[BASSMotor] BassAsio can't set Devices id:" + i + " - " + bassAsioDeviceinfo[i].name + "Error : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                }

            }



            //////////////////////////////////////////////////////
            // Load Bass Device
            //////////////////////////////////////////////////////
            Console.WriteLine("[BASSMotor] BassAsio Init WDM Devices", 5);

            // Get WDM Devices
            bassDeviceinfo = Bass.BASS_GetDeviceInfos();
            Console.WriteLine("[BASSMotor] Bass Fond " + bassDeviceinfo.Length + " Devices " + Bass.BASS_ErrorGetCode(), 3);

            // Init WDM Devices
            for (int i = 0; i < bassDeviceinfo.Length; i++)
            {
                if (!Bass.BASS_Init(i, 48000, BASSInit.BASS_DEVICE_DEFAULT, this.Handle))
                {
                    bassDeviceinfo[i].name = "Error " + bassDeviceinfo[i].name;
                    Console.WriteLine("[BASSMotor] Bass can't Init Device id:" + i + " - " + bassDeviceinfo[i].name + " : " + BassAsio.BASS_ASIO_ErrorGetCode(), 0);
                    //sBassError = Bass.BASS_ErrorGetCode().ToString();
                }
                else
                {
                    Console.WriteLine("[BASSMotor] Bass Device id:" + i + " - " + bassDeviceinfo[i].name + " : Init Sucess", 3);
                    if (bassDeviceinfo[i].IsDefault)
                    { }
                }

            }







            bassAsioHandler = new BassAsioHandler(true, 0, 2, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000d);

            if (!bassAsioHandler.Start(512))
            {
                Console.WriteLine("[SoundcardMOTOR] Could not start AsioHandler " + BassAsio.BASS_ASIO_ErrorGetCode());
                bassAsioHandler.Dispose();
                bassAsioHandler = null;
            }
            else
            {

                Console.WriteLine("[SoundcardMOTOR] Start AsioHandler ");

                DspLevelMeter = new DSP_PeakLevelMeter(bassAsioHandler.InputChannel, 0);
                DspLevelMeter.Notification += new EventHandler(_plm_Rec_Notification);
               
            }
        }



        public void _plm_Rec_Notification(object sender, EventArgs e)
        {
            //Console.WriteLine(Tools.SoundcardDSP_PeakLevelMeter[iId].LevelL);
            Console.WriteLine(DspLevelMeter.LevelL.ToString());
            progressBar1.Value = DspLevelMeter.LevelL;
            //channelMotor_Graphic.ProgressBar.Value = 32768d;//DspLevelMeter.LevelL;
        }
    }
Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #2 on: 15 Aug '12 - 16:58 »
Reply with quoteQuote

Please clarify what the problem/error is. If a function call is failing, which function is that and what is the error code?
Logged
Kmaa
Posts: 20


« Reply #3 on: 3 Sep '12 - 13:34 »
Reply with quoteQuote

When you are in WPF, it's not possible tu set  " progressBar1.Value ". it's necessary to use an Invoke fonction

Error Message is : "Created by an over thread"


No problème in a Winform app
Logged
ken
Posts: 630


« Reply #4 on: 4 Sep '12 - 11:21 »
Reply with quoteQuote

When you are in WPF, it's not possible tu set  " progressBar1.Value ". it's necessary to use an Invoke fonction

Error Message is : "Created by an over thread"


No problème in a Winform app

Try this code (C# WPF)


Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
        //Do your stuff here (that is GUI controls)... Ex:
        progressBar1.Value  = MyValue
});

« Last Edit: 4 Sep '12 - 11:24 by ken » Logged
Kmaa
Posts: 20


« Reply #5 on: 5 Sep '12 - 14:12 »
Reply with quoteQuote

I have already use this code, and it's work without error.

tanks a lot
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines