🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.multimedia
Article #10

Playing Audio from a memory array

#10
From: Joe Gabriele
Date: Sat, 22 Apr 2006 03:47
37 lines
2125 bytes
Hi,

Is there a way to use DirectSound to create a SecondaryBuffer from a WAV 
file stored in memory?

I can create a wave file, write it to the hard drive and then play it back 
with DirectSound by first creating the buffer : sound = new 
SecondaryBuffer("\\test.wav",bDesc,sndDevice)  and then using the sound.Play 
method send it to the sound card.

What I want to do is create the wave file in memory and then create the 
SecondaryBuffer from that memory stream. I can successfully create the wave 
file in memory as follows:

MemoryStream stream = new MemoryStream();

I then use the stream.Write method to load the various part of the wave file 
(header info and data);

I finally transfer the stream to a byte array (though I don't know if this 
is necessary):

byte[] snd = stream.GetBuffer();

When I try to create the SecondaryBuffer to play the sound,

sound = new SecondaryBuffer(snd,dSound) or sound = new 
SecondaryBuffer(snd,fileSize,dSound);

it crashes. I know that the array snd has all the proper information as I 
can view it as it's being populated.

Any help would be greatly appreciated.

Thanks.

Joe Gabriele 
Technical Details
Message-ID: <4449a749$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.inode.at!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 21671d,b006e4bb13642a97,start
X-Google-Attributes: gid21671d,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Joe Gabriele" <SORRY@TOO.MUCH.SPAM>
Newsgroups: borland.public.csharpbuilder.multimedia
Subject: Playing Audio from a memory array
Date: Fri, 21 Apr 2006 23:47:22 -0400
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
NNTP-Posting-Host: 67.70.68.126
Message-ID: <4449a749$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1145677641 67.70.68.126 (21 Apr 2006 20:47:21 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.inode.at!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail