EDN Admin
Well-known member
i wanna generate .wav file of 32 bit............but i m having problem with the .wav file 32 file format.......i know that we have to use WAVEFORMATEXTENSIBLE....but that is not working i dont know why..........
i have used formatchunk like this....................
public struct Waveformat<br/>
{<br/>
public string sChunkID;<br/>
public uint dwChunkSize;<br/>
public ushort wFormatTag;<br/>
public ushort wChannels;<br/>
public uint dwSamplesPerSec;<br/>
public uint dwAvgBytesPerSec;<br/>
public ushort wBlockAlign;<br/>
public ushort wBitsPerSample;<br/>
public ushort wcbsize;<br/>
}<br/>
public class WaveFormatExtensible<br/>
{<br/>
public const ushort WAVE_FORMAT_EXTENSIBLE =65534;<br/>
public static Guid KSDATAFORMAT_SUBTYPE_PCM = new Guid("00000001-0000-0010-8000-00aa00389b71");<br/>
public static Guid KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = new Guid("00000003-0000-0010-8000-00aa00389b71");<br/>
public Waveformat Format; <br/>
public ushort wvalid;<br/>
public uint dwChannelMask;<br/>
public Guid SubFormat;<br/>
<br/>
public WaveFormatExtensible()<br/>
{<br/>
Format.sChunkID = "fmt ";<br/>
Format.dwChunkSize = 40;<br/>
Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;<br/>
Format.wChannels = 2;<br/>
Format.dwSamplesPerSec = 44100;<br/>
Format.wBitsPerSample = 32;<br/>
Format.wBlockAlign = (ushort)(Format.wChannels * (Format.wBitsPerSample / 8));<br/>
Format.dwAvgBytesPerSec = Format.dwSamplesPerSec * Format.wBlockAlign;<br/>
Format.wcbsize = 22;<br/>
wvalid = 32;<br/>
dwChannelMask = 3;<br/>
SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;<br/>
<br/>
i hope u all r getting this..............
and for printing i m using this code.................
public void Save(string filePath)<br/>
{<br/>
FileStream fileStream = new FileStream(filePath, FileMode.Create);<br/>
BinaryWriter writer = new BinaryWriter(fileStream);<br/>
try<br/>
{<br/>
writer.Write(header.sGroupID.ToCharArray());<br/>
writer.Write(header.dwFileLength);<br/>
writer.Write(header.sRiffType.ToCharArray());<br/>
writer.Write(Extensible.Format.sChunkID.ToCharArray());<br/>
writer.Write(Extensible.Format.dwChunkSize);<br/>
writer.Write(Extensible.Format.wFormatTag.ToString());<br/>
writer.Write(Extensible.Format.wChannels);<br/>
writer.Write(Extensible.Format.dwSamplesPerSec);<br/>
writer.Write(Extensible.Format.wBitsPerSample);<br/>
writer.Write(Extensible.Format.wBlockAlign);<br/>
writer.Write(Extensible.Format.dwAvgBytesPerSec);<br/>
writer.Write(Extensible.Format.wcbsize);<br/>
writer.Write(Extensible.wvalid);<br/>
writer.Write(Extensible.dwChannelMask);<br/>
byte[] guid = new byte[16];<br/>
guid = Extensible.SubFormat.ToByteArray();<br/>
writer.Write(guid, 0, guid.Length);<br/>
}<br/>
catch (Exception ex)<br/>
{<br/>
MessageBox.Show(ex.Message);<br/>
}<br/>
<br/>
<br/>
<br/>
writer.Write(data.sChunkID.ToCharArray());<br/>
writer.Write(data.dwChunkSize);<br/>
foreach (float dataPoint in data.Array)<br/>
writer.Write(dataPoint);<br/>
writer.Seek(4, SeekOrigin.Begin);<br/>
uint filesize = (uint)writer.BaseStream.Length;<br/>
writer.Write(filesize - 8);<br/>
writer.Close();<br/>
fileStream.Close();
............thts it...............but my wav file is giving any output......when i m trying to run it window media player giving error(player is unable to run or the header is corrupt)............vlc player is also not working.....................so plz
correct me and tell me where i m wrong................asap............
View the full article
i have used formatchunk like this....................
public struct Waveformat<br/>
{<br/>
public string sChunkID;<br/>
public uint dwChunkSize;<br/>
public ushort wFormatTag;<br/>
public ushort wChannels;<br/>
public uint dwSamplesPerSec;<br/>
public uint dwAvgBytesPerSec;<br/>
public ushort wBlockAlign;<br/>
public ushort wBitsPerSample;<br/>
public ushort wcbsize;<br/>
}<br/>
public class WaveFormatExtensible<br/>
{<br/>
public const ushort WAVE_FORMAT_EXTENSIBLE =65534;<br/>
public static Guid KSDATAFORMAT_SUBTYPE_PCM = new Guid("00000001-0000-0010-8000-00aa00389b71");<br/>
public static Guid KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = new Guid("00000003-0000-0010-8000-00aa00389b71");<br/>
public Waveformat Format; <br/>
public ushort wvalid;<br/>
public uint dwChannelMask;<br/>
public Guid SubFormat;<br/>
<br/>
public WaveFormatExtensible()<br/>
{<br/>
Format.sChunkID = "fmt ";<br/>
Format.dwChunkSize = 40;<br/>
Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;<br/>
Format.wChannels = 2;<br/>
Format.dwSamplesPerSec = 44100;<br/>
Format.wBitsPerSample = 32;<br/>
Format.wBlockAlign = (ushort)(Format.wChannels * (Format.wBitsPerSample / 8));<br/>
Format.dwAvgBytesPerSec = Format.dwSamplesPerSec * Format.wBlockAlign;<br/>
Format.wcbsize = 22;<br/>
wvalid = 32;<br/>
dwChannelMask = 3;<br/>
SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;<br/>
<br/>
i hope u all r getting this..............
and for printing i m using this code.................
public void Save(string filePath)<br/>
{<br/>
FileStream fileStream = new FileStream(filePath, FileMode.Create);<br/>
BinaryWriter writer = new BinaryWriter(fileStream);<br/>
try<br/>
{<br/>
writer.Write(header.sGroupID.ToCharArray());<br/>
writer.Write(header.dwFileLength);<br/>
writer.Write(header.sRiffType.ToCharArray());<br/>
writer.Write(Extensible.Format.sChunkID.ToCharArray());<br/>
writer.Write(Extensible.Format.dwChunkSize);<br/>
writer.Write(Extensible.Format.wFormatTag.ToString());<br/>
writer.Write(Extensible.Format.wChannels);<br/>
writer.Write(Extensible.Format.dwSamplesPerSec);<br/>
writer.Write(Extensible.Format.wBitsPerSample);<br/>
writer.Write(Extensible.Format.wBlockAlign);<br/>
writer.Write(Extensible.Format.dwAvgBytesPerSec);<br/>
writer.Write(Extensible.Format.wcbsize);<br/>
writer.Write(Extensible.wvalid);<br/>
writer.Write(Extensible.dwChannelMask);<br/>
byte[] guid = new byte[16];<br/>
guid = Extensible.SubFormat.ToByteArray();<br/>
writer.Write(guid, 0, guid.Length);<br/>
}<br/>
catch (Exception ex)<br/>
{<br/>
MessageBox.Show(ex.Message);<br/>
}<br/>
<br/>
<br/>
<br/>
writer.Write(data.sChunkID.ToCharArray());<br/>
writer.Write(data.dwChunkSize);<br/>
foreach (float dataPoint in data.Array)<br/>
writer.Write(dataPoint);<br/>
writer.Seek(4, SeekOrigin.Begin);<br/>
uint filesize = (uint)writer.BaseStream.Length;<br/>
writer.Write(filesize - 8);<br/>
writer.Close();<br/>
fileStream.Close();
............thts it...............but my wav file is giving any output......when i m trying to run it window media player giving error(player is unable to run or the header is corrupt)............vlc player is also not working.....................so plz
correct me and tell me where i m wrong................asap............
View the full article