Author Topic: BASS_WASAPI and CastInit  (Read 3219 times)

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #50 on: 5 May '17 - 10:21 »
Broadcasting is now working fine. But I have minor question.

On some sound cards Microphone output is only audible on the left side. Is it possible with my WASAPI en StreamCreate microphone unit to merge left and right so you can here the voice left and right?

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #51 on: 5 May '17 - 13:54 »
Is the problem that the microphone is stereo but it only has sound in the left channel? If so, you could use matrix mixing to replicate the left channel on the right channel, something like this:

Code: [Select]
BASS_Mixer_StreamAddChannel(mixer, source, BASS_MIXER_MATRIX);
float matrix[2][2]={
{1, 0}, // left out = left in
{1, 0} // right out = left in
};
BASS_Mixer_ChannelSetMatrix(source, matrix); // apply the matrix

Note this is assuming that the mixer is stereo. Adjust the matrix dimensions if not.

Another way to do it is to use the BASS_FX add-on's BASS_FX_BFX_MIX effect.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #52 on: 6 May '17 - 13:13 »
Found solution with BASS_MIXER_MATRIX. Thank you :)

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #53 on: 14 May '17 - 10:59 »
I try to sent ImageArt to Shoutcast v2. I get this result:

Code: [Select]
  const
      BASS_METADATA_BIN_ALBUMART_JPG = 16640;    // SHOUTcast v2 Cacheable Binary Metadata (Album art image/jpeg).

Result := BASS_Encode_CastSendMeta(Encoder,  BASS_METADATA_BIN_ALBUMART_JPG, LogoData, LogoStream.Size);

10-05-2017 10:53:31 ~ Broadcast: BASS_Encode_Start (1580)
10-05-2017 10:53:31 ~ Broadcast: BASS_Encode_CastInit (Default) (True)
10-05-2017 10:53:31 ~ Broadcast: BASS_Encode_CastSendMeta (1580, False) [Requested data is not available]

Coding in Delphi for init Image:
Code: [Select]
    LogoStream := TFileStream.Create(LogoFileName, fmOpenRead);
    GetMem(LogoData, LogoStream.Size);
    LogoStream.Read(LogoData^, LogoStream.Size);

Is this my problem or is support v2 not actually right?



Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #54 on: 15 May '17 - 17:49 »
Is the BASS_Encode_CastSendMeta error code BASS_ERROR_NOTAVAIL? If so, that sounds like a Shoutcast 2 connection wasn't setup in the BASS_Encode_CastInit call, ie. a "streamid" wasn't provided?

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #55 on: 16 May '17 - 10:53 »
Yes, the Error message is BASS_ERROR_NOTAVAIL.
I will investigate further.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #56 on: 6 Jun '17 - 09:37 »
Hi,

I have little question.

I use WASAPI for Microphone and Line-in. Sometimes the sound is gone and only WASAPI Stop and then START will fix this. 
That is happening by some other users and for me difficult to check.
Maybe they use Windows sound to change something or other software that change something.

Is it better to add flag BASS_WASAPI_EXCLUSIVE?
Lot of work so I ask you first. And little afraid that it don't work with everybody.

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #57 on: 6 Jun '17 - 17:19 »
When you say the sound "is gone", do you mean your WASAPIPROC stops getting called? What does BASS_WASAPI_IsStarted say at that point? It might be that another app has started using the device in exclusive mode. Can you check with the user if that is what happened? If your app uses the device in exclusive mode, it will prevent other apps doing that, but it will also prevent other apps using the device at all.

If you aren't already using it, please also try this latest BASSWASAPI build:

   www.un4seen.com/stuff/basswasapi.zip

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #58 on: 7 Jun '17 - 08:27 »
If WASAPI is really stopped I don't know. STOP and START will re-start so it's possible driver is stopped. Must do more check in program.
I think it's another app and the user don't understand. I know that some using echo software besides my music program. I now add choice for exclusive mode.

I was using 12 may 2015 version DLL. But the same size. Now replaced with the new one.

