|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionEver wanted to host a Winamp plug-in? No? Hmm... Ever wanted an exercise in good code writing practices? Not even sometimes? OK... How about this... Have you ever wanted to write a coin-op juke box app, based on Winamp, that could provide the control over its plug-ins that only Winamp can? I did, and this article is the result. This article will not tell you how to make a plug-in. There's enough information floating around in other places which would make this article redundant. Instead, this article will show you how to properly host a Winamp output plug-in. As far as the plug-in is concerned, your app is Winamp. This article is part of a possible series on the Winamp plug-ins and system. BackgroundWinamp, a freeware program developed by Nullsoft, is a program that was originally written to play music files. It originally had a unique user-interface, and became widely known when some tech-savvy users decided to toy around with the resources in the program. This led to an underground community of people who would write 'skins' for Winamp. Nullsoft embraced this community, and made skinning easier in future releases. Nullsoft also developed a plug-in system that allowed third-party developers to add functionality to Winamp, such as adding file format support, visualizations, DSP support, as well as a multitude of other types of functionality. Output plug-ins allow the audio to be routed to different locations. The output plug-ins included with Winamp allow the audio to be routed to your soundcard through the wave mapper, through DirectSound (to allow music when you're playing a game), or to a wave file. Using the codeTo use the code, add a reference to the Winamp Plugin Host. Create an instance of the plug-in like so: Dim Plugin As New OutputPlugin("full path to plugin.dll")
I'm not going to get into the nuts and bolts of the Winamp SDK at this time, but suffice it to say, the only thing this plug-in host does for you automatically is pass the InitializationTo properly initialize the plug-in, you should call these methods: Plugin.MainWindow = Me
Plugin.Init()
Opening the deviceThe best analogy to an output plug-in is a hardware device or a file. To do anything, you first open the device. Dim LatencyMS As Integer = Plugin.Open(44100, 2, 16, 100, 0)
Writing data to the deviceTo get actual sound, you write to the device. The plug-in expects raw, uncompressed, sound data, and will play it with the parameters specified when you opened the device. Dim data As Byte()
'todo: get the data from somewhere... maybe a file? or an input plugin?
Plugin.Write(data, data.GetLength(0))
Closing the deviceWhen you are no longer expecting to write data to the device, close it. Some plug-ins have exclusive access to the device (e.g., the Wave mapper plug-in). If such a plug-in is open, no other application can have access to the device. This may result in sounds from other applications not being heard. Close the device to prevent this from happening: Plugin.Close()
FinalizationSome plug-ins may have settings that may need to be saved, or file system transactions (it could happen...) that need to be finalized. Before you exit the program, call: Plugin.Quit()
Points of interestPlug-in systems, in general, and Winamp plug-ins, in particular, have always fascinated me. I've spent a lot of time trying to design new systems and implement older ones. While I have yet to actually write a Winamp plug-in, I do plan to at some point. The one thing I may run into is that while VB.NET can import functions from a DLL file (using One particular hoop I had to jump through to get this to work is that the When I saw the article, it seemed overly complicated for what I was trying to do, so instead I rolled my own. The method used was to write a piece of template code and replace the DLL filename in it at runtime. The code would then be compiled and called. When I wrote that, it worked, that is, until it tried to call the DLL. It simply gave the same exception. This time, though, I had to write a few dozen lines of code to read an array of errors to find that out. I solved the problem by having the imported function declared 'As History
When I add more Winamp related articles, I will add links to them here.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||