You could try streaming it into/from a byte array (as described at MSDN's Streaming Data from a WAV File).
Basically, use TitleContainer.OpenStream(@"soundfile.wav")
in your LoadContent()
function to create a System.IO.Stream
object. Then to a BinaryReader
with new BinaryReader(wavStream)
.
Read the header:
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
Read the actual sound data:
byteArray = reader.ReadBytes(dataSize);
Then a whole bunch of complicated code to set up the DynamicSoundEffect
object (detailed at the link above)
Then you can just use dynamicSound.Play()
and dynamicSound.Stop()
to play and stop your sound!
Disclaimer: I haven't tested this method of playing sounds, but it's from MSDN so it's probably accurate