#include "AudioStream.h"
#include <pthread.h>
#include <sys/prctl.h>
#include "ModuleList.h"
#include <pthread.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include "stdio.h"
#include <unistd.h>
#include <signal.h>
AudioStream *as;
UINT32 hwInputChannels = 1;
UINT32 hwOutputChannels = 2;
char* inputDeviceName;
char* outputDeviceName;
UINT32 portNo = 15002;
UINT32 fundamentalBlockSize = 32;
double sampleRate = 48000.0;
UINT32 enableAudioLogging = 0;
const char* awbPath;
UINT32 loadAWB = 0;
float coreSpeed = 1e9f;
float profileSpeed = 10e6f;
static const void* moduleDescriptorTable[] =
{
LISTOFCLASSOBJECTS
};
UINT32 moduleDescriptorTableSize = sizeof(moduleDescriptorTable) / sizeof(moduleDescriptorTable[0]);
{
printf("Audio Start Callback: Starting audio stream \n");
AudioStream_start(as);
return 0;
}
{
printf("Audio Stop Callback: Stopping audio stream \n");
AudioStream_stop(as);
return 0;
}
{
{
printf(
"Got xrun on audio recording input stream: total xruns = %d, time of xrun = %f\n", recordingNotification->
xruns, recordingNotification->
xrunTime);
}
{
printf(
"Got xrun on audio recording output stream: total xruns = %d, time of xrun = %f\n", recordingNotification->
xruns, recordingNotification->
xrunTime);
}
else
{
printf(
"Got audio recording error notification: %d\n", recordingNotification->
error);
}
}
{
UINT32 position = 0;
if (0 == ret)
{
printf("The layout %s loaded succesfully\n", filePath);
}
else
{
printf("The layout %s download unsuccessfullu in the position %d with Error = %s \n", filePath, position, strerror(ret));
exit(1);
}
}
AudioStream_CallbackResult audio_callback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
AudioStream_CallbackFlag statusFlags,
void *userData)
{
(void)userData;
UINT32 i, j;
INT32 pumpRet;
if (statusFlags != 0)
{
printf("xrun ");
return AudioStream_CallbackResult_Continue;
}
{
{
INT32 ret;
for (i = 0; i < hwInputChannels; i++)
{
if (ret != 0)
{
}
}
if (pumpRet < 0)
{
}
for (j = 0; j < hwOutputChannels; j++)
{
if (ret != 0)
{
}
}
}
}
return AudioStream_CallbackResult_Continue;
}
int initializeAudioStream()
{
as = AudioStream_create();
if (as == NULL)
{
printf("Error initializing AudioStream\n");
}
else
{
printf("AudioStream init success\n");
}
AudioStream_open(as, inputDeviceName, hwInputChannels,
outputDeviceName, hwOutputChannels,
AudioStream_SampleFormat_S32_LE,
sampleRate, fundamentalBlockSize,
audio_callback, NULL);
return 0;
}
static void usage(const char *program)
{
printf(
"Usage: %s [args]\n"
" -load:<file> AWB file to load. If no AWB is specified, then app waits for a layout from tuning interface\n"
" -inputdevice:<str> The alsa device id for the input device. Default hw:0,0 \n"
" -outputdevice:<str> The alsa device id for the output device. Default hw:0,0\n"
" -hwinchannels:<int> The number of hw input channels for the alsa audio device \n"
" -hwoutchannels:<int> The number of hw output channels for the alsa audio device\n"
" -blocksize:<int> The fundamental hw blocksize of the alsa device (DMA)\n"
" -samplerate:<int> The samplerate of the audio hw\n"
" -enabledAudioLog Enable audio logging. Logs will be saved to <appdirectory>/audio-logs/\n"
" -portno:<int> Port number to open the TCP tuning socket on. Default 15002\n"
" -coreSpeed:<float> Processor clock speed in Hz. Default 1 GHz\n"
" -profileSpeed:<float> Application profiling speed in Hz. Default 10 MHz. \n"
" -help Show usage\n"
"This program shows realtime audio integration with the alsa API.\n",
program);
exit(0);
}
int main(int argc, char **argv)
{
inputDeviceName = "hw:0,0";
outputDeviceName = "hw:0,0";
UINT32 i;
if (1 == argc)
{
printf("No command line options specified. Using defaults\n");
}
else
{
for (i = 1; i < argc; i++)
{
const char *arg = argv[i];
if ((0 == strncmp(arg, "-inputdevice:", 13)))
{
inputDeviceName = (char*)(arg + 13);
printf("cmd line arg set inputdevice to %s \n ", inputDeviceName);
}
else if ((0 == strncmp(arg, "-outputdevice:", 14)))
{
outputDeviceName = (char*)(arg + 14);
printf("cmd line arg set outputdevice to %s \n ", outputDeviceName);
}
else if ((0 == strncmp(arg, "-hwinchannels:", 14)))
{
hwInputChannels = atoi(arg + 14);
printf("Hardware input channels set to %d \n ", hwInputChannels);
}
else if ((0 == strncmp(arg, "-hwoutchannels:", 15)))
{
hwOutputChannels = atoi(arg + 15);
printf("Hardware output channels set to %d \n ", hwOutputChannels);
}
else if ((0 == strncmp(arg, "-blocksize:", 11)))
{
fundamentalBlockSize = atoi(arg + 11);
printf("fundamental block size set to %d \n ", fundamentalBlockSize);
}
else if ((0 == strncmp(arg, "-samplerate:", 12)))
{
sampleRate = atof(arg + 12);
printf("sample rate set to %f \n ", sampleRate);
}
else if ((0 == strncmp(arg, "-portno:", 8)))
{
portNo = atoi(arg + 8);
printf("portno for socket is %d \n", portNo);
}
else if (0 == strncmp(arg, "-load:", 6))
{
awbPath = arg + 6;
loadAWB = 1;
printf("-load: %s\n",awbPath);
}
else if ((0 == strncmp(arg, "-enableAudioLog", 15)))
{
enableAudioLogging = 1;
printf("Audio logging enabled \n");
}
else if ((0 == strncmp(arg, "-coreSpeed:", 11)))
{
coreSpeed = atof(arg + 11);
printf("coreSpeed set to %f\n", coreSpeed);
}
else if ((0 == strncmp(arg, "-profileSpeed:", 14)))
{
profileSpeed = atof(arg + 14);
printf("profileSpeed set to %f \n", profileSpeed);
}
else if ((0 == strncmp(arg, "-help", 5)))
{
usage(argv[0]);
}
else
{
printf("main: unknown option '%s'\n", arg);
}
}
}
INT32 ret;
ret =
aweOS_init(&g_AWEOSInstance, &configParams, moduleDescriptorTable, moduleDescriptorTableSize);
if (ret != 0)
{
printf("FATAL: aweOS_init failed. exiting application \n");
exit(1);
}
else
{
initializeAudioStream();
if (enableAudioLogging)
{
if (ret != 0)
{
printf("failed to enable audio logging: ret = %d\n", ret);
}
if (ret != 0)
{
printf("Failed to register audio logging callback function: ret = %d\n", ret);
}
}
if (tuningRet < 0)
{
}
else
{
printf("Opened TCP tuning interface on port %d: Waiting for AWE Server Connection from PC... \n", portNo);
}
if (loadAWB)
{
loadAWBFile(g_AWEOSInstance, awbPath);
}
while (1)
{
usleep(1000);
}
}
}