Author Topic: Store - bass/or Bass.Net broken RecordStart in Fall Creators Edition.  (Read 1385 times)

cablehead

  • Posts: 315
Installed the latest Windows 10 (Fall Creators Edition)...and all preexisting recording code is broken (UWP).

            Bass.BASS_RecordInit(-1);
            var init = Bass.BASS_ErrorGetCode();
            Debug.WriteLine(init);

            var loopback = new BASS_RECORDINFO();
            Bass.BASS_RecordGetInfo(loopback);
            var error = Bass.BASS_ErrorGetCode();
           
            recProc = new RECORDPROC(RECPROC);
            Debug.WriteLine(loopback.freq);

            var recordHandle = Bass.BASS_RecordStart(loopback.freq, loopback.Channels,
            BASSFlag.BASS_SAMPLE_FLOAT, 50, recProc, IntPtr.Zero);
            error = Bass.BASS_ErrorGetCode();
            Debug.WriteLine(error); // Will always return BASS_ERROR_UNKNOWN.

EDIT: Just tried ManagedBass ( Not sure if it ever worked (UWP)...same result.
EDIT FIX: Not needed with older versions of Windows 10
 await Task.Run(() =>
                {
                    var recordHandle = Bass.BASS_RecordStart(loopback.freq, loopback.Channels, BASSFlag.BASS_SAMPLE_FLOAT, 30, null, IntPtr.Zero);
                });
« Last Edit: 22 Oct '17 - 15:53 by cablehead »

Ian @ un4seen

  • Administrator
  • Posts: 21991
Good to see that you have already found the solution. A BASS_ERROR_UNKNOWN error from BASS_RecordStart indicates that the device initialization failed for some unknown reason (not because it was busy). I will look into that, but if the solution is to make the call asynchronously then it looks like the device initialization needs to be done outside of the main thread now.

Manolo

  • Posts: 12
So, what do I need to change in my app?
It seems like my app has been broken by updating to a new BASS dll set. But maybe, this happens on any actualized Win10 machine! :o

Where would I need to place this await... code and what does it do in detail? What is actually the problem and why would this fix help?

Ian @ un4seen

  • Administrator
  • Posts: 21991
Some functions (generally those that might have some delay, eg. file stuff) can't be called in the main thread in UWP. "Task.Run" causes the code block to run in another thread, which avoids such issues. Here's the documentation for that:

   https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.run

Manolo

  • Posts: 12
First of all: Thanks for your help.
But still, it seems like I'm a bit too stupid to get it right ;-)

My problem does not happen on every machine. The good message, however, is that I have one of the bad ones at home and I can do a quick test...

Next premise is: My app is running on .net 2.0 in order to have the least requirements. Thus, I don't have Task.Run. Instead, I read that I need to start a thread.

So, finally, I ended in this construct, which works perfectly on a good machine, but gives me an endless loop on a bad machine:
Code: [Select]
Aufnahmestream = 0;

                Thread thread = new Thread(
                    () =>
                    {
                        while (Aufnahmestream == 0)
                            Aufnahmestream = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, BassCallback, IntPtr.Zero);
                    });
                thread.Start();
                // Thread.Sleep(100);
                thread.Join();

                // Eingangsstream an BASS anbinden
                if (Aufnahmestream == 0)
                {
                    //Error Message
                   Application.Exit();
                }

So, for any reason, BASS_RecordStart never returns an object?

If I don't have the while loop in the thread, I get the error message with BASS_ErrorGetCode() = "BASS_OK" !?!

The Thread.Sleep(100) doesn't either change a thing.
« Last Edit: 17 Mar '19 - 22:08 by Manolo »

Ian @ un4seen

  • Administrator
  • Posts: 21991
Are you calling BASS_ErrorGetCode immediately after the failed BASS_RecordStart call, in the same thread? Note that error codes are thread-specific, ie. you can't get a failed call's error code in a different thread. Calling BASS_ErrorGetCode in another thread where a BASS call didn't fail would give BASS_OK.

Manolo

  • Posts: 12
No, it wasn't called in that thread. OK understood that.

Now, the code is like this:

Code: [Select]
                Aufnahmestream = 0;
                string Message = "";

                Thread thread = new Thread(
                    () =>
                    {
                        while (Aufnahmestream == 0)
                        {
                            Aufnahmestream = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, BassCallback, IntPtr.Zero);
                            Message = Bass.BASS_ErrorGetCode().ToString();
                            MessageBox.Show("Result: " + Message, "BASSRecordStart Thread", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }   
                    });
                thread.Start();
                //Thread.Sleep(100);
                thread.Join();

                // Eingangsstream an BASS anbinden
                if (Aufnahmestream == 0)
                {
                    // Error Message...
                    Application.Exit();
                }

On the good machine, that gives me one MessageBox with "BASS_OK" and the app is running.

On the bad machine, The program gets stuck in the task giving an endless loop of "BASS_ERROR_UNKNOWN" MessageBoxes.

How can I help solving this puzzle?
Can there be any "bad" HW or SW configuration causing the problem on the bad machine?

Ian @ un4seen

  • Administrator
  • Posts: 21991
What device are you using in your BASS_RecordInit call? If not -1, does using that work?

To help narrow down what/where the problem is, please try running the pre-compiled RECTEST.EXE example from the BASS package (C\BIN folder) on the same system and see whether that gives an error message too.

Manolo

  • Posts: 12
I am checking the devices before calling BASS_RecordInit, so the App Initializes
1) the last used device
2) if that doesn't exist any more, the first found device.
Plus, there seems to be no failure at RecordInit.
Anyway, I tried BASS_RecordInit(-1) - the result is exactly the same: BASS_ERROR_UNKNOWN at BASS_RecordStart. ???

rectest.exe is working on my development (good) machine. On the bad machine, if I click the record button, it gives me an error message: "Couldn't start recording (error code: -1)"  ??? ???

The bad machine is running Windows 10 bit, actual patch level on a Medion MD61100 (E6436), which has a Realtek HD Audio chipset.
« Last Edit: 19 Mar '19 - 21:57 by Manolo »

Ian @ un4seen

  • Administrator
  • Posts: 21991
OK. I will send you a debug BASS version to get some more info on that BASS_ERROR_UNKNOWN error.

Manolo

  • Posts: 12
Dear Ian and dear community,

the problem seems to be solved!

First, I tried if other SW can record any audio from the microphone: No, even Audacity can't record and gives an error, which usually appears, when there is no sound device!
So, there must be a basic fault in this system!

Then, I found (with the help of my son) the Windows 10 security setting, which allows Apps to access the microphone. That was off, so BASS did not get access. When I turned it on (see attachment - sorry for the german), both Audacity, as well as my App was working.  ;D

--> Don't switch this setting off, if you want to record from the microphone! As usual, it's simple if you know what's going wrong.