BassPlayer: Adding WASAPI support (1 Viewer)

morpheus_xx

Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    Currently the BassPlayer in MP2 already plays many file types, including FLAC. It handles 24bit, 96/192KHz and even multichannel files properly.
    (see request in german forum: https://forum.team-mediaportal.com/...-einsatz-ein-fazit.124473/page-5#post-1071687)

    As output device there is only DirectSound implemented, but we have already a big "TODO" in code: ;)
    C#:
      public enum OutputMode
      {
        DirectSound,
        // TODO: WASAPI
      }

    The used BassNet library contains all code for WASAPI support, so I think this feature could be added.

    But we need to consider MP2's features like concurrent playback (audio/video, video/video), where we could be required to change the output stream. When using "exclusive" mode this could lead to issues if device is blocked.

    I'll try to implement the output device...

    2014-03-28:
    First testbuild available! (See attachment). It adds new configuration so you can select DirectSound (old default) and WASAPI (new).
    01_AudioPlayerSettings_DS.jpg 02_AudioPlayerSettings_WASAPI.jpg
    Extract the contents of archive to "C:\Program Files (x86)\Team MediaPortal\MP2-Client\Plugins" and overwrite existing files.
    2014-03-29
    Updated build that fix device selection for shared mode

    2014-03-31
    Fixed playback end in shared mode
     

    Attachments

    • 20140331-BassPlayer_WASAPI.7z
      833.5 KB
    Last edited:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #2
    I got already to a point where playback is working, but only as "Mickey Mouse" :) But I expect a test version mid or end of week
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #3
    I've put some more work into this topic: While I got the exclusive mode working nicely with common formats (but not 192khz), the shared mode still goes "Mickey Mouse" (which means playback speed is much to high).

    For shared mode I've seen in MP1 code that there is a mixer involved. I didn't work with all that stuff before, so I need some more background information when to use what approach.
    Also the existing MP1 code can't be taken directly, as BassPlayer in MP2 got completely rewritten (and restructured), so I need to find the right places where to put what.

    @BassFan @hwahrmann can you give me some support in this questions?
     
    B

    BassFan

    Guest
    yes you should set the BASS_WASAPI_BUFFER Flag in INIT call
    that will fix your "Mickey Mouse" LOL.

    Code:
    BassWasapi.BASS_WASAPI_Init(_bassPlayer.DeviceNumber, stream.ChannelInfo.freq, outputChannels,
    initFlags | BASSWASAPIInit.BASS_WASAPI_BUFFER, Convert.ToSingle(Config.BufferingMs / 1000.0), 0f, _wasapiProc, IntPtr.Zero))

    See
    Code:
    case AudioPlayer.WasApi:
    in MixerStream.cs

    greets
     
    Last edited by a moderator:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #5
    It's set already, but problem is still there.

    In MP2 code there is currently no mixer involved(?)
     
    B

    BassFan

    Guest
    It's set already, but problem is still there.

    In MP2 code there is currently no mixer involved(?)

    where you get the data ? then..
    BASS_ChannelGetData = Bass
    BASS_Mixer_ChannelGetData = Bassmixer
    BASS_WASAPI_GetData = Basswasapi

    check BASS_ErrorGetCode

    greets
     
    Last edited by a moderator:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #7
    Playback in EXCLUSIVE mode seems to work now. One sample file fails to be played back.

    Next part will be shared mode.
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #8
    Shared is still playing too fast.
    where you get the data ? then..
    BASS_ChannelGetData = Bass
    BASS_Mixer_ChannelGetData = Bassmixer
    BASS_WASAPI_GetData = Basswasapi
    Please check this part: https://github.com/MediaPortal/Medi...PlayerComponents/PlaybackSession.cs#L274-L308

    Here a playback session is started. It constructs as playback stream chain:
    InputStream->UpDownMixer->VstProcessor->WinAmpProcessor->PlaybackBuffer->OutputDevice.

    There seem to be multiple things to consider:
    • If I understand the code correctly, channel mapping would be needed to moved into UpDownMixer class (currently no processing, just pass through).
    • PlaybackBuffer: "Buffers the output stream to ensure stable playback. Also provides a synchronized stream for visualization purposes."
      • The "VizStream" is used to get data for Visualization (i.e. spectrum analyzer)
    Why the source chain is working well for DirectSound device and for Exclusive WASAPI, but "Shared WASAPI" gives "Mickey Mouse"?
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #9
    Ah:
    The EXCLUSIVE mode opens the device using the sample rate of input. So here it plays at correct speed.
    In SHARED mode the device works at the configured default rate/bit (I set it in control panel to maximum sample rate 24bit/192kHz).

    Do I understand correctly, that exactly for this case I need a mixer that will transform sampling rates?
     

    Users who are viewing this thread

    Top Bottom