Jump to content
  • 0
Alexey

WbtVRTFileReadIterator API and features

Question

I have a few questions regarding certain use-cases of reading data from a QVRT file:

  1. If I need to read a chunk of data in the middle of the file (for example from 10th second to 20th), there is the moveToTimeInSeconds method that will move the iterator to the starting position. But how do I know when to stop? Do I access the raw data with getCurrentPacketData and read the timestamp with help of the QVRT format spec? Or do I get it from getCurrentMetadataAsJSON - if so, what is the structure of returned JSON?
  2. How do I know how much data (IQ) packets does the file contain? Do I iterate over the whole file incrementing some counter when I see an IQ packet (VRT_IF_DATA)?
  3. How do I actually read the data? Is the following code snippet correct:
    WbtVRTFileReadIterator it("qvrtfile.qvrt");
    it.moveToTimeInSeconds(5);
    while(!it.isEndOfStream())
    {
        if(it.getCurrentPacketType() == 1) // VRT_IF_DATA
        {
            const int size = it.getCurrentSizeBytes();
            float *data = new float[size];
            it.getCurrentIQDataFloat(data, size);
            foobar(data, size);
            delete[] data;
        }
        ++it;
    }

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 1

1. Most sure way is to count samples and use your sample rate, for example, when processing data that has a span value of 25 MHz, 25,000,000 samples is one second. Sample count timestamp will get you this too. The JSON structure has wall clock time of your last context packet, so I would not rely on this for this purpose.

2. Yes, this is the only way at this time.

3.  Not too far off from this. I would make this adjustment to get the size more exact:

WbtVRTFileReadIterator it("qvrtfile.qvrt");
it.moveToTimeInSeconds(5);
while(!it.isEndOfStream())
{
    if(it.getCurrentPacketType() == 1) // VRT_IF_DATA
    {
        const int size = 65670; //995 samples per packet * 33 packets per chunk * 2 floats per sample

        float *data = new float[size];
        it.getCurrentIQDataFloat(data, size);
        foobar(data, size);
        delete[] data;
    }
    ++it;
}

 

Share this post


Link to post
Share on other sites
  • 1

Good question!

You are close. The QVRT format in the buffers has headers and footers interspersed, So for every 4000 bytes within the buffer chunk, you are going to have 20 bytes of headers and footers and 3980 bytes worth of samples.

The following will get you the amount of samples:

// divide by 4 bytes since the samples are stored as 2 16-bit numbers, then account for headers
samples += it.getCurrentSizeBytes() / 4 * 995 / 1000;

Share this post


Link to post
Share on other sites
  • 0

The WbtVRTFileReadIterator doesn't seem to work at all. It doesn't matter which filename is supplied to the constructor - "foobar" or "/data1/foobar.qvrt" - isValid() always returns false. If I still attempt to read the file then initially isEndOfStream is false, but after reading one packet (but not actually reading since getCurrentPacketType returns 0, which is not a valid packet type) isEndOfStream returns true and reading stops.

Also, attempting to use moveToStart() or moveToTimeInSeconds(int) results in "undefined reference" linking error.

The API version is 2.4.2.41.

Share this post


Link to post
Share on other sites
  • 0

We will definitely look into this and if there is a fix to be made (I anticipate there will be) we will get an updated beta build to you shortly (to replace the beta build you are using presently). Sorry for the inconvenience.

Share this post


Link to post
Share on other sites
  • 0

2. How do I know how much data (IQ) packets does the file contain? Do I iterate over the whole file incrementing some counter when I see an IQ packet (VRT_IF_DATA)?

2. Yes, this is the only way at this time.

How do I do that, without actually processing the data (without getCurrentIQDataFloat)? Is the following code correct:

WbtVRTFileReadIterator it("some_file", WbtCommon::Data::Radio_A);
int samples = 0;
while(!it.isEndOfStream())
{
    if(it.getCurrentPacketType() == VRT_IF_DATA)
    {
        // divide by 4 bytes since the samples are stored as 2 16-bit numbers
        samples += it.getCurrentSizeBytes() / 4;
    }
    ++it;
}
cout << "total samples" << samples;

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×