Author Topic: BassWasapi repeats endless after EndSync  (Read 146 times)

udo

  • Posts: 21
BassWasapi repeats endless after EndSync
« on: 15 Apr '17 - 18:05 »
Hi,
if i play a file with wasapi the last part will repeat endless.
It means after WasapiEndSync the WasapiOutputProc is still called.
If i use BassWasapi.BASS_WASAPI_Stop at WasapiEndSync the output is cutted about 500ms.
Strange is that i dont hear the repeat at every computer. I have two with different soundcards.

Some code:
Code: [Select]
BassWasapi.BASS_WASAPI_Init(wasapiDevice, ci.freq, ci.chans,
                            BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE |
                            BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT |
                            BASSWASAPIInit.BASS_WASAPI_BUFFER,
                            buflen, 0.05f, WasapiProc, IntPtr.Zero);

WasapiSyncProcEnd = new SYNCPROC(WasapiEndSync);
WasapiSyncHandleProcEnd = Bass.BASS_ChannelSetSync(Outstream, BASSSync.BASS_SYNC_END, 0, WasapiSyncProcEnd, IntPtr.Zero);

private int WasapiOutputProc(IntPtr buffer, int length, IntPtr user)
{
    int c = Bass.BASS_ChannelGetData(Mixer, buffer, length);
    if (c == -1) c = 0; // an error, no data
    if (EndDetected)
        Console.WriteLine("STREAM END WasapiOutputProc: length " + length + " return " + c); // length is different at computers(same file), return is one time about 8000 later always 0

    return c;
}

private void WasapiEndSync(int handle, int channel, int data, IntPtr user)
{
    EndDetected = true;
    Console.WriteLine("-----> WasapiEndSync handle: " + handle + " channel: " + channel);
    //BassWasapi.BASS_WASAPI_Stop(true);
   
}

I cannot compare with asio, but there i see the OutputProc is also still called after the file did end.

Whats wrong?
thanks
Udo
« Last Edit: 16 Apr '17 - 15:14 by udo »

Ian @ un4seen

  • Administrator
  • Posts: 19987
Re: BassWasapi repeats endless after EndSync
« Reply #1 on: 17 Apr '17 - 16:19 »
The BASS_SYNC_END sync set on the source stream will tell you when that reaches the end, but it won't stop the WASAPIPROC being called (BASSWASAPI has no knowledge of the source). You can try calling BASS_WASAPI_Stop in the WASAPIPROC when there is no more buffered data, like this:

Code: [Select]
if (c == -1) {
c = 0; // an error, no data
if (!BassWasapi.BASS_WASAPI_GetData(NULL, BASSData.BASS_DATA_AVAILABLE)) // if there is no data buffered...
BassWasapi.BASS_WASAPI_Stop(false); // stop the output
}

udo

  • Posts: 21
Re: BassWasapi repeats endless after EndSync
« Reply #2 on: 18 Apr '17 - 14:09 »
Thank you!