@VolNoAGC(s16 *lbuf,s16 *rbuf,u32 count,s32 vol)
    .ALIGN
    .GLOBAL VolNoAGC	@ r0:Destp  ok
    .CODE 32

VolNoAGC:
  stmfd   r13!,{r4,r5,r6,lr}

  ldr r5,=-32768
  ldr r6,=32767
  
VolNoAGC_loop:
  ldrsh r4,[r0]
  ldrsh lr,[r1]
  mul r4,r4,r3
  mul lr,lr,r3
  asr r4,r4,#11 
  asr lr,lr,#11
  cmps r4,r5
  movlt r4,r5
  cmps r4,r6
  movgt r4,r6
  cmps lr,r5
  movlt lr,r5
  cmps lr,r6
  movgt lr,r6
  strh r4,[r0],#2
  subs r2,#1
  strh lr,[r1],#2
  bne VolNoAGC_loop
  
  ldmfd	r13!,{r4,r5,r6,lr}
  bx lr

@    .ALIGN
@    .GLOBAL VolUseAGC	@ r0:Destp  ok
@    .CODE 32
@@asm u32 VolUseAGC(s16 *lbuf,s16 *rbuf,u32 count,s32 vol)
@VolUseAGC:
@
@  stmfd   r13!,{r4,r5,r6,r7,lr}
@
@  ldr r5,=-32768
@  ldr r6,=32767
@  
@  mov r7,#0
@
@VolUseAGC_loop:
@  ldrsh r4,[r0]
@  ldrsh lr,[r1]
@  mul r4,r4,r3
@  mul lr,lr,r3
@  asr r4,r4,#11 
@  asr lr,lr,#11 
@  cmps r4,r5
@  movlt r4,r5
@  movlt r7,#1
@  cmps r4,r6
@  movgt r4,r6
@  movgt r7,#1
@  cmps lr,r5
@  movlt lr,r5
@  movlt r7,#1
@  cmps lr,r6
@  movgt lr,r6
@  movgt r7,#1
@  strh r4,[r0],#2
@  subs r2,#1
@  strh lr,[r1],#2
@  bne VolUseAGC_loop
@  
@  mov r0,r7
@  
@  ldmfd	r13!,{r4,r5,r6,r7,lr}
@  bx lr

    .ALIGN
    .GLOBAL fix_PCM2_0	@ r0:Destp  ok
    .CODE 32

