Examples.
#include "ModuleList.h"
#include <errno.h>
#include <math.h>
#include <float.h>
#include <stdlib.h>
#define true 1
#define false 0
#include "passthrough_InitAWB.h"
#include "passthrough_ControlInterface.h"
const char inFilename[] = "../Audio/in_s32_stereo.raw";
const char outFilename[] = "../Audio/out_s32_stereo.raw";
const char awbFilename[] = "../Designs/passthrough.awb";
INT32 * inputBuffer, * outputBuffer;
FILE *fin;
FILE *fout;
static const void* moduleDescriptorTable[] =
{
LISTOFCLASSOBJECTS
};
UINT32 moduleDescriptorTableSize = sizeof(moduleDescriptorTable) / sizeof(moduleDescriptorTable[0]);
int isNearlyEqual(float a, float b, float epsilon)
{
float absA = fabsf(a);
float absB = fabsf(b);
float diff = fabsf(a - b);
if (a == b) {
return 1;
} else if (a == 0 || b == 0 || diff < FLT_MIN) {
return diff < (epsilon * FLT_MIN);
} else {
if ((absA + absB) < FLT_MAX)
{
return diff / (absA + absB) < epsilon;
}
else
{
return diff / FLT_MAX < epsilon;
}
}
}
void destroyExample()
{
INT32 ret;
fclose(fin);
fclose(fout);
free(inputBuffer);
free(outputBuffer);
inputBuffer = NULL;
outputBuffer = NULL;
{
}
}
int main()
{
#define FASTHEAP_A_SIZE 420000
static UINT32 fastHeapA[FASTHEAP_A_SIZE];
#define FASTHEAP_B_SIZE 420000
static UINT32 fastHeapB[FASTHEAP_B_SIZE];
#define SLOWHEAP_SIZE 420000
static UINT32 slowHeap[SLOWHEAP_SIZE];
INT32 ret;
ret =
aweOS_init(&g_AWEOSInstance, &configParams, moduleDescriptorTable, moduleDescriptorTableSize);
{
printf("aweOS Initialised \n");
}
else
{
printf(
"aweOS init failed. exiting application with error = %d %s\n", ret,
aweOS_errorToString(ret));
exit(1);
}
UINT32 position=0;
{
printf("Loaded layout loaded from file %s\n", awbFilename);
}
else
{
{
printf(
"Layout %s load unsuccessful with Error = %d %s \n", awbFilename, ret,
aweOS_errorToString(ret));
}
else
{
printf(
"Layout %s load unsuccessful in the positions %u with Error = %d %s \n", awbFilename, position, ret,
aweOS_errorToString(ret));
}
exit(1);
}
if (1 != ret)
{
exit(1);
}
if (1 != ret)
{
exit(1);
}
UINT32 layoutInChannels, layoutOutChannels, layoutBlockSize;
FLOAT32 SR;
{
exit(1);
}
{
exit(1);
}
{
exit(1);
}
printf("Layout loaded with inputChannels=%u, outputChannels=%u, blockSize=%u, SR=%f\n", layoutInChannels, layoutOutChannels, layoutBlockSize, SR);
UINT32 inSize, outSize;
const INT32 inputChannels = 2;
const INT32 outputChannels = 2;
inSize = inputChannels * layoutBlockSize;
outSize = outputChannels * layoutBlockSize;
inputBuffer = malloc(inSize * sizeof(INT32));
outputBuffer = malloc(outSize * sizeof(INT32));
fin = fopen(inFilename, "rb");
if (NULL == fin )
{
printf("Error opening input file %s\n", inFilename);
printf("Error %d \n", errno);
exit(1);
}
else
{
printf("Opening input file %s\n", inFilename);
}
fout = fopen(outFilename, "wb");
if (NULL == fout)
{
printf("Error opening input file %s\n", outFilename);
printf("Error %d \n", errno);
exit(1);
}
else
{
printf("Opening output file %s\n", outFilename);
}
float scaler1Gain;
float scaler1TargetGain;
float meter1Values[AWE_Meter1_value_SIZE];
long count = 0;
int numSamplesRead = 0;
UINT32 classId;
{
if (AWE_Scaler1_classID != classId )
{
printf("Error: Scaler1 module not found in layout (%u)\n", AWE_Scaler1_classID );
exit(1);
}
}
else
{
}
{
if (AWE_Meter1_classID != classId)
{
printf("Error: Meter module not found in layout (%u)\n",AWE_Meter1_classID);
exit(1);
}
}
else
{
}
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Scaler1_gain_HANDLE, &scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
{
printf("\nGetValue: Default scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
}
else
{
}
scaler1Gain = -10.0;
ret =
aweOS_ctrlSetValue(g_AWEOSInstance, AWE_Scaler1_gain_HANDLE, (
void *)&scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
{
printf("SetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
}
else
{
}
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Scaler1_gain_HANDLE, &scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
{
printf("GetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
}
else
{
}
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Scaler1_targetGain_HANDLE, &scaler1TargetGain, 0, AWE_Scaler1_targetGain_SIZE);
{
printf("GetValue: scalerTarget1Gain = %f, error = %d\n", scaler1TargetGain, ret);
}
else
{
}
printf("\nStarting to process [%s] into [%s]\n\n", inFilename, outFilename);
while ((numSamplesRead = fread(inputBuffer, sizeof(int), inSize, fin)) > 0)
{
INT32 i, j;
INT32 numOutFrames;
for (i = 0; i < inputChannels; i++)
{
{
printf(
"Error: aweOS_audioImportSamples() failed: error = %d %s exiting application\n", ret,
aweOS_errorToString(ret));
exit(1);
}
}
for (i = 0; i < outputChannels; i++)
{
{
printf(
"Error: aweOS_audioExportSamples() failed: error = %d %s exiting application\n", ret,
aweOS_errorToString(ret));
exit(1);
}
}
count++;
if (1024 == count)
{
count = 0;
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Meter1_value_HANDLE, &meter1Values, 0, AWE_Meter1_value_SIZE);
{
printf("GetValue: meter1Value = %f, error = %d\n", meter1Values[0], ret);
}
else
{
}
}
fwrite(outputBuffer, sizeof(int), outSize, fout);
#define EPSILON 0.1f
numOutFrames = numSamplesRead / outputChannels;
for (j = 0; j < numOutFrames; j++)
{
float expectedValueChannel1 = powf(10.0, scaler1Gain / 20.0) * (float)inputBuffer[inputChannels * j];
float expectedValueChannel2 = (float)inputBuffer[inputChannels * j + 1];
if (isNearlyEqual(expectedValueChannel1, (float)outputBuffer[outputChannels * j], EPSILON) == 0)
{
printf("Verification error. Expected %f on channel 1 but got %f, sample %d\n", expectedValueChannel1,
(float)outputBuffer[outputChannels * j], j);
destroyExample();
exit(1);
}
if (isNearlyEqual(expectedValueChannel2, (float)outputBuffer[outputChannels * j + 1], EPSILON) == 0)
{
printf("Verification error. Expected %f on channel 2 but got %f\n, sample %d\n", expectedValueChannel2,
(float)outputBuffer[outputChannels * j + 1], j);
destroyExample();
exit(1);
}
}
}
printf("\n");
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Scaler1_gain_HANDLE, &scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
{
printf("GetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
}
else
{
}
ret =
aweOS_ctrlGetValue(g_AWEOSInstance, AWE_Scaler1_targetGain_HANDLE, &scaler1TargetGain, 0, AWE_Scaler1_targetGain_SIZE);
{
printf("GetValue: scalerTarget1Gain = %f, error = %d\n", scaler1TargetGain, ret);
}
else
{
}
UINT32 avgCycles;
printf("Processed %ld audio frames -- average cycles per pump = %u\n", count, avgCycles);
destroyExample();
return 0;
}
The AWE Core OS API header file.
#define E_CANTOPEN
Can't open the specified file.
Definition: Errors.h:157
#define E_NOSUCHFILE
The specified file does not exist.
Definition: Errors.h:160
#define E_SUCCESS
OK result.
Definition: Errors.h:31
@ Sample32bit
Data is 32 bit PCM .
Definition: StandardDefs.h:231
void AWEOSInstance
The AWE Core OS Instance instance type.
Definition: AWECoreOS.h:103
INT32 aweOS_ctrlGetValue(const AWEOSInstance *pAWEOS, UINT32 handle, void *value, INT32 arrayOffset, UINT32 length)
Get a scalar or array value(s) of a module parameter by handle.
INT32 aweOS_ctrlGetModuleClass(const AWEOSInstance *pAWEOS, UINT32 handle, UINT32 *pClassID)
Get a module's object class from its handle.
INT32 aweOS_layoutGetSampleRate(const AWEOSInstance *pAWEOS, FLOAT32 *sampleRate)
Returns the sample rate of the loaded layout.
INT32 aweOS_audioExportSamples(AWEOSInstance *pAWEOS, void *outSamples, INT32 outStride, INT32 channel, SampleType outType)
Export samples to a user buffer from a specific channel of the AWEOSInstance's output pin.
INT32 aweOS_audioPumpAll(AWEOSInstance *pAWEOS)
Pump one fundamental block size of audio through the loaded layout and all of its sublayouts.
INT32 aweOS_audioIsStarted(const AWEOSInstance *pAWEOS)
Check if this instance has received an Audio Start command.
INT32 aweOS_init(AWEOSInstance **pAWEOS, const AWEOSConfigParameters *aweParams, const void *pModuleDescriptorTable, UINT32 moduleDescriptorTableSize)
Initialize the AWEOSInstance with the specified configuration parameters.
INT32 aweOS_layoutGetBlockSize(const AWEOSInstance *pAWEOS, UINT32 *blockSize)
Returns the block size of the loaded layout.
INT32 aweOS_layoutIsValid(const AWEOSInstance *pAWEOS)
Determines if a layout is loaded and valid.
INT32 aweOS_layoutGetChannelCount(const AWEOSInstance *pAWEOS, UINT32 *inCount, UINT32 *outCount)
Returns the number of input and output channels in the loaded layout.
INT32 aweOS_ctrlSetValue(const AWEOSInstance *pAWEOS, UINT32 handle, void *value, INT32 arrayOffset, UINT32 length)
Set a scalar or array value(s) of a module parameter by handle.
INT32 aweOS_destroy(AWEOSInstance **pAWEOS)
Destroys the AWEOSInstance and closes all associated threads.
const char * aweOS_errorToString(INT32 errorCode)
Convert an error code (INT32) to its corresponding error string.
INT32 aweOS_audioImportSamples(AWEOSInstance *pAWEOS, void *inSamples, INT32 inStride, INT32 channel, SampleType inType)
Import samples from an audio buffer to a specific channel of the AWEOSInstance's input pin.
INT32 aweOS_getParamDefaults(AWEOSConfigParameters *aweParams)
Populates an AWEOSConfigParameters structure with defaults.
INT32 aweOS_getAverageLayoutCycles(AWEOSInstance *pAWEOS, UINT32 idx, UINT32 *averageCycles)
Get the average cycles of a running layout, in units of cycles at profileSpeed.
INT32 aweOS_loadAWBFile(AWEOSInstance *pAWEOS, const char *binaryFile, UINT32 *pErrorOffset)
Executes packet commands from an AWB file on the filesystem.
AWEOSConfigParameters.
Definition: AWECoreOS.h:114
UINT32 fastHeapBSize
Size of fast heap B in 32-bit words.
Definition: AWECoreOS.h:120
UINT32 * pFastHeapA
Pointer to fast heap A.
Definition: AWECoreOS.h:116
UINT32 * pSlowHeap
Pointer to slow heap.
Definition: AWECoreOS.h:118
UINT32 slowHeapSize
Size of slow heap in 32-bit words.
Definition: AWECoreOS.h:121
UINT32 * pFastHeapB
Pointer to fast heap B.
Definition: AWECoreOS.h:117
UINT32 fastHeapASize
Size of fast heap A in 32-bit words.
Definition: AWECoreOS.h:119