📄 pcm_out.s
字号:
;************************************************************************
; (c)1996-1997 Copyright M-Pact, Inc. All rights reserved
;
; Revision 1.0
;
;
;
; Module: SUB_SubBandSynthesis
;
; Initial version:Jinshi Huang 4/1/97
;
; Calling : SUB_pack_pcm
; Called by: Main
; Return: r26
; Param in:
; Temp reg:
; AGR reg:
; Local buffer:
;************************************************************************
.nolist
#include "regdef.h"
#include "memory.h"
#include "constant.h"
#include "user.h"
.list
.text
#if SR48
.extern PCM_store_ptr
.extern PCM_load_ptr
.extern PCM_blk_cnt
.extern PCM_bcnt
.extern PCM_scnt
.extern PCM_gcnt
#if ISO
#ifndef MPEG_2
.extern frmsize_offset_cnt
#endif // MPEG_2
#else // ISO
.extern frmsize_offset_cnt
#endif // ISO
#endif // SR48
.global SUB_pack_pcm
SUB_pack_pcm:
movb r3, LBfr_ps_stereo
movb r0, LBhdr_lay
tsti r0, 1
bgt Layer_II_pack //if layer_II, pack 3 blocks now
movb r0, LBout_blk //if layer_I, accumulate 3 blocks
multi r2, r0, SBLIMIT*4
movi AGRAdr0, local_sample_d_byte //chan 0
movi AGRAdr1, local_sample_d_byte + 3*SBLIMIT*4 //chan 1
addi r2, local_pcm_sample_byte
mov AGRAdr2, r2
movi r4, 0xffff //lower 16-bit mask
mupi r5, 0xffff //upper 16-bit mask
mupi r6, 0x007f //max
ori r6, 0xff00
mupi r7, 0xff80 //-max
movi r8, 0x0080 //round
CLR_TrapReg
loop SBLIMIT, pack_pcm_I
add r0, r8, a0(1*4) //round
abs r2, r0
sub r2, r6
blte lower_I_not_overflow
tsti r0, 0
mov r0, r6 //saturation
bgt lower_I_not_overflow
mov r0, r7 //-saturation
lower_I_not_overflow:
mov r1,r0
shr r0, 8 //align to lower 16-bit
and r0, r4 //mask
tsti r3,1
beq upper_I_not_overflow // branch if mono mode
add r1, r8, a1(1*4) //round
abs r2, r1
sub r2, r6
blte upper_I_not_overflow
tsti r1, 0
mov r1, r6 //saturation
bgt upper_I_not_overflow
mov r1, r7 //-saturation
upper_I_not_overflow:
shl r1, 8 //align to upper 16-bit
and r1, r5 //mask
or a2(1*4), r0, r1 //put together
pack_pcm_I:
SET_TrapReg
movb r0, LBout_blk //if layer_I, accumulate 3 blocks
addi r0, 1
movb LBout_blk, r0 //# of blocks ready for output
j r26 //return without output
Layer_II_pack:
movi AGRAdr0, local_sample_d_byte //chan 0
movi AGRAdr1, local_sample_d_byte + 3*SBLIMIT*4 //chan 1
movi AGRAdr2, local_pcm_sample_byte
movi r4, 0xffff //lower 16-bit mask
mupi r5, 0xffff //upper 16-bit mask
// mupi r6, 0x007f //max
mupi r6, 0x00ff //max
// ori r6, 0xff00
ori r6, 0xff80
// mupi r7,0xff80 //-max
mupi r7,0xff00 //-max
// movi r8, 0x0080 //round
movi r8, 0x0100 //round
#if 0
dlw r9, 0xffb4
#endif
CLR_TrapReg
loop 3*SBLIMIT, pack_pcm_II
#if 1
add r0, r8, a0(1*4) //round
#else
mulf r0, r9, a0(1*4) //round
nop
nop
rnd r0
nop
nop
nop
nop
#endif
abs r2, r0
sub r2, r6
blte lower_II_not_overflow
tsti r0, 0
mov r0, r6 //saturation
bgt lower_II_not_overflow
mov r0, r7 //-saturation
lower_II_not_overflow:
mov r1,r0
shr r0, 8 //align to lower 16-bit
// shr r0, 7 //align to lower 16-bit
and r0, r4 //mask
tsti r3,1
beq upper_II_not_overflow // branch if mono mode
#if 1
add r1, r8, a1(1*4) //round
#else
madd r10, r9, a1(1*4) //round
nop
nop
rnd r1, r10
nop
nop
nop
#endif
abs r2, r1
sub r2, r6
blte upper_II_not_overflow
tsti r1, 0
mov r1, r6 //saturation
bgt upper_II_not_overflow
mov r1, r7 //-saturation
upper_II_not_overflow:
shl r1, 8 //align to upper 16-bit
// shl r1, 9 //align to upper 16-bit
and r1, r5 //mask
or a2(1*4), r0, r1 //put together
pack_pcm_II:
SET_TrapReg
j r26
#if SR48
;************************************************************************
; (c)1996-1997 Copyright M-Pact, Inc. All rights reserved
;
; Revision 1.0
;
;
;
; Module: SUB_out_fifo (with 48kHz fixed sampling rate)
;
; Initial version: Richard Huang 10/21/97
;
; Calling : SUB_check_PTS
; Called by: SUB_MPEG_decoder
; Return: r26
; Param in:
; Temp reg:
; AGR reg:
; Local buffer:
;************************************************************************
.nolist
#include "regdef.h"
#include "memory.h"
#include "constant.h"
.list
.text
.global SUB_out_fifo_SR48
SUB_out_fifo_SR48:
#if SPDIF_OUT
dlw r0,USER_ICFG
nop
andi r0,ICFG_SPDIF_ENA
tsti r0,ICFG_SPDIF_ENA
beq Out_fifo_spdif
#endif
movb r0, LBhdr_lay
tsti r0, 1
bgt output_1_block //if layer_II, output now
movb r0, LBout_blk //if layer_I, accumulate 3 blocks
tsti r0, 3
beq output_1_block
movi r1, 1
movb LBPCM_flag, r1 ;set the flag so that main loop
//can continue
j r26 //return without output
output_1_block:
;; read location of read fifo
rlwi r1, PCM_Rd_Ptr ; read current pointer register (28c)
dlw r9,PCM_store_ptr
andi r1, 0xffff
sub r1, r9
bgte chk_fifo_space
addi r1, PCM_FIFO_SIZE
chk_fifo_space:
tsti r1, PCM_STORE_SIZE
blte pcm_not_out_48 ; if begin <= ptr <= end, wait
// Adjust bytecount and update PTS if necessary
movb r4, LBblknum
tsti r4,0
bne Lskip_PTS_48
dlw r1, PCM_blk_cnt
movh r28,LIfrmsize
tsti r1,0
bne Lskip_PTS_48
#if 0 // 5-7-98
shl r28,1
movw r1,LWbytecount
add r1,r28
#if ISO
#ifndef MPEG_2
dlw r0,frmsize_offset_cnt
nop
tsti r0,0
beq Lno_offset_48
subi r0,1
addi r1,2
dsw r0,frmsize_offset_cnt
Lno_offset_48:
#endif // MPEG_2
#else // ISO
#ifdef MPEG_2
movb r0,LBhdr_sampling_frequency
tsti r0,1
beq Lno_offset_48
#endif // MPEG_2
dlw r0,frmsize_offset_cnt
nop
tsti r0,0
beq Lno_offset_48
subi r0,1
addi r1,2
dsw r0,frmsize_offset_cnt
Lno_offset_48:
#endif // ISO
movw LWbytecount,r1
#endif // 0
jsr r28,SUB_check_PTS
Lskip_PTS_48:
// apply the gain to the samples
movw r4,LWpcmscale
movi r0, 0xffff //lower 16-bit mask
mupi r1, 0xffff //upper 16-bit mask
dlw r6, PCM_blk_cnt
nop
multi r6, 32*4
nop
nop
nop
nop
addi r6, local_pcm_sample_byte
mov AGRAdr0,r6
dlw r3,KARAOKE_0
#ifdef I2S
movi AGRAdr1, local_scaled_pcm_byte
CLR_TrapReg_1
// nop
// nop
andi r3,0x3
tsti r3,3 // check KARAOKE_0
beq Lswap_lr // R=melody, L=vocal
tsti r3,2
beq Ll_to_lr // R=vocal, L=vocal
tsti r3,1
beq Lr_to_lr // R=melody, L=melody
// default: R=vocal, L=melody
loop 32, Lpcm_gain_loop_48
shl r3, a0(0*4), 16 //get lower 16-bit
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
and r3, r1, a0(1*4) //get upper 16-bit; pipeline
rnd r6
shra r3, 8 //sign-extented to 1.23 format
mulf r8, r4, r3
nop
rnd r8
shl a1(1*4), r6, 7 //L sample. align to MSB with 1 shift
nop
nop
shl a1(1*4), r8, 7 //R sample. align to MSB with 1 shift
Lpcm_gain_loop_48:
j Lend_of_gain_loop_48
Lswap_lr:
loop 32, Lpcm_gain_loop_48_3
and r3, r1, a0(0*4) //get upper 16-bit; pipeline
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
shl r3, a0(1*4), 16 //get lower 16-bit
rnd r6
shra r3, 8 //sign-extented to 1.23 format
mulf r8, r4, r3
nop
rnd r8
shl a1(1*4), r6, 7 //L sample. align to MSB with 1 shift
nop
nop
shl a1(1*4), r8, 7 //R sample. align to MSB with 1 shift
Lpcm_gain_loop_48_3:
j Lend_of_gain_loop_48
Lr_to_lr:
loop 32, Lpcm_gain_loop_48_2
and r3, r1, a0(1*4) //get upper 16-bit; pipeline
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
nop
rnd r6
nop
nop
nop
rnd r8
shl a1(1*4), r6, 7 //L sample. align to MSB with 1 shift
shl a1(1*4), r6, 7 //R sample. align to MSB with 1 shift
Lpcm_gain_loop_48_2:
j Lend_of_gain_loop_48
Ll_to_lr:
loop 32, Lpcm_gain_loop_48_1
shl r3, a0(1*4), 16 //get lower 16-bit
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
nop
rnd r6
nop
nop
nop
shl a1(1*4), r6, 7 //L sample. align to MSB with 1 shift
shl a1(1*4), r6, 7 //R sample. align to MSB with 1 shift
Lpcm_gain_loop_48_1:
#else // I2S
CLR_TrapReg_1
// nop
// nop
andi r3,0x3
tsti r3,3 // check KARAOKE_0
beq Lswap_lr // R=melody, L=vocal
tsti r3,2
beq Ll_to_lr // R=vocal, L=vocal
tsti r3,1
beq Lr_to_lr // R=melody, L=melody
// default: R=vocal, L=melody
loop 32, Lpcm_gain_loop_48
and r3, r1, a0(0*4) //get upper 16-bit
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
and r3, r0, a0(0*4) //get lower 16-bit; pipeline
rnd r6
shl r3, 16
shra r3, 8 //sign-extented to 1.23 format
mulf r8, r4, r3
shl r6, 8 //align to upper 16-bit; pipeline
rnd r8
and r6, r1 //keep only 16-bit data
nop
nop //pipeline
shr r8, 8 //align to lower 16-bit
and r8, r0 //keep only 16-bit data
or a0(1*4), r6, r8 //put back 32-bit pair
Lpcm_gain_loop_48:
j Lend_of_gain_loop_48
Lswap_lr:
loop 32, Lpcm_gain_loop_48_3
and r3, r1, a0(0*4) //get upper 16-bit
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
and r3, r0, a0(0*4) //get lower 16-bit; pipeline
rnd r6
shl r3, 16
shra r3, 8 //sign-extented to 1.23 format
mulf r8, r4, r3
shr r6, 8 //align to lower 16-bit; pipeline
rnd r8
and r6, r0 //keep only 16-bit data
nop
nop //pipeline
shl r8, 8 //align to upper 16-bit
and r8, r1 //keep only 16-bit data
or a0(1*4), r6, r8 //put back 32-bit pair
Lpcm_gain_loop_48_3:
j Lend_of_gain_loop_48
Lr_to_lr:
loop 32, Lpcm_gain_loop_48_2
and r3, r1, a0(0*4) //get upper 16-bit
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
nop
rnd r6
nop
nop
nop
shr r8, r6, 8 //align to lower 16-bit
and r8, r0 //keep only 16-bit data
shl r6, 8 //align to upper 16-bit; pipeline
and r6, r1 //keep only 16-bit data
or a0(1*4), r6, r8 //put back 32-bit pair
Lpcm_gain_loop_48_2:
j Lend_of_gain_loop_48
Ll_to_lr:
loop 32, Lpcm_gain_loop_48_1
and r3, r0, a0(0*4) //get lower 16-bit
shl r3, 16
shra r3, 8 //sign-extented to 1.23 format
mulf r6, r4, r3
nop
rnd r6
nop
nop
nop
shr r8, r6, 8 //align to lower 16-bit
and r8, r0 //keep only 16-bit data
shl r6, 8 //align to upper 16-bit; pipeline
and r6, r1 //keep only 16-bit data
or a0(1*4), r6, r8 //put back 32-bit pair
Lpcm_gain_loop_48_1:
#endif // I2S
Lend_of_gain_loop_48:
SET_TrapReg
// Store scaled sample to FIFO
#if 0
//------------------------------------------------------------------
Pseudo code:
init:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -