3 posts tagged “music”
In the absence of my coding articles I have created a starter kit for creating audio-visuals with the Bass.NET API. With this starter kit you will be able to have a nice starting point to work with Bass and different audio-visual techniques. The kit, once installed, can be run by hitting F5. You can immediately load up any of your favorite songs or a simple Shoutcast playlist. In a few of my future articles I will introduce some techniques for creating audio-visuals including: bars, waves and ambient lighting. Let's take a quick look at Adosi from where it stands.
Make sure that you have the following requirements before installing:
The Player
When you first start the program you will notice some of the interaction and animation touches that have been made. The entire interface has been designed so that when any audio-visual is added, any one of the components can be apart of the addition. There isn't much to it at this point, but we can however use it as a nice starting point. Let's go ahead and start modifying it. We are going to attempt to wire the bars-visual to the actual music.
Bars Audio-Visual
Before we can create our own audio-visual, we must first understand how most audio-visuals actually work. The idea is based on tracking two distinct variables in all audio: frequency and amplitude. In our case, to create an equalizer all we need to do is average amplitude values into a number of sections. The Bass api contains a simple method for obtaining all this data in the following snippet:
The first parameter refers to audio stream handle (known whenever you create a new channel stream) while the second parameter should be the buffer array created to hold the data itself. It's usually best to use a float array here but you can place doubles, bytes, ints or an IntPtr. The last parameter is the length of the data to receive from the stream. The best place to determine this amount is by using the following snippet:Bass.BASS_ChannelGetData(handle, buffer, length);
All you need to do to create the equalizer is create averages for the number of bars you want. Go ahead and check out the download for the completed version of the equalizer in my modifications below. The equalizer is the easiest to create, so in the future we'll have to get a little more serious in our visualizations.BASSData.BASS_DATA_FFT2048
- you can use any of the given values in the enumeration. Note the actual length in the comments (where 2048 FFT actually refers to 1024 allocated to a single buffer.
Internet radio, a phenomena that appeared in the early 90's that soon made it's way to it's grand stature today. Sure politics are trying to destroy it, but it's not going away any time soon. There is a great deal of history in Internet Radio from war protests to social networking. The latest advent in internet radio, Pandora, from the Music Genome Project, combines the analysis of each song to provide users the ability to listen to similar music; thus creating their own stations based on style, rhythms, lyrics and more. Nevertheless, I suggest you review the history on Wikipedia. I believe the next step in Internet Radio is playing from your mobile phone which doesn't seem that far off. [note project]
At any rate, our little music player doesn't seem to support internet radio at all. Well, I simply won't have that! Especially because supporting internet streams is so very simple with the Bass.NET api. In this tutorial you will learn to accomplish the following:
- Play streaming audio from an internet radio station.
- Visual C# Express (sorry, Visual C# Express 2005 is no longer available)
- Bass.NET 2.3 (scroll down until you find the .NET 2.0 link)
- Un4seen Bass api (top download link for Windows)
I am going to create a new Windows Form project called MyRadio. To start, you will need to add the reference to the Bass.NET api. Then copy the bass.dll to your output directory by including it in your project followed by setting the Copy to Output Directory property to Copy if newer. Your solution explorer should look like the following:
Once you have that setup look for the Player code from the previous tutorial. If you can't find it, you will find the code layout here.
We are going to modify this class to support internet radio streams. Open up the Player class and add the following code snippet.
public void LoadURL(string url)
{
stream = Bass.BASS_StreamCreateURL(url, 0,
BASSStream.BASS_SAMPLE_FLOAT, null, 0);
}
Bass provides this function for loading a stream from a url. In most cases, it won't matter if the stream is a file or a broadcasting stream; bass handles this for you.
You'll notice that this function looks a lot like our original. Except, instead of StreamCreateFile we are using StreamCreateURL. With the fourth parameter, specified as null, is a callback to the function to receive the stream as it's being downloaded. Also, the BASSStream contains a few flags that may allow us to obtain tags about the music including the title, author, genre and more. There are many flags that have a very specific purpose, but for now we are just going to use the default like in our previous case.
The only thing left for us to do is to provide access in our user interface. I have simply copied our previous UI and added a textbox to allow the url to be entered. When you're done, your user interface may look like the following.
There you go. Hit F5 type in an address to an internet radio station or an hosted song online and you should be good to go. In this tutorial you learned how to use Bass to stream internet radio. In my next tutorial I will be teaching you how to create your own playlist allowing for even more support for internet radio stations.