Author Topic: BASSWASAPI beta  (Read 154736 times)

Ian @ un4seen

  • Administrator
  • Posts: 20436
BASSWASAPI beta
« on: 14 Apr '10 - 15:38 »
Now available on the BASS page.


Here is a new BASSWASAPI add-on, making it possible to use WASAPI output and input (available on Windows Vista and beyond) with BASS. Both exclusive and shared modes are supported, as are both output and input devices, as well as "loopback" devices (which capture the sound from output devices). WASAPI's regular and event-driven buffering systems are both supported.

32-bit and 64-bit versions are included. C/C++, Delphi, and Visual Basic APIs are provided (BASS.Net also includes support for it). Documentation is also included, so please see that for information on the various functions. Some examples are also included, but they're currently C/C++ only (RECTEST is available for VB); if anyone would like to port any of them to Delphi/VB, that would be handy :)

Unlike BASSASIO, BASSWASAPI does require BASS, and the BASSmix add-on is recommended too. WASAPI doesn't support arbitrary sample formats (like DirectSound does), and BASSWASAPI doesn't include built-in resampling capability; BASSmix can be used to handle resampling instead (as well as playing multiple sounds), as in the examples. BASSmix 2.4.5 is required by the examples for the BASS_Mixer_ChannelGetPositionEx function, which is used to account for output latency when getting the position of a source channel.

This is not a final release, so things may change; feel free to make suggestions for changes/improvements/etc. Please also report any problems that you encounter.
« Last Edit: 13 Sep '13 - 15:46 by Ian @ un4seen »

radio42

  • Posts: 4576
Re: BASSWASAPI beta
« Reply #1 on: 14 Apr '10 - 16:23 »
The latest Bass.Net version fully supports the new WASAPI stuff.
It also includes (just like the BassAsioHandler) a BassWasapiHandler helper class, which takes care of almost anything.

Get it here: BASS.NET API
« Last Edit: 18 Jun '10 - 11:19 by radio42 »

fmcoder

  • Posts: 436
Re: BASSWASAPI beta
« Reply #2 on: 16 Apr '10 - 16:32 »
What we achieve using WASAPI instead of DirectSound?

radio42

  • Posts: 4576
Re: BASSWASAPI beta
« Reply #3 on: 16 Apr '10 - 16:46 »
WASAPI (Windows Audio Session API) is the new audio standard introduced with Vista and WIndows 7.
It is a kind of replacement for DirectSound - which is not going to be further developed by Microsoft.
As such all new sound drivers of modern soundcards needs to support this new API.

WASAPI has a couple of benefits over DirectSound - the major benifit is low latency.
Depending on the quality of the driver of your soundcard you can get to the latency of ASIO.

There are a couple of other benefits, like session management, seperation of shared and exclusive mode, better driver and device management etc.

On Vista and Win7 DirectSound is also using WASAPI in the background, since now all audio stuff is going through WASAPI.
So using WASAPI directly is just more performent and uses less resources.

jeffdavis

  • Posts: 297
Re: BASSWASAPI beta
« Reply #4 on: 19 Apr '10 - 18:51 »
Ian, this is FANTASTIC!   We've been waiting for this for 3 years!!!!!

Couple of intial observations.

The CHM doesn't seem to have any content?

Would be nice to seem some more examples?


Bert

  • Posts: 176
Re: BASSWASAPI beta
« Reply #5 on: 20 Apr '10 - 11:20 »
Thank You Ian,
great improvement!
Do you plan to implement it directly to the bass.dll?
It would be easier for writing apps which should run on different Windows versions.

Bert

Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #6 on: 20 Apr '10 - 17:17 »
The CHM doesn't seem to have any content?

That's strange. Do you have the same problem with the other BASS/add-on documentation?

Actually, I vaguely recall seeing a previous thread about this issue (with the other CHM files). I don't remember the details, but I think it may have been a permissions issue and/or trying to open the documentation straight from the ZIP without extracting it first?

Would be nice to seem some more examples?

Yes, more will be added.

Do you plan to implement it directly to the bass.dll?
It would be easier for writing apps which should run on different Windows versions.

I'm not sure. There are no immediate plans for it, but I guess it might be incorporated into BASS.DLL at some point. BASSmix probably will be though, at which point an output plugin system would become more feasible, which would allow BASSWASAPI to be more integrated with BASS, if not built-in.

Note that BASSWASAPI.DLL will still load on older Windows, ie. there won't be any "This application has failed to start..." error messages, in case that is what you're concerned about :)

jeffdavis

  • Posts: 297
Re: BASSWASAPI beta
« Reply #7 on: 21 Apr '10 - 22:04 »
That's strange. Do you have the same problem with the other BASS/add-on documentation?

