Browse Source

Implement noise shaping dither

Michael Panzlaff 6 years ago
parent
commit
7ce6dbe493
1 changed files with 41 additions and 56 deletions
  1. 41
    56
      src/music/main_mixer.s

+ 41
- 56
src/music/main_mixer.s View File

870
         B       C_channel_state_loop
870
         B       C_channel_state_loop
871
 
871
 
872
 C_main_mixer_return:
872
 C_main_mixer_return:
873
-        ADR     R0, C_downsampler
874
-        BX      R0
873
+    ADR     R5, V_noise_shape
874
+    LDRB    R4, [R5, #0]            @ left noise shape
875
+    LSL     R4, R4, #16
876
+    LDRB    R5, [R5, #1]            @ right noise shape
877
+    LSL     R5, R5, #16
878
+    ADR     R0, C_downsampler
879
+    BX      R0
880
+
881
+
882
+V_noise_shape:
883
+    .byte 0, 0
875
 
884
 
876
     .arm
885
     .arm
877
     .align  2
886
     .align  2
878
 
887
 
879
 C_downsampler:
888
 C_downsampler:
880
-    LDR     R4, =0xFFF80035
881
-    LDR     R5, =0x0034FFF8
882
     LDR     R8, [SP, #ARG_FRAME_LENGTH]
889
     LDR     R8, [SP, #ARG_FRAME_LENGTH]
883
     LDR     R9, [SP, #ARG_BUFFER_POS]
890
     LDR     R9, [SP, #ARG_BUFFER_POS]
884
     LDR     R10, hq_buffer
891
     LDR     R10, hq_buffer
885
     MOV     R11, #0xFF000000
892
     MOV     R11, #0xFF000000
893
+    MOV     LR, #0x007F0000
886
 
894
 
887
 C_downsampler_loop:
895
 C_downsampler_loop:
888
         LDMIA   R10, {R0, R1, R2, R3}
896
         LDMIA   R10, {R0, R1, R2, R3}
889
 
897
 
890
-        MOV     R12, R0             @ left sample #1
891
-        CMP     R12, #0x40000000
898
+        ADD     R12, R4, R0         @ left sample #1
899
+        CMP     R12, #0x3FC00000
892
         MOVGE   R12, #0x3FC00000
900
         MOVGE   R12, #0x3FC00000
893
         CMP     R12, #-0x40000000
901
         CMP     R12, #-0x40000000
894
         MOVLT   R12, #-0x40000000
902
         MOVLT   R12, #-0x40000000
903
+        AND     R4, LR, R12
895
         AND     R6, R11, R12, LSL#1
904
         AND     R6, R11, R12, LSL#1
896
 
905
 
897
-        MOV     R0, R0, LSL#16      @ right
898
-        CMP     R0, #0x40000000
906
+        ADD     R0, R5, R0, LSL#16  @ right
907
+        CMP     R0, #0x3FC00000
899
         MOVGE   R0, #0x3FC00000
908
         MOVGE   R0, #0x3FC00000
900
         CMP     R0, #-0x40000000
909
         CMP     R0, #-0x40000000
901
         MOVLT   R0, #-0x40000000
910
         MOVLT   R0, #-0x40000000
911
+        AND     R5, LR, R0
902
         AND     R7, R11, R0, LSL#1
912
         AND     R7, R11, R0, LSL#1
903
 
913
 
904
-        MOV     R12, R1             @ left sample #2
905
-        CMP     R12, #0x40000000
914
+        ADD     R12, R4, R1         @ left sample #2
915
+        CMP     R12, #0x3FC00000
906
         MOVGE   R12, #0x3FC00000
916
         MOVGE   R12, #0x3FC00000
907
         CMP     R12, #-0x40000000
917
         CMP     R12, #-0x40000000
908
         MOVLT   R12, #-0x40000000
918
         MOVLT   R12, #-0x40000000
919
+        AND     R4, LR, R12
909
         AND     R12, R11, R12, LSL#1
920
         AND     R12, R11, R12, LSL#1
910
         ORR     R6, R12, R6, LSR#8
921
         ORR     R6, R12, R6, LSR#8
911
 
922
 
912
-        MOV     R1, R1, LSL#16      @ right
913
-        CMP     R1, #0x40000000
923
+        ADD     R1, R5, R1, LSL#16  @ right
924
+        CMP     R1, #0x3FC00000
914
         MOVGE   R1, #0x3FC00000
925
         MOVGE   R1, #0x3FC00000
915
         CMP     R1, #-0x40000000
926
         CMP     R1, #-0x40000000
916
         MOVLT   R1, #-0x40000000
927
         MOVLT   R1, #-0x40000000
928
+        AND     R5, LR, R1
917
         AND     R1, R11, R1, LSL#1
929
         AND     R1, R11, R1, LSL#1
918
         ORR     R7, R1, R7, LSR#8
930
         ORR     R7, R1, R7, LSR#8
919
 
931
 
920
-        MOV     R12, R2             @ left sample #3
921
-        CMP     R12, #0x40000000
932
+        ADD     R12, R4, R2         @ left sample #3
933
+        CMP     R12, #0x3FC00000
922
         MOVGE   R12, #0x3FC00000
934
         MOVGE   R12, #0x3FC00000
923
         CMP     R12, #-0x40000000
935
         CMP     R12, #-0x40000000
924
         MOVLT   R12, #-0x40000000
936
         MOVLT   R12, #-0x40000000
937
+        AND     R4, LR, R12
925
         AND     R12, R11, R12, LSL#1
938
         AND     R12, R11, R12, LSL#1
926
         ORR     R6, R12, R6, LSR#8
939
         ORR     R6, R12, R6, LSR#8
927
 
940
 
928
-        MOV     R2, R2, LSL#16      @ right
929
-        CMP     R2, #0x40000000
941
+        ADD     R2, R5, R2, LSL#16  @ right
942
+        CMP     R2, #0x3FC00000
930
         MOVGE   R2, #0x3FC00000
943
         MOVGE   R2, #0x3FC00000
931
         CMP     R2, #-0x40000000
944
         CMP     R2, #-0x40000000
932
         MOVLT   R2, #-0x40000000
945
         MOVLT   R2, #-0x40000000
946
+        AND     R5, LR, R2
933
         AND     R2, R11, R2, LSL#1
947
         AND     R2, R11, R2, LSL#1
934
         ORR     R7, R2, R7, LSR#8
948
         ORR     R7, R2, R7, LSR#8
935
 
949
 
936
-        MOV     R12, R3             @ left sample #4
937
-        CMP     R12, #0x40000000
950
+        ADD     R12, R4, R3         @ left sample #4
951
+        CMP     R12, #0x3FC00000
938
         MOVGE   R12, #0x3FC00000
952
         MOVGE   R12, #0x3FC00000
939
         CMP     R12, #-0x40000000
953
         CMP     R12, #-0x40000000
940
         MOVLT   R12, #-0x40000000
954
         MOVLT   R12, #-0x40000000
955
+        AND     R4, LR, R12
941
         AND     R12, R11, R12, LSL#1
956
         AND     R12, R11, R12, LSL#1
942
         ORR     R6, R12, R6, LSR#8
957
         ORR     R6, R12, R6, LSR#8
943
 
958
 
944
-        MOV     R3, R3, LSL#16      @ right
945
-        CMP     R3, #0x40000000
959
+        ADD     R3, R5, R3, LSL#16  @ right
960
+        CMP     R3, #0x3FC00000
946
         MOVGE   R3, #0x3FC00000
961
         MOVGE   R3, #0x3FC00000
947
         CMP     R3, #-0x40000000
962
         CMP     R3, #-0x40000000
948
         MOVLT   R3, #-0x40000000
963
         MOVLT   R3, #-0x40000000
964
+        AND     R5, LR, R3
949
         AND     R3, R11, R3, LSL#1
965
         AND     R3, R11, R3, LSL#1
950
         ORR     R7, R3, R7, LSR#8
966
         ORR     R7, R3, R7, LSR#8
951
 
967
 
952
-        @LDR     R12, [R9, #0x630]    @ left
953
         STR     R6, [R9, #0x630]
968
         STR     R6, [R9, #0x630]
954
-        @LDR     R6, [R9]            @ right
955
         STR     R7, [R9], #4
969
         STR     R7, [R9], #4
956
-
957
-        @MOVS    R7, R12, ASR#24
958
-        @ADDMI   R7, R7, #1
959
-        @MUL     R3, R4, R7
960
-        @MOVS    R7, R6, ASR#24
961
-        @ADDMI   R7, R7, #1
962
-        @MLA     R3, R5, R7, R3
963
-        @MOV     R12, R12, LSL#8
964
-        @MOV     R6, R6, LSL#8
965
-
966
-        @MOVS    R7, R12, ASR#24
967
-        @ADDMI   R7, R7, #1
968
-        @MUL     R2, R4, R7
969
-        @MOVS    R7, R6, ASR#24
970
-        @ADDMI   R7, R7, #1
971
-        @MLA     R2, R5, R7, R2
972
-        @MOV     R12, R12, LSL#8
973
-        @MOV     R6, R6, LSL#8
974
-
975
-        @MOVS    R7, R12, ASR#24
976
-        @ADDMI   R7, R7, #1
977
-        @MUL     R1, R4, R7
978
-        @MOVS    R7, R6, ASR#24
979
-        @ADDMI   R7, R7, #1
980
-        @MLA     R1, R5, R7, R1
981
-        @MOV     R12, R12, LSL#8
982
-        @MOV     R6, R6, LSL#8
983
-
984
-        @MOVS    R7, R12, ASR#24
985
-        @ADDMI   R7, R7, #1
986
-        @MUL     R0, R4, R7
987
-        @MOVS    R7, R6, ASR#24
988
-        @ADDMI   R7, R7, #1
989
-        @MLA     R0, R5, R7, R0
990
         MOV     R0, #0
970
         MOV     R0, #0
991
         MOV     R1, #0
971
         MOV     R1, #0
992
         MOV     R2, #0
972
         MOV     R2, #0
997
         SUBS    R8, #4
977
         SUBS    R8, #4
998
         BGT     C_downsampler_loop
978
         BGT     C_downsampler_loop
999
 
979
 
980
+    ADR     R1, V_noise_shape
1000
     ADR     R0, (C_downsampler_return+1)
981
     ADR     R0, (C_downsampler_return+1)
1001
     BX      R0
982
     BX      R0
1002
 
983
 
1006
     .thumb
987
     .thumb
1007
 
988
 
1008
 C_downsampler_return:
989
 C_downsampler_return:
990
+    LSR     R4, #16
991
+    STRB    R4, [R1, #0]
992
+    LSR     R5, #16
993
+    STRB    R5, [R1, #1]
1009
     LDR     R0, [SP, #ARG_PCM_STRUCT]
994
     LDR     R0, [SP, #ARG_PCM_STRUCT]
1010
     LDR     R3, mixer_finished_status           @ this is used to indicate the interrupt handler the rendering was finished properly
995
     LDR     R3, mixer_finished_status           @ this is used to indicate the interrupt handler the rendering was finished properly
1011
     STR     R3, [R0]
996
     STR     R3, [R0]