#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()
{
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("The layout loaded from the file\n");
}
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 %d with Error = %d %s \n", awbFilename, position, ret,
aweOS_errorToString(ret));
}
exit(1);
}
if (1 != ret)
{
printf("Error: Loaded layout is not valid: error = %d\n", ret);
exit(1);
}
if (1 != ret)
{
printf("Error: Audio not started: error = %d\n", ret);
exit(1);
}
UINT32 layoutInChannels, layoutOutChannels, layoutBlockSize;
{
exit(1);
}
{
exit(1);
}
printf("Layout loaded with inputChannels=%u, outputChannels=%u, blockSize=%u\n", layoutInChannels, layoutOutChannels, layoutBlockSize);
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 (%d)\n", AWE_Scaler1_classID );
exit(1);
}
}
else
{
}
{
if (AWE_Meter1_classID != classId)
{
printf("Error: Meter module not found in layout (%d)\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 = %d\n", count, avgCycles);
destroyExample();
return 0;
}