#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "TargetInfo.h"
#include "passthrough_InitAWB.h"
#include "passthrough_ControlInterface.h"
const char awbFilename[] = "../Designs/passthrough.awb";
const char inFilename[] = "../Audio/in_s32_stereo.raw";
const char outFilename[] = "../Audio/out_s32_stereo.raw";
const void* module_descriptor_table[] =
{
LISTOFCLASSOBJECTS
};
UINT32 fastHeapA[FASTA_HEAP_SIZE];
UINT32 fastHeapB[FASTB_HEAP_SIZE];
UINT32 slowHeap[SLOW_HEAP_SIZE];
UINT32 awePacketBuffer[MAX_COMMAND_BUFFER_LEN];
INT32 * inputBuffer, * outputBuffer;
FILE *fin;
FILE *fout;
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;
}
void InitializeAWEInstance()
{
int ret;
UINT32 module_descriptor_table_size;
module_descriptor_table_size = sizeof(module_descriptor_table) / sizeof(module_descriptor_table[0]);
aweInstance.
numModules = module_descriptor_table_size;
aweInstance.
pName = NULL;
ret =
awe_initPin(&aweInputPin, NUM_INPUT_CHANNELS, NULL);
if (ret != 0)
{
printf("awe_initPin inputPin failed\n");
}
ret =
awe_initPin(&aweOutputPin, NUM_OUTPUT_CHANNELS, NULL);
if (ret != 0)
{
printf("awe_initPin outputPin failed\n");
}
if (ret != 0)
{
printf("awe_init failed\n");
}
}
int main() {
INT32 ret = 0;
UINT32 position;
UINT32 layoutInChannels, layoutOutChannels, layoutBlockSize;
const INT32 inputChannels = 2;
const INT32 outputChannels = 2;
UINT32 inSize, outSize;
InitializeAWEInstance();
{
printf("Error loading AWB from array: error = %d, at offset %u\n", ret, position);
exit(1);
}
if (ret != 1)
{
printf("Error: Loaded layout is not valid: error = %d\n", ret);
exit(1);
}
if (ret != 1)
{
printf("Error: Audio not started: error = %d\n", ret);
exit(1);
}
{
printf("Error: GetBlockSize failed: error = %d\n", ret);
exit(1);
}
printf("Layout loaded with inputChannels=%u, outputChannels=%u, blockSize=%u\n", layoutInChannels, layoutOutChannels, layoutBlockSize);
inSize = inputChannels * layoutBlockSize;
outSize = outputChannels * layoutBlockSize;
inputBuffer = malloc(inSize * sizeof(INT32));
outputBuffer = malloc(outSize * sizeof(INT32));
fin = fopen(inFilename, "rb");
if (fin == NULL)
{
printf("Error opening file %s\n", inFilename);
exit(1);
}
fout = fopen(outFilename, "wb");
if (fout == NULL)
{
printf("Error opening file %s\n", outFilename);
exit(1);
}
{
float scaler1Gain;
float scaler1TargetGain;
float meter1Values[AWE_Meter1_value_SIZE];
long count = 0;
int numSamplesRead = 0;
UINT32 classId;
int moduleFound = 0;
{
if (classId == AWE_Scaler1_classID)
{
moduleFound = 1;
}
}
if (!moduleFound)
{
printf("Error: Scaler1 module not found in layout\n");
}
{
if (classId == AWE_Meter1_classID)
{
moduleFound = 1;
}
}
if (!moduleFound)
{
printf("Error: Meter1 module not found in layout\n");
}
printf("\n");
scaler1Gain = -10.0;
ret =
awe_ctrlSetValue(&aweInstance, AWE_Scaler1_gain_HANDLE, (
const void *)&scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
printf("SetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
ret =
awe_ctrlGetValue(&aweInstance, AWE_Scaler1_gain_HANDLE, &scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
printf("GetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
ret =
awe_ctrlGetValue(&aweInstance, AWE_Scaler1_targetGain_HANDLE, &scaler1TargetGain, 0, AWE_Scaler1_targetGain_SIZE);
printf("GetValue: scalerTarget1Gain = %f, error = %d\n", scaler1TargetGain, ret);
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;
UINT32 pumpMask;
for (i = 0; i < inputChannels; i++)
{
{
printf("Error: audio import failed: error = %d\n", ret);
}
}
if (pumpMask & 1U)
{
{
printf("Error: audio pump failed: layout=%d, error=%d\n", 0, ret);
}
}
for (i = 0; i < outputChannels; i++)
{
{
printf("Error: audio export failed: error = %d\n", ret);
}
}
count++;
if ((count % 1024) == 0)
{
ret =
awe_ctrlGetValue(&aweInstance, AWE_Meter1_value_HANDLE, &meter1Values, 0, AWE_Meter1_value_SIZE);
printf("GetValue: meter1Value = %f, error = %d\n", meter1Values[0], ret);
}
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 =
awe_ctrlGetValue(&aweInstance, AWE_Scaler1_gain_HANDLE, &scaler1Gain, 0, AWE_Scaler1_gain_SIZE);
printf("GetValue: scaler1Gain = %f, error = %d\n", scaler1Gain, ret);
ret =
awe_ctrlGetValue(&aweInstance, AWE_Scaler1_targetGain_HANDLE, &scaler1TargetGain, 0, AWE_Scaler1_targetGain_SIZE);
printf("GetValue: scalerTarget1Gain = %f, error = %d\n", scaler1TargetGain, ret);
}
destroyExample();
return 0;
}