Actually, I vaguely recall seeing a previous thread about this issue (with the other CHM files). I don't remember the details, but I think it may have been a permissions issue and/or trying to open the documentation straight from the ZIP without extracting it first?

My other CHM files from BASS all read fine.  This one displays the content on the left but the pane on the right is empty with a "Navigation to the webpage was canceld".   Also get a warning when opening this CHM saying it is an unknown publisher?

Nevermind.  Read another thread that said to click the unblock button in properties in Window 7.  Works fine now.

« Last Edit: 21 Apr '10 - 22:07 by jeffdavis »

Bert B.

  • Posts: 118
Re: BASSWASAPI beta
« Reply #8 on: 22 Apr '10 - 07:42 »
Quote
This one displays the content on the left but the pane on the right is empty with a "Navigation to the webpage was canceld".

You can find more information about that here:

http://www.helpandmanual.com/products_hhreg.html

ken

  • Posts: 739
Re: BASSWASAPI beta
« Reply #9 on: 26 Apr '10 - 10:20 »
And here comes the Bass.Net (pre) version which supports the new WASAPI stuff.
It also includes (just like the BassAsioHandler) a BassWasapiHandler helper class, which takes care of almost anything.


Bernd,

I'm litle confused on how to use inputs with BassWasapiHandler.  I'm not sure how to add an input device. (I wanna use SetFullDuplex and add the input to a mixer, I do have several in/out on my soundcard [M-Audio Delta 1010])  It's bit different to AsioHandler. Also the documentation for "BassWasapiHandler Class" have a "Wasapi input" but I can't see that in code..

Next one..
 
How to list devices, I do like this, but get's doublles on the output devices.

Code: [Select]
BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();

            for (int i = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(i, info); i++)
            {
               if(!info.IsInput)
                    cmbDevOut.Items.Add(info.ToString());

               if (info.SupportsRecording)
                   cmbDevIn.Items.Add(info.ToString());
            }




and last...

When usng BassWasapiHandler or BASS_WASAPI_DEVICEINFO, I get messagebox saying that I use version 0.0 and 1.0 was expected of Wasapi.

/Ken




Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #10 on: 26 Apr '10 - 13:07 »
How to list devices, I do like this, but get's doublles on the output devices.

Those duplicates are probably the "loopback" devices, which capture the sound coming from the corresponding output devices. They can be identified by the BASS_DEVICE_LOOPBACK flag, but they don't currently have the BASS_DEVICE_INPUT flag set. Looking at the BASS_WASAPI_GetDeviceInfo documentation, it does mean that the example there is incomplete, as it is only checking for the BASS_DEVICE_INPUT flag and is overlooking BASS_DEVICE_LOOPBACK. So either that example (and BASS.Net I suspect) need updating or the BASS_DEVICE_INPUT flag needs to be added to the loopback devices. I think the latter is probably a slightly better solution, so an updated DLL is now in the package (see the 1st post).

radio42

  • Posts: 4576
Re: BASSWASAPI beta
« Reply #11 on: 27 Apr '10 - 10:29 »
@Ken:

I am not sure about your issues, as here it works just fine, so maybe you should re-download from the above post.

Here is some code snippet for using the BassWaspiHandler (which works almost exactly like the BassAsioHandler):
Code: [Select]
private BassWasapiHandler _wasapiHandler = null;
private int _recordStream = 0;
private int _fullDuplexStream = 0;
...

_wasapiHandler = new BassWasapiHandler(deviceId, false, 48000, 2, 0f, 0f);
if (_wasapiHandler.Init())
{
    _recordStream = _wasapiHandler.InputChannel;

    // double check, that the device is not muted externally
    if (_wasapiHandler.DeviceMute)
        _wasapiHandler.DeviceMute = false;
    // check, that the master volume is not 0
    if (_wasapiHandler.DeviceVolume == 0f)
        _wasapiHandler.DeviceVolume = 1f;

    // start WASAPI
    _wasapiHandler.Start();
}
...

// create a full-duplex channel which might be added to an output mixer
_wasapiHandler.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false);
_fullDuplexStream = _wasapiHandler.OutputChannel;
...

To get all available WASAPI recording devices you might use something like this:
Code: [Select]
BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
for (int i = 0; i < wasapiDevices.Length; i++)
{
    try
    {
        if (!wasapiDevices[i].IsEnabled)
        {
            wasapiDevices[i].name = "ERROR N/A: " + wasapiDevices[i].name;
        }
        else
        {
            if (wasapiDevices[i].SupportsRecording)
            {
                // this is a recording device
            }
            else
            {
                // this is a playback device
            }
        }
    }
    catch { }
}

