📄 audio.c
字号:
/*
* ======== audio.c ========
*
* This example demonstrates the use of LIO drivers with PIPs and
* the lio_pip adapter code. The application performs a loopback, that
* is audio data is read from one PIP connected to an input LIO
* channel, the the data is written back out on a PIP connected to an
* output LIO channel.
*
* The following objects need to be created in the DSP/BIOS
* configuration for this application:
*
* * A SWI object named swiEcho. Configure the function as _echo,
* and the mailbox value as 3.
*
* * 2 PIP objects, one named pipTx, the other pipRx. The length of the
* buffers should be the same and can be any size. See the comments
* by the declarations below of pipTx and pipRx for the writer and
* reader notify function settings.
*
* * A LOG object named trace, used for status and debug output. Can be
* any size and can be circular or fixed.
*/
#include <std.h>
#include <log.h>
#include <pip.h>
#include <swi.h>
#include <sys.h>
#include <lio.h>
#include <plio.h>
#include "fdacoefs.h"
/* Set CONTROLLER_FXN_TABLE in the linker command file. */
extern LIO_Fxns CONTROLLER_FXN_TABLE;
static LIO_Fxns *controller = &CONTROLLER_FXN_TABLE;
extern far LOG_Obj trace; /* application printf() log, any size */
extern far PIP_Obj pipRx; /* writerNotify -> PLIO_rxPrime(plioRx)
* readerNotify -> SWI_andn(swiEcho,1) */
extern far PIP_Obj pipTx; /* writerNotify -> SWI_andn(swiEcho,2)
* readerNotify -> PLIO_txPrime(plioTx) */
extern far SWI_Obj swiMyEQ; /* SWI object which runs when buffers are ready. */
/*define my varible*/
int gain=1;
unsigned echo=0xfffe;
/*
* 'plioRx' and 'plioTx' objects will be initialized by PLIO_new().
*/
PLIO_Obj plioRx, plioTx;
/*
* ======== main ========
*/
void main()
{
LOG_printf(&trace, "Audio using PIP, LIO and BSL started!");
/*
* CONTROLLER_init() initializes the device controller.
* See CONTROLLER_init() in the linker command file.
*/
CONTROLLER_init();
/*
* CONTROLLER_setup() configures device with parameter.
* If NULL is specified then the default settings will be used.
* Set CONTROLLER_setup() in the linker command file.
* The LIO controller comes from the BSL lib (ex. c5400\dsk5416\lib).
*/
CONTROLLER_setup(NULL);
/* Bind the PIPs to LIO channels */
PLIO_new(&plioRx, &pipRx, LIO_INPUT, controller, NULL);
PLIO_new(&plioTx, &pipTx, LIO_OUTPUT, controller, NULL);
/*
* Prime the transmit side with buffers of silence.
* The transmitter should be started before the receiver.
* This results in input-to-output latency being one full
* buffer period if the pipes is configured for 2 frames.
*/
PLIO_txStart(&plioTx, PIP_getWriterNumFrames(&pipTx), 0);
/* Prime the receive side with empty buffers to be filled. */
PLIO_rxStart(&plioRx, PIP_getWriterNumFrames(&pipRx));
return;
/* exit from main into the DSP/BIOS idle loop */
}
/*
* ======== echo ========
*
* This function is executed from the swiEcho DSP/BIOS SWI thread created
* statically with the DSP/BIOS configuration tool. The PLIO adapter
* posts the swi when an the input PIP has a buffer of data and the
* output PIP has an empty buffer to put new data into. This function
* copies from the input PIP to the output PIP. You could easily
* replace the copy function with signal processing code.
*/
Void myEQ(Void)
{
Int i, size;
unsigned short *src, *dst;
/*
* Check that the precondions are met, that is pipRx has a buffer of
* data and pipTx has a free buffer.
*/
if (PIP_getReaderNumFrames(&pipRx) <= 0) {
LOG_error("echo: No reader frame!", 0);
return;
}
if (PIP_getWriterNumFrames(&pipTx) <= 0) {
LOG_error("echo: No writer frame!", 0);
return;
}
/* get the full buffer from the receive PIP */
PIP_get(&pipRx);
src = PIP_getReaderAddr(&pipRx);
size = PIP_getReaderSize(&pipRx) * sizeof(short);
/* get the empty buffer from the transmit PIP */
PIP_alloc(&pipTx);
dst = PIP_getWriterAddr(&pipTx);
/*
* Do the data move. Mask off the low bit for compatibility with
* those codecs that interpret a low bit of '1' as a command flag.
*/
for (i = 0; i < size; i++) {
*dst++= *src++;
}
/* Record the amount of actual data being sent */
PIP_setWriterSize(&pipTx, PIP_getReaderSize(&pipRx));
/* Free the receive buffer, put the transmit buffer */
PIP_free(&pipRx);
PIP_put(&pipTx);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -