Ogg Sound stops after 2 secs and app crashes

Nov 4, 2012 at 10:03 PM
Edited Nov 4, 2012 at 10:11 PM

Hello friends!

First of all I need to thank you for your great work, I´ve never seen an managed audio lib before. My name is Freefall and I was working with native C++ libs like bass or fmod in VB .NET, but the problem always was, that you couldn´t use them without local extraction. Then I found another way which was opened by a friend: He built a .netmodule out of a C++ ufmod .obj file and included it in his C# project with a really comlicate batch compile script that linked this module into the final executable. It took me long to manage this way on my system and finally got it also to work, but still there was the problem that it only worked on C# and I was using VB .NET :( .

Then, I found a new lib: irrklang was released by ambiera and offered an support for VB .NET! The lib worked great and it even supported chiptunes, which managed to make small apps. But still you needed to have the dll lying in your app´s folder or extracting it on your system to use the functions. The trick ambiera used: the audio lib was also a mixture of managed and unmanaged code which I found out when I wanted to include their dll with ilmerge. So the search went on and I asked myself "Is there no library for playing audio files in VB .NET from ressources???".

So after a long search I finally found your page and you seem to be my last hope of playing ogg´s from the programs resources in vb .NET. Support for Chiptunes would be also great, but they´re not that important now. And I could also play them as an ogg :) What also would be really cool: if you could help me to inface .v2m music playback to .NET ( http://forum.tuts4you.com/topic/30260-listen-v2m-module-music-in-vb-net/ ), the source code of this audio files and lib is here: https://github.com/farbrausch/fr_public/tree/master/v2 , unfortunately it is all written in native C++ -.- .

Why everybody always uses C++ for playing audio files? Is there any logical reason?  -.-


Now here comes my question:

I´ve tried to figure out how your playback works and all went fine, but after playing 2 seconds the app always crashes/hangs. I´ve upped my project with an example ogg here:


Was the problem that I´ve interfaced your code to vb? Well, if you would release a tutorial project to handle with VB .NET would be great.



Nov 5, 2012 at 1:38 PM

Hi, and thank you for trying out NVorbis!

There is no reason VB.Net should have any issues using NVorbis.  In your example project, you can remove the first "Using" block as it is for when you aren't using NAudio.  The second "Using" block (including the "Using waveOut" section) should be correct.  Does your example file play correctly in a "known working" Ogg audio player (I use XMPlay for this test)?

As far as other formats, I really don't have time to build them currently.  I would like to have a managed Farbrausch audio decoder, but it'll have to come from someone else as I won't be able to get to it any time soon.

And yes, there is a logical reason for C++ in audio...  performance.  As good as .Net is, fully optimized C++ will always out-perform fully optimized .Net.

Nov 5, 2012 at 2:39 PM

Yep, the first block was useless in this case, I forgot to remove it. The ogg test file is definately correct as it plays in xmplay and wavepad. Btw: that file was a self made v2m file, that was written into wave by xmplay and encoded to ogg by wavepad, so you see how cool this files can sound with only 20kb filesize instead of many many mb´s :)  And if you pack the final application, you don´t even recognize a size difference because these files can be heavily compressed.

Well, you tell me my code is right, so I can´t image what the problem is. Did my project work on your Visual Studio? Do the compiler options like "Any CPU" and "x86" play a role to get it working?

Concerning the v2m implementation: I would really like to do so, but I´m not that advanced in coding and I don´t know a good c++ to vb project converter which could give me an chance to get started. :( Perhaps you could help me and we work together on that to save our spare time.

And I see another aspect why C++ outperforms .NET: it has much less file size... E.g. the bass.Net.dll is about 600kb filesize as it is only a Wrapper for the bass.dll functions, while the bass.dll only needs 100kb filesize for the real code... 

Nov 5, 2012 at 8:59 PM

Hmmm...  I may need a copy of the ogg file in question...  Can you upload it somewhere and send me the link?

Nov 6, 2012 at 7:07 AM

I´ve already uploaded the project above, the ogg file is in the debug directory. Here is the link again:


Nov 6, 2012 at 9:30 PM

Ah, OK...  I see what is happening now...

The short version:  Refactor your click handler so it can return without waiting for the playback to finish.

Your app hangs because of the way WaveOut works:  Windows sends a message for the click, WaveOut populates its buffers and starts playback, Windows then sends a message to get more data for the WaveOut buffers, but the message is never processed because the UI thread is blocked until playback finishes.  Your application is now hung.

Nov 6, 2012 at 10:44 PM

Mate you are a genius! :) It´s working like a charm, hell yeah! :D Thank you Andrew.

