📄 main.c
字号:
// Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
// This software is proprietary and confidential to Analog Devices, Inc. and its licensors.
// File : $Id: //depot/Development/VisualAudio/Platforms/EZKit_BF533_Basic/2.5.0/main.c#2 $
// Part of : VisualAudio V2.5.0
// Updated : $Date: 2006/10/12 $ by $Author: Fernando $
/*****************************************************************************
Project name: VisualAudio Layout example
Hardware: see 'readme.txt' file
Date : 9/01/2005
Description : This example program sets up the Audio device driver, which
configures the codecs via SPI ports and SPORT ports.
Audio data is transferred through DMA.
This program passes the input audio data to the VisualAudio
layout processing function, and sends output data through DMA.
*****************************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include "Basic.h"
#include "VALayout1Presets.h"
/*********************************************************************
Definitions & Local variables
*********************************************************************/
#define PRINT_ERROR_MESSAGES 1
#define TUNING_ENABLED 1
/* Tuning command buffer. Size is specified in VALayouts.h. */
#if TUNING_ENABLED
static unsigned int tuningCommandBuffer[AMF_MAX_MSG_SIZE+1];
#endif
/* Array of layouts. */
static AMF_Layout *layouts[] = AMF_LAYOUT_LIST_INITIALIZER;
/**
* The one and only master object for the VA Layout Support (AMF) library.
*/
AMF_Master AMFMaster =
{
AMF_MAX_MSG_SIZE,
#if TUNING_ENABLED
tuningCommandBuffer,
#else
NULL,
#endif
1,
layouts,
0
};
#if TUNING_ENABLED
/* BTC Definitions */
#include "btc.h"
BTC_MAP_BEGIN
// Channel Name, Starting Address, Length
BTC_MAP_ENTRY("VisualAudio", (long)tuningCommandBuffer, sizeof(tuningCommandBuffer))
// Insert any addition BTC_MAP_ENTRY's here
BTC_MAP_END
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#if Layout1_SCRATCH_COUNT
static SEG_MOD_FAST_SDATA AMF_Signal fastDMMemArray[Layout1_SCRATCH_COUNT];
#define fastDMMem &fastDMMemArray[0]
#else
#define fastDMMem NULL
#endif
#if Layout1_PM_SCRATCH_COUNT
static SEG_MOD_FAST_SDATA_PM AMF_Signal PMMemArray[Layout1_PM_SCRATCH_COUNT];
#define PMMem &PMMemArray[0]
#else
#define PMMem NULL
#endif
#if Layout1_SLOW_SCRATCH_COUNT
static SEG_MOD_SLOW_SDATA AMF_Signal slowDMMemArray[Layout1_SLOW_SCRATCH_COUNT];
#define slowDMMem &slowDMMemArray[0]
#else
#define slowDMMem NULL
#endif
// Audio processing buffer
static SEG_MOD_FAST_SDATA AMF_Signal
processingBuffer[MAX(Layout1_INPUT_PIN_COUNT,Layout1_OUTPUT_PIN_COUNT)*Layout1_TICK_SIZE];
/*********************************************************************
*
* Function: main
*
*********************************************************************/
#ifndef NO_OPTIMIZE
#pragma optimize_for_space
#endif
void main(void)
{
// initialize system
SYS_Init();
// init processing
Layout1.pProcessingBuffer = (AMF_Signal *)processingBuffer;
#if TUNING_ENABLED
btc_init();
#endif
AMF_Layout_Init(&Layout1,fastDMMem,PMMem,slowDMMem);
// initialize profiling
AMF_Layout_InitProfile(&Layout1,Layout1_TICK_SIZE);
// initialize the audio driver
SYSAudio_Init(DEFAULT_AUDIO_IO_MODE);
for (;;)
{
// infinite loop while audio flows at interrupt level. Poll for tuning commands.
#if TUNING_ENABLED
btc_poll();
if (AMF_TUNING_CONTROL == AMFTuningAction_PC_SENDING_COMMAND)
AMF_TUNING_CONTROL = AMF_HandleTuningCommand();
#endif
DoControlCode(); // See DoControlCode.c
asm("idle;"); // Save power... wake up only once per DMA
}
// Terminate Audio Driver, not used in current example.
// SYSAudio_Close();
}
/*********************************************************************
*
* Function: DoProcessing
* Description: Process VisualAudio layout
*
*********************************************************************/
#ifndef NO_OPTIMIZE
#pragma optimize_for_speed
#endif
void DoProcessing(int **pInputPtrs,int **pOutputPtrs) {
// Called from ISR. Arguments are arrays of pointers to channels
unsigned int startCycles;
int *pSrc, *pDst;
int i, j;
int *pInput,*pOutput;
if ((AMFMaster.iFlags & AMFFlag_PAUSED) != 0) { // Can be paused by (e.g.) demand render mode
// clear output buffers
for (i = 0, pSrc = (int*)Layout1.pProcessingBuffer; i < SYSAudio_MAX_OUTPUT_CHANNEL_COUNT; i++)
{
pOutput = pOutputPtrs[i];
for (j = 0; j < (TDM_FRAME_SIZE * Layout1_TICK_SIZE); j += TDM_FRAME_SIZE)
pOutput[j] = 0;
}
return;
}
startCycles = AMF_Layout_BeginProfile(&Layout1); /* Start profiling interval */
//========================================================================
// read input buffer
// convert RX DMA frame formatted data into sequential array for each valid input channel
for (i = 0, pDst = (int*)Layout1.pProcessingBuffer; i < Layout1_INPUT_PIN_COUNT; i++)
{
if (i < SYSAudio_MAX_INPUT_CHANNEL_COUNT) {
pInput = pInputPtrs[i];
for (j = 0; j < (TDM_FRAME_SIZE * Layout1_TICK_SIZE); j += TDM_FRAME_SIZE)
*pDst++ = pInput[j];
}
else
for (j = 0; j < Layout1_TICK_SIZE; j++)
*pDst++ = 0;
}
//========================================================================
// do rendering
AMF_Layout_Render(&Layout1, Layout1_TICK_SIZE);
//========================================================================
// write output buffer
// convert array of valid output channels into TX DMA frame formatted data
for (i = 0, pSrc = (int*)Layout1.pProcessingBuffer; i < SYSAudio_MAX_OUTPUT_CHANNEL_COUNT; i++)
{
pOutput = pOutputPtrs[i];
if (i < Layout1_OUTPUT_PIN_COUNT)
for (j = 0; j < (TDM_FRAME_SIZE * Layout1_TICK_SIZE); j += TDM_FRAME_SIZE)
pOutput[j] = *pSrc++;
else
for (j = 0; j < (TDM_FRAME_SIZE * Layout1_TICK_SIZE); j += TDM_FRAME_SIZE)
pOutput[j] = 0;
}
AMF_Layout_EndProfile(&Layout1,startCycles); /* End of profiling interval */
}
/*********************************************************************
*
* Function: ErrorMessage
* Description: Do something when an error happens
*
*********************************************************************/
#if PRINT_ERROR_MESSAGES
#include <stdio.h>
void ErrorMessage(char *s) {
printf(s);
}
#else
void ErrorMessage(char *s) {
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -