C# DSP-Core Library Vector File
Feb-9-2022
功能
- 位置:Vector File Library
- 方法
- Open
- Seek
- Read (6种重载)
- Write (5种重载)
- Close
- 类库公开方法
/// <summary>
/// 打开或创建文件。
/// </summary>
/// <param name="filePath"></param>
/// <param name="mode"></param>
/// <param name="fileAccess"></param>
/// <param name="disableBuffering">Specifies whether the file will read/write without buffering.
/// Disable buffering willl speed up data transfers but require read/write block size to be integer multiple of disk sector size.</param>
public virtual void Open(string filePath, FileMode mode, FileAccess fileAccess, bool disableBuffering = false)
/// <summary>
/// Set the current read-write location of the file to a given value.
/// </summary>
/// <param name="offset">The number of frames relative to origin. 。</param>
/// <param name="origin">Using a value of type System.IO.SeekOrigin, the start, end, or current position is specified as a reference point for offset.</param>
/// <returns>The new location of the file read and write, the number of frames away from the starting point of the data, that is, the value of the attribute "Position". 。</returns>
public long Seek(long offset, SeekOrigin origin)
/// <summary>
/// Write data information to file header, could be called after writing data.
/// After the operation, file pointer will be set to the beginning of data (value of property "Position" is 0 after operation).
/// In creating new file use case, it must be called once before writing first block data.
/// </summary>
public virtual void WriteFileHeader()
/// <summary>
/// 写入I8类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Write(sbyte[] data)
/// <summary>
/// 写入I16类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Write(short[] data)
/// <summary>
/// 写入Float32类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Write(float[] data)
/// <summary>
/// 写入double64类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Write(double[] data)
/// <summary>
/// 以IntPtr写入数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
/// <param name="lengthInBytes">数据长度,字节数。</param>
public virtual void Write(IntPtr data, int lengthInBytes)
/// <summary>
/// 读出I8类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Read(sbyte[] data)
/// <summary>
/// 读出I16类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Read(short[] data)
/// <summary>
/// 读出Float32类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Read(float[] data)
/// <summary>
/// 读出Double64类型数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
public virtual void Read(double[] data)
/// <summary>
/// 以IntPtr读出数据,若为多通道,则data中的数据为Channel Interleave(通道交织)存放。
/// </summary>
/// <param name="data"></param>
/// <param name="lengthInBytes">数据长度,字节数。</param>
public virtual void Read(IntPtr data, int lengthInBytes)
/// <summary>
/// 关闭当前文件并释放与之关联的所有资源(如文件句柄)。
/// </summary>
public void Close()
Example 范例
FixFreqFrame Read Complex
界面
核心代码
/// <summary>
/// 在文件的当前位置读取IQ数据,计算频谱并显示。
/// </summary>
private void ReadDataAndDisplay()
{
// 在当前位置读取IQ数据,若“当前位置 + 读取长度”已超出文件长度,则先将“当前读取位置”向前移动。
if (_iqFrameFile.Position + 1 > _iqFrameFile.NumberOfFrames) {
_iqFrameFile.Seek(-1, SeekOrigin.End); }
// 读取数据。
_iqFrameFile.Read(_shortIQAllChannels);
}
FixFreqFrame Write Complex
界面
核心代码
// 实例化FixFrameFile对象,创建文件。
vectorFile = new FixFrequencyFrameFile();
vectorFile.Open(filePath, FileMode.Create, FileAccess.Write, false);
// 写入数据。
for (int indexOfFrame = 0; indexOfFrame < numOfFrames; indexOfFrame++)
{
// 写入文件。
vectorFile.Write(shortSineAllChannels);
// 更新进度,并检查用户是否取消了操作。
bgWorker.ReportProgress((int)((indexOfFrame + 1) / (float)numOfFrames * 100));
if (bgWorker.CancellationPending == true) {
e.Cancel = true; break; }
}
finally
{
// 总是关闭文件。
vectorFile?.Close();
}