Yet Another (WA)SAPI Output Plugin for Winamp (YASAPI)

Copyright © 2015 by Peter Belkner (http://home.snafu.de/pbelkner/)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

The "Yet Another (WA)SAPI Output Plugin for Winamp" (YASAPI) utilizes the "Windows Audio Session API" (WASAPI). WASAPI's exclusive mode for rendering audio is a native way on Windows to render audio undisturbed, similar to Steinberg's "Audio Stream Input/Output" (ASIO). The YASAPI output plugin may serve as a replacement for any other Winamp output plugin.

Home:   http://out-yasapi.sourceforge.net/
Project:   http://sourceforge.net/projects/out-yasapi/
Download:   http://sourceforge.net/projects/out-yasapi/files/out-yasapi/
WA Forum:   http://forums.winamp.com/showthread.php?t=380396

Content

  1. History
  2. Introduction
  3. Implementation
  4. Configuration
  5. Debug

1. History

2015-10-29 0.8.0
2015-10-26 0.7.1
  • Automatic re-sampling in shared mode seems to work now.
  • Added an "Exit Winamp" option to the error message dialog box.
2015-10-26 0.7.0
  • Support for multiple devices.
  • Configuration options per device.
  • Various fixes.
Note: Prior configuration for the default device may be lost. Please re-configure.
2015-10-03 0.6.1 Corrected a silly bug in testing for share mode.
2015-10-03 0.6.0 Add AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM flag when in shared mode (doesn't have any effect on Vista).
2015-02-14 0.5.0
  • Utilization of the IAudioClock interface instead of the GetTickCount() or the timeGetTime() functions for reporting the elapsed time to Winamp.
  • Option for controlling whether "written time" should be calculated.
2015-01-30 0.4.0
  • Option for treating mono as stero (default switched on).
  • New default options for buffer configuration.
  • Some fixes.
2015-01-25 0.3.0
  • Support for pull strategy.
  • Support for volume control.
2015-01-24 0.2.1
  • Component Object Model (COM) error messages are displayed with the file and the line number where they occur.
  • Compiled with shared "MSVCR110.DLL" (instead of static as before).
2015-01-24 0.2.0
  • Improved configuration for buffer sizes.
  • Provided a SSE2 version.
  • Compiled with the C compiler from "Visual Studio 10 Express" (instead of "Visual Studio 9 Express" as before).
2015-01-23 0.1.0 Initial release.

2. Introduction

According to Microsoft:

The Core Audio APIs were introduced in Windows Vista. This is a new set of user-mode audio components provides client applications with improved audio capabilities. These capabilities include the following:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd370784%28v=vs.85%29.aspx

Of special interest is that there is an exclusive mode for rendering audio, i.e. there is a mode where an application has exclusive access to the audio device without being disturbed by third parties.

The aim of the YASAPI plugin is to make the WASAPI exclusive mode for audio rendering available to the users of Winamp.

The name of the plugin was choosen because there are already at least two WASAPI output plugins for Winamp:

3. Implementation

There are two sides the YASAPI plugin has to take into account:

The implementation on the WASAPI side follows along the lines of an example provided by Microsoft. The startegy shown in this example is not only applicable for shared mode streams but also for exclusive mode ones, i.e. not the share mode should be emphasized but what is known as the push model. There is also an example demonstrating the pull model in conjunction with the exclusive mode. In that sence there are four strategies:

The YASAPI plugin implements the first two strategies, i.e. the ones based on the push model.

The push model, in principle, works as follows:

  1. Query the size of the buffer shared with the audio device.
  2. Fill in completety the buffer shared with the audio device.
  3. Start playing.
  4. Loop until the track is played:
    1. Sleep half of the time corresponding to the size of the buffer shared with the audio device.
    2. Into the buffer shared with the audio device, fill in the gap which was growing free by playing during sleep.
  5. Sleep until the possibly remaining filled rest of the buffer shared with the audio device was played.
  6. Stop playing.

But the YASAPI plugin not only has to take into account the WASAPI side (the loop consisting of sleeping and writing to the audio device) but also the Winamp side because Winamp provides the audio samples which should be played in an completely unpredictable way.

The YASAPI plugin decouples the two sides by means of a ring or circular buffer. That way,

According to step 2 of the push model sketched above, it shoud become clear that the ring buffer should be at least as large (or larger) as the buffer the plugin's WASAPI component shares with the audio device.

4. Configuration

The YASAPI plugin comes with the following configuration dialog where you can configure the following general options:

There are the following per device options:

Finally you can configure the following per device buffer sizes:

From the above sketch of the push model it shold be clear that the following relation holds (which is enforced by the configuration dialog):

minimum size of the buffer shared with the device (provided by WASAPI) <= size of buffer shared with the device <= number of samples in the ring buffer before start playing <= size of ring buffer

5. Debug

In case something went wrong you may be interested in some more information. In order to utilize this there is a debug version of the plugin (distinguished by a lower case "d" at the and of the name, i.e. out_yasapid.dll) available from the download site.

Do the following:

  1. Close Winamp.
  2. Copy "out_yasapid.dll" to Winamp's "Plugin" folder.
  3. Start Winamp.
  4. A console window should pop up tracing the initialiazation of the debug YASAPI plugin.
  5. From Winamps's preferences dialog choose "out_yasapid.dll" as output plugin.
  6. When playing tracks in Winamp, the debug YASAPI plugin traces initialization and cleanup of each track.
  7. When shutting down Winamp, the cleanup of the YASAPI debug plugin is traced.
  8. After closing Winamp, the console window remains visible for another 5 s before vanishing.

The debug console.

You can get rid of the debug console by choosing the respective "Console" option from the debug YASAPI plugin's configuration dialog:

Please note that no option takes effect before hitting the OK button.