AudioScience HPI Version_4.24.1
|
The following figure describes the states an InStream uses. More...
Enumerations | |
enum | HPI_ISTREAM_MPEG_ANC_ALIGNS { HPI_MPEG_ANC_ALIGN_LEFT = 0, HPI_MPEG_ANC_ALIGN_RIGHT = 1 } |
Ancillary Data Alignment. More... | |
Functions | |
hpi_err_t | HPI_InStreamOpen (const hpi_hsubsys_t *phSubSys, uint16_t wAdapterIndex, uint16_t wInStreamIndex, hpi_handle_t *phInStream) |
Open and initializes an input stream. | |
hpi_err_t | HPI_InStreamClose (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Closes an input stream. | |
hpi_err_t | HPI_InStreamQueryFormat (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, const struct hpi_format *pFormat) |
Queries an input stream to see whether it supports a certain audio format, described in pFormat. | |
hpi_err_t | HPI_InStreamSetFormat (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, const struct hpi_format *pFormat) |
Sets the recording format for an input stream. | |
hpi_err_t | HPI_InStreamReadBuf (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint8_t *pbData, uint32_t dwBytesToRead) |
Read data from an InStream into a buffer Reads dwBytesToRead bytes of audio data from the specified InStream into a memory buffer pointed to by pbData. | |
hpi_err_t | HPI_InStreamStart (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Starts an input stream recording audio data. | |
hpi_err_t | HPI_InStreamWaitStart (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Get a stream ready for sync'd start across multiple adapters. | |
hpi_err_t | HPI_InStreamStop (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Stops an input stream recording audio data. | |
hpi_err_t | HPI_InStreamReset (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Clears the audio data buffer of an input stream. | |
hpi_err_t | HPI_InStreamGetInfoEx (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint16_t *pwState, uint32_t *pdwBufferSize, uint32_t *pdwDataRecorded, uint32_t *pdwSamplesRecorded, uint32_t *pdwAuxiliaryDataRecorded) |
Returns extended information about the input stream. | |
hpi_err_t | HPI_InStreamAncillaryReset (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint16_t wBytesPerFrame, uint16_t wMode, uint16_t wAlignment, uint16_t wIdleBit) |
Initializes the MPEG Layer II / III Ancillary data channel. | |
hpi_err_t | HPI_InStreamAncillaryGetInfo (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint32_t *pdwFrameSpace) |
Returns information about the ancillary data stream. | |
hpi_err_t | HPI_InStreamAncillaryWrite (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, const struct hpi_anc_frame *pAncFrameBuffer, uint32_t dwAncFrameBufferSizeInBytes, uint32_t dwNumberOfAncillaryFramesToWrite) |
Writes frames to the stream's ancillary data buffer. | |
hpi_err_t | HPI_InStreamHostBufferAllocate (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint32_t dwSizeInBytes) |
Allocates a buffer on the host PC for bus mastering transfers. | |
hpi_err_t | HPI_InStreamHostBufferFree (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Free any buffers allocated by HPI_InStreamHostBufferAllocate. | |
hpi_err_t | HPI_InStreamGroupAdd (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, hpi_handle_t hStream) |
This function adds a stream to a group of streams. | |
hpi_err_t | HPI_InStreamGroupGetMap (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint32_t *pdwOutStreamMap, uint32_t *pdwInStreamMap) |
This function returns information about the streams that form a group. | |
hpi_err_t | HPI_InStreamGroupReset (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream) |
Resets stream grouping information for a given InStream. | |
hpi_err_t | HPI_InStreamWait (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint32_t dwThresholdBytes) |
Returns when the input stream hits the threshold. | |
hpi_err_t | HPI_InStreamGetTimestamp (const hpi_hsubsys_t *phSubSys, hpi_handle_t hInStream, uint32_t *pdwSample, uint32_t *pdwNanosPerSample, int64_t *pqwTimestamp) |
Returns the timestamp from the last stream update. |
The following figure describes the states an InStream uses.
hpi_err_t HPI_InStreamOpen | ( | const hpi_hsubsys_t * | phSubSys, |
uint16_t | wAdapterIndex, | ||
uint16_t | wInStreamIndex, | ||
hpi_handle_t * | phInStream | ||
) |
Open and initializes an input stream.
An Adapter index and InStream index are passed in and an InStream handle is passed back. The handle is used for all future calls to that InStream. A particular input stream may only be open by one application at a time.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
wAdapterIndex | Index of adapter to be accessed. Ranges from 0 to 15 and corresponds to the Adapter Index set on the adapter hardware. |
wInStreamIndex | Index of the InStream to be opened. Ranges from 0 to wNumInStreams-1 (returned by HPI_AdapterGetInfo()) |
phInStream | Returned handle to the opened InStream. |
References HPI_IndexesToHandle().
hpi_err_t HPI_InStreamClose | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Closes an input stream.
Deallocates allocated host buffer.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to the InStream to close. |
hpi_err_t HPI_InStreamQueryFormat | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
const struct hpi_format * | pFormat | ||
) |
Queries an input stream to see whether it supports a certain audio format, described in pFormat.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
pFormat | Pointer to an struct hpi_format structure containing info about the audio format to query. |
hpi_err_t HPI_InStreamSetFormat | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
const struct hpi_format * | pFormat | ||
) |
Sets the recording format for an input stream.
The format to set is described by pFormat.
For example, to set an InStream to stereo, MPEG Layer II @ 256kbps, 44.1kHz sample rate:
err = HPI_FormatCreate( &hpiFormat, 2, // stereo channel HPI_FORMAT_MPEG_L2,// compression format 44100, // sample rate 256000, // bits/sec (only used for MPEG) 0 // currently no attributes ); err = HPI_InStreamSetFormat( phSubSys, hInStream, &hpiFormat );
MP3 Variable Bitrate
On adapters that support MP3 encoding, a quality factor between 0 and 100 controls variable bitrate encoding. The quality factor replaces the bitrate in the dwBitrate parameter of HPI_FormatCreate(). Setting the "bitrate" to 100 or less automatically activates variable bitrate encoding.
err = HPI_FormatCreate( &hpiFormat, 2, // stereo channel HPI_FORMAT_MPEG_L2, // compression format 44100, // sample rate 75, // VBR quality setting 0 // currently no attributes );
InStream interaction with Bitstream
Where an instream HPI_DESTNODE_ISTREAM is connected to a bitstream input HPI_SOURCENODE_RAW_BITSTREAM, the bitstream input provides an unformatted stream of data bits. How this data is treated is affected by the format chosen when HPI_InStreamSetFormat() is called. There are two valid choices:
(1) HPI_FORMAT_RAW_BITSTREAM
The raw bits are copied into the stream without synchronization. The value returned by HPI_InStreamGetInfoEx() into *pdwSamplesRecorded is the number of 32 bit words of data recorded.
(2) HPI_FORMAT_MPEG_L2 After the InStream has been reset the incoming bitstream is scanned for the MPEG2 Layer 2 sync pattern (0xFFFE or 0xFFFC), and input (recording) of the bitstream data is inhibited until this pattern is found. The first word of recorded or monitored data will be this sync pattern, and following data will be word-aligned to it.
This synchronization process only takes place once after stream reset. There is a small chance that the sync pattern appears elsewhere in the data and the mpeg sync in recorded data won't be byte aligned.
The value returned by HPI_InStreamGetInfoEx() into *pdwSamplesRecorded is calculated from the number of bits recorded using the values for dwBitRate and dwSampleRate set by HPI_InStreamSetFormat().
samples = bits recorded * dwSampleRate / dwBitRate
If the samplerate is 44.1kHz, then the samplecount will not be exact.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
pFormat | Format to set, created using HPI_FormatCreate(). |
hpi_err_t HPI_InStreamReadBuf | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint8_t * | pbData, | ||
uint32_t | dwBytesToRead | ||
) |
Read data from an InStream into a buffer Reads dwBytesToRead bytes of audio data from the specified InStream into a memory buffer pointed to by pbData.
The amount of data requested may be any size up to the amount of data available in the hardware buffer specified by dwDataAvailable returned by HPI_InStreamGetInfoEx().
HPI_ERROR_INVALID_DATASIZE | if trying to read more data than available. |
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
pbData | Pointer to buffer for read data. |
dwBytesToRead | Number of bytes to read, must be <= number available. |
hpi_err_t HPI_InStreamStart | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Starts an input stream recording audio data.
Audio data is written into the adapters hardware buffer using the currently selected audio format (channels, sample rate, compression format etc.). Data is then read from the buffer using HPI_InStreamRead().
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle |
hpi_err_t HPI_InStreamWaitStart | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Get a stream ready for sync'd start across multiple adapters.
Only audio adapters with an inter-card sync header support this function. Streams on each adapter should be called with this function. Then streams on each adapater should be called using HPI_InStreamStart() to begin recording. This function supports grouped streams.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle |
hpi_err_t HPI_InStreamStop | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Stops an input stream recording audio data.
The audio data buffers is not cleared, so a subsequent InStreamStart will resume recording at the position in the buffer where the record had been stopped.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
hpi_err_t HPI_InStreamReset | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Clears the audio data buffer of an input stream.
If the stream was recording at the time, it will be stopped.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
hpi_err_t HPI_InStreamGetInfoEx | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint16_t * | pwState, | ||
uint32_t * | pdwBufferSize, | ||
uint32_t * | pdwDataRecorded, | ||
uint32_t * | pdwSamplesRecorded, | ||
uint32_t * | pdwAuxiliaryDataRecorded | ||
) |
Returns extended information about the input stream.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle. |
pwState | State of stream = HPI_STATE_STOPPED or HPI_STATE_RECORDING. |
pdwBufferSize | Size in bytes of stream data buffer. |
pdwSamplesRecorded | The SamplesRecorded parameter returns the number of samples recorded since the last HPI_InStreamReset() command was issued. It reflects the number of stereo samples for a stereo stream and the number of mono samples for a mono stream. This means that if a 44.1kHz stereo and mono stream were both recording they would both return SamplesRecorded=44100 after 1 second. |
pdwDataRecorded | DataRecorded returns the amount of data available to be read back in the next HPI_InStreamRead() call. When BBM is active this is the data in the host buffer, otherwise it is the amount in the on-card buffer. |
pdwAuxiliaryDataRecorded | AuxiliaryDataRecorded is only valid when BBM is being used (see HPI_InStreamHostBufferAllocate()). In BBM mode it returns the amount of data left in the on-card buffers. This can be used to determine if a record overrun has occurred (both BBM and card buffers full), or at the end of recording to ensure that all recorded data has been read. |
hpi_err_t HPI_InStreamAncillaryReset | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint16_t | wBytesPerFrame, | ||
uint16_t | wMode, | ||
uint16_t | wAlignment, | ||
uint16_t | wIdleBit | ||
) |
Initializes the MPEG Layer II / III Ancillary data channel.
Initializes the MPEG Layer II / III Ancillary data channel to support the embedding of wBytesPerFrame bytes into the MPEG bitstream.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle for InStream. |
wBytesPerFrame | Specifies the rate at which data is inserted into the Ancillary data channel. Note that when (wMode== HPI_MPEG_ANC_HASENERGY, see below) an additional 5 bytes per frame are automatically allocated for energy information. |
wMode | One of the HPI_MPEG_ANC_MODES. The mode for the ancillary data extraction to operate in. Valid settings are HPI_MPEG_ANC_RAW and HPI_MPEG_ANC_HASENERGY. The RAW mode indicates that the entire ancillary data field is taken up by data from the Anc data buffer. The HASENERGY option tells the encoder that the MPEG frames have energy information stored in them (5 bytes per stereo frame, 3 per mono). The encoder will insert the energy bytes before filling the remainder of the ancillary data space with data from the ancillary data buffer. |
wAlignment | One of the HPI_ISTREAM_MPEG_ANC_ALIGNS. HPI_MPEG_ANC_ALIGN_LEFT the wBytesPerFrame data immediately follow the audio data. Spare space is left at the end of the frame. HPI_MPEG_ANC_ALIGN_RIGHT the wBytesPerFrame data is packed against the end of the frame. Spare space is left at the start of the frame. HPI_MPEG_ANC_ALIGN_FILL all ancillary data space in the frame is used. wBytesPerFrame or more data is written per frame. There is no spare space. This parameter is ignored for MP3 encoding, effectively it is fixed at HPI_MPEG_ANC_ALIGN_FILL (See Note 2) |
wIdleBit | This field tells the encoder what to set all the bits of the ancillary data field to in the case where there is no data waiting to be inserted. Valid values are 0 or 1. This parameter is ignored for MP3 encoding, if no data is available, no data will be inserted (See Note 2) |
See the below table for the relationship between wBytesPerFrame and the datarate on the ancillary data channel. For stereo recording, ancillary data is organized as follows:
Sample rate | Frame rate | Energy rate | Bitrate per byte on ancillary data |
48 kHz | 41.66 frames/sec | 1333.33 bits/sec | 1333.33 bits/sec |
44.1 kHz | 38.28 frames/sec | 1224.96 bits/sec | 306.25 bits/sec |
32 kHz | 27.77 frames/sec | 888.89 bits/sec | 222.22 bits/sec |
Ancillary data is embedded at the end of each MPEG frame as follows:
Key: e = ancillary energy bits (correct number of bits not shown) d = ancillary data bits a = audio bits f = fill bits x = don't care bits\n HPI_MPEG_ANC_ALIGN_LEFT (fill is at end for "raw" case) wMode = HPI_MPEG_ANC_RAW a,a,a,d,d,d,d,d,d,f,f,f <eof> wMode = HPI_MPEG_ANC_HASENERGY a,a,a,d,d,d,d,..,f,f,f,e,e,e,e <eof> HPI_MPEG_ANC_ALIGN_RIGHT (fill is at front) wMode = HPI_MPEG_ANC_RAW a,a,a,f,f,f,d,d,d,d,d,d<eof> wMode = HPI_MPEG_ANC_HASENERGY a,a,a,f,f,f,d,d,d,d,..,e,e,e,e <eof> HPI_MPEG_ANC_ALIGN_FILL (all available ancillary data spots are used) wMode = HPI_MPEG_ANC_RAW a,a,a,d,d,d,d,d,d,d,d,d<eof> wMode = HPI_MPEG_ANC_HASENERGY a,a,a,d,d,d,d,d,d,d,..,e,e,e,e <eof>
Note1 (Calling order):
This call must be made before an HPI_InStreamSetFormat() call.
Note2 (MP3):
Embedded energy information in an MPEG1 layer III (MP3) stream is quite difficult to utilize because its position is not constant within the MPEG frame. With MP2, the ancillary data field always appears at the end of the MPEG frame. The parameters wIdleBit and wAlignment are ignored for MP3 due to the inherently more efficient data packing scheme used.
Note3 (Default settings):
A side effect of HPI_InStreamOpen() is that the following default ancillary data settings are made:
Ancillary Bytes Per Frame = 0
Ancillary Mode = HPI_MPEG_ANC_HASENERGY
Ancillary Alignment = HPI_MPEG_ANC_ALIGN_RIGHT
hpi_err_t HPI_InStreamAncillaryGetInfo | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint32_t * | pdwFrameSpace | ||
) |
Returns information about the ancillary data stream.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to the InStream. |
pdwFrameSpace | Maximum number of ancillary data frames that can be written to the anc frame buffer. |
hpi_err_t HPI_InStreamAncillaryWrite | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
const struct hpi_anc_frame * | pAncFrameBuffer, | ||
uint32_t | dwAncFrameBufferSizeInBytes, | ||
uint32_t | dwNumberOfAncillaryFramesToWrite | ||
) |
Writes frames to the stream's ancillary data buffer.
Writes dwNumberOfAncDataFramesToWrite frames from pAncFrameBuffer to the streams ancillary data buffer. The first bit of ancillary information that follows the valid audio data is bit 7 of bData[0]. The first 8 bits of ancillary information following valid audio data are from bData[0]. In the case where there are 6 bytes total of ancillary information (48 bits) the last byte inserted in the frame is bData[5].
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to the InStream. |
pAncFrameBuffer | A pointer to a buffer where the ancillary data frames to write should be placed. |
dwAncFrameBufferSizeInBytes | The size of the Ancillary data buffer in bytes (used for a sanity check). |
dwNumberOfAncillaryFramesToWrite | How many frames to write. |
References HPI_ERROR_INVALID_DATASIZE.
hpi_err_t HPI_InStreamHostBufferAllocate | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint32_t | dwSizeInBytes | ||
) |
Allocates a buffer on the host PC for bus mastering transfers.
Assuming no error: Allocates a buffer on the host PC for bus mastering transfers. Once the buffer is allocated, InStream data will be transferred to it in the background. (rather than the application having to wait for the transfer) This function is provided so that the application can match the size of its transfers to the size of the buffer.
From now on, HPI_InStreamGetInfoEx() will return the size and data available in host buffer rather than the buffers on the adapter. However, if the host buffer is allowed to fill up, the adapter buffers will then begin to fill up. In other words you still have the benefit of the larger adapter buffers
HPI_ERROR_INVALID_DATASIZE | memory can't be allocated (retrying the call with a smaller size may succeed) |
HPI_ERROR_MEMORY_ALLOC | virtual address of the allocated buffer can't be found. |
HPI_ERROR_INVALID_FUNC | the adapter doesn't support busmastering |
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle of the InStream. |
dwSizeInBytes | Size of bus mastering buffer to allocate. |
hpi_err_t HPI_InStreamHostBufferFree | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Free any buffers allocated by HPI_InStreamHostBufferAllocate.
HPI_ERROR_INVALID_FUNC | if the function is not implemented |
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle of the InStream. |
hpi_err_t HPI_InStreamGroupAdd | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
hpi_handle_t | hStream | ||
) |
This function adds a stream to a group of streams.
Stream groups are used to synchronise starting and stopping of multiple streams at once. The application of this is to support recording (or playing) multiple streams at once, enabling multi-channel recording and playback.
When using the "Group" functions all streams that are to be grouped together should be opened. One of the streams should be selected to be the master stream and the other streams should be added to it's group. Both in streams and out streams can be added to the same group. Once a group has been formed, HPI_InStreamStart() called on the master will cause all streams to start at once.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to InStream. |
hStream | Handle to an InStream or an OutStream. |
References HPI_ERROR_INVALID_OBJ, and HPI_ERROR_NO_INTERADAPTER_GROUPS.
hpi_err_t HPI_InStreamGroupGetMap | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint32_t * | pdwOutStreamMap, | ||
uint32_t * | pdwInStreamMap | ||
) |
This function returns information about the streams that form a group.
Given an out stream handle, it returns a bit mapped representation of which streams belong to the group.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to InStream. |
pdwOutStreamMap | Bitmapped representation of OutStreams grouped with this output stream. b0 represents OutStream 0, b1 OutStream 1, b2 OutStream 2 etc. |
pdwInStreamMap | Bitmapped representation of InStreams grouped with this output stream. b0 represents InStream 0, b1 InStream 1, b2 InStream 2 etc. |
hpi_err_t HPI_InStreamGroupReset | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream | ||
) |
Resets stream grouping information for a given InStream.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | Handle to InStream. |
hpi_err_t HPI_InStreamWait | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint32_t | dwThresholdBytes | ||
) |
Returns when the input stream hits the threshold.
This function will block in the driver until the count of bytes in the record stream's BBM buffer meets or exceeds the specified threshold. This should be called from a background thread.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle |
dwThresholdBytes | Threshold |
hpi_err_t HPI_InStreamGetTimestamp | ( | const hpi_hsubsys_t * | phSubSys, |
hpi_handle_t | hInStream, | ||
uint32_t * | pdwSample, | ||
uint32_t * | pdwNanosPerSample, | ||
int64_t * | pqwTimestamp | ||
) |
Returns the timestamp from the last stream update.
phSubSys | Vestigial subsys handle (unused), may be set to NULL |
hInStream | InStream handle |
pdwSample | Sample |
pdwNanosPerSample | Nanoseconds Per Sample |
pqwTimestamp | Timestamp |