ivan

  • Posts: 2
Re: BASSWASAPI beta
« Reply #12 on: 29 Apr '10 - 18:38 »
Hi Ian,

some small changes on basswasapi.pas. For info see *.pas file

regards

Ivan

Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #13 on: 30 Apr '10 - 15:43 »
Thanks, the updated Delphi API is now in the package.

An updated DLL is also in the package, which adds the option of an input device's WASAPIPROC returning 0 to stop the device (like a RECORDPROC) and fixes a loopback recording bug. A WASAPI version of the BASS "RECTEST" recording example has been added too.

radio42

  • Posts: 4576
Re: BASSWASAPI beta
« Reply #14 on: 30 Apr '10 - 16:18 »
A new pre-version of BASS.NET is available here:
   www.un4seen.com/filez/4/Bass24.Net_pre.zip

It incorporates the latest BASS_DSHOW version (v2.4.0.8) as well as the latest BASSWASAPI version (v0.0.0.2).

jeffdavis

  • Posts: 297
Re: BASSWASAPI beta
« Reply #15 on: 30 Apr '10 - 17:08 »
How about converting BASStest to using BASSWASAPI?


Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #16 on: 30 Apr '10 - 18:03 »
I think the next examples to be ported will be LIVEFX and MULTI, but perhaps a BASSTEST port could come after that; it would basically be a matter of plugging multiple sources into a mixer, with the WASAPI part of it being much the same as in the CONTEST and SPEAKERS examples.

jeffdavis

  • Posts: 297
Re: BASSWASAPI beta
« Reply #17 on: 30 Apr '10 - 18:34 »
I was just thinking that for those of us that use BASS to just play audio files as a player an example of the best way to use BASSWASAPI for Vista / Windows 7  OS.    A simple example of a media player that detects if BASSWASAPI can be used otherwise uses standard BASS.   And of course I'd like to see the demos in VB6 but thats just me.


 

Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #18 on: 3 May '10 - 15:35 »
Yes, an example for using WASAPI output when available, and BASS/DirectSound when not, could indeed be useful. I'll look into adding one.

Mike Wittman

  • Posts: 20
Re: BASSWASAPI beta
« Reply #19 on: 5 May '10 - 05:06 »
Ian (or other informed sources);

I'm trying to use the WASAPI "Exclusive" mode to achieve a "bit-perfect" rendering of "lossless" audio.  I don't have a problem with the sample data being converted (up to 24 "bits per sample") into 32 bit FP data.  But I want to be sure that the soundcard is rendering at that original bps or better (ex., 96kHz, 2 Channel @ 24 bits per sample). 

In your BASS_WASAPI_GetInfo method; the "format" field will return the devices "bits per sample" (bps); which is useful when inspecting the "mixer" format.  However it does not seem possible to "set" this field in the BASS_WASAPI_Init for Exclusive mode.  I would also have expected to see this in the BASS_WASAPI_CheckFormat method.

When using the IAudioClient interface directly; I can test and inititalize this using "IsFormatSupported" and "Initialize" with the correct WaveFormatEx structure.

Using your implementation; how do I ensure that a valid "bits per sample" is correctly selected in the soundcard/device?

PS:  Nice job on the WASAPI package.  If I had to write this framework myself .. I'd have to quit my "day job"!

ken

  • Posts: 739
Re: BASSWASAPI beta
« Reply #20 on: 5 May '10 - 09:20 »
Just get "real" audio-devices was a tricky thing. Here I do it in C# with Bass.NET filling two comboboxes (cmbDevOut and cmbDevIn).  It can proberly made in outher ways, but this works for me...

Code: [Select]

        private void GetDevices()
        {
           

            BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();

            for (int i = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(i, info); i++)
            {
                AudioDevice _AudioDevice = new AudioDevice();
                _AudioDevice.DeviceName = info.name;


                if (!info.IsInput)
                {
                    if (info.IsEnabled)
                    {
                        _AudioDevice.DeviceID = i;
                        cmbDevOut.Items.Add(_AudioDevice);
                    }
                }

                if (info.SupportsRecording)
                {
                    if (info.IsEnabled && info.IsLoopback == false)
                    {
                        _AudioDevice.DeviceID = i;
                        cmbDevIn.Items.Add(_AudioDevice);
                    }
                }
               
            }
        }


//my class for device infos
public class AudioDevice
    {
        public AudioDevice()
        { }

        public int DeviceID { get; set; }
        public string DeviceName { get; set; }

    }



And get Device id for BASSWasapi

Code: [Select]

AudioDevice _AudioDevice = (AudioDevice)cmbDevOut.SelectedItem;

