Author Topic: How to record audio card output with Bass.Net ?  (Read 50 times)

iCorp

  • Posts: 68
Hello,

I try to get audio card output (all channels or only one) and stream it with ShoutCast.
I found a way to do this with BassWasapi

So first I found my loopback device and create outputStream1 channel
Code: [Select]
        var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(1);
        _wasapi = new BassWasapiHandler(1, false, 0, 0, 0f, 0f);
        _wasapi.Init();
        outputStream1 = _wasapi.InputChannel;
        _wasapi.Start();

Then I created a mixer, turn volume off and added outputStream1 to mixer.
And at this stage I got a distorted sound on my audio card output :(

Code: [Select]
        BASS_CHANNELINFO info = new BASS_CHANNELINFO();
        Bass.BASS_ChannelGetInfo(outputStream1, info);
        _mixerStream = BassMix.BASS_Mixer_StreamCreate(info.freq, info.chans,
         BASSFlag.BASS_MIXER_RESUME | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_NONSTOP);

        Bass.BASS_ChannelSetAttribute(_mixerStream, BASSAttribute.BASS_ATTRIB_VOL, 0);
        Bass.BASS_ChannelPlay(_mixerStream, true);
        BassMix.BASS_Mixer_StreamAddChannel(_mixerStream, outputStream1, BASSFlag.BASS_MIXER_DOWNMIX);

So the question is: How to get audio card output (each channel separately) and then prepare this stream for ShoutCast streaming.
Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: How to record audio card output with Bass.Net ?
« Reply #1 on: 15 Dec '17 - 13:46 »
Is it the Shoutcast stream that has the distorted sound? If so, what encoder are you using for that, and how are you setting it up? Note that LAME does not support floating-point sample data, so you should include the BASS_ENCODE_FP_24BIT flag in your BASS_Encode_Start call when using LAME on a floating-point BASS channel. Another thing to check with LAME is the "-x" option; that will be needed with older (pre-3.98) LAME versions.

iCorp

  • Posts: 68
Re: How to record audio card output with Bass.Net ?
« Reply #2 on: 15 Dec '17 - 15:56 »
Thanks for reply, Ian.

Now I try to get not distorted sound before lame encoder.
So I commented line below
//Bass.BASS_ChannelSetAttribute(_mixerStream, BASSAttribute.BASS_ATTRIB_VOL, 0);

But even without BASSFlag.BASS_SAMPLE_FLOAT in the mixer I got distorted music when added channel to mixer :(
So definitely I'm doing something wrong way :( but what?

And one more question, how to record only one channel (left fro example) from device?
Do I have to use exclusive mode?

Thank you.

iCorp

  • Posts: 68
Re: How to record audio card output with Bass.Net ?
« Reply #3 on: 15 Dec '17 - 16:11 »
with BASSFlag.BASS_SAMPLE_FLOAT, even sound that plays via this audio device becomes distorted :(
            _mixerStream = BassMix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASSFlag.BASS_MIXER_RESUME | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_NONSTOP);

but without BASSFlag.BASS_SAMPLE_FLOAT, I hear original sound and get distorted one after BASS_Mixer_StreamAddChannel
            _mixerStream = BassMix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASSFlag.BASS_MIXER_RESUME | BASSFlag.BASS_MIXER_NONSTOP);

Bass.BASS_ChannelGetInfo(outputStream1, info) reports that channel is 32bit, stereo, 48K
info = {Custom Stream, 48000Hz, Stereo, 32bit}


Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: How to record audio card output with Bass.Net ?
« Reply #4 on: 15 Dec '17 - 17:34 »
Now I try to get not distorted sound before lame encoder.
So I commented line below
//Bass.BASS_ChannelSetAttribute(_mixerStream, BASSAttribute.BASS_ATTRIB_VOL, 0);

But even without BASSFlag.BASS_SAMPLE_FLOAT in the mixer I got distorted music when added channel to mixer :(
So definitely I'm doing something wrong way :( but what?

Does removing the BASS_MIXER_NONSTOP flag from the mixer help? You could also try adding BASS_MIXER_LIMIT to the BASS_Mixer_StreamAddChannel call.

If you still get the distortion, what does it look like, eg. if you record it and load it in a sample editor?

And one more question, how to record only one channel (left fro example) from device?

You could use a splitter stream to extract the channel that you want from the recording, and plug that (instead of the recording) into the mixer. For example, if you want to keep the left channel from the recording:

Code: [Select]
int chanmap = {0, -1}; // channel mapping for only the 1st channel
split = BASS_Split_StreamCreate(outputStream1, BASS_STREAM_DECODE, chanmap); // create the splitter
BASS_Mixer_StreamAddChannel(_mixerStream, split, 0); // plug it into the mixer

Or to keep the right channel:

Code: [Select]
int chanmap = {1, -1}; // channel mapping for only the 2nd channel
split = BASS_Split_StreamCreate(outputStream1, BASS_STREAM_DECODE, chanmap); // create the splitter
BASS_Mixer_StreamAddChannel(_mixerStream, split, 0); // plug it into the mixer

Please see the BASS_Split_StreamCreate documentation for details.