Fixed working Version: ftp://www.untergrund.net/users/Freefall/News%20Section/NVorbisTestVB2008_Working.rar

If you would include playback of v2m files it would be fantastic! I would help with all I can give, every second of my free time. I could help you with basic coding, documentation and testing. I could also provide you with the C++ source code and self made v2m files for testing, I could even remake your favourite songs as v2m :) . Please just think about this, your sound lib would be sooo unique...  it might be even more popular as irrklang...

Nov 7, 2012 at 11:46 AM

I have still some questions about ogg playback left:

1.     Is there a way now to play my test.ogg from the program´s ressources? I couldn´t figure out if this is possible so far, that´s why I ask. I tried all evening yesterday without a success :(

2.    And another thing is important to me: my code is a bit nooblike to fool the click handler problem, but I saw no other way - I would be glad if someone could optimize it. You can also upp my project to the public to help people with the same problems. 

3.    How can I stop playback because waveout.stop doesn´t work in my code, the file just plays as if nothing was happening. I´ll upp this project in the evening, please take a look at that.

I know this is much work for you and I really appreciate your help.

Nov 7, 2012 at 1:17 PM

1) Yes.  Embed it and use Assembly::GetManifestResourceStream(string) to get a Stream instance.  Pay attention to the documentation on MSDN.

2 & 3) Try reviewing the examples attached to the NAudio project.  Mark does a really good job explaining how to use his library.  "Nooblike" code can be fixed with lots of study.  Code Project is pretty good for examples, as are CodePlex and Github.  Stack Overflow is good for more targeted examples.

On the v2m decoder, I would recommend that you first document the file format (read the C++ code) and how the synth works (again, read the C++ code).  Post that to Codeplex or Github and just start working on the code to implement it.  Most likely you'll get some help at that point or shortly after.

Nov 7, 2012 at 4:21 PM

RE: 1)     http://msdn.microsoft.com/de-de/library/vstudio/xc4235zt.aspx

This gives me a stream, but


Using vorbis = New NVorbis.NAudioSupport.VorbisWaveReader(HERE MUST BE A STRING!!!)


 End Using


needs a string input for the vorbiswavereader. You see I need the other way round xD







Nov 7, 2012 at 4:30 PM

Point.  I've added the needed constructor to the source in my local copy.  It'll be checked in later today if all goes well.  I won't make a new release for a while longer, though.

Nov 7, 2012 at 11:13 PM

Cool. Meanwhile I took a look into the V2 sources and used a tool and some knowledge to get a starting point for the vb .net player implementation. Now I could need your help to get it to work, many structures of C++ don´t have a VB .NET equivalent -.-  :


The original C++ project is included.

Nov 8, 2012 at 2:21 PM

Please create a CodePlex or Github project for your library and post the code there.  I can look at it, but think you'll be better off if the whole internet can see and assist.

Nov 8, 2012 at 2:53 PM

Ok, good idea. I´ve created a new Codeplex Project called NV2.


I hope somebody would help me with coding, I´m unfortunately atm not skilled enough to make it working by only myself.

Is it a problem if this project is vb and not c# for you and your friend or can you deal with that? Because I enjoy working with vb more than with c# ;)

I´ll upload the source as soon as I have the time. Of course the source is not ready to use yet, there are many things to fix and much work to do until it would work. I also can´t guarantee for getting it working at all, we´ll see.

Did you implement the ressource playback feature yet or will it take some more time? :) Can´t wait to see the new Lib :)

Nov 8, 2012 at 8:26 PM

Hey how can I upload the project into the source code section?

Nov 13, 2012 at 1:12 PM

You should be able to upload source code with whichever source control tool you chose during project creation on CodePlex.  Instructions for doing that can be put together from reading the documentation for the tool and by looking at the information CodePlex gives you on the Source Code page.

Good Luck!

Dec 7, 2012 at 10:22 PM

Well I found a conversion tool and published the Project here: http://nv2.codeplex.com/SourceControl/changeset/view/21818#378415

Any suggestions how to continue?

Jan 28, 2013 at 10:21 PM

Any News concerning the ressource playback? Would be cool!

Jan 29, 2013 at 12:30 PM

That's included in release 0.5.5. :)

Jan 29, 2013 at 9:36 PM

WUT, great dude :) thank you very much! This is the first native .NET compressed Music ressource playback engine that is working for me so far. Fantastic!