📄 audio.c
字号:
/*
* Copyright 2002 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/* "@(#) DSP/BIOS 4.80.208 12-06-02 (barracuda-l19)" */
/*
* ======== audio.c ========
*/
#include <std.h>
#include <pip.h>
#include <log.h>
#include <trc.h>
#include <hst.h>
#include <string.h> /* memset() */
#include <stdarg.h> /* var arg stuff */
#include "dss.h"
#include "audio.h"
Int PHASE = 0; /* number of samples of phase difference */
static Uns allocBuf(PIP_Obj *out, Uns **buf);
static Void freeBuf(PIP_Obj *out);
static Uns getBuf(PIP_Obj *in, Uns **buf);
static Void process(Uns *src, Int size, Uns *dst);
static Void putBuf(PIP_Obj *out, Uns size);
static Void writeBuf(PIP_Obj *out, Uns *buf, Uns size);
static Int loadVal = 0;
static PIP_Obj *hostPipe = NULL;
/*
* ======== main ========
*/
Void main()
{
Int size;
Uns *buf;
#if AUDIO_USEHST
hostPipe = HST_getpipe(&hostOutputProbe);
#endif
DSS_init(); /* Initialize codec and serial port */
LOG_printf(&trace, "Audio example started!!\n");
/* Prime output buffers with silence */
size = allocBuf(&DSS_txPipe, &buf);
memset(buf, 0, size * sizeof (Uns));
putBuf(&DSS_txPipe, size);
size = allocBuf(&DSS_txPipe, &buf);
memset(buf, 0, size * sizeof (Uns));
putBuf(&DSS_txPipe, size - PHASE);
/* Fall into BIOS idle loop */
return;
}
/*
* ======== audio ========
*/
Void audio(PIP_Obj *in, PIP_Obj *out)
{
Uns *src, *dst;
Uns size;
if (PIP_getReaderNumFrames(in) == 0 || PIP_getWriterNumFrames(out) == 0) {
error("Error: audio signal falsely triggered!");
}
/* get input data and allocate output buffer */
size = getBuf(in, &src);
allocBuf(out, &dst);
/* process input data in src to output buffer dst */
process(src, size, dst);
/* check for real-time error */
if (DSS_error != 0) {
LOG_printf(&trace,
"Error: DSS missed real-time! (DSS_error = 0x%x)", DSS_error);
loadVal -= 1;
DSS_error = 0;
}
/* output data and free input buffer */
putBuf(out, size);
freeBuf(in);
}
/*
* ======== error ========
*/
Void error(String msg, ...)
{
va_list va;
va_start(va, msg);
LOG_error(msg, va_arg(va, Arg)); /* write error message to sys log */
LOG_disable(LOG_D_system); /* stop system log */
for (;;) {
; /* loop for ever */
}
}
/*
* ======== load ========
*/
Void load(Arg Arg_prd_ms)
{
static int oldLoad = 0;
Int prd_ms = ArgToInt(Arg_prd_ms);
/* display confirmation of load changes */
if (oldLoad != loadVal ) {
oldLoad = loadVal;
LOG_printf(&trace,
"load: new load = %d000 instructions every %d ms", loadVal, prd_ms);
}
if (loadVal) {
AUDIO_load(loadVal);
}
}
/*
* ======== step ========
*/
Void step(void)
{
static Int direction = 1;
if (loadVal > MAXLOAD) {
direction = -1;
}
if (loadVal <= 0) {
direction = 1;
}
loadVal = loadVal + (100 * direction);
}
/*
* ======== allocBuf ========
*/
static Uns allocBuf(PIP_Obj *out, Uns **buf)
{
PIP_alloc(out);
*buf = PIP_getWriterAddr(out);;
return (PIP_getWriterSize(out));
}
/*
* ======== freeBuf ========
*/
static Void freeBuf(PIP_Obj *out)
{
PIP_free(out);
}
/*
* ======== getBuf ========
*/
static Uns getBuf(PIP_Obj *in, Uns **buf)
{
PIP_get(in);
*buf = PIP_getReaderAddr(in);;
return (PIP_getReaderSize(in));
}
/*
* ======== process ========
*/
static Void process(Uns *src, Int size, Uns *dst)
{
Int i;
for (i = size - 1; i >= 0; i--) {
dst[i] = src[i];
}
/* if hostPipe is non-NULL write data to this pipe */
if (hostPipe != NULL) {
writeBuf(hostPipe, dst, size);
}
}
/*
* ======== putBuf ========
*/
static Void putBuf(PIP_Obj *out, Uns size)
{
PIP_setWriterSize(out, size);
PIP_put(out);
}
/*
* ======== writeBuf ========
*/
static Void writeBuf(PIP_Obj *out, Uns *buf, Uns size)
{
Uns dstSize;
Uns *dst;
Int i;
/* allocate outBuffer for output */
dstSize = allocBuf(out, &dst);
/* copy data to output buffer (but not more than output buffer size) */
for (i = (dstSize >= size) ? size : dstSize; i > 0; i--) {
*dst++ = *buf++;
}
/* put buffer to output pipe */
putBuf(out, size);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -