Streaming sound in C#

Comments

[this is good]

I am looking for an example for playing input stream of WAV from C#.

Can you direct me to such ?

What if I've an application that is recording audio stream, and sending it to me over a tcp-channel for example. Assume I do not want to wait for loading the whole song before I start playing it, what then ? How do I play while keep waiting for more data to come ?

I've failed to far in searching for a solution to my question, and failed to find an implementation that will help me with my problem.

Regards,

Rani

You'll be happy to know that streaming wave is completely supported by the Bass api. In my above sample I am using an Mp3, but Bass supports many types of audio streaming including:
MP3, MP2, MP1, OGG, WAV, AIFF, custom generated, and more via add-ons), MOD music (XM, IT, S3M, MOD, MTM, UMX), MO3 music (MP3/OGG compressed MODs

Specifically, converting audio data from it's original byte stream into a playable type is quite simple with the Bass arena. I don't have a sample just yet, but until I have one up I suggest looking to the Un4seen forums for help.

- Thomas
Also, I have a Recording audio in C# sample posted here on my blog.
I have posted my solution to Voice Chat in C#.

http://www.microsoft.com/express/2005/download/default.aspx

You can download the 2005 versions of visual studio express

Hello, Thomas!!!

I am from Russia and am working on my small project with using of C#.NET (sorry for my English, it mught be some mistakes). And in this programm I need to work with sound (mp3, m3u and others), but, as you know, c# can play only wav-files with its standard library System.Media. That's why, I go to Google where I found your tutorials and read about bass.dll. I've downloaded it, but when I was trying to add it to my project there was a mistake: "A reference to 'some path\bass.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM componnent"

Maybe you can answer me, what exactly you've done for adding this library to yours project? I'll be very grateful to you)))

P.S. my e-mail: tonlo@mail.ru, and I work with Microsoft Visual C# 2008 Express Edition

Thank you
Hi Dmitrij,

There are actually 2 libraries discussed here. One is the Bass.NET library (that's the one you want to add as a reference to your project) and the bass.dll library (which you need to include in the output directory of your project).

I can send you a screenshot if you need any help :)

You can download each here: http://www.un4seen.com/bass.html
Thank you for answering, Thomas, about Bass.Net it is clear, I've got it:) But about bass.dll, I haven't... If you tell me, where is the output directory, it would be great))) Because I'm a beginner in a programming, and have some problems with terms in English))) Is this directory somewhere in folder, where are all files of project or somewhere else?

Thanks again)))
I see, whenever your project builds it will go to the \bin\Debug. Put the bass.dll into the \bin\Debug folder. :)
Well, I've done it, but it doesn't work, I can't find it in Solution Explorer... And when I try to write something like "Bass.BASS_Init..." there is a mistake... Maybe, I should activate this library in wy Windows, but I don't know how...
Sorry: in my Windows...

Hello Tomas,

Thank you very much for recommending the BASS api, and it looks great!

Huh? My reply got cutted...

So basically, I only have 1 question: If I make a game with using this api, then to play it on other people computers, do they need to install BASS api as well?

Thanks,

Hi Eric, that would be correct. They would need to have the DLL available on their machines. However, what you can do is check the copy local property on the referenced assembly in Visual Studio to use a local copy of the DLL instead of having them install it. That's usually what I do for my demos.

Bass.NET also has a license, so depending on the kind of release you plan on having you may or may not need a license. If it's a non-commercial program then you are okay to use it on your own. I recommend reading the terms on the un4seen website just to make sure though.

Thanks alot for the quick response and easy solution!

We are not make profit, it is just a demo. lol

Anyway, we will check the terms.

Many thanks again!

Hi,

I want to convert wav to mp3; how can i do this with bass?? also i am developing in .net compact framework.

Regards,
Unfortunately the .NET Compact Framework does not support many things that Bass uses to stream audio playback, not to mention the mp3 encoder LAME will not run under the .NET Compact Framework.

When working under the .NET Compact Framework your best available options are to use the Win APIs for audio recording and playback.

These are the waveIn/waveOut apis - available with the .NET Compact Framework (as in it is available on Windows Mobile) and in the standard Windows Environment.


As you can see on the documentation, it is supported under the .NET Compact Framework 1.0 and so on. I found a solution that already takes care of the P/Invoking in C#.

http://www.codeproject.com/KB/audio-video/cswavrec.aspx

Nevertheless, I have not discovered any encoder that will work with mp3 (besides LAME) that is supported on lesser platforms. The only C# library for working with the LAME encoder is the Bass.NET library (that I know of).

Hope this helps

Thx Thomas !

Well what u say is true, actually i have already developed a recording aplication with wavein/waveout apis; the big problem is that i need those audio files in mp3 format(wich are recorded in wav format only :S).

The reason i need

[this is good]
Hi !!
thanks for the information..about base.net and Lame,
i was wondering about mixing streaming file with the recording one...
is it possible in C# ??
moreover i was developing asp.net web application using ur code but i m stuck in some problems..

So I think the major problem you will have with the Asp.NET app is that when you use the encoder, or mostly any part of the api, it will only attempt to use the local hardware that the application is running on. So for instance, if you want to record someone on the microphone it will be attempting to record wherever the server is. I'm sure it will work for local purposes, but this will no doubt no work in a live web app scenario.

As for mixing streams, although I haven't deal personally with it, I have read in many of the forum posts in the un4seen Bass API forums about mixing streams to do exactly what you are saying. You may have to go further in to investigate though.

Thanks :)
so ..
do u have any other option to record music live ...
what ll be the logic behind recording and streaming music live..
and u have used base.net lib is there any other opensource library..which can work on asp.net and codec....
[いいですね]
Okei, now to the business. Is it somehow possible to use this API for streaming over the network or even Internet? Surely hope someone will see this.
There is in fact a way to stream this over the internet. I've covered a simple article on using a Network library for a Voice Chat Session. I will need to update for WCF and possibly newer codecs, but nevertheless it works for what it needs to do.

There is a newer library that I plan on writing articles about called NAudio. It supports much of the work I've seen here.

Can this be run under Windows Mobile x / Windows CE ?

Regards

[this is good]
Nice post! I have one issue if you could help. :)

I have the dll pasted in all my folders. I added the reference after installing. However I am getting errors like "Bass and Bass_Init" does not exist in the current context".

What should I do next?

Vista 64 bit
VS 2008
C# .NET 2.0 application
I found out that there is a 64-bit of the Un4seen Bass.dll library that you have to use when on 64-bit.

hello thomas, i using Bass.NET. 2.4.4.4 and i got some error which r the BASSStream does not exits in the current context.

What is the problem?

Post a comment

Already a Vox member? Sign in

Thomas Holloway

About Me

Thomas Holloway
United States
worry less, do more
Messaging:
Send

My Groups

Neighborhood

Explore friends, family, friends & family, or entire neighborhood.

Archives