Generating Waveforms Using Streaming
Streaming is a method of generating waveforms that are too large to fit in the onboard memory of the device. Streaming can be used in dynamic generation sessions.
To stream waveform data, you allocate and identify all or a portion of the device onboard memory to act as an onboard waveform for streaming. Before initiating generation, you fill that onboard memory with the first part of your waveform. As the waveform is generated, space in the onboard memory becomes free and you fill that space with new waveform data. You repeat the process of filling the freed onboard memory in blocks of new waveform data until the waveform is complete.
The following instructions are a guide for configuring your application for streaming.
As an example, we have a 1.6 GB waveform we want to generate and a device with 256 MB of onboard memory. This 1.6 GB waveform may be in the host memory, on disk, or data that your application generates on-the-fly during generation.
- Specify the amount of onboard memory used for streaming.
Use the niHSDIO Allocate Named Waveform VI or the niHSDIO_AllocateNamedWaveform function to specify the amount of onboard memory to reserve for streaming. This memory serves as a buffer for the streaming process. The niHSDIO Allocate Waveform VI/function returns a waveform handle.
- Identify the streaming waveform.
Set the Streaming Waveform Name property or the NIHSDIO_ATTR_STREAMING_WAVEFORM_NAME attribute to the waveform handle returned in Step 1. Setting this property ensures that no streaming data is overwritten before it is generated. NI-HSDIO monitors your progress to ensure that you write fresh data fast enough to keep up with the generation. If your application fails to keep up, or attempts to write fresh data on top of data that has not been generated, NI-HSDIO returns an error.
- Fill the streaming waveform with initial data.
Call the niHSDIO Write Named Waveform VI or the one of the Write Named Waveform functions to write the first part of the waveform data to the streaming waveform in onboard memory.
Tip When transferring large blocks of waveform data, break up the data into smaller blocks and call the niHSDIO Write Named Waveform VI or the one of the Write Named Waveform functions multiple times—the data is appended sequentially. A computer can allocate smaller blocks of a large waveform faster than allocating a single large contiguous block in memory. Depending on the amount of RAM on the computer, transferring ten 16 MB blocks can be faster than transferring one 160 MB block. - Begin generating the waveform.
Call the niHSDIO Init Generation Session VI or the niHSDIO_InitGenerationSession function to begin the waveform generation. As the waveform generates, space in the streaming waveform becomes free.
- As the waveform generates, monitor available memory.
Use the Space Available in Streaming Waveform property or the NIHSDIO_ATTR_SPACE_AVAILABLE_IN_STREAMING_WAVEFORM attribute to determine how much of the onboard waveform is free for writing new data. As the waveform generates, space becomes available to write more waveform data. Once a certain amount of the onboard memory becomes available, say 10 percent of the allocated onboard memory, you can write more of the waveform to the streaming waveform in onboard memory. In general, writing in larger blocks, such as 16 MB, results in more efficient streaming and faster streaming rates.
- Write a block of waveform data.
Call the niHSDIO Write Named Waveform VI or the one of the Write Named Waveform functions to write a new block of waveform data to the streaming waveform in onboard memory.
-
Repeat the process of monitoring the available memory and writing waveform data in blocks as free space becomes available.
Improving Streaming Performance
To improve your maximum sustainable transfer rate for streaming, consider the following:
- Adjust the Data Transfer Block Size property or the NIHSDIO_ATTR_DATA_TRANSFER_BLOCK_SIZE attribute to be closer to the waveform size. This change makes the data transfer is more efficient and is accomplished in a single transfer instead of four transfers.
- When streaming from hard drives, consider the hard drive speed for maximum sustainable rates. Laptop hard drives typically have a data transfer rate of 5 to 10 MB/s. Desktop hard drives often can meet or exceed 20 MB/s.
Transfer rates from hard drives can vary for a number of reasons. For example, where the data is physically stored on the hard drive and how much data is stored can affect transfer rates. Storing your waveform files on a fairly empty, defragmented hard drive may help increase performance.
- Consider using a RAID configuration to utilize striping to increase data transfer rates from disk.
- When using 18-slot PXI chassis, install the device used for streaming in the first segment, Slots 2 to 6, of the PXI chassis.
- Utilize Direct DMA.