Author Topic: BASS_WASAPI and CastInit  (Read 2643 times)

Ed1966

  • Posts: 51
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: 20210
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: 51
Re: BASS_WASAPI and CastInit
« Reply #52 on: 6 May '17 - 13:13 »
Found solution with BASS_MIXER_MATRIX. Thank you :)

Ed1966

  • Posts: 51
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: 20210
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: 51
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: 51
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: 20210
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: 51
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: 20210
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: 51
Re: BASS_WASAPI and CastInit
« Reply #60 on: 8 Jun '17 - 03:42 »
Thanks Ian for all your help  8) :)

Ed1966

  • Posts: 51
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: 20210
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: 51
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: 20210
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: 51
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.