📄 pcm_soft.c
字号:
/*****************************************************************************
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: pcm_soft.c 585 2006-01-16 09:48:55Z picard $
*
* The Core Pocket Media Player
* Copyright (c) 2004-2005 Gabor Kovacs
*
****************************************************************************/
#include "../common.h"
#include "../dyncode/dyncode.h"
#include "pcm_soft.h"
static INLINE int PCMShift(const audio* Format)
{
int Bit = 0;
if (Format->Bits>8) Bit = 1;
if (Format->Bits>16) Bit = 2;
if (!(Format->Flags & PCM_PLANES) && Format->Channels==2)
++Bit;
return Bit;
}
void PCM_Init()
{
}
void PCM_Done()
{
pcm_soft* p;
while ((p = Context()->PCM)!=NULL)
{
Context()->PCM = p->Next;
CodeDone(&p->Code);
free(p);
}
}
#if (!defined(ARM) && !defined(SH3) && !defined(MIPS)) || !defined(CONFIG_DYNCODE)
void PCM_S16_To_S16_Stereo(pcm_soft* This,const planes DstPtr,const constplanes SrcPtr,int DstLength,pcmstate* State,int Volume)
{
const int32_t* Src = SrcPtr[0];
int32_t* Dst = DstPtr[0];
int32_t* DstEnd = Dst + (DstLength >> 2);
if (State->Step == 256)
memcpy(Dst,Src,DstLength);
else
{
int Pos = State->Pos;
int Step = State->Step;
while (Dst != DstEnd)
{
*(Dst++) = Src[Pos >> 8];
Pos += Step;
}
}
}
void PCM_P32_To_S16_Stereo(pcm_soft* This,const planes DstPtr,const constplanes SrcPtr,int DstLength,pcmstate* State,int Volume)
{
const int32_t* SrcA = SrcPtr[0];
const int32_t* SrcB = SrcPtr[1];
int16_t* Dst = DstPtr[0];
int16_t* DstEnd = Dst + (DstLength >> 1);
int UpLimit = (1 << This->Src.FracBits) - 1;
int DownLimit = -(1 << This->Src.FracBits);
int Shift = This->Src.FracBits - This->Dst.FracBits;
if (State->Step == 256)
{
while (Dst != DstEnd)
{
int Left = *(SrcA++);
int Right = *(SrcB++);
if (Left > UpLimit) Left = UpLimit;
if (Left < DownLimit) Left = DownLimit;
if (Right > UpLimit) Right = UpLimit;
if (Right < DownLimit) Right = DownLimit;
Dst[0] = (int16_t)(Left >> Shift);
Dst[1] = (int16_t)(Right >> Shift);
Dst += 2;
}
}
else
{
int Pos = State->Pos;
int Step = State->Step;
while (Dst != DstEnd)
{
int Left = SrcA[Pos >> 8];
int Right = SrcB[Pos >> 8];
if (Left > UpLimit) Left = UpLimit;
if (Left < DownLimit) Left = DownLimit;
if (Right > UpLimit) Right = UpLimit;
if (Right < DownLimit) Right = DownLimit;
Dst[0] = (int16_t)(Left >> Shift);
Dst[1] = (int16_t)(Right >> Shift);
Dst += 2;
Pos += Step;
}
}
}
void PCMUniversal(pcm_soft* This,const planes DstPtr,const constplanes SrcPtr,int DstLength,pcmstate* State,int Volume)
{
const uint8_t* Src[2];
const uint8_t* DstEnd;
uint8_t* Dst[2];
bool_t SrcSwap = This->SrcSwap;
bool_t DstSwap = This->DstSwap;
int DstType = This->DstType;
int SrcType = This->SrcType;
int DstStep = 1 << This->DstShift;
int Pos = State->Pos;
int Step = State->Step;
float SrcScale = 0;
float DstScale = 0;
int SrcUnsigned = This->SrcUnsigned;
int DstUnsigned = This->DstUnsigned;
int UpLimit = (1 << This->Src.FracBits) - 1;
int DownLimit = -(1 << This->Src.FracBits);
int SrcShift = 31 - This->Src.FracBits;
int DstShift = 31 - This->Dst.FracBits;
bool_t OnlyLeft = (This->Dst.Flags & PCM_ONLY_LEFT) != 0;
bool_t OnlyRight = (This->Dst.Flags & PCM_ONLY_RIGHT) != 0;
bool_t VolumeShift = This->Src.Bits >= 23;
if (!This->UseVolume)
Volume = 256;
if (SrcType >= 12) SrcScale = (float)(1 << This->Src.FracBits);
if (DstType >= 12) DstScale = 1.0f/(1 << This->Dst.FracBits);
Dst[0] = (uint8_t*) DstPtr[0];
Dst[1] = (uint8_t*) DstPtr[1];
Src[0] = (uint8_t*) SrcPtr[0];
Src[1] = (uint8_t*) SrcPtr[1];
DstEnd = Dst[0] + DstLength;
// mono,packed
// mono,planar
// stereo,packed
// stereo,planar
while (Dst[0] != DstEnd)
{
int Left;
int Right;
if (SrcUnsigned)
switch (SrcType)
{
default:
case 0:
case 1:
Left = Right = ((uint8_t*)Src[0])[Pos >> 8] - SrcUnsigned;
break;
case 2:
Left = ((uint8_t*)Src[0])[(Pos >> 8)*2] - SrcUnsigned;
Right = ((uint8_t*)Src[0])[(Pos >> 8)*2+1] - SrcUnsigned;
break;
case 3:
Left = ((uint8_t*)Src[0])[(Pos >> 8)] - SrcUnsigned;
Right = ((uint8_t*)Src[1])[(Pos >> 8)] - SrcUnsigned;
break;
case 4:
case 5:
Left = ((uint16_t*)Src[0])[Pos >> 8];
if (SrcSwap)
Left = SWAP16(Left);
Left -= SrcUnsigned;
Right = Left;
break;
case 6:
Left = ((uint16_t*)Src[0])[(Pos >> 8)*2];
Right = ((uint16_t*)Src[0])[(Pos >> 8)*2+1];
if (SrcSwap)
{
Left = SWAP16(Left);
Right = SWAP16(Right);
}
Left -= SrcUnsigned;
Right -= SrcUnsigned;
break;
case 7:
Left = ((uint16_t*)Src[0])[(Pos >> 8)];
Right = ((uint16_t*)Src[1])[(Pos >> 8)];
if (SrcSwap)
{
Left = SWAP16(Left);
Right = SWAP16(Right);
}
Left -= SrcUnsigned;
Right -= SrcUnsigned;
break;
case 8:
case 9:
Left = ((uint32_t*)Src[0])[Pos >> 8];
if (SrcSwap)
Left = SWAP32(Left);
Left -= SrcUnsigned;
Right = Left;
break;
case 10:
Left = ((uint32_t*)Src[0])[(Pos >> 8)*2];
Right = ((uint32_t*)Src[0])[(Pos >> 8)*2+1];
if (SrcSwap)
{
Left = SWAP32(Left);
Right = SWAP32(Right);
}
Left -= SrcUnsigned;
Right -= SrcUnsigned;
break;
case 11:
Left = ((uint32_t*)Src[0])[(Pos >> 8)];
Right = ((uint32_t*)Src[1])[(Pos >> 8)];
if (SrcSwap)
{
Left = SWAP32(Left);
Right = SWAP32(Right);
}
Left -= SrcUnsigned;
Right -= SrcUnsigned;
break;
}
else
switch (SrcType)
{
default:
case 0:
case 1:
Left = Right = ((int8_t*)Src[0])[Pos >> 8];
break;
case 2:
Left = ((int8_t*)Src[0])[(Pos >> 8)*2];
Right = ((int8_t*)Src[0])[(Pos >> 8)*2+1];
break;
case 3:
Left = ((int8_t*)Src[0])[(Pos >> 8)];
Right = ((int8_t*)Src[1])[(Pos >> 8)];
break;
case 4:
case 5:
Left = ((int16_t*)Src[0])[Pos >> 8];
if (SrcSwap)
Left = (int16_t)SWAP16(Left);
Right = Left;
break;
case 6:
Left = ((int16_t*)Src[0])[(Pos >> 8)*2];
Right = ((int16_t*)Src[0])[(Pos >> 8)*2+1];
if (SrcSwap)
{
Left = (int16_t)SWAP16(Left);
Right = (int16_t)SWAP16(Right);
}
break;
case 7:
Left = ((int16_t*)Src[0])[(Pos >> 8)];
Right = ((int16_t*)Src[1])[(Pos >> 8)];
if (SrcSwap)
{
Left = (int16_t)SWAP16(Left);
Right = (int16_t)SWAP16(Right);
}
break;
case 8:
case 9:
Left = ((int32_t*)Src[0])[Pos >> 8];
if (SrcSwap)
Left = (int32_t)SWAP32(Left);
Right = Left;
break;
case 10:
Left = ((int32_t*)Src[0])[(Pos >> 8)*2];
Right = ((int32_t*)Src[0])[(Pos >> 8)*2+1];
if (SrcSwap)
{
Left = (int32_t)SWAP32(Left);
Right = (int32_t)SWAP32(Right);
}
break;
case 11:
Left = ((int32_t*)Src[0])[(Pos >> 8)];
Right = ((int32_t*)Src[1])[(Pos >> 8)];
if (SrcSwap)
{
Left = (int32_t)SWAP32(Left);
Right = (int32_t)SWAP32(Right);
}
break;
case 12:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -