1

I used this article to write Audio CD

Creating Audio CDs using IMAPI2

Following this article i can write Audio CD, but with smaller wav files (upto 30 min audio file)

And OutOfMemoryException is thrown on line

IntPtr fileData = Marshal.AllocHGlobal((IntPtr)SizeOnDisc);

public void PrepareStream()
{
byte[] waveData = new byte[SizeOnDisc];

//
// The size of the stream must be a multiple of the sector size 2352
// SizeOnDisc rounds up to the next sector size
//
IntPtr fileData = Marshal.AllocHGlobal((IntPtr)SizeOnDisc);
FileStream fileStream = File.OpenRead(filePath);

int sizeOfHeader = Marshal.SizeOf(typeof(WAV_HEADER));

//
// Skip over the Wav header data, because it only needs the actual data
//
fileStream.Read(waveData, sizeOfHeader, (int)m_fileLength - sizeOfHeader);

Marshal.Copy(waveData, 0, fileData, (int)m_fileLength - sizeOfHeader);

CreateStreamOnHGlobal(fileData, true, out wavStream);
}

I tried to create IStream some other ways but IMAPI2 API gives following error E_IMAPI_DF2RAW_STREAM_NOT_SUPPORTED (HRESULT)0xC0AA060D The provided audio stream is not valid.

So, please can any buddy help me to write very large wav file to Audio CD

  • So why do you need to read the entire file into memory in order to write it? – Tony Hopkinson Dec 15 '11 at 12:37
  • It's required by IMAPI2 API to read the entire file into memory IStream stream = mediaFile.GetTrackIStream(); trackAtOnce.AddAudioTrack(stream); If you have any suggestion, please provide i can test them – Kashif Ahmed Dec 15 '11 at 13:23
  • Must be another way, That would mean to write one file onto a dvd you'd use up 4 gig of ram just for the data... – Tony Hopkinson Dec 15 '11 at 17:11
  • yes, i am also writing DVD and it has no issue, here i am creating IStream with this methos Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream); but after obtaining stream i am passing this stream to trackatonce.AddTrack method throws ComException E_IMAPI_DF2RAW_STREAM_NOT_SUPPORTED (HRESULT)0xC0AA060D – Kashif Ahmed Dec 16 '11 at 12:52

0 Answers0