_wasapi = new BassWasapiHandler(_AudioDevice.DeviceID, false, 48000, 2, 0, 0);


Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #21 on: 5 May '10 - 15:32 »
I'm trying to use the WASAPI "Exclusive" mode to achieve a "bit-perfect" rendering of "lossless" audio.  I don't have a problem with the sample data being converted (up to 24 "bits per sample") into 32 bit FP data.  But I want to be sure that the soundcard is rendering at that original bps or better (ex., 96kHz, 2 Channel @ 24 bits per sample). 

In your BASS_WASAPI_GetInfo method; the "format" field will return the devices "bits per sample" (bps); which is useful when inspecting the "mixer" format.  However it does not seem possible to "set" this field in the BASS_WASAPI_Init for Exclusive mode.  I would also have expected to see this in the BASS_WASAPI_CheckFormat method.

When using the IAudioClient interface directly; I can test and inititalize this using "IsFormatSupported" and "Initialize" with the correct WaveFormatEx structure.

Using your implementation; how do I ensure that a valid "bits per sample" is correctly selected in the soundcard/device?

To simplify matters, BASSWASAPI_Init always initializes the device to use the highest supported resolution, which is then available via the BASS_WASAPI_INFO "format" member. Note that is the format currently in use, not necesarily the "mix" format (which is always floating-point).

Just get "real" audio-devices was a tricky thing. Here I do it in C# with Bass.NET filling two comboboxes (cmbDevOut and cmbDevIn).  It can proberly made in outher ways, but this works for me...

Code: [Select]
...

That looks fine. The key thing is to store the device number (as you have done), ie. don't just use a list index to determine which device to initialize. The same applies to BASS device selectors.

Mike Wittman

  • Posts: 20
Re: BASSWASAPI beta
« Reply #22 on: 10 May '10 - 01:05 »
Good Evening Ian; (2 questions)

I am looking for an easy way to get the current soundcard default "output format" (as in the Windows Control Panel)

It seems that when initializing WASAPI as "BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_EXCLUSIVE, 0.4 , 0.05, WasapiProc, NULL)" I receive this information correctly. (NOTE: Uses mix format, but Exclusive Flag)

Is this a reliable method to achieve this goal?

Secondly, using the same technique but, substituting the mix format (0, 0) with a requested format (ex., 96000, 2); if the function returns true then; is this "output format" actually supported by the soundcard.

I am using these techniques now and they seem to work, but I wanted to verify this with you.

Thank-you;
Mike Wittman

Mike Wittman

  • Posts: 20
Re: BASSWASAPI beta
« Reply #23 on: 10 May '10 - 05:20 »
Good Morning Ian;

With a little more testing this technique for discovering the "bit resolution" (see previous post) works fine until the frequency is NOT supported.  In which case; the error number returned is -1 (BASS_ERROR_UNKNOWN).  I believe it should be BASS_ERROR_FORMAT.

PS: This is in a tight  loop to "discover" some common rates like 44.1, 48 & 96 KHz

Your thoughts on all this ?

Regards .. Mike Wittman

Ian @ un4seen

  • Administrator
  • Posts: 20436
Re: BASSWASAPI beta
« Reply #24 on: 10 May '10 - 14:37 »
I am looking for an easy way to get the current soundcard default "output format" (as in the Windows Control Panel)

It seems that when initializing WASAPI as "BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_EXCLUSIVE, 0.4 , 0.05, WasapiProc, NULL)" I receive this information correctly. (NOTE: Uses mix format, but Exclusive Flag)

Is this a reliable method to achieve this goal?

That information is actually available without having to initialize the device, from BASS_GetDeviceInfo (see the "mixfreq" and "mixchans"). Perhaps you are using BASS_WASAPI_Init in order to get the shared mode output resolution too? That probably won't be reliable, as the user might not have chosen the highest available resolution, while BASS_WASAPI_Init will.

Secondly, using the same technique but, substituting the mix format (0, 0) with a requested format (ex., 96000, 2); if the function returns true then; is this "output format" actually supported by the soundcard.

Yes, so long as you don't use the BASS_WASAPI_AUTOFORMAT flag, a successful BASS_WASAPI_Init call means that the requested format is supported. You could also use BASS_WASAPI_CheckFormat for that purpose, which should be quicker, but that won't tell you the resolution (if you want to know that too).

With a little more testing this technique for discovering the "bit resolution" (see previous post) works fine until the frequency is NOT supported.  In which case; the error number returned is -1 (BASS_ERROR_UNKNOWN).  I believe it should be BASS_ERROR_FORMAT.

That does sound like it should result in BASS_ERROR_FORMAT, but I guess WASAPI is reporting something other than a format problem; I'll send you a debug version to find out what exactly.