Get the Parameters of an Audio Effect#
The number of channels in input/output audio are fixed for the Audio Effect and cannot be changed. Before running an audio effect, the input and output sample rates and number of channels supported by the effect must be queried.
The SDK also supports several frame sizes (number of samples per frame), which can be queried and set by using the set API. (For more information, see Set the Parameters of an Audio Effect.) The application can also query and use the default frame size supported by the SDK, as demonstrated in the following example.
Chained effects currently support only a 10ms frame size.
Note
Effect parameters (except for supported frame size list) can be queried only after the effect is loaded.
Querying parameters before model load might return invalid values or the function might fail with an error code.
To ensure that the sample rate of the input audio is compatible with the effect, query the sample rate first.
To query these parameters, call the NvAFX_GetU32() function with the following parameters:
Previously created effect handle.
The selector string for the parameter to be queried:
To get the default number of samples per input frame, specify
NVAFX_PARAM_NUM_SAMPLES_PER_INPUT_FRAME.To get the default number of samples per output frame per channel, specify
NVAFX_PARAM_NUM_SAMPLES_PER_OUTPUT_FRAME.The number of samples for each input frame and output frame is the same for all effects except Superresolution. In the Superresolution effect, output frames will contain more data than input frames.
To get the number of channels in input/output audio, specify
NVAFX_PARAM_NUM_INPUT_CHANNELS/NVAFX_PARAM_NUM_OUTPUT_CHANNELS.To get the sample rate for input/output audio, specify
NVAFX_PARAM_INPUT_SAMPLE_RATE/NVAFX_PARAM_OUTPUT_SAMPLE_RATE.For Voice Font, to get the length of the reference file needed, specify
NVAFX_PARAM_REFERENCE_NUM_SAMPLES_PER_INPUT_FRAME.
A pointer to the location where the value will be stored.
To query lists, the user must first query the list size and allocate memory for the output and then pass in the newly allocated memory and size to NvAFX_GetU32List().
To query the list size, call the NvAFX_GetU32List() function with the following parameters:
Previously created effect handle.
The selector string for the parameter to be queried.
To get the list of the number of supported samples per frame, specify
NVAFX_PARAM_SUPPORTED_NUM_SAMPLES_PER_FRAME.Input sample rate must be set before querying this list.
An output pointer, set to
nullptr(orNULL) to query size.A pointer to the location where the size of the list is to be stored. The size should be initialized to zero and will be updated with the actual size when this function is called.
The preceding NvAFX_GetU32List() call retrieves the size of the list for the corresponding parameter selector with an
NVAFX_STATUS_OUTPUT_BUFFER_TOO_SMALLerror status. To obtain the actual list values, allocate memory for the list with the returned size and call the NvAFX_GetU32List() function again with the following parameters:The selector string for the parameter to be queried. To get the list of supported number of samples per frame, specify
NVAFX_PARAM_SUPPORTED_NUM_SAMPLES_PER_FRAME.A pointer to a U32 array of size at least of the list size retrieved from the above call. The list values are written to this array.
A pointer to a location where the value of the size of the list is stored.
The VAD status for the last NvAFX_Run call can also be queried by using the NvAFX_GetBoolList() function. This query can be helpful when the audio output pipeline has an alternative packet loss concealment algorithm.
The following example queries an effect for the supported number of samples per frame, the number of channels in input/output audio, the sample rate, and the supported frame sizes:
NvAFX_Status err;
std::unique_ptr<unsigned int[]> supported_list = nullptr;
int list_size = 0;
// Query with list_size set to zero to get the actual list size
err = NvAFX_GetU32List(handle, NVAFX_PARAM_SUPPORTED_NUM_SAMPLES_PER_FRAME, supported_list.get(), &list_size);
if (err != NVAFX_STATUS_OUTPUT_BUFFER_TOO_SMALL) {
// This indicates API failure
return;
}
// Allocate memory based on the returned size, and query with this pointer
supported_list.reset(new unsigned int[list_size]);
err = NvAFX_GetU32List(handle,
NVAFX_PARAM_SUPPORTED_NUM_SAMPLES_PER_FRAME, supported_list.get(), &list_size);
// Load model
unsigned num_samples_per_frame, num_channels, sample_rate;
err = NvAFX_GetU32(handle, NVAFX_PARAM_NUM_SAMPLES_PER_INPUT_FRAME, &num_samples_per_frame);
err = NvAFX_GetU32(handle, NVAFX_PARAM_NUM_INPUT_CHANNELS, &num_channels);
err = NvAFX_GetU32(handle, NVAFX_PARAM_OUTPUT_SAMPLE_RATE, &sample_rate);
// Querying VAD results
// VAD must be supported and enabled on the handle
NvAFX_Run(...); // Process input first
// Query results for last input
// Note: If no voice is detected, output audio is zeroed by the effect
// However, result is also returned (in case custom packet loss concealment is desired).
// Returns NVAFX_TRUE if input audio had voice, NVAFX_FALSE otherwise
std::vector<NvAFX_Bool> out(num_streams, 0);
uint32_t s = out.size();
auto status = NvAFX_GetBoolList(handle, NVAFX_PARAM_VAD_RESULT, out.data(), &s);
assert(status == NVAFX_STATUS_SUCCESS);
// Use VAD result