JXI C# DSP-Core Library 向量文件

本文档详细介绍了C# DSP-Core Library中针对向量文件的各种操作,包括Open、Seek、Read和Write等方法,以及FixFreqFrame、FixFreqStream的读写示例。同时展示了如何读写INI文件和查看Spectrum数据,提供了丰富的界面和核心代码示例。
摘要由CSDN通过智能技术生成

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();
}

FixFreqStream Read Complex

界面

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值