Examples.
#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";
static IOPinDescriptor aweInputPin;
static IOPinDescriptor aweOutputPin;
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");
}
if (ret != 0)
{
printf("awe_setProfilingStatus 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;
}
The AWECore API Header File.
INT32 awe_initPin(IOPinDescriptor *pPin, UINT32 channels, const char *name)
Initialize an input or output pin.
INT32 awe_ctrlSetValue(const AWEInstance *pAWE, UINT32 handle, const void *value, INT32 arrayOffset, UINT32 length)
Set a scalar or array value of a module variable by handle.
INT32 awe_audioPump(AWEInstance *pAWE, UINT32 layoutIndex)
Audio pump function.
void awe_layoutGetChannelCount(const AWEInstance *pAWE, UINT32 pinIdx, UINT32 *inCount, UINT32 *outCount)
Returns the number of channels in the Layout's input and output pins.
INT32 awe_audioImportSamples(const AWEInstance *pAWE, const void *inSamples, INT32 inStride, INT32 channel, SampleType inType)
Import samples from a user buffer to a channel.
INT32 awe_layoutIsValid(const AWEInstance *pAWE)
Determines if a layout is loaded and valid.
INT32 awe_ctrlGetValue(const AWEInstance *pAWE, UINT32 handle, void *value, INT32 arrayOffset, UINT32 length)
Get a scalar or array value of a module variable by handle.
INT32 awe_loadAWBfromArray(AWEInstance *pAWE, const UINT32 *pCommands, UINT32 arraySize, UINT32 *pPos)
Executes packet commands from an in-memory array.
INT32 awe_audioExportSamples(const AWEInstance *pAWE, void *outSamples, INT32 outStride, INT32 channel, SampleType outType)
Export samples to a user buffer from a channel.
INT32 awe_audioGetPumpMask(AWEInstance *pAWE)
Test if AWE is ready to run.
INT32 awe_setProfilingStatus(AWEInstance *pAWE, UINT32 status)
Enable or disable the profiling ability of the AWE Core.
INT32 awe_init(AWEInstance *pAWE)
Initialize the instance.
INT32 awe_layoutGetInputBlockSize(const AWEInstance *pAWE, UINT32 pinIdx, UINT32 *blockSize)
Returns the block size of a pin.
INT32 awe_ctrlGetModuleClass(const AWEInstance *pAWE, UINT32 handle, UINT32 *pClassID)
Get an object class from its handle.
INT32 awe_audioIsStarted(const AWEInstance *pAWE)
Check if this instance is running.
A list of all possible Audio Weaver errors and their IDs.
#define E_SUCCESS
OK result.
Definition: Errors.h:31
@ Sample32bit
Data is 32 bit PCM .
Definition: StandardDefs.h:231
The AWE instance.
Definition: AWEInstance.h:45
IOPinDescriptor * pInputPin
A BSP author must define/allocate an input pin in their BSP and assign it to this member NOTE: AudioW...
Definition: AWEInstance.h:103
const char * pName
The name of the AWE Instance that will be displayed in Server.
Definition: AWEInstance.h:172
float profileSpeed
Profiling clock speed in Hz.
Definition: AWEInstance.h:164
UINT32 * pReplyBuffer
Reply buffer pointer.
Definition: AWEInstance.h:146
UINT32 * pFastHeapB
The second fast heap, B .
Definition: AWEInstance.h:57
UINT32 numThreads
Number of threads supported for multithreaded systems(1-4).
Definition: AWEInstance.h:176
IOPinDescriptor * pOutputPin
A BSP author must define/allocate an output pin in their BSP and assign it to this member NOTE: Audio...
Definition: AWEInstance.h:109
UINT32 * pPacketBuffer
The Packet buffer pointer.
Definition: AWEInstance.h:137
INT32(* cbAudioStart)(struct _AWEInstance *PAWE)
OPTIONAL This callback is invoked when a layout is run or when a StartAudio command is sent.
Definition: AWEInstance.h:79
INT32(* cbAudioStop)(struct _AWEInstance *pAWE)
OPTIONAL.
Definition: AWEInstance.h:85
UINT32 slowHeapSize
The slow heap size.
Definition: AWEInstance.h:71
UINT32 fundamentalBlockSize
Base frame size of this instance.
Definition: AWEInstance.h:183
UINT32 * pSlowHeap
The slow heap.
Definition: AWEInstance.h:60
float sampleRate
Default sample rate of this instance.
Definition: AWEInstance.h:179
UINT32 packetBufferSize
Packet buffer size.
Definition: AWEInstance.h:153
UINT32 fastHeapBSize
The fast heap B size.
Definition: AWEInstance.h:68
AWEFlashFSInstance * pFlashFileSystem
DSPC Flash file system instance.
Definition: AWEInstance.h:188
float coreSpeed
A BSP author will set this to the speed of the CPU they are integrating into.
Definition: AWEInstance.h:161
UINT32 numModules
Number of modules in module table.
Definition: AWEInstance.h:119
const ModClassModule ** pModuleDescriptorTable
Pointer to module table.
Definition: AWEInstance.h:127
UINT32 fastHeapASize
The fast heap A size in 32-bit words.
Definition: AWEInstance.h:65
UINT32 * pFastHeapA
Fast heap A.
Definition: AWEInstance.h:54