Author Topic: BASSWASAPI beta  (Read 141591 times)

yosato

  • Posts: 6
Re: BASSWASAPI beta
« Reply #125 on: 16 Jun '11 - 02:26 »
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);

I tried to record satellite radio using WASAPI. But I cannot do it.
For example, when running quoted code, no device was listed up in the combobox.
I have three audio devices. Each devices is suitable for WASAPI when using other library(eg.NAudio)
Tell me, what is wrong, what can I do?

Ian @ un4seen

  • Administrator
  • Posts: 19371
Re: BASSWASAPI beta
« Reply #126 on: 17 Jun '11 - 15:04 »
If you run the pre-compiled LIST.EXE example (in the C\BIN directory of the BASSWASAPI package), what do you see? Please also confirm what Windows version you are using.

yosato

  • Posts: 6
Re: BASSWASAPI beta
« Reply #127 on: 17 Jun '11 - 21:17 »
If you run the pre-compiled LIST.EXE example (in the C\BIN directory of the BASSWASAPI package), what do you see? Please also confirm what Windows version you are using.
There is the result of LIST.EXE. I am sorry device names are written in Japanese.
There are many input devices.
Code: [Select]
....
dev 14: デジタル オーディオ インターフェイス (SB X-Fi Surround 5.1 Pro)
id: {0.0.0.00000000}.{32abd17d-c504-4f05-b715-44f82497d5cd}
flags: enabled (1)
dev 15: デジタル オーディオ インターフェイス (SB X-Fi Surround 5.1 Pro)
id: {0.0.0.00000000}.{32abd17d-c504-4f05-b715-44f82497d5cd}
flags: loopback input enabled (25)
dev 17: スピーカー (SB X-Fi Surround 5.1 Pro)
id: {0.0.0.00000000}.{335f67b5-7d5b-48d4-8f1e-cab5f63d15ae}
flags: loopback input enabled (25)
dev 19: スピーカー (UA-1EX)
id: {0.0.0.00000000}.{35017af5-6db7-4595-add0-dd85695bb803}
flags: loopback input (24)
dev 21: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.0.00000000}.{3940bfd2-fb94-4aed-81d3-6691f2999fe6}
flags: loopback input (24)
dev 23: ヘッドホン (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{40ef57ad-3ba0-4215-9ef6-920d14fd7b05}
flags: loopback input (24)
dev 24: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.0.00000000}.{459dc6c9-87f4-4da0-bfa0-fbf7169e7005}
flags: (0)
dev 25: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.0.00000000}.{459dc6c9-87f4-4da0-bfa0-fbf7169e7005}
flags: loopback input (24)
dev 27: OUT (2- UA-1EX)
id: {0.0.0.00000000}.{4ab2b412-6ca7-44a3-a819-5f5ef8f95c21}
flags: loopback input (24)
dev 29: OUT (3- UA-1EX)
id: {0.0.0.00000000}.{4d8babf2-2d81-4736-858d-4b73db8e5c00}
flags: loopback input (24)
dev 30: 内蔵 AUX ジャック (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{4fff95b6-5972-4331-9dd3-ec33f75d52f4}
flags: (0)
dev 31: 内蔵 AUX ジャック (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{4fff95b6-5972-4331-9dd3-ec33f75d52f4}
flags: loopback input (24)
dev 33: OUT (5- UA-1EX)
id: {0.0.0.00000000}.{5bd6a192-5b7e-4b73-8227-d94ee7a05385}
flags: loopback input (24)
dev 35: ATI HDMI Output (3- ATI High Definition Audio Device)
id: {0.0.0.00000000}.{61859fce-d279-4382-aa1d-98027e82c0b2}
flags: loopback input (24)
dev 36: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.0.00000000}.{622c06f0-cc9b-46ac-a91e-fac91d19e7df}
flags: (0)
dev 37: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.0.00000000}.{622c06f0-cc9b-46ac-a91e-fac91d19e7df}
flags: loopback input (24)
dev 39: 内蔵 AUX ジャック (3- UA-1EX)
id: {0.0.0.00000000}.{6273a6db-43c5-420d-8f4a-bdd34f65431e}
flags: loopback input (24)
dev 41: スピーカー (USB オーディオ デバイス)
id: {0.0.0.00000000}.{6dd2f10a-db89-40f0-8667-05a8f81603ff}
flags: loopback input (24)
dev 43: OUT (3- UA-1EX)
id: {0.0.0.00000000}.{768118d7-040d-4e30-ad7d-4fc1ec17e617}
flags: loopback input (24)
dev 44: デジタル オーディオ (S/PDIF) (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{875add29-5b8b-4b00-bc71-bd643ef9d3d6}
flags: enabled (1)
dev 45: デジタル オーディオ (S/PDIF) (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{875add29-5b8b-4b00-bc71-bd643ef9d3d6}
flags: loopback input enabled (25)
dev 46: OUT (4- UA-1EX)
id: {0.0.0.00000000}.{8ab45b5f-d0e6-44da-8821-9c5e0164482c}
flags: (0)
dev 47: OUT (4- UA-1EX)
id: {0.0.0.00000000}.{8ab45b5f-d0e6-44da-8821-9c5e0164482c}
flags: loopback input (24)
dev 48: OUT (5- UA-1EX)
id: {0.0.0.00000000}.{923669ef-a9e3-4591-ad54-9752c2bcd227}
flags: enabled (1)
dev 49: OUT (5- UA-1EX)
id: {0.0.0.00000000}.{923669ef-a9e3-4591-ad54-9752c2bcd227}
flags: loopback input enabled (25)
dev 50: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.0.00000000}.{94b664af-387c-46cb-80ee-3ea4eef8febc}
flags: (0)
dev 51: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.0.00000000}.{94b664af-387c-46cb-80ee-3ea4eef8febc}
flags: loopback input (24)
dev 53: OUT (4- UA-1EX)
id: {0.0.0.00000000}.{97f84ed2-6507-4963-8c44-0b89bbb5c3fc}
flags: loopback input (24)
dev 55: スピーカー (C-Media USB Audio Device   )
id: {0.0.0.00000000}.{9da11567-ad5f-44c1-90bb-9dfd50c4b10a}
flags: loopback input (24)
dev 56: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.0.00000000}.{9fed840d-c0f9-4698-b172-b2c7f1e93507}
flags: (0)
dev 57: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.0.00000000}.{9fed840d-c0f9-4698-b172-b2c7f1e93507}
flags: loopback input (24)
dev 59: 内蔵 AUX ジャック (3- UA-1EX)
id: {0.0.0.00000000}.{a26bc227-1ba3-4c81-9fc5-43850ecc083e}
flags: loopback input (24)
dev 61: OUT (3- UA-1EX)
id: {0.0.0.00000000}.{b5b5609f-72c8-4228-b9d9-6e7772b6ba4a}
flags: loopback input (24)
dev 62: OUT (2- UA-1EX)
id: {0.0.0.00000000}.{c0d7ac0c-bf8f-4c9c-932c-c9f97f283567}
flags: (0)
dev 63: OUT (2- UA-1EX)
id: {0.0.0.00000000}.{c0d7ac0c-bf8f-4c9c-932c-c9f97f283567}
flags: loopback input (24)
dev 64: OUT (4- UA-1EX)
id: {0.0.0.00000000}.{c1a1d634-a859-44d4-a0a7-68857c6fb14a}
flags: (0)
dev 65: OUT (4- UA-1EX)
id: {0.0.0.00000000}.{c1a1d634-a859-44d4-a0a7-68857c6fb14a}
flags: loopback input (24)
dev 67: スピーカー (USB Headphone Set)
id: {0.0.0.00000000}.{c506d436-694c-466a-bb86-a69f186d0382}
flags: loopback input (24)
dev 69: ATI HDMI Output (ATI High Definition Audio Device)
id: {0.0.0.00000000}.{c682bce0-c3b0-413a-ab89-a8697a95541b}
flags: loopback input (24)
dev 70: ATI HDMI Output (2- ATI High Definition Audio Device)
id: {0.0.0.00000000}.{ca16185a-1a6d-4ac6-8dfb-9ba5147a2e8c}
flags: (0)
dev 71: ATI HDMI Output (2- ATI High Definition Audio Device)
id: {0.0.0.00000000}.{ca16185a-1a6d-4ac6-8dfb-9ba5147a2e8c}
flags: loopback input (24)
dev 73: 内蔵 AUX ジャック (2- High Definition Audio デバイス)
id: {0.0.0.00000000}.{cc95be97-b340-4565-ada7-6ccec05f10ab}
flags: loopback input (24)
dev 74: デジタル オーディオ (S/PDIF) (Sound Blaster X-Fi Xtreme Audio)
id: {0.0.0.00000000}.{cd5e6449-d5cf-4032-8b8d-81037dae02ad}
flags: enabled default (3)
dev 75: デジタル オーディオ (S/PDIF) (Sound Blaster X-Fi Xtreme Audio)
id: {0.0.0.00000000}.{cd5e6449-d5cf-4032-8b8d-81037dae02ad}
flags: loopback input enabled (25)
dev 77: OUT (5- UA-1EX)
id: {0.0.0.00000000}.{d0545ef2-eb1d-4ca6-9cdc-71a7808272fd}
flags: loopback input (24)
dev 79: OUT (2- UA-1EX)
id: {0.0.0.00000000}.{d815600c-6b5c-4542-b538-105f0ea1696c}
flags: loopback input (24)
dev 81: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.0.00000000}.{dda739a1-7f38-438f-9f84-5a71fc46c4f5}
flags: loopback input (24)
dev 83: OUT (3- UA-1EX)
id: {0.0.0.00000000}.{e0b7a7e9-cb33-4e60-bfe6-1c952d4863cf}
flags: loopback input (24)
dev 85: OUT (5- UA-1EX)
id: {0.0.0.00000000}.{e25edf48-5014-4143-bd7f-6b4c56646ed8}
flags: loopback input (24)
dev 87: OUT (2- UA-1EX)
id: {0.0.0.00000000}.{e2ad067f-e2d7-488d-8f60-96d740a9731e}
flags: loopback input (24)
dev 89: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.0.00000000}.{e35b1235-4136-46f2-a570-785eecf855cf}
flags: loopback input (24)
dev 90: アナログ コネクタ (UA-1EX)
id: {0.0.1.00000000}.{05e8aa0d-36fa-4528-84ba-62113f170bae}
flags: input (16)
dev 91: ライン (SB X-Fi Surround 5.1 Pro)
id: {0.0.1.00000000}.{0773d814-73b5-4b98-8c79-d633118424f1}
flags: input enabled (17)
dev 92: IN (4- UA-1EX)
id: {0.0.1.00000000}.{11420e9b-4c54-42e6-be2f-2e1956e71118}
flags: input (16)
dev 93: マイク (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{1409b49a-783a-4f99-941a-885599b4dc5e}
flags: input (16)
dev 94: IN (3- UA-1EX)
id: {0.0.1.00000000}.{188d70b6-27b6-4c16-a01c-bc3a2142c688}
flags: input (16)
dev 95: デジタル オーディオ (S/PDIF) (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{193b528c-7b14-498d-82e2-c666672e03e4}
flags: input enabled default (19)
dev 96: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.1.00000000}.{195b3661-8c63-40d0-b188-e5b7a2c86eac}
flags: input (16)
dev 97: IN (2- UA-1EX)
id: {0.0.1.00000000}.{1a9d1ff4-4e14-4eba-b648-087ace4901f6}
flags: input (16)
dev 98: IN (3- UA-1EX)
id: {0.0.1.00000000}.{1e55930c-0855-430c-b487-149f09cf9fec}
flags: input (16)
dev 99: 内蔵 AUX ジャック (3- UA-1EX)
id: {0.0.1.00000000}.{25aa9218-0f75-4770-bef1-9ff85ae08e3d}
flags: input (16)
dev 100: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.1.00000000}.{274fd99f-b273-441d-be8e-8030c541df53}
flags: input (16)
dev 101: IN (3- UA-1EX)
id: {0.0.1.00000000}.{31b39665-a455-4b97-9741-4fc2d352d70b}
flags: input (16)
dev 102: デジタル オーディオ (S/PDIF) (Sound Blaster X-Fi Xtreme Audio)
id: {0.0.1.00000000}.{373eb2a1-331c-4b2c-9f2c-92da863c7bb2}
flags: input enabled (17)
dev 103: IN (4- UA-1EX)
id: {0.0.1.00000000}.{4b81cbab-6471-485e-92a7-bb657db920bb}
flags: input (16)
dev 104: IN (4- UA-1EX)
id: {0.0.1.00000000}.{4c451f29-2a18-4804-86fa-935ea15318cf}
flags: input (16)
dev 105: 内蔵 AUX ジャック (3- UA-1EX)
id: {0.0.1.00000000}.{4f54b14d-309f-44f3-899a-89d954dc4c6b}
flags: input (16)
dev 106: IN (5- UA-1EX)
id: {0.0.1.00000000}.{526db7c5-655c-420e-8bcf-b2a9c47c0223}
flags: input enabled (17)
dev 107: IN (5- UA-1EX)
id: {0.0.1.00000000}.{5791307c-90c9-49a1-ad62-560aa3b54cf9}
flags: input (16)
dev 108: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.1.00000000}.{57ae5d47-b5f3-49c7-bc95-3e383b6f6c44}
flags: input (16)
dev 109: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.1.00000000}.{57afd9d9-8724-4eeb-9839-aa926e0d94f2}
flags: input (16)
dev 110: IN (2- UA-1EX)
id: {0.0.1.00000000}.{5f9de996-f8f6-4707-8d5c-b7a21a1aa367}
flags: input (16)
dev 111: IN (2- UA-1EX)
id: {0.0.1.00000000}.{609a8c66-2eb8-4c7a-830e-f34f2c6129c7}
flags: input (16)
dev 112: ライン入力 (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{69d17e4f-fd76-4807-ad3d-fd3b4ecf9f72}
flags: input (16)
dev 113: マイク (USB Headphone Set)
id: {0.0.1.00000000}.{6dc88f1b-9bf8-4936-84d0-f0673a5eaa0c}
flags: input (16)
dev 114: マイク FP (Sound Blaster X-Fi Xtreme Audio)
id: {0.0.1.00000000}.{6e6d024b-06ad-4f57-8dcf-b39e0a43e39a}
flags: input (16)
dev 115: マイク (USB オーディオ デバイス)
id: {0.0.1.00000000}.{7067d729-1bad-45c9-b3db-51ec3e82c962}
flags: input (16)
dev 116: 内蔵 AUX ジャック (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{73a88ce3-5547-496a-85bc-ce0813a77537}
flags: input (16)
dev 117: マイク (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{7d512e59-08ad-43bf-8adf-3c0d157fd4a6}
flags: input (16)
dev 118: IN (3- UA-1EX)
id: {0.0.1.00000000}.{842bc4a1-1a35-4b4f-84b5-59177b9e12e5}
flags: input (16)
dev 119: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.1.00000000}.{84c93af5-b986-482e-8ded-2c187447fa9d}
flags: input (16)
dev 120: 内蔵 AUX ジャック (2- High Definition Audio デバイス)
id: {0.0.1.00000000}.{8624cff9-1776-48a5-ba41-1536a204f186}
flags: input (16)
dev 121: マイク (C-Media USB Audio Device   )
id: {0.0.1.00000000}.{8e1fe9cd-38e0-455a-bff6-9b32828b3763}
flags: input (16)
dev 122: ライン イン (Sound Blaster X-Fi Xtreme Audio)
id: {0.0.1.00000000}.{8f3de40e-add1-4a1b-9ed4-8713b8247fc7}
flags: input enabled (17)
dev 123: マイク (SB Play!)
id: {0.0.1.00000000}.{9e9fcf91-8dcd-41df-87ff-8a094e77f482}
flags: input (16)
dev 124: IN (2- UA-1EX)
id: {0.0.1.00000000}.{a2bec556-0ef5-46f3-a823-d592da2fa022}
flags: input (16)
dev 125: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.1.00000000}.{a4e88049-600e-4c08-b573-ebfa1a355be8}
flags: input (16)
dev 126: 内蔵 AUX ジャック (5- UA-1EX)
id: {0.0.1.00000000}.{a7c57420-8056-4f2c-8c92-cf4fc9c3acba}
flags: input (16)
dev 127: IN (5- UA-1EX)
id: {0.0.1.00000000}.{a9d526fc-50a9-44b3-a204-b650667a85f8}
flags: input (16)
dev 128: 内蔵 AUX ジャック (2- UA-1EX)
id: {0.0.1.00000000}.{b681339f-9d1e-43b7-950f-50cf7f983102}
flags: input (16)
dev 129: IN (4- UA-1EX)
id: {0.0.1.00000000}.{d1f64a95-9d47-4de9-a346-fe690e315b3e}
flags: input (16)
dev 130: 内蔵 AUX ジャック (3- UA-1EX)
id: {0.0.1.00000000}.{d6ae85c1-d351-4400-9d84-66eb9bda1a25}
flags: input (16)
dev 131: IN (5- UA-1EX)
id: {0.0.1.00000000}.{f6baf843-980f-4b51-81a6-f45dfa58dcac}
flags: input (16)
dev 132: 内蔵 AUX ジャック (4- UA-1EX)
id: {0.0.1.00000000}.{fb2d2b1c-f1de-42ed-84ed-141b4e641873}
flags: input (16)


I am using Windows 7 Home Premium 64bit.

yosato

  • Posts: 6
Re: BASSWASAPI beta
« Reply #128 on: 18 Jun '11 - 03:23 »
Thank you very much, Ian. I was confused that index of BASS_RecordInt and index of wasapi device are the same. Everything seems to go well now.

Jinja

  • Posts: 34
Re: BASSWASAPI beta
« Reply #129 on: 3 Jul '11 - 21:02 »
Hi all,

So I (or should I say my colleague) got WASAPI playback working in our audio playback software, and I took it to a friendly contact who tested the before and after on about 50,000 pounds of high-fi heaven.  Results were a definite improvement over directSound, a real sense of space and clarity that didn't exist before.  I have never heard our software sound so good!

But results suggest that I may not be doing something right, or my understanding of expected behaviour is wrong. 

The DAC was always reporting whatever 'Default Format' I had specified under the Advanced Tab of the Toslink output I was using, no matter whether the tracks I was playing was 16/44 or 24/96. (I'm using the std. Realtek Optical MB-output on an average i3 Motherboard.)

WASAPI should be bypassing the Windows mixer and thus output the bit-format of whatever source is being played, with no specific code-changes to support that.
Assuming that's correct, are there any instant areas which come to mind where we might have gone wrong?

Many thanks!


Ian @ un4seen

  • Administrator
  • Posts: 19371
Re: BASSWASAPI beta
« Reply #130 on: 4 Jul '11 - 15:04 »
Are you using the BASS_WASAPI_EXCLUSIVE flag in your BASS_WASAPI_Init call to enable exclusive mode? Without that flag, shared mode (Windows-mixed) will be used, which always uses the sample format set in the Sound control panel. It could also just be that the device only supports a single output format. For comparison, you could try playing the files with the pre-compiled CONTEST.EXE example (in the C\BIN directory of the BASSWASAPI package) and see what output mode/format is used (it's displayed).

WACKA

  • Posts: 14
Re: BASSWASAPI beta
« Reply #131 on: 4 Jul '11 - 15:39 »
Hi Ian,

Would it be possible to get a hold of the BassWasapiHandler helper class code?

The handler class is working great at present but I need to pass a BASS_WASAPI_AUTOFORMAT in the Init/BASS_WASAPI_Init  function. I also need to place a handler around the proc function as I get an intermittent Access violation exception coming from inside the handler code.

Many thanks,

Conor

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #132 on: 4 Jul '11 - 16:50 »
The BassWasapiHandler isn't actually part of BASS - it's a little helper/wrapper class to make Wasapi more easy to use for Bass.Net users.
The source is unfortunately not available and I think (as I am using it heavily myself) its pretty stable.

The BassWasapiHandler.Init() method doesn't currently support/use the AUTOFORMAT flag, as this might also be determined prior by calling BASS_WASAPI_CheckFormat.

Note, that the BassWasapiHandler needs/uses the BASSmix add-on - so make sure it exists/is accessible from your application.
Else I couldn't think of any other AccessViolation happening.

WACKA

  • Posts: 14
Re: BASSWASAPI beta
« Reply #133 on: 4 Jul '11 - 17:37 »
Hi Radio42,

Many thanks for the reply. I will explain my problem further:

I am looking to play tracks of differing quality using WASAPI (exclusive mode):

BassWasapi.BASS_WASAPI_Init(index, 96000, 0, BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE, 0.4F, 0.0F, _wasapiProc, IntPtr.Zero)

At the minute I can use BASS_WASAPI_Init to init to a frequency of 96kh, so far, so good, the 96kh tracks play fine. The problem is with the tracks at 44kh, they are still coming out on my DAC at 96kh.

The question is how do I set basswasapi to correctly output at the correct frequency for the lower quality tracks?

Many thanks,

Conor

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #134 on: 5 Jul '11 - 11:31 »
I am affraid this is not possible (no limit inside BASS or Bass.Net - this is the way how WASAPI works).

Once you successfully initialized a WASAPI device with a certain samplerate (e.g. 96kHz) any audio data must be submitted in that samplerate to the device/driver.
That means you can not (within a sesison) switch between different samplerates.
That is also the reason, why a BASSmix mixer stream is used inside the BassWasapiHandler class - as it makes sure to automatically resample any source streams as need to the defined 'target/output' samplerate.

If you want to 'playback' different sources with their original samplerate - you would need to always free BASSWASAPI and reinitialize it with a new samplerate - but I guess this something you don't want to do for each stream you intend to play?!

WACKA

  • Posts: 14
Re: BASSWASAPI beta
« Reply #135 on: 5 Jul '11 - 12:14 »
Many thanks again Radio42,

Just to clarify:
If I have 2 tracks, one @48kh and one @192kh then to play each, one after another at their source sample rate I will need to:
1. Detect the source sample rate for the file
2. Re initialize the wasapi channel with this sample rate.


If the above is the case, then could you point me in the right direction for getting the source sample rate of the file?

Also, I have tested software such as JRiver on my DAC and it seems to change samplerate depending on the track, do you reckon they are doing something similar i.e. reinitializing their wasapi output for each track?

Regards,

Conor

Ian @ un4seen

  • Administrator
  • Posts: 19371
Re: BASSWASAPI beta
« Reply #136 on: 7 Jul '11 - 17:59 »
Just to clarify:
If I have 2 tracks, one @48kh and one @192kh then to play each, one after another at their source sample rate I will need to:
1. Detect the source sample rate for the file
2. Re initialize the wasapi channel with this sample rate.


If the above is the case, then could you point me in the right direction for getting the source sample rate of the file?

That is correct. The default sample rate of a BASS channel/stream can be obtained from BASS_ChannelGetInfo (see the "freq" information).

Meanwhile... a BASSWASAPI update is up (in the 1st post) to fix 24-bit exclusive mode output with the Realtek HD driver.

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #137 on: 7 Jul '11 - 19:58 »
I guess JRiver might not be using WASAPI but a different output model, e.g. KernelStreaming or even WDM?
Just like the old Windows Media Player would do, they change the drivers sample rate for each track played. That's also the reason, why you can not mix two tracks overlapped.

Rescator

  • Guest
Re: BASSWASAPI beta
« Reply #138 on: 20 Jul '11 - 02:44 »
Wading through MSDN I tripped over this: http://msdn.microsoft.com/en-us/library/ff819070%28v=VS.85%29.aspx
The real interesting thing is that I spy the mention of a default re-sampling quality of 30, this means I assume the possibility of using the Windows re-sampler at higher quality levels.
"The valid range of this property is 1 to 60, inclusive. Higher values produce higher-quality output, but introduce more latency. A value of 1 is essentially the same as linear interpolation."

There is also a fascinating Voice Capture DSP that lets you use fun things like AGC, echo cancellation, microphone arrays, etc.
http://msdn.microsoft.com/en-us/library/ff819492%28v=VS.85%29.aspx

BaseHead

  • Posts: 125
Re: BASSWASAPI beta
« Reply #139 on: 27 Jul '11 - 03:06 »
Hey WASAPI.NET experts!
I popped Ken's exact code below in, but all the names in the combo boxes are
BaseHead.MainWindow + AudioDevice
BaseHead.MainWindow + AudioDevice
BaseHead.MainWindow + AudioDevice

instead of the proper names but it does work properly
If I change the combo add line to
cmbDevOut.Items.Add(_AudioDevice.DeviceName);
it displays correctly  in the combos, but crashes
I'm using this exact code in my test app with then same results..

Anyone know what I could be missing to cause the combo boxes to fill like that?, cuz I'm assuming that it's NOT the desired result.....hehehehe

thx!

Steve


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);







radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #140 on: 27 Jul '11 - 08:39 »
When you popuplate a combobox the items are objects!
The combobox uses the 'ToString' overload of the item's class to display it's value.
So simply implement the overload for the 'ToString' method for your 'AudioDevice' class:
Code: [Select]
public class AudioDevice
{
    public AudioDevice()
    { }

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

    public override string ToString()
    {
        return DeviceName;
    }
}


The crash you experience when using cmbDevOut.Items.Add(_AudioDevice.DeviceName); instead of cmbDevOut.Items.Add(_AudioDevice); is probably due to the fact, that when you access the cmbDevOut.SelectedItem you cast this back to (AudioDevice).
But when adding a string to the combobox item's you can not cast them back to an AudioDevice ;-)

BaseHead

  • Posts: 125
Re: BASSWASAPI beta
« Reply #141 on: 27 Jul '11 - 08:56 »
Whoo!
You rock!!     ;D
I was just scratching my head cuz I thought for sure everyone would want real names filled in the combo boxes and I didn't see mention of it so I figure it was something wrong on my end till I popped it in a test app with the same results.

all good now!
thx!

Steve


morcibacsi

  • Posts: 11
Re: BASSWASAPI beta
« Reply #142 on: 28 Jul '11 - 21:02 »
Hi!

I'm trying to record from stereo mix and from mic using BassMix to an mp3 file with C#, but I could not get it to work. Tried to set things up using a BassWasapiHandler, and without it too, but due to the "new nature" of this stuff, I couldn't came up with nothing :( There aren't as many examples as with regular BASS stuff :( Could anybody give me a kickstart with the BassWasapiHandler and the encoder part please? :$

What I have so far:
Code: [Select]
...
        private EncoderLAME encoder;
        private int stereo_mixer;
        private int microphone;
        private int mixer;
        private BassWasapiHandler stereoHandler;
        private BassWasapiHandler micHandler;
...
        private void btStartWASAPI_Click(object sender, EventArgs e)
        {
            Bass.BASS_Init(-1, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            stereoHandler = new BassWasapiHandler(int.Parse(textBox1.Text), false, 48000, 2, 0, 0);
            log(string.Format("smINIT: {0}", stereoHandler.Init()));
            stereoHandler.DeviceVolume = 1;
            stereoHandler.Volume = 1;
            int stereo_mixer = stereoHandler.InputChannel;
            log(string.Format("stereo mixer: {0} ({1})", stereo_mixer, Bass.BASS_ErrorGetCode()));
            // double check, that the device is not muted externally
            if (stereoHandler.DeviceMute)
                stereoHandler.DeviceMute = false;
            log(string.Format("smSTART: {0}", stereoHandler.Start()));
            log(string.Format("stereo mixer: {0} ({1})", stereo_mixer, Bass.BASS_ErrorGetCode()));


            micHandler = new BassWasapiHandler(int.Parse(textBox2.Text), false, 48000, 2, 0, 0);
            log(string.Format("micInit: {0}", micHandler.Init()));
            micHandler.DeviceVolume = 1;
            micHandler.Volume = 1;
            int microphone = micHandler.InputChannel;
            log(string.Format("microphone: {0} ({1})", microphone, Bass.BASS_ErrorGetCode()));
            // double check, that the device is not muted externally
            if (micHandler.DeviceMute)
                micHandler.DeviceMute = false;
            log(string.Format("micSTART: {0}", micHandler.Start()));
            log(string.Format("microphone: {0} ({1})", microphone, Bass.BASS_ErrorGetCode()));

            mixer = BassMix.BASS_Mixer_StreamCreate(48000, 2, BASSFlag.BASS_SAMPLE_FLOAT);
            log(string.Format("Mixer: {0} ({1})", mixer, Bass.BASS_ErrorGetCode()));

            bool res = BassMix.BASS_Mixer_StreamAddChannel(mixer, stereo_mixer, BASSFlag.BASS_MIXER_END);//  BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_FILTER);
            log(string.Format("Channel1: {0} ({1})", res, Bass.BASS_ErrorGetCode()));


            res = BassMix.BASS_Mixer_StreamAddChannel(mixer, microphone, BASSFlag.BASS_MIXER_END);// BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_FILTER);
            log(string.Format("Channel2: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            // mute the mixer, so that you don't hear it in the output to avoid echos!
            res = Bass.BASS_ChannelSetAttribute(mixer, BASSAttribute.BASS_ATTRIB_VOL, 0f);
            log(string.Format("ChannelSet: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            encoder = new EncoderLAME(mixer);
            encoder.InputFile = null;
            encoder.OutputFile = "out.mp3";
            encoder.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
            encoder.LAME_Mode = EncoderLAME.LAMEMode.Default;
            encoder.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100;
            encoder.LAME_Quality = EncoderLAME.LAMEQuality.Quality;

            res = encoder.Start(null, IntPtr.Zero, false); //new version
            log(string.Format("encodeStart: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            // start the mixer
            Bass.BASS_ChannelPlay(mixer, false);
            log(string.Format("ChannelPlay: {0} ({1})", res, Bass.BASS_ErrorGetCode()));
        }

        private void btStopWASAPI_Click(object sender, EventArgs e)
        {
            encoder.Stop();
            Bass.BASS_ChannelStop(mixer);
            stereoHandler.Stop();
            micHandler.Stop();

« Last Edit: 28 Jul '11 - 22:23 by morcibacsi »

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #143 on: 29 Jul '11 - 18:52 »
The problem are your "BassMix.BASS_Mixer_StreamAddChannel" calls.
You are trying to add the "BassWasapiHandler.InputChannel" to a mixer.
However, the "BassWasapiHandler.InputChannel" is a Dummy decoding stream which can not be added to a mixer itself.
You can only use them to apply DSP/FX or encoders on it - but they can not be used in sub-sequent mixers!

What you can do is to set the 'full-duplex' option (see the "SetFullDuplex" method).
You might use the 0 (no-sound) bass device together with the BASS_STREAM_DECODE flag when calling the "SetFullDuplex" method in order to create a custom decoding "OutputChannel" which might then be used as a source for a mixer channel!
See the docs for details.

morcibacsi

  • Posts: 11
Re: BASSWASAPI beta
« Reply #144 on: 30 Jul '11 - 21:09 »
Thanks for the fast reply. Tried what you suggested, and inserted the SetFullDuplex method, after the init calls, and now using the OutputChannel for the mixer, but the SetFullDuplex calls return false, however the Bass.BASS_ErrorGetCode() says BASS_OK (and the OutpuChannel returns 0). I'm digging the help of the BassWasapiHandler, but I'm feeling I am missing something. What would it be?

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #145 on: 30 Jul '11 - 21:52 »
pls post your updated code to take a look at

morcibacsi

  • Posts: 11
Re: BASSWASAPI beta
« Reply #146 on: 30 Jul '11 - 21:59 »
Here's the updated code:

Code: [Select]
           Bass.BASS_Init(-1, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            stereoHandler = new BassWasapiHandler(int.Parse(textBox1.Text), false, 48000, 2, 0, 0);
            log(string.Format("smINIT: {0}", stereoHandler.Init()));
            log(string.Format("stereo mixer isInput: {0}", stereoHandler.IsInput));
            stereoHandler.DeviceVolume = 1;
            stereoHandler.Volume = 1;

            bool res = stereoHandler.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false);
            log(string.Format("stereo mixer fullduplex: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            int stereo_mixer = stereoHandler.OutputChannel;
            log(string.Format("stereo mixer: {0} ({1})", stereo_mixer, Bass.BASS_ErrorGetCode()));

            // double check, that the device is not muted externally
            if (stereoHandler.DeviceMute)
                stereoHandler.DeviceMute = false;

            log(string.Format("smSTART: {0}", stereoHandler.Start()));
            log(string.Format("stereo mixer: {0} ({1})", stereo_mixer, Bass.BASS_ErrorGetCode()));
//---------------------------------------------------------------------------------------------------------
            micHandler = new BassWasapiHandler(int.Parse(textBox2.Text), false, 48000, 2, 0, 0);
            log(string.Format("micInit: {0}", micHandler.Init()));
            log(string.Format("microphone isInput: {0}", micHandler.IsInput));
            micHandler.DeviceVolume = 1;
            micHandler.Volume = 1;

            res = micHandler.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false);
            log(string.Format("microphone fullduplex: {0} ({1})", res, Bass.BASS_ErrorGetCode()));


            int microphone = micHandler.OutputChannel;
            log(string.Format("microphone: {0} ({1})", microphone, Bass.BASS_ErrorGetCode()));
            
            // double check, that the device is not muted externally
            if (micHandler.DeviceMute)
                micHandler.DeviceMute = false;
            log(string.Format("micSTART: {0}", micHandler.Start()));
            log(string.Format("microphone: {0} ({1})", microphone, Bass.BASS_ErrorGetCode()));


            mixer = BassMix.BASS_Mixer_StreamCreate(48000, 2, BASSFlag.BASS_SAMPLE_FLOAT);
            log(string.Format("Mixer: {0} ({1})", mixer, Bass.BASS_ErrorGetCode()));

            res = BassMix.BASS_Mixer_StreamAddChannel(mixer, stereo_mixer, BASSFlag.BASS_MIXER_END);//  BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_FILTER);
            log(string.Format("Channel1: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            res = BassMix.BASS_Mixer_StreamAddChannel(mixer, microphone, BASSFlag.BASS_MIXER_END);// BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_FILTER);
            log(string.Format("Channel2: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            // mute the mixer, so that you don't hear it in the output to avoid echos!
            res = Bass.BASS_ChannelSetAttribute(mixer, BASSAttribute.BASS_ATTRIB_VOL, 0f);
            log(string.Format("ChannelSet: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            encoder = new EncoderLAME(mixer);
            encoder.InputFile = null;
            encoder.OutputFile = "out.mp3";
            encoder.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192;
            encoder.LAME_Mode = EncoderLAME.LAMEMode.Default;
            encoder.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100;
            encoder.LAME_Quality = EncoderLAME.LAMEQuality.Quality;

            res = encoder.Start(null, IntPtr.Zero, false); //new version
            log(string.Format("encodeStart: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

            // start the mixer
            Bass.BASS_ChannelPlay(mixer, false);
            log(string.Format("ChannelPlay: {0} ({1})", res, Bass.BASS_ErrorGetCode()));

Thanks for your time  ;)

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #147 on: 31 Jul '11 - 18:49 »
Please check, if the "BassWasapiHandler.IsInput" returns TRUE!
E.g. if "stereoHandler.IsInput" returns TRUE?

If that is not the case, you are dealing with an WASAPI output device and you can not use this with the "SetFullDuplex" function, as it is only supported for recording or loopback devices.
I.e. you had passed a 'wrong' device id to the BassWasapiHandler constructor.
Meaning the device must have the BASS_DEVICE_INPUT or the BASS_DEVICE_LOOPBACK flag set whan calling BASS_WASAPI_GetDeviceInfo.

morcibacsi

  • Posts: 11
Re: BASSWASAPI beta
« Reply #148 on: 31 Jul '11 - 21:16 »
I've checked them, both of them returns true. I'm passing device id 21 and 25 to the BassWasapiHandler's constructors. List.exe from the "basswasapi.zip\c\bin" shows these infos for the two ids:

Code: [Select]
dev 21: Speaker (Creative SB Audigy)
        id: {0.0.0.00000000}.{ce78ef44-568a-4024-aebb-250021779435}
        flags: loopback input enabled (25)
dev 25: Microphone (2 - Realtek High Definition Audio)
        id: {0.0.1.00000000}.{104927e3-ae98-4aa9-abed-813780fdaf37}
        flags: input enabled default (19)
« Last Edit: 31 Jul '11 - 21:18 by morcibacsi »

radio42

  • Posts: 4455
Re: BASSWASAPI beta
« Reply #149 on: 1 Aug '11 - 09:19 »
Are you actually calling "BASS_WASAPI_Init" somewhere (as I couldn't see that in your code)?!
Note, that you need to call "BASS_Init" as well as "BASS_WASAPI_Init"!