📄 audiolibrary.c
字号:
/*======================================================================
Project Name : S3C2450
Copyright 2006 by Samsung Electronics, Inc.
All rights reserved.
Project Description :
This software is only for verifying functions of the S3C2443.
Anybody can use this code without our permission.
File Name : iisnew.c
Description : S3C2450 IIS ip driver
Author : Dongjin Kim
Dept : AP
Created Date : 2007.10.19
Version : 0.0
History
R0.0 (2007.10.19): draft
- S3C2450 IIS codec code is derived from 2443 IIS test code & SA 2450 IIS test code
=======================================================================*/
#include "System.h"
#include "audiolibrary.h"
//static function(private)
bool PCM_Resampling96to64(unsigned int destaddr, unsigned int* destsizeByte,
unsigned int orgaddr, int orgsizeByte);
const unsigned int cTestpattern8bit[SIZE_TESTPATTERN8]=
{
//I2S link(FIFO)
//Left(Low 8bit) Right(High 8bit)
0x810081, //1000 0001 1000 0001
0xC10083, //1000 0011 1100 0001
0xA10085, //1000 0101 1010 0001
0x910089, //1000 1001 1001 0001
0x890091, //1001 0001 1000 1001
0x8500A1, //1010 0001 1000 0101
0x8300C1, //1100 0001 1000 0011
0x810081, //1000 0001 1000 0001
};
const unsigned int cTestpattern16bit[SIZE_TESTPATTERN16]=
{
//I2S link(FIFO)
//Left(Low 16bit) Right(High 16bit)
0x80018001, //1000 0000 0000 0001 1000 0000 0000 0001
//0111 1111 1111 1111
0xC0018003, //1000 0000 0000 0011 1100 0000 0000 0001
0xA0018005, //1000 0000 0000 0101 1010 0000 0000 0001
0x90018009, //1000 0000 0000 1001 1001 0000 0000 0001
0x88018011, //1000 0000 0001 0001 1000 1000 0000 0001
0x84018021, //1000 0000 0010 0001 1000 0100 0000 0001
0x82018041, //1000 0000 0100 0001 1000 0010 0000 0001
0x81018081, //1000 0000 1000 0001 1000 0001 0000 0001
0x80818101, //1000 0001 0000 0001 1000 0000 1000 0001
0x80418201, //1000 0010 0000 0001 1000 0000 0100 0001
0x80218401, //1000 0100 0000 0001 1000 0000 0010 0001
0x80118801, //1000 1000 0000 0001 1000 0000 0001 0001
//0111 0111 1111 1111
0x80099001, //1001 0000 0000 0001 1000 0000 0000 1001
0x8005A001, //1010 0000 0000 0001 1000 0000 0000 0101
0x8003C001, //1100 0000 0000 0001 1000 0000 0000 0011
//0011 1111 1111 1111
0x80018001, //1000 0000 0000 0001 1000 0000 0000 0001
};
const unsigned int cTestpattern24bit[SIZE_TESTPATTERN24]=
{
//I2S link(FIFO)
//Left(Low 32bit(24bit valid) Right(High-next 32bit(24bit valid) )
0x00800001, //1000 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000 0001
0x00800001,
0x00800003, //1000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0001
0x00C00001,
0x00800005, //1000 0000 0000 0000 0000 0101 1010 0000 0000 0000 0000 0001
0x00A00001,
0x00800009, //1000 0000 0000 0000 0000 1001 1001 0000 0000 0000 0000 0001
0x00900001,
0x00800011, //1000 0000 0000 0000 0001 0001 1000 1000 0000 0000 0000 0001
0x00880001,
0x00800021, //1000 0000 0000 0000 0010 0001 1000 0100 0000 0000 0000 0001
0x00840001,
0x00800041, //1000 0000 0000 0000 0100 0001 1000 0010 0000 0000 0000 0001
0x00820001,
0x00800081, //1000 0000 0000 0000 1000 0001 1000 0001 0000 0000 0000 0001
0x00810001,
0x00800101, //1000 0000 0000 0001 0000 0101 1000 0000 1000 0000 0000 0001
0x00808001,
0x00800201, //1000 0000 0000 0010 0000 0001 1000 0000 0100 0000 0000 0001
0x00804001,
0x00800401, //1000 0000 0000 0100 0000 0001 1000 0000 0010 0000 0000 0001
0x00802001,
0x00800801, //1000 0000 0000 1000 0000 0001 1000 0000 0001 0000 0000 0001
0x00801001,
0x00801001, //1000 0000 0001 0000 0000 0001 1000 0000 0000 1000 0000 0001
0x00800801,
0x00802001, //1000 0000 0010 0000 0000 0001 1000 0000 0000 0100 0000 0001
0x00800401,
0x00804001, //1000 0000 0100 0000 0000 0001 1000 0000 0000 0010 0000 0001
0x00800201,
0x00808001, //1000 0000 1000 0000 0000 0001 1000 0000 0000 0001 0000 0001
0x00800101,
0x00810001, //1000 0001 0000 0000 0000 0001 1000 0000 0000 0000 1000 0001
0x00800081,
0x00820001, //1000 0010 0000 0000 0000 0001 1000 0000 0000 0000 0100 0001
0x00800041,
0x00840001, //1000 0100 0000 0000 0000 0001 1000 0000 0000 0000 0010 0001
0x00800021,
0x00880001, //1000 1000 0000 0000 0000 0001 1000 0000 0000 0000 0001 0001
0x00800011,
0x00900001, //1001 0000 0000 0000 0000 0101 1000 0000 0000 0000 0000 1001
0x00800009,
0x00A00001, //1010 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000 0101
0x00800005,
0x00C00001, //1100 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000 0011
0x00800003,
0x00800001, //1000 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000 0001
};
//uSize : byte
void PCM_Data_init(unsigned int uBufferAddr, unsigned int uSize)
{
int iIndex;
unsigned int wordSize = uSize/4;
// Reg_Buf Memory init
for(iIndex=0;iIndex<wordSize;iIndex+=1)
{
*( (unsigned int*)(uBufferAddr)+iIndex)=0x0;
}
printf("\n Check 0x%x Memory Init and Press Ant Key! \n", uBufferAddr);
}
//uSize : byte
void PCM_Data_making(unsigned int uBufferAddr, unsigned int uSize)
{
int i;
unsigned int *rec_buf = (unsigned int *)uBufferAddr;
unsigned int wordSize = uSize/4;
for(i=0;i<wordSize;i++)
{
*(rec_buf+i)=i;
}
//or
// *(rec_buf+0)=0xa5a5a5a5;
// *(rec_buf+1)=0x5a5a5a5a;
// *(rec_buf+2)=0xffff0000;
// *(rec_buf+3)=0xffffffff;
// *(rec_buf+4)=0x0000ffff;
}
//output : return success/fail
// pcmdata address
bool PCM_waveparser(unsigned int uWaveStartAddr,
unsigned short* uTotch,
unsigned int* uSampleRate,
unsigned short* uBitperch,
unsigned int* uSize,
unsigned int *uWaveDataAddr
)
{
unsigned char* pch=(unsigned char *)(uWaveStartAddr+8);//8 is wave loc offset
unsigned short* u16data=(unsigned short *)(uWaveStartAddr+0x16);
unsigned int* u32data=(unsigned int *)(uWaveStartAddr+0x18);
if(pch[0] == 'W' && pch[1] == 'A' && pch[2] == 'V' && pch[3] == 'E')
{
*uTotch = *u16data;
*uSampleRate = *u32data;
*uBitperch=*(unsigned short *)(uWaveStartAddr+0x22);
pch=(unsigned char *)(uWaveStartAddr+0x28-4);
if(pch[0] == 'd' && pch[1] == 'a' && pch[2] == 't' && pch[3] == 'a')
{
*uSize = *(unsigned int *)(uWaveStartAddr+0x28);
*uWaveDataAddr = (uWaveStartAddr+0x28+4);
}
else
{
pch=(unsigned char *)(uWaveStartAddr+0x40-4);
if(pch[0] == 'd' && pch[1] == 'a' && pch[2] == 't' && pch[3] == 'a')
{
*uSize = *(unsigned int *)(uWaveStartAddr+0x40);
*uWaveDataAddr = (uWaveStartAddr+0x40+4);
}
else
{
pch=(unsigned char *)(uWaveStartAddr+0x4c-4);
if(pch[0] == 'd' && pch[1] == 'a' && pch[2] == 't' && pch[3] == 'a')
{
*uSize = *(unsigned int *)(uWaveStartAddr+0x4c);
*uWaveDataAddr = (uWaveStartAddr+0x4c+4);
}
else
{
pch=(unsigned char *)(uWaveStartAddr+0x7c-4);
if(pch[0] == 'd' && pch[1] == 'a' && pch[2] == 't' && pch[3] == 'a')
{
*uSize = *(unsigned int *)(uWaveStartAddr+0x7c);
*uWaveDataAddr = (uWaveStartAddr+0x7c+4);
}
else
*uSize = 0;
}
}
}
printf("wave parsed result : totch-%d, samplerate-%d, bitperch-%d, size-%d byte",
*uTotch, *uSampleRate, *uBitperch, *uSize);
return 1;
}
else return 0;
}
/////////////////////////////////////////////////////////////////////////
// For test scenario
// First download 32bit wave file to base(0x32000000)
// if, "WAVE" is presented at 0xC exit
// else redownload put size(u32) to base
//
// string to show when the file is not present.
//
// return size at base address
unsigned int PCM_TestSourceDownload(unsigned int destaddr, char* string)
{
unsigned int* paddr=(unsigned int *)(destaddr);
unsigned char* pch=(unsigned char *)(destaddr+4+8);//4 is uart download offset, 8 is wave loc offset
unsigned int filesize;
//check
if(pch[0] == 'W' && pch[1] == 'A' && pch[2] == 'V' && pch[3] == 'E')
return *paddr;//ok
else
{
//redownload
printf(string);//"please download 44000Hz 32bit 2ch stereo Wave pcm file\n"
filesize=AUTO_DownloadData( (int)paddr);
//and save filesize
*paddr = filesize;
return filesize;
}
}
//makes pcm pattern data to observe link.
//
//output
// - bool : success or fail
// - destsizeByte : size(byte) of pattern made
//
//Input
// - destaddr : starting address of destination
// - totrepeat : repeat count of test patterns
// - eachrepeat : repeat count of one element of test pattern
// - BitperCh : bit per channel of test pattern to make
bool PCM_DATA_2chpattern_making( unsigned int* destsizeByte,
unsigned int destaddr, unsigned int totrepeat, int eachrepeat, int BitperCh)
{
unsigned char* pstartaddr=(unsigned char *)destaddr;
unsigned int* paddr=(unsigned int *)destaddr;
unsigned int wsize;
int patternsize;
unsigned int allowedunitsize;
unsigned int estimatedsizeByte;
int i,j;
bool bprint=0;
//assert
if(destsizeByte==0 || destaddr == 0 || totrepeat ==0 || eachrepeat == 0) return 0 ;
patternsize = (BitperCh==8)? SIZE_TESTPATTERN8:
(BitperCh==16)? SIZE_TESTPATTERN16:
(BitperCh==24)? SIZE_TESTPATTERN24: -1;
if(patternsize<0) return 0;
wsize = (BitperCh == 8)? totrepeat*SIZE_TESTPATTERN8 :
(BitperCh==16)? totrepeat*SIZE_TESTPATTERN16:
totrepeat*SIZE_TESTPATTERN24;
//1,
estimatedsizeByte = patternsize*eachrepeat*totrepeat*4;
if(estimatedsizeByte>MAX_PCMDATASIZE)
{
printf("data overflow the limit of 0x%x(%d byte)\n", MAX_PCMDATASIZE, MAX_PCMDATASIZE);
printf("current pattern size is 0x%x(%d byte)\n", estimatedsizeByte, estimatedsizeByte);
return 0;
}
//2
allowedunitsize = 0xffffffff/(patternsize *4* 6);
if( (totrepeat*eachrepeat) > allowedunitsize)
{
printf("data overflow the limit of totrepeat*eachrepeat count %d\n", allowedunitsize);
printf("current count is %d\n", totrepeat*eachrepeat);
return 0;
}
if(BitperCh == 8)
{
for(i=0; i<wsize; i++)
{
for(j=0; j<eachrepeat; j++)
{
*paddr = cTestpattern8bit[i%patternsize];
if(bprint)printf("%d %x : %x\n", i, paddr, *paddr);
paddr++;
}
}
}
else
if(BitperCh == 16)
{
for(i=0; i<wsize; i++)
{
for(j=0; j<eachrepeat; j++)
{
*paddr = cTestpattern16bit[i%patternsize];
if(bprint)printf("%d %x : %x\n", i, paddr, *paddr);
paddr++;
}
}
}
else
if(BitperCh == 24)
{
for(i=0; i<wsize; i=i+2)
{
for(j=0; j<eachrepeat; j++)
{
*paddr = cTestpattern24bit[i%patternsize];//left
if(bprint)printf("%d %x : %x\n", i, paddr, *paddr);
paddr++;
*paddr = cTestpattern24bit[(i%patternsize)+1];//right
if(bprint)printf("%d %x : %x\n", i, paddr, *paddr);
paddr++;
}
}
}
*destsizeByte = (unsigned int)((unsigned char* )paddr - (unsigned char* )pstartaddr);
printf("pcm pattern making : %d bit 2ch\n", BitperCh);
printf("data pattern made starting from 0x%x to 0x%x, Byte size : %d(0x%x)\n", pstartaddr, paddr, *destsizeByte, *destsizeByte);
printf("testpattern:%d, eachrepeat:%d, totrepeat:%d, calculated totsize:0x%x(%d byte) , real totsize:0x%x(%d byte)\n",
patternsize, eachrepeat, totrepeat, patternsize*eachrepeat*totrepeat*4, patternsize*eachrepeat*totrepeat*4,
*destsizeByte, *destsizeByte);
if(estimatedsizeByte == *destsizeByte)
return 1;
else
return 0;
}
//expand 2ch pcm fifo format data to designated channels
//
//output
// - bool : success or fail
// - destsizeByte : expanded data size(byte)
//
//input
// - destaddr : starting address of destination to make a data
// - destTotch : total channels number to expand
// - orgaddr : starting address of original pcm(fifo format) data is located.
// - orgTotch : 2ch is supported
// - orgsizeByte : data size(byte) of original pcm data
// - orgBit : Bit per channel of pcmdata
bool PCM_DATA_2chexpanding(unsigned int destaddr, int destTotch, unsigned int* destsizeByte,
unsigned int orgaddr , int orgTotch, unsigned int orgsizeByte, int orgBit)
{
unsigned char* pstartaddr=(unsigned char *)destaddr;
unsigned int* paddr=(unsigned int*)destaddr;
unsigned int* paddrorg=(unsigned int*)orgaddr;
unsigned int wsize;
unsigned int twochnum;
unsigned int i, j;
//assert
if(orgsizeByte==0 || destaddr == 0 || destsizeByte == NULL || destTotch==0) return 0;
if(orgTotch !=2 )
{
printf("only 2ch original data is supported!!!\n");
return 0;
}
if(destTotch%2!=0)
{
printf("only even tot channels are supported!!!\n");
return 0;
}
wsize = orgsizeByte/4;
twochnum=destTotch/2;
if(orgBit == 8 || orgBit == 16)
{
for(i=0; i<wsize; i++)
{
for(j=0; j<twochnum; j++)
{
*paddr = *paddrorg;
paddr++;
}
paddrorg++;
}
}
else
if(orgBit == 24)
{
for(i=0; i<wsize; i+=2)//2ch org
{
for(j=0; j<twochnum; j++)
{
*paddr = *paddrorg & 0x00ffffff;
paddr++;
*paddr = *(paddrorg+1) & 0x00ffffff;//be careful 1 unit is word size
paddr++;
}
//printf("%d paddrorg:0x%x *paddrorg:0x%x , paddrorg+4:0x%x , *paddrorg+4:0x%x, paddrorg+1:0x%x , *paddrorg+1:0x%x\n",
// i, paddrorg, *paddrorg, paddrorg+4, *(paddrorg+4), paddrorg+1, *(paddrorg+1));
//2ch org
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -