Skip to main content

Topic: Winamp 2 Kernel Streaming Output Plugin (Read 399066 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
I just wrote a simple Kernel Streaming output plugin for WA2 - check it out at http://www.cs.indiana.edu/~cshei/out_ks.dll.  It's very experimental right now - it just uses the first output device it finds, and it's currently hard-coded to use 10 output buffers (so it might skip if you have all those WinXP visual effects enabled).  Source code is at http://www.cs.indiana.edu/~cshei/out_ks.zip (a VC++ .NET project - sorry VC++ 6 users).  I just wrote it this afternoon, because Microsoft released a Kernel Streaming demo today .  I'll be adding tons of stuff soon, including SSRC resampling (for those who are blessed with fixed sampling rate DACs  ) and selection of output device and # of buffers.

Annuka: using Kernel Streaming should prevent ALL other programs from using the sound device, which should solve the "Silence Flash" problem.

Edit: By the way, if you do give it a try, give me some comments/suggestions
  • Last Edit: 28 November, 2002, 07:54:16 PM by Chun-Yu

  • cynix
  • [*]
Winamp 2 Kernel Streaming Output Plugin
Reply #1
will kernel streaming allow me to play mp3s while i'm in ntice?

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #2
out_ks.dll apparently needs msvc7 dlls, which i dont have on my win2k. i don't have msvc7 either, i use only msvc6.


Code: [Select]
dumpbin /imports out_ks.dll
Microsoft ® COFF Binary File Dumper Version 6.00.8447
Copyright © Microsoft Corp 1992-1998. All rights reserved.


Dump of file out_ks.dll

File Type: DLL

  Section contains the following imports:

   KERNEL32.DLL
             1000F064 Import Address Table
                     0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   0  LoadLibraryA
                   0  GetProcAddress

   [b]MSVCR70.dll[/b]
             1000F070 Import Address Table
                     0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   0  free

   SETUPAPI.dll
             1000F078 Import Address Table
                     0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   0  SetupDiGetClassDevsA

   USER32.dll
             1000F080 Import Address Table
                     0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   0  MessageBoxA

  Summary

       A000 UPX0
       3000 UPX1
       1000 UPX2
  • Last Edit: 16 May, 2009, 06:46:41 PM by Peter

  • Gabriel
  • [*][*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #3
Sorry, but what does "kernel streaming" means?

  • cynix
  • [*]
Winamp 2 Kernel Streaming Output Plugin
Reply #4
Quote
Sorry, but what does "kernel streaming" means?

http://www.microsoft.com/hwdev/tech/stream/csa1.asp

Winamp 2 Kernel Streaming Output Plugin
Reply #5
What are the advantages over a directsound output?
netjukebox - the flexible media share
http://www.netjukebox.nl

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #6
from my short IRC survey, you should give it a try if your favourite colors are blue and white.

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #7
Ok - point taken, Peter.  Although I don't think msvcr70.dll is part of the .NET framework, it probably comes with it.  I've changed it to be statically linked (same URL).
Quote
What are the advantages over a directsound output?

Well, the main reason I wrote it is because Kernel Streaming prevents all other programs from playing sound, so my music won't be interrupted by some other sound (yes, I could just disable the Windows sounds, but I don't mind hearing them at other times).  Kernel Streaming bypasses the Windows KMixer and sends data directly to the audio driver, so I suppose another benefit would be that KMixer doesn't get to mess with your audio data (which can give you a warm, fuzzy feeling  ).  Generally, the main reason to use kernel streaming is to achieve extremely low latency output, because KMixer adds about 30 ms latency.  Low latency output isn't useful/possible with Winamp because the input plugins send data in like 13-26 ms bursts.  Low latency output is really useful for audio editing programs.

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #8
"low-latency output" is totally useless for music playback because it kills any underrun protection.
BTW, just tested your plugin, works on my win2k / terratec sixpack. i'm too lazy to look at the source but you should make sure that the thread which *started* playback doesn't die until playback is legally terminated, otherwise it makes bad sounds on stop (i had similar "problem" in out_ds a while ago, its a bug in win2k/xp WDM).

  • Jasper
  • [*][*][*]
Winamp 2 Kernel Streaming Output Plugin
Reply #9
Actually low-latency output doesn't have to (entirely) "kill" any underrun protection, since the audio files can usually be read faster than they are played, which means the program can still build up a buffer. Of course the small buffers that are sent to the soundcard will mean a little more skipping if you keep the processor real busy, but under normal use you shouldn't notice that a lot (I haven't had a single skip for months, and I'm using ASIO to output the sound, which has a very low latency).

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #10
depends what else you are using the computer playing music for.

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #11
Quote
"low-latency output" is totally useless for music playback because it kills any underrun protection.

Yep - that pretty much what I just said in my previous post.

Quote
i'm too lazy to look at the source but you should make sure that the thread which *started* playback doesn't die until playback is legally terminated, otherwise it makes bad sounds on stop (i had similar "problem" in out_ds a while ago, its a bug in win2k/xp WDM).

Actually, I'm not starting any threads of my own - the IO is done asynchronously.  So what happens is that each buffer has an event associated with it, and IsPlaying() checks to see if any buffers aren't done playing yet.  So in theory, the input plugin should handle this, since that thread is *supposed* to check IsPlaying() and not quit until the output plugin is done playing.

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #12
yeah yeah. your plugin isn't creating threads, but playback is started from input plugin's thread; if user presses stop, this thread dies before you are closed. you need multithread hacks to workaround this. welcome in winamp v2.x input/output plugin hell.

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #13
Ah! - now I see what you mean!  My plugin doesn't make werid noises when you hit stop, though.  Hmm.  I don't know - maybe the bug only happens when using DirectSound/MME?  The data is sent to the audio driver using asynchronous DeviceIoControl()s in my plugin, so I don't think the calling thread matters, as long as the buffer isn't deleted before the audio driver finishes with it.

  • Peter
  • [*][*][*][*][*]
  • Administrator
Winamp 2 Kernel Streaming Output Plugin
Reply #14
i believe that exact effect depends on your drivers, i researched it back then in early out_ds2 days. the thing is, when the thread which *started* playback (eg. queued first waveOut block or called IDirectSoundBuffer::Start()) dies, playback dies too (usually with a weird sound, like on my card). this problem is relatively unimportant for basic functionality, but it will blow up when you try to add "gapless mode".

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #15
I'll look into it (probably just try it on a bunch of different soundcards) - thanks for the warning, Peter!  Gapless output isn't a very high priority for me right now, but it'll probably be added in the future, so I should find out about this...

  • Case
  • [*][*][*][*][*]
  • Developer (Donating)
Winamp 2 Kernel Streaming Output Plugin
Reply #16
Quote
using Kernel Streaming should prevent ALL other programs from using the sound device, which should solve the "Silence Flash" problem.

I tested this on SB Live!, SB Audigy and Turtle Beach Santa Cruz and other programs were able to play sound without any problems when out_ks was in use.

There's also very nice bug, it bluescreens my computer immediately if I don't disable my TV-tuner drivers. It would be nice if it checked that it actually found sound card.

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #17
Quote
Quote
using Kernel Streaming should prevent ALL other programs from using the sound device, which should solve the "Silence Flash" problem.

I tested this on SB Live!, SB Audigy and Turtle Beach Santa Cruz and other programs were able to play sound without any problems when out_ks was in use.

I suppose it depends on your audio driver.  I tested it on a Yamaha WaveForce 192 and it does allow other programs to play sound, but on a Creative AudioPCI no other programs can play sound.  Anyway, according to Microsoft's documentation, Kernel Streaming should take over the audio device:
Quote
Note

Using the DirectKS approach results in exclusive access to the audio device, which can break many aspects of the user experience, including disabling warning alert sounds and loss of interoperability with other audio applications.


Quote
There's also very nice bug, it bluescreens my computer immediately if I don't disable my TV-tuner drivers. It would be nice if it checked that it actually found sound card.

Yep - I need to add device selection stuff.

  • jrj
  • [*]
Winamp 2 Kernel Streaming Output Plugin
Reply #18
On my system, currently using only a Realtek AC97 spdif out, the sample rate is being converted from 44.1 to 48 kHz as per normal kmixer experience. Shouldn't Kernel Streaming enable direct 44.1 digital output?

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #19
Quote
On my system, currently using only a Realtek AC97 spdif out, the sample rate is being converted from 44.1 to 48 kHz as per normal kmixer experience. Shouldn't Kernel Streaming enable direct 44.1 digital output?

No, if your audio driver only outputs at 48 kHz (probably because your DAC only supports a fixed rate of 48 kHz).  I'm guessing that since the DAC is fixed at 48 kHz, so is the digital out (like the SB Live!?).  In this case, the sampling rate conversion isn't done by KMixer, but by the audio driver, which cannot be bypassed.  All I can suggest is...getting a new soundcard?

  • jrj
  • [*]
Winamp 2 Kernel Streaming Output Plugin
Reply #20
After a little further experimentation, it looks like your explanation is on the mark. As best I can tell, in my system, out_ks bypasses windows as desired (the winamp volume control doesn't work) and sends the bits to the Intel ICH4 chipset, which resamples to 48 kHz, then sends the bits to the Realtek AC97 Codec. That can be set to output either 48 kHz or 44.1, but since 44.1 involves another resample (down from 48) it sounds terrible. So I'm stuck resampling to 48 somewhere along the line, since the ICH4 seems to require it.

Too bad. I don't have another slot for a soundcard.

  • c^2
  • [*]
Winamp 2 Kernel Streaming Output Plugin
Reply #21
Any update on your progress, Chun-yu?  I'm really interested in this, as it would allow those of us without ASIO capable cards to bypass kmixer without using SSRC.  (SSRC uses up to 40% of my Athlon 650)

The current build works fine for me, but breaks into static when there is heavy activity on the PCI bus.  Would it be possible to put in an option to increase the buffers?  As I just use it for listening, I wouldn't mind the increased latency at all.  Or is there a bigger problem with increased buffers that I don't understand?

Edit:  I've found that if I boost Winamp's priority to high in task manager the static is no longer a problem.  I guess it was heavy CPU usage by another program that was causing the static.
  • Last Edit: 13 December, 2002, 11:13:08 PM by c^2

  • thomaspf
  • [*][*]
Winamp 2 Kernel Streaming Output Plugin
Reply #22
Chun-Yu,

great effort! A kernel streaming output has the potential of bypassing kmixer for more sound cards that allow pass through of PCM data but do not have an ASIO driver available.

In addition to resampling kmixer has the undesirable side effect of modifying all stream even if the input and output format are 16/44.1Khz. SSRC does not help with that either. If you upsample kmixer will mangle the upsampled stream before handing it to the sound card.  The effects of this are quite audible and affect any PCM data played through waveout or direct sound on sound cards with a native WDM audio driver. Another benefit of kernel streaming is very low overhead.

Many sound cards do have multiple devices on it and your current plugin follows the SDK sample in just taking the head of the enumerated list. One urgent feature request would be to provide for a selector for which device to use. By looking at the sample code I could not find a way to expose the actual device name but just giving the option to pick from a numbered list will do. Once you have that we could test this plugin for bit transparency via a digital output.

Cheers

    Thomas

  • KikeG
  • [*][*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #23
Ehm... any update on the plugin, Chun-Yu? 

  • Chun-Yu
  • [*][*][*][*]
  • Developer
Winamp 2 Kernel Streaming Output Plugin
Reply #24
Not yet - been real busy.  Should have much more time in about 2 1/2 weeks - when classes at IU end .