This is the correct way to check?

BASS_WASAPI_SetDevice(LineMonitorInputDevice);
Result := BASS_WASAPI_IsStarted;

Regards,
Eduard.
« Last Edit: 7 Jun '17 - 08:32 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #59 on: 7 Jun '17 - 16:12 »
Yes, if you have multiple WASAPI device initialized, then you should use BASS_WASAPI_SetDevice before BASS_WASAPI_IsStarted, to set the device of interest.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #60 on: 8 Jun '17 - 03:42 »
Thanks Ian for all your help  8) :)

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #61 on: 12 Jun '17 - 12:41 »
Now I little confused.

I Start WASAPI for input Microphone. Never Stop this!
When switch to ON and OFF I use the stream volume for the Mixer. But after do this he delay for Microphone is not right. Longer.
After STOP and START for WASAPI it's to start better. Why?
Must I do WASAPI start and Stop in place of volume to zero? to Microphone On and Off?

Regards,
Eduard.

 



Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #62 on: 12 Jun '17 - 17:14 »
Are you sending the captured microphone data to an output device? If so, which device (the microphone or output) are you stop/starting to remove the delay, and what size buffer is requested in its BASS_WASAPI_Init call?

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #63 on: 13 Jun '17 - 07:42 »
Using Microphone WASAPI to remove if delayed.

Code: [Select]
{ WASAPI callback - not doing anything with the data }
  function DuffRecording(buffer: Pointer; length: DWORD; user: Pointer): DWORD; stdcall;
  begin
    { Feed recorded data to output stream }
    Result := BASS_StreamPutData(MicrophoneInputStream, buffer, length);
  end;

  // Size buffer 0.1 works the same as 0.0
  Result := BASS_WASAPI_Init(ADevice, 0, 0, 0, 0.0, 0, @DuffRecording, nil);
  LogEntry('Microphone', 'BASS_WASAPI_Init', BASS_ErrorGetCode, Result);
 
  MicrophoneInputStream := BASS_StreamCreate(WASAPI_INFO.freq, WASAPI_INFO.chans, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE, STREAMPROC_PUSH, nil);
  LogEntry('Microphone', 'BASS_StreamCreate', MicrophoneInputStream, (BASS_ErrorGetCode = 0));
 
  // OUTPUT ONLY WHEN NOT STARTED BY BROADCAST!
  Result := BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_EVENT, 0.0, 0, @OutputRecording, nil);
  LogEntry('SetOutput', 'BASS_WASAPI_Init_Output', BASS_ErrorGetCode, Result);
  WASAPIOuput_Start;

  Result := BASS_Mixer_StreamAddChannel(GlobalOutputMixer, MicrophoneInputStream, BASS_MIXER_MATRIX); // plug in the input stream
  LogEntry('SetOutput', 'BASS_Mixer_StreamAddChannel_Output', BASS_ErrorGetCode, Result);

  Result := BASS_Mixer_ChannelSetMatrix((MicrophoneInputStream, @MatrixMonoStereo);
  LogEntry('Microphone', 'BASS_Mixer_ChannelSetMatrix', BASS_ErrorGetCode, Result);

  Result := BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, 0);
  LogEntry('Microphone', 'BASS_ChannelSetAttribute', BASS_ErrorGetCode, Result);

  Result := BASS_WASAPI_SetDevice(MicrophoneInputDevice);
  Result := BASS_WASAPI_Start; // start it

Now when speaking I only do this:

BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, AVolume); // Speak
BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, 0); // Silence


Or is this better:

BASS_Mixer_ChannelRemove // Silence
BASS_Mixer_StreamAddChannel // Speak

I think the ChannelSetMatrix gives me a kind of feeling that it's a little more Delayed. Is this possible? 

Regards,
Eduard.




Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #64 on: 13 Jun '17 - 16:25 »
Now when speaking I only do this:

BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, AVolume); // Speak
BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, 0); // Silence


Or is this better:

BASS_Mixer_ChannelRemove // Silence
BASS_Mixer_StreamAddChannel // Speak

