using System;
using System.Runtime.InteropServices;
namespace NAudio.Wave
{
///
/// MP3 WaveFormat, MPEGLAYER3WAVEFORMAT from mmreg.h
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
public class Mp3WaveFormat : WaveFormat
{
///
/// Wave format ID (wID)
///
public Mp3WaveFormatId id;
///
/// Padding flags (fdwFlags)
///
public Mp3WaveFormatFlags flags;
///
/// Block Size (nBlockSize)
///
public ushort blockSize;
///
/// Frames per block (nFramesPerBlock)
///
public ushort framesPerBlock;
///
/// Codec Delay (nCodecDelay)
///
public ushort codecDelay;
private const short Mp3WaveFormatExtraBytes = 12; // MPEGLAYER3_WFX_EXTRA_BYTES
///
/// Creates a new MP3 WaveFormat
///
public Mp3WaveFormat(int sampleRate, int channels, int blockSize, int bitRate)
{
waveFormatTag = WaveFormatEncoding.MpegLayer3;
this.channels = (short)channels;
this.averageBytesPerSecond = bitRate / 8;
this.bitsPerSample = 0; // must be zero
this.blockAlign = 1; // must be 1
this.sampleRate = sampleRate;
this.extraSize = Mp3WaveFormatExtraBytes;
this.id = Mp3WaveFormatId.Mpeg;
this.flags = Mp3WaveFormatFlags.PaddingIso;
this.blockSize = (ushort)blockSize;
this.framesPerBlock = 1;
this.codecDelay = 0;
}
}
///
/// Wave Format Padding Flags
///
[Flags]
public enum Mp3WaveFormatFlags
{
///
/// MPEGLAYER3_FLAG_PADDING_ISO
///
PaddingIso = 0,
///
/// MPEGLAYER3_FLAG_PADDING_ON
///
PaddingOn = 1,
///
/// MPEGLAYER3_FLAG_PADDING_OFF
///
PaddingOff = 2,
}
///
/// Wave Format ID
///
public enum Mp3WaveFormatId : ushort
{
/// MPEGLAYER3_ID_UNKNOWN
Unknown = 0,
/// MPEGLAYER3_ID_MPEG
Mpeg = 1,
/// MPEGLAYER3_ID_CONSTANTFRAMESIZE
ConstantFrameSize = 2
}
}