@plsrc,prsrc,plbuf,prbuf,strpcmLastL,strpcmLastR,LastSamples,mask
fix_PCM2_0:
    stmfd   r13!,{r4,r5,r6,r7,r8,r9,lr}
    add lr,r13,#(4*7)
    ldr r4,[lr]
    ldr r4,[r4]
    ldr r5,[lr,#4]
    ldr r5,[r5]
    ldr r6,[lr,#8]
    ldr r7,[lr,#0xc]


InterruptHandler_Timer1_PCMx2_2ch_OverSampling_Loop:
    ldrsh r8,[r0],#2
    ldrsh r9,[r1],#2

    add r4,r4,r8,asr #1
    and r4,r4,r7
    orr r4,r4,r8,lsl #16
    str r4,[r2],#4
    mov r4,r8,asr #1

    add r5,r5,r9,asr #1
    and r5,r5,r7
    orr r5,r5,r9,lsl #16
    str r5,[r3],#4
    mov r5,r9,asr #1

    subs r6,r6,#2
    bne InterruptHandler_Timer1_PCMx2_2ch_OverSampling_Loop


    ldr r0,[lr]
    str r4,[r0]
    ldr r0,[lr,#4]
    str r5,[r0]

    ldmfd	r13!,{r4,r5,r6,r7,r8,r9,lr}
    bx lr
    .ALIGN
    .GLOBAL fix_PCM2_1	@ r0:Destp  ok
    .CODE 32


@plsrc,      plbuf,prbuf,strpcmLastL,            LastSamples,mask

@plsrc,prsrc,plbuf,prbuf,strpcmLastL,strpcmLastR,LastSamples,mask
fix_PCM2_1:

    stmfd   r13!,{r4,r6,r7,r8,lr}
    add lr,r13,#(4*5)
    ldr r4,[lr]
    ldr r4,[r4]
    ldr r6,[lr,#8]
    ldr r7,[lr,#0xc]


InterruptHandler_Timer1_PCMx2_1ch_OverSampling_Loop:
    ldrsh r8,[r0],#2

    add r4,r4,r8,asr #1
    and r4,r4,r7
    orr r4,r4,r8,lsl #16
    str r4,[r2],#4
    str r4,[r3],#4
    mov r4,r8,asr #1

    subs r6,r6,#2
    bne InterruptHandler_Timer1_PCMx2_1ch_OverSampling_Loop



    ldr r0,[lr]
    str r4,[r0]
    ldmfd	r13!,{r4,r6,r7,r8,lr}
    bx lr

    .ALIGN
    .GLOBAL fix_PCM4_0	@ r0:Destp  ok
    .CODE 32


@plsrc,prsrc,plbuf,prbuf,strpcmLastL,strpcmLastR,LastSamples,mask
fix_PCM4_0:
    stmfd   r13!,{r4,r5,r6,r8,r9,r10,lr}
    add lr,r13,#(4*7)
    ldr r4,[lr]
    ldr r4,[r4]
    ldr r5,[lr,#4]
    ldr r5,[r5]
    ldr r6,[lr,#8]

InterruptHandler_Timer1_PCMx4_2ch_OverSampling_Loop:
    ldrsh r8,[r0],#2
    ldrsh r9,[r1],#2

    strh r4,[r2],#2
    add r10,r4,r4
    add r10,r10,r4
    add r10,r10,r8
    mov r10,r10,asr #2
    strh r10,[r2],#2
    add r10,r4,r8
    mov r10,r10,asr #1
    strh r10,[r2],#2
    add r10,r8,r8
    add r10,r10,r8
    add r10,r10,r4
    mov r10,r10,asr #2
    strh r10,[r2],#2
    mov r4,r8

    strh r5,[r3],#2
    add r10,r5,r5
    add r10,r10,r5
    add r10,r10,r9
    mov r10,r10,asr #2
    strh r10,[r3],#2
    add r10,r5,r9
    mov r10,r10,asr #1
    strh r10,[r3],#2
    add r10,r9,r9
    add r10,r10,r9
    add r10,r10,r5
    mov r10,r10,asr #2
    strh r10,[r3],#2
    mov r5,r9

    subs r6,r6,#4
    bne InterruptHandler_Timer1_PCMx4_2ch_OverSampling_Loop

    ldr r0,[lr]
    str r4,[r0]
    ldr r0,[lr,#4]
    str r5,[r0]

    ldmfd	r13!,{r4,r5,r6,r8,r9,r10,lr}
    bx lr
    .ALIGN
    .GLOBAL fix_PCM4_1	@ r0:Destp  ok
    .CODE 32

@plsrc,      plbuf,prbuf,strpcmLastL,            LastSamples,mask
@plsrc,prsrc,plbuf,prbuf,strpcmLastL,strpcmLastR,LastSamples,mask
      
fix_PCM4_1:
    stmfd   r13!,{r4,r6,r8,r10,lr}
    add lr,r13,#(4*5)
    ldr r4,[lr]
    ldr r4,[r4]
    ldr r6,[lr,#8]

InterruptHandler_Timer1_PCMx4_1ch_OverSampling_Loop:
    ldrsh r8,[r0],#2

    strh r4,[r2],#2
    add r10,r4,r4
    add r10,r10,r4
    add r10,r10,r8
    mov r10,r10,asr #2
    strh r10,[r2],#2
    add r10,r4,r8
    mov r10,r10,asr #1
    strh r10,[r2],#2
    add r10,r8,r8
    add r10,r10,r8
    add r10,r10,r4
    mov r10,r10,asr #2
    strh r10,[r2],#2
    mov r4,r8

    subs r6,r6,#4
    bne InterruptHandler_Timer1_PCMx4_1ch_OverSampling_Loop


    ldr r0,[lr]
    str r4,[r0]

    ldmfd	r13!,{r4,r6,r8,r10,lr}
    bx lr