Is the latter giving you lower latency? I don't think it should do. If anything, I would expect it to give much higher latency because data would be building up in MicrophoneInputStream (the mixer isn't taking it).

I think stopping and starting the microphone may be better:

Code: [Select]
  Result := BASS_WASAPI_SetDevice(MicrophoneInputDevice);
  Result := BASS_WASAPI_Stop(1); // stop it
...
  Result := BASS_WASAPI_SetDevice(MicrophoneInputDevice);
  Result := BASS_WASAPI_Start; // start it

I think the ChannelSetMatrix gives me a kind of feeling that it's a little more Delayed. Is this possible? 

No, matrix mixing doesn't add any extra latency.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #65 on: 14 Jun '17 - 15:17 »
OK, I will try START / STOP and stop thinking about Microphone :)
Thanks.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #66 on: 25 Oct '17 - 13:16 »
Hello,

I'm back with some Windows 10 issues.

BASS_WASAPI Start and Stop is working perfect with microphone on Windows 7
(see threads before this post)
Code: [Select]
  Result := BASS_WASAPI_SetDevice(MicrophoneInputDevice);
  Result := BASS_WASAPI_Stop(1); // stop it
...
  Result := BASS_WASAPI_SetDevice(MicrophoneInputDevice);
  Result := BASS_WASAPI_Start; // start it

Now after update to W10 and after a couple times (think 4-5 times) START/STOP for Microphone the voice is cracking, squeaking or whatever you may call it.
The more often I turn on and off, the noise is getting worse.
Returning to W7 then everything is fine.

Tried bigger Buffer for WASAPI but no changes.

Is there a way to solve this problem? Maybe advanced settings for WASAPI?

Note: This is the same PC and Soundcard !

Regards,
Eduard.
« Last Edit: 25 Oct '17 - 15:00 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #67 on: 25 Oct '17 - 17:49 »
Is the cracking sound in the recorded data or only in the mixer output? If you are unsure, you can set a WAV writer on the MicrophoneInputStream handle and then listen back to the written WAV file afterwards. If it is only in the mixer output, then the problem is probably that the mixer is processing more data than the recording has available. Try adding the BASS_MIXER_LIMIT flag to the BASS_Mixer_StreamAddChannel call (with the MicrophoneInputStream handle).

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #68 on: 25 Oct '17 - 18:18 »
The cracking sound is also in the output file.  :(
I tried  BASS_MIXER_LIMIT flag as well but no different.

More ideas?

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #69 on: 26 Oct '17 - 14:12 »
If the noise is already in the data when it's received from the device then perhaps it's a driver bug - you could check for an update. You said you already tried using a bigger "buffer" value, but was that on the recording or output device? If not the recording, try that. You could also try higher "period" values. If none of that helps, you could also try event-driven buffering via the BASS_WASAPI_EVENT flag.

Ed1966

  • Posts: 54
Re: BASS_WASAPI and CastInit
« Reply #70 on: 26 Oct '17 - 18:58 »
Maybe it's a driver problem. It's a old Maya44 Soundcard and is doing well but the latest driver (also for W10) is from 8 February, 2016. End of Live product.

Output is Loopback and the music itself is fine. But there is no START/STOP every time. Only for the Microphone.

I tried buffer at recording (Microphone), enlarge period but same story and delay when talking.
BASS_WASAPI_EVENT doesn't work either. 

If I START the Microphone and never STOP for the time I am playing everything is fine. At least for testing time.   

Add some lines in my program to test it with: 
Code: [Select]
BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, AVolume); // Speak
BASS_ChannelSetAttribute(MicrophoneInputStream, BASS_ATTRIB_VOL, 0); // Silence
and this is much better.
Maybe I can make a choice in my program what to do with handling Microphone recording and sound. 

I think where out of ideas?
If so thank you for your time.

Regards,
Eduard.


Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: BASS_WASAPI and CastInit
« Reply #71 on: 27 Oct '17 - 16:19 »
Yes, just muting/unmuting the microphone in the mix is a good idea.