BassPlayer: Adding WASAPI support

Discussion in 'Plugin Development' started by morpheus_xx, March 23, 2014.

  1. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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: ;)
    Code (C#):
    1.   public enum OutputMode
    2.   {
    3.     DirectSound,
    4.     // TODO: WASAPI
    5.   }
    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


     

    Attached Files:

    Last edited: March 31, 2014
    • Like Like x 3
    • Thank You! Thank You! x 3
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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
     
    • Like Like x 3
  4. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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?
     
  5. BassFan

    BassFan Guest

    Ratings:
    +0 / 0
    yes you should set the BASS_WASAPI_BUFFER Flag in INIT call
    that will fix your "Mickey Mouse" LOL.

    Code (Text):
    1. BassWasapi.BASS_WASAPI_Init(_bassPlayer.DeviceNumber, stream.ChannelInfo.freq, outputChannels,
    2. initFlags | BASSWASAPIInit.BASS_WASAPI_BUFFER, Convert.ToSingle(Config.BufferingMs / 1000.0), 0f, _wasapiProc, IntPtr.Zero))
    See
    Code (Text):
    1. case AudioPlayer.WasApi:
    in MixerStream.cs

    greets
     
    Last edited by a moderator: March 25, 2014
    • Like Like x 1
  6. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    It's set already, but problem is still there.

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

    BassFan Guest

    Ratings:
    +0 / 0
    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: March 25, 2014
  8. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    Playback in EXCLUSIVE mode seems to work now. One sample file fails to be played back.

    Next part will be shared mode.
     
  9. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    Shared is still playing too fast.
    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"?
     
  10. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    10,853
    Likes Received:
    4,680
    Ratings:
    +6,704 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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?
     
  11. BassFan

    BassFan Guest

    Ratings:
    +0 / 0
    correctly!

    greets
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!