AWE Core 8.D.6 Documentation
singleinstance_simple.c

A very simple example of a single instance integration without real-time audio on Linux.

A very simple example of a single instance integration without real-time audio on Linux. Ethernet tuning interface. Examples

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include "AWECore.h"
#include "ProxyIDs.h"
#include "AWECoreUtils.h"
#include "TargetInfo.h"
AWEInstance g_AWEInstance;
static IOPinDescriptor g_InputPin[1];
static IOPinDescriptor g_OutputPin[1];
const void* g_module_descriptor_table[] =
{
LISTOFCLASSOBJECTS
};
/* ----------------------------------------------------------------------
** Specify the size in 32-bit words of each of the heaps on this target
** ------------------------------------------------------------------- */
#define MASTER_HEAP_SIZE (1024*1024)
#define FASTB_HEAP_SIZE (1024*1024)
#define SLOW_HEAP_SIZE (1024*1024)
UINT32 g_FastHeapA[MASTER_HEAP_SIZE];
UINT32 g_SlowHeap[MASTER_HEAP_SIZE];
UINT32 g_FastHeapB[MASTER_HEAP_SIZE];
//global packet buffers
UINT32 AWE_Packet_Buffer[264];
UINT32 AWE_Packet_Buffer_Reply[264];
void error(const char *msg)
{
perror(msg);
exit(1);
}
void *tuningPacketRxThread(void*)
{
/*
Tuning packets can be recieved and processed here. Another implementation
may choose to process the packet in another thread.
*/
int sockfd, newsockfd;
socklen_t clilen;
unsigned char buffer[264];
struct sockaddr_in serv_addr, cli_addr;
int n;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
error("ERROR opening socket");
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(15098);
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
{
error("ERROR on binding");
}
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
if (newsockfd < 0)
error("ERROR on accept");
int i=1;
/* Enter a tuning loop. This will be in a separate thread */
printf( "entering loop ...\n");
while(1)
{
bzero(AWE_Packet_Buffer,264);
n = read(newsockfd,AWE_Packet_Buffer,264*sizeof(AWE_Packet_Buffer[0]));
if (n < 0) error("ERROR reading from socket");
volatile INT32 opcode = PACKET_OPCODE(AWE_Packet_Buffer);
volatile UINT32 packetInstanceID = PACKET_INSTANCEID(AWE_Packet_Buffer); //snoop the instance ID off of the packet
awe_packetProcess(&g_AWEInstance);
unsigned int plen = AWE_Packet_Buffer[0]>>16;
n = write(newsockfd,AWE_Packet_Buffer,plen*sizeof(AWE_Packet_Buffer[0]));
if (n < 0) error("ERROR writing to socket");
}
close(newsockfd);
close(sockfd);
}
void InitializeAWEInstance()
{
int ret = 0;
//set memory for awe instance and initialize to 0's
memset(&g_AWEInstance, 0, sizeof(AWEInstance));
g_AWEInstance.instanceId = 0;
g_AWEInstance.pInputPin = g_InputPin;
g_AWEInstance.pOutputPin = g_OutputPin;
g_AWEInstance.pPacketBuffer = AWE_Packet_Buffer;
g_AWEInstance.pReplyBuffer = AWE_Packet_Buffer;
g_AWEInstance.packetBufferSize = 264;
g_AWEInstance.pModuleDescriptorTable = g_module_descriptor_table;
UINT32 module_descriptor_table_size = sizeof(g_module_descriptor_table) / sizeof(g_module_descriptor_table[0]);
g_AWEInstance.numModules = module_descriptor_table_size;
g_AWEInstance.numThreads = 1;
g_AWEInstance.sampleRate = 48000.f;
g_AWEInstance.fundamentalBlockSize = 32;
g_AWEInstance.pFlashFileSystem = 0;
g_AWEInstance.fastHeapASize = MASTER_HEAP_SIZE;
g_AWEInstance.slowHeapSize = SLOW_HEAP_SIZE;
g_AWEInstance.fastHeapBSize = FASTB_HEAP_SIZE;
g_AWEInstance.pFastHeapA = g_FastHeapA;
g_AWEInstance.pSlowHeap = g_SlowHeap;
g_AWEInstance.pFastHeapB = g_FastHeapB;
g_AWEInstance.coreSpeed = 10e6f;
g_AWEInstance.profileSpeed = 10e6f;
g_AWEInstance.pName = TARGET_NAME;
ret = awe_initPin(g_InputPin, INPUT_CHANNEL_COUNT, NULL);
if (ret != 0)
{
printf("awe_initPin inputPin failed\n");
}
ret = awe_initPin(g_OutputPin, OUTPUT_CHANNEL_COUNT, NULL);
if (ret != 0)
{
printf("awe_initPin outputPin failed\n");
}
ret = awe_init(&g_AWEInstance);
if (ret != 0)
{
printf("awe_init instance 1 failed\n");
}
}
int main( int argc, const char* argv[] )
{
pthread_t rxthread_id;
pthread_t processthread_id;
InitializeAWEInstance();
pthread_create(&rxthread_id, NULL, tuningPacketRxThread, NULL);
pthread_join(rxthread_id, NULL);
while(1)
{
//printf("main idle loop")
}
}
The AWECore API Header File.
The AWECore Helper Functions File.
#define PACKET_OPCODE(x)
Get the OPCODE of the packet.
Definition: AWECoreUtils.h:50
#define PACKET_INSTANCEID(x)
This will get the instance ID of a packet.
Definition: AWECoreUtils.h:46
INT32 awe_initPin(IOPinDescriptor *pPin, UINT32 channels, const char *name)
Initialize an input or output pin.
INT32 awe_packetProcess(AWEInstance *pAWE)
Process an AWEInstance's newly received tuning packet.
INT32 awe_init(AWEInstance *pAWE)
Initialize the instance.
A list of all AWE Server Commands.
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
Name of this instance as a string
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
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 instanceId
The ID of this instance.
Definition: AWEInstance.h:50
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.
Definition: AWEInstance.h:65
UINT32 * pFastHeapA
Fast heap A.
Definition: AWEInstance.h:54