📄 mp3decnew.s
字号:
.rounding 0
.include "mp3_def.h"
.include "mp3_ext.h"
.include "mp12_ext.h"
.include "mp12_def.h"
.extern DecodingHuffman,DecodingDequantizer,DecodingStereo,DecodingReordering
.extern DecodingAntialias,DecodingIMDCT,SynthesisPolyphase,InversionFreqLine
.extern FindJointStereoSfb,VolumeControl,MP3Equalizer,DecodingStereoLSF
.extern InitalizeForL2Decoding,ParsingHeaderL2,SelectTableL2,BitAllocationL2
.extern ScfsiL2,ScalefactorsL2,DequantizerL2,Separate_channel,FetchDequanData
.extern ComposeStereoL12,MP12Equalizer,VolumeConFreq,MP3SpectrumDisplay,MP3LevelMeter
.extern VolumeFadeIn
.extern InitalizeForL1Decoding,ParsingHeaderL1,SelectTableL1,BitAllocationL1
.extern ScalefactorsL1,DequantizerL1,Separate_channelL1,Load_L1table
.extern huff_xdeq_tbl,sec_tbl2,anc_tbl,ancL2_cod,ancL1_cod
.extern LnkBackup,G_cnt,CodecSharedMP3,
.global _MP3Decoder
/////////////////////////////////////////////////////////////
Mp3Decoding_section
/////////////////////////////////////////////////////////////
_MP3Decoder::
Mp3Decoding::
push a14
jsr BackupGPRSFR
jsr InitalizeForDecoding
cmp eq ,r0 ,#0
jpt Mp3DecodingReturn
ld a12 ,#0x2c0050
%1: ldw r2 ,@[a12]
and r2, #0x7000
cmp eq, r2, #(0x1<<12)
brt %b1
cmp eq, r2, #(0x2<<12)
brt %b1
ld a12 ,#0x2c0000 //CONFIG0
ldw r0 ,@[a12]
and r0, #0xff
ldb r1 ,@[a10+Index_OutPCMSize]
cmp eq ,r1 ,#24
brt PCM24
or r0 ,#0x4600
jmp PCM24End
PCM24:
or r0 ,#0x4000
PCM24End:
ldw @[a12+0],r0 //SBF1 mac[23:0]->ext[31:0] & zero extension
// 0ffset read
ld a12 ,#0x2c0000
.ifdef PtrLongSize
ldw r0 ,@[a10+Index_InputBufferOffset]
ldw @[a12+0x52],r0
ldw r0 ,@[a10+Index_InputBufferOffset+2]
ldw @[a12+0x54],r0
.else
ld r0 ,#0
ldw @[a12+0x52],r0
ldw r0 ,@[a10+Index_InputBufferOffset]
ldw @[a12+0x54],r0
.endif
ld r0 ,#0x1000 //SBFCON SBF0 FILL COMMAND & SBF1 FLUSH COMMAND
ldw @[a12+0x4a],r0
//
// jsr DetectVolumeOffset
///////////////////////////////////////////////////////////////////////////////////
// previous buffer level up & down for Digital Volume
///////////////////////////////////////////////////////////////////////////////////
.if(0)
// ldb r0 ,@[a10+Index_VolumeIndex]
ldb r0 ,@[a13+Index_VolumeControl]
eld a ,G_PrevVol
ecld r1 ,a
cmp eq ,r0 ,r1
brt NotChangedVolFreqLevel
ecld a ,r0
efz16 a
eld G_PrevVol,a
// ld a12 ,#IndexFD_Vol
// ldw r5 ,@[a12+0]
eld a ,IndexFD_Vol
ecld r5 ,a
// cmp ge ,r0 ,#18
cmp ge ,r0 ,r5
brf NotChangedVolFreqLevel
eadd a ,#tbl_volume ; get the value from
eld rp1 ,a
eld x0 ,@rp1
eld sd0 ,#((-1&0fh)<<12)|(1<<8)|((-1&0fh)<<4)|(1<<0)
eld sd2 ,#((-1&0fh)<<12)|(1<<8)|((-1&0fh)<<4)|(1<<0)
ld r6 ,#1024-1
eld rp0 ,#Area_imdctPrevCh0
eld rp2 ,rp0
eld y0 ,@rp0+s0
PrevSynthLevel2
emul x0y0 ,y0 ,@rp0+s0
//eld p ,#0
bnzd r6 ,PrevSynthLevel2
eld @rp2+d0 ,p
ld r6 ,#2048-1
eld rp0 ,#Area_synthesisBufferCh0
eld rp2 ,rp0
eld y0 ,@rp0+s0
PrevSynthLevel3
emul x0y0 ,y0 ,@rp0+s0
//eld p ,#0
bnzd r6 ,PrevSynthLevel3
eld @rp2+d0 ,p
NotChangedVolFreqLevel
.endif
///////////////////////////////////////////////////////////////////////////////////
eld a ,rpd1.index_Glsf
ecld r0 ,a
cmp eq ,r0 ,#0
brt FirstGranule
eld a ,#1
eld rpd1.index_GranuleLoop ,a
FirstGranule
eld a ,rpd1.index_GranuleLoop
ecld r0 ,a
cmp eq ,r0 ,#0
brt Mp3DecodingSecondGranule
eld a ,#1
eld rpd1.index_GranuleLoop, a
eld a ,#Area_sideInformation+const_sideInformationSize
eld rpd1.index_GptrSideInformation, a
jsr Fill_bufferMP3
jsr ParsingHeader ;when error, nz
///////////////////////////////////////////////////////////////
eld a ,GLayerDiff
ecld r1 ,a
cmp eq ,r1 ,#1
jpt L2Decoding
cmp eq ,r1 ,#2
jpt L1Decoding
///////////////////////////////////////////////////////////////
cmp eq ,r0 ,#0
jpf Mp3DecodingFrameError
jsr GetSideInformation
jsr FetchMainData
eld a ,G_cnt
eadd a ,#1
eld G_cnt ,a
ecld r0 ,a
cmp eq ,r0 ,#957
brf pass_debug
nop
nop
pass_debug
jmp Mp3DecodingSecondGranuleSUB
Mp3DecodingSecondGranule
ldw r0 ,@[a13+Index_FrameLength]
ecld b ,r0
efz8 b ;b<-frame size
esub b ,#1
eneg b
esra b
ecld r0 ,b
ldw r5 ,@[a13+Index_InputBufferValidData]
add r0 ,r5
ldw @[a13+Index_InputBufferValidData] ,r0
Mp3DecodingSecondGranuleSUB
eld a ,rpd1.index_GmpegChannel
ecld r0 ,a
and r0 ,#0xff
ldb @[a13+Index_ChannelLoop] ,r0
eld a, #Area_leftChannel
Mp3DecodingChannelLoop1
eld rpd1.index_GptrCurrentDecodingData, a
jsr CopySideInformation
jsr RestoreForDecoding
eld a ,rpd1.index_Glsf
ecld r0 ,a
cmp eq ,r0 ,#0
brf LSF_Scalefactor
jsr GetScalefactor
bra LSF_ScalefactorEnd
LSF_Scalefactor
jsr GetScalefactorLSF
LSF_ScalefactorEnd
jsr DecodingHuffman
jsr StoreForNextDecoding
jsr FindJointStereoSfb
jsr DecodingDequantizer
eld a ,#Area_rightChannel
ldb r6 ,@[a13+Index_ChannelLoop]
dec r6
ldb @[a13+Index_ChannelLoop] ,r6
cmp eq ,r6 ,#0
brt Mp3DecodingChannelLoop1
jsr DecodingStereoLSF
eld a ,rpd1.index_GmpegChannel
ecld r0 ,a
and r0 ,#0xff
ldb @[a13+Index_ChannelLoop] ,r0
eld b ,#const_sideInformationSize
efz16 a
etst nz ,t
eslat b
eld a ,rpd1.index_GptrSideInformation
esub a ,b
eld rpd1.index_GptrSideInformation, a
eld a ,#Area_leftChannel
Mp3DecodingChannelLoop2
eld rpd1.index_GptrCurrentDecodingData, a
jsr CopySideInformation
jsr DecodingReordering
///////////////////////////////////////////////////////////////////
// Digital Function On Frequency Domain
///////////////////////////////////////////////////////////////////
// ldb r0 ,@[a10+Index_OptionalFunctionOnOff]
ldb r0 ,@[a13+Index_EQ_VolumeFlag]
and r0 ,#0x08
cmp eq ,r0 ,#0x08
brf MP3DigitalSpectrum_Pass
// jsr MP3SpectrumDisplay
MP3DigitalSpectrum_Pass
// ldb r0 ,@[a10+Index_OptionalFunctionOnOff]
ldb r0 ,@[a13+Index_EQ_VolumeFlag]
and r0 ,#0x04
cmp eq ,r0 ,#0x04
brf MP3DigitalLevel_Pass
// jsr MP3LevelMeter
MP3DigitalLevel_Pass
// ldb r0 ,@[a10+Index_OptionalFunctionOnOff]
ldb r0 ,@[a13+Index_EQ_VolumeFlag]
and r0 ,#0x01
cmp eq ,r0 ,#0x01
brf MP3DigitalVOL_Pass
// jsr VolumeConFreq
MP3DigitalVOL_Pass
// ldb r0 ,@[a10+Index_OptionalFunctionOnOff]
ldb r0 ,@[a13+Index_EQ_VolumeFlag]
and r0 ,#0x02
cmp eq ,r0 ,#0x02
brf MP3DigitalEQ_Pass
// jsr MP3Equalizer
MP3DigitalEQ_Pass
///////////////////////////////////////////////////////////////////
jsr DecodingAntialias
jsr DecodingIMDCT
jsr InversionFreqLine
jsr SynthesisPolyphase ;b is returned with a updated
eld a ,#Area_rightChannel
ldb r6 ,@[a13+Index_ChannelLoop]
dec r6
ldb @[a13+Index_ChannelLoop] ,r6
cmp eq ,r6 ,#0
brt Mp3DecodingChannelLoop2
esub b ,#1024
eld rpd1.index_GptrSynPrevious, b ;update the pointer of
;synthesis buffer-1024
eld a ,rpd1.index_GranuleLoop
eadd a ,#-1
efz16 a
eld rpd1.index_GranuleLoop, a
Mp3DecodingFrame
// ldb r0 ,@[a10+Index_OptionalFunctionOnOff]
ldb r0 ,@[a13+Index_EQ_VolumeFlag]
and r0 ,#0x01
cmp eq ,r0 ,#0x01
brf MP3DigitalTDVOL_Pass
// jsr VolumeControl
MP3DigitalTDVOL_Pass
eld a ,rpd1.index_Glsf
ecld r1 ,a
cmp eq ,r1 ,#0
brf LSF_start_reset
eld a ,G_cnt
ecp a ,#3
// ecp a ,#5
enop
bra ec1 ,start_reset
jmp start_resetEnd
start_reset
push a14
jsr PcmBufferReset
pop a14
start_resetEnd
jmp StartReset_End
LSF_start_reset
cmp eq ,r1 ,#2
brt Mpeg25_start
eld a ,G_cnt
ecp a ,#5
enop
bra ec1 ,start_reset2
jmp start_reset2End
start_reset2
push a14
jsr PcmBufferReset
pop a14
start_reset2End
jmp StartReset_End
Mpeg25_start
eld a ,G_cnt
ecp a ,#8
enop
bra ec1 ,start_reset3
jmp start_reset3End
start_reset3
push a14
jsr PcmBufferReset
pop a14
start_reset3End
StartReset_End
jsr ComposeStereo
// jsr VolumeFadeIn
jsr MP3_SaveDecodedAudio
ldw r0 ,@[a10+Index_pParameterH]
ld e12 ,r0
ldw r0 ,@[a10+Index_pParameterL]
ld r12 ,r0
ldb r0 ,@[a13+Index_Mode]
ldb @[a12+Index_P_ChannelLoop] ,r0 //Channel Information
Mp3DecodingFrameError
.if(0)
eld sd0 ,#((-1&0fh)<<12)|(1<<8)|((-1&0fh)<<4)|(1<<0)
eld a ,#0
ld r6 ,#1024-1
eld rp0 ,#Area_imdctPrevCh0
PrevSynthzero
bnzd r6 ,PrevSynthzero
eld @rp0+d0 ,a
ld r6 ,#2048-1
eld rp0 ,#Area_synthesisBufferCh0
PrevSynthzero1
bnzd r6 ,PrevSynthzero1
eld @rp0+d0 ,a
.endif
Mp3DecodingReturn
jsr RestoreGPRSFR
pop a14
ret
//////////////////////////////////////////////////////////////////////////////////
; Layer2 Main
;
//////////////////////////////////////////////////////////////////////////////////
L2Decoding::
ld a12 ,#0x2c0050
%1: ldw r2 ,@[a12]
and r2, #0x7000
cmp eq, r2, #(0x1<<12)
brt %b1
cmp eq, r2, #(0x2<<12)
brt %b1
ld a12 ,#0x2c0000 //CONFIG0
ldw r0 ,@[a12]
and r0, #0xff
ldb r1 ,@[a10+Index_OutPCMSize]
cmp eq ,r1 ,#24
brt PCM24L2
or r0 ,#0x4600
jmp PCM24EndL2
PCM24L2:
or r0 ,#0x4000
PCM24EndL2:
ldw @[a12+0],r0 //SBF1 mac[23:0]->ext[31:0] & zero extension
// 0ffset read
ld a12 ,#0x2c0000
.ifdef PtrLongSize
ldw r0 ,@[a10+Index_InputBufferOffset]
ldw @[a12+0x52],r0
ldw r0 ,@[a10+Index_InputBufferOffset+2]
ldw @[a12+0x54],r0
.else
ld r0 ,#0
ldw @[a12+0x52],r0
ldw r0 ,@[a10+Index_InputBufferOffset]
ldw @[a12+0x54],r0
.endif
ld r0 ,#0x1000 //SBFCON SBF0 FILL COMMAND & SBF1 FLUSH COMMAND
ldw @[a12+0x4a],r0
////////////////////////////////////////
jsr InitalizeForL2Decoding
eld a ,G_cnt
eadd a ,#1
eld G_cnt ,a
eld a ,rpd1.index_GranuleLoop
ecld r1 ,a
cmp eq ,r1 ,#0
brt SecondGranuleL2
jsr Fill_bufferMP3
jsr ParsingHeaderL2
///////////////////////////////////////////////////////////////
eld a ,GLayerDiff
ecld r1 ,a
ld r2 ,#0
cmp eq ,r1 ,#1
brt Layer_sel
ldb @[a13+Index_FrameStartFlag] ,r2
ldb @[a13+Index_GL2Done] ,r2 // warning
ldw r0 ,@[a10+Index_pParameterH]
ld e12 ,r0
ldw r0 ,@[a10+Index_pParameterL]
ld r12 ,r0
ldb @[a12+Index_P_GL2Done] ,r2
jmp Mp3DecodingReturn
///////////////////////////////////////////////////////////////
Layer_sel
cmp eq ,r0 ,#0
jpf Mp3DecodingReturn
eld sd0 ,#((1&0fh)<<12)|(1<<8)|((2&0fh)<<4)|(1<<0)
eld sd1 ,#((1&0fh)<<12)|(1<<8)|((2&0fh)<<4)|(1<<0)
jsr SelectTableL2
jsr BitAllocationL2
jsr ScfsiL2
jsr ScalefactorsL2
jsr FetchDequanData
jsr StoreForNextDecoding
SecondGranuleL2
jsr RestoreForDecoding
eld c ,#0
eld rpd0.index_Ggr ,c
eld a ,rpd1.index_GranuleLoop
ecp a ,#1
enop
bra ec0 ,first_Ggr
eld c ,#6
eld rpd0.index_Ggr ,c
first_Ggr
eld a ,#0
eld rpd0.index_GdequanCnt ,a
DequanGrLoop
jsr DequantizerL2
eld a ,rpd0.index_Ggr
eadd a ,#1
eld rpd0.index_Ggr ,a
eld a ,rpd0.index_GdequanCnt
eadd a ,#1
eld rpd0.index_GdequanCnt ,a
ecp a ,#6
enop
bra ec2 ,DequanGrLoop
jsr Separate_channel
eld a ,rpd0.index_Gnch
esub a ,#1
ecld r0 ,a
ldb @[a13+Index_ChannelLoop] ,r0
jsr StoreForNextDecoding
eld a ,#Area_leftChannel
L2DecodingChannelLoop2
eld rpd1.index_GptrCurrentDecodingData, a
jsr SynthesisPolyphase
eld a ,#Area_rightChannel
ldb r6 ,@[a13+Index_ChannelLoop]
dec r6
ldb @[a13+Index_ChannelLoop] ,r6
cmp eq ,r6 ,#0
brt L2DecodingChannelLoop2
esub b ,#1024
eld rpd1.index_GptrSynPrevious, b ;update the pointer of
eld a ,rpd1.index_GranuleLoop
ecld r0 ,a
cmp eq ,r0 ,#0
brf pass_firstGr
///////////////////////////////////////////////////////////////////////////////////
ldw r2 ,@[a13+Index_FrameLength] ;r0<-frame length
ldw r3 ,@[a13+Index_InputBufferValidData]
sub r3 ,r2
ldw @[a13+Index_InputBufferValidData] ,r3
ldw r3 ,@[a13+Index_InputBufferRPointerL] ;source
add r3 ,r2
and r3 ,#FetchMASK
or r3 ,#StartReadPointer
ldw @[a13+Index_InputBufferRPointerL] ,r3 ;source
ld r3 ,#0x20
ldw @[a13+Index_InputBufferRPointerH] ,r3 ;source
///////////////////////////////////////////////////////////////////////////////////
pass_firstGr
eadd a ,#-1
eabs a
eld rpd1.index_GranuleLoop, a
jsr ComposeStereoL12 //2002
jmp Mp3DecodingFrame
//////////////////////////////////////////////////////////////////////////////////
; Layer1 Main
;
//////////////////////////////////////////////////////////////////////////////////
L1Decoding::
ld a12 ,#0x2c0050
%1: ldw r2 ,@[a12]
and r2, #0x7000
cmp eq, r2, #(0x1<<12)
brt %b1
cmp eq, r2, #(0x2<<12)
brt %b1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -