Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Playing embedded wav file in C

gerroff
Registered User
Quote
2012-05-18 13:39:55

Hello,

It is about C-Sharp, .NET 3.5 application.

I'm trying to play a wav file embedded in my application.

Here is my not working code (no exceptions, it just doesn't play the wav):

            Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("App.Resourses.Notify2.wav");
if (stream != null)
{
BinaryReader reader = new BinaryReader(stream);
byte[] byteArray = reader.ReadBytes((int)stream.Length);
ISoundEngine engine = new ISoundEngine();
ISoundSource source = engine.AddSoundSourceFromMemory(byteArray, "a.wav");
engine.Play2D("a.wav");
}


What am I doing wrong?


gerroff
Registered User
Quote
2012-05-18 13:46:00


...
ISoundSource source2 = engine.AddSoundSourceFromIOStream(stream, "b.wav");
engine.Play2D("b.wav");
...


Doesn't work for me either.


gerroff
Registered User
Quote
2012-06-09 22:02:30

Bump.

Admin please add a "sharp" sign or word to the subject. It didn't save a sharp sign when I created a topic.


niko
Moderator
Quote
2012-06-10 22:07:22

Not sure there. Any error message? Maybe you are trying to play back an unsupported wave file (with an unsupported compression format), did you try another one?
BTW: Yes, this forum doesn't like the sharp sign, sorry :)


gerroff
Guest
Quote
2012-09-23 19:41:21

I left this issue for some time, but today I came back to and was able to resolve it.

niko was right, the wav file I tried to embed and play had unsupported compression format. As a man not familiar with sound encodings at all I found it just by accident.

I played with project CSharp.03.MemoryPlayback from examples.net. I converted the initial wav file I couldn't play from the stream to DataArray with bin2h tool (http://www.deadnode.org/sw/bin2h/) and replaced the SoundDataArray with my data in that example. At some point I received a message in console that "The wav has unsupported MPEGLAYER3 encoding and only PCM encoding is currently supported", though it played the wav (SoundDataArray) anyway.

I went from there and searched how to convert MPEGLAYER3 wav file to PCM wav file. I found that it can be done with FFMPEG tool (http://ffmpeg.zeranoe.com/builds/ ---- windows builds) with the follwing command: "ffmpeg -i source.wav -f wav -acodec pcm_s16le dest.wav". The source.wav file was the one I couldn't play from the stream after embedding file in my application and the dest.wav is the one I was able to embed and play from the stream in my application. The size of the initial source.wav was 20kb, the size after conversion to the dest.wav became 176kb.

I also was always able to play the initial sourse.wav from file. It didn't work only when I tried to embed and play it from a stream.


gerroff
Guest
Quote
2012-09-23 20:10:27

Em... I've just updated irrKlang library and now it works even with my initial source.wav I couldn't play from the stream before. May be some bugs were fixed in irrKlang, may be I did something wrong the first time I encountered this problem. Anyway now it just works.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact