Explorar el Código

Implement noise shaping dither

Michael Panzlaff hace 6 años
padre
commit
7ce6dbe493
Se han modificado 1 ficheros con 41 adiciones y 56 borrados
  1. 41
    56
      src/music/main_mixer.s

+ 41
- 56
src/music/main_mixer.s Ver fichero

@@ -870,123 +870,103 @@ C_end_channel_state_loop:
870 870
         B       C_channel_state_loop
871 871
 
872 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 885
     .arm
877 886
     .align  2
878 887
 
879 888
 C_downsampler:
880
-    LDR     R4, =0xFFF80035
881
-    LDR     R5, =0x0034FFF8
882 889
     LDR     R8, [SP, #ARG_FRAME_LENGTH]
883 890
     LDR     R9, [SP, #ARG_BUFFER_POS]
884 891
     LDR     R10, hq_buffer
885 892
     MOV     R11, #0xFF000000
893
+    MOV     LR, #0x007F0000
886 894
 
887 895
 C_downsampler_loop:
888 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 900
         MOVGE   R12, #0x3FC00000
893 901
         CMP     R12, #-0x40000000
894 902
         MOVLT   R12, #-0x40000000
903
+        AND     R4, LR, R12
895 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 908
         MOVGE   R0, #0x3FC00000
900 909
         CMP     R0, #-0x40000000
901 910
         MOVLT   R0, #-0x40000000
911
+        AND     R5, LR, R0
902 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 916
         MOVGE   R12, #0x3FC00000
907 917
         CMP     R12, #-0x40000000
908 918
         MOVLT   R12, #-0x40000000
919
+        AND     R4, LR, R12
909 920
         AND     R12, R11, R12, LSL#1
910 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 925
         MOVGE   R1, #0x3FC00000
915 926
         CMP     R1, #-0x40000000
916 927
         MOVLT   R1, #-0x40000000
928
+        AND     R5, LR, R1
917 929
         AND     R1, R11, R1, LSL#1
918 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 934
         MOVGE   R12, #0x3FC00000
923 935
         CMP     R12, #-0x40000000
924 936
         MOVLT   R12, #-0x40000000
937
+        AND     R4, LR, R12
925 938
         AND     R12, R11, R12, LSL#1
926 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 943
         MOVGE   R2, #0x3FC00000
931 944
         CMP     R2, #-0x40000000
932 945
         MOVLT   R2, #-0x40000000
946
+        AND     R5, LR, R2
933 947
         AND     R2, R11, R2, LSL#1
934 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 952
         MOVGE   R12, #0x3FC00000
939 953
         CMP     R12, #-0x40000000
940 954
         MOVLT   R12, #-0x40000000
955
+        AND     R4, LR, R12
941 956
         AND     R12, R11, R12, LSL#1
942 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 961
         MOVGE   R3, #0x3FC00000
947 962
         CMP     R3, #-0x40000000
948 963
         MOVLT   R3, #-0x40000000
964
+        AND     R5, LR, R3
949 965
         AND     R3, R11, R3, LSL#1
950 966
         ORR     R7, R3, R7, LSR#8
951 967
 
952
-        @LDR     R12, [R9, #0x630]    @ left
953 968
         STR     R6, [R9, #0x630]
954
-        @LDR     R6, [R9]            @ right
955 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 970
         MOV     R0, #0
991 971
         MOV     R1, #0
992 972
         MOV     R2, #0
@@ -997,6 +977,7 @@ C_downsampler_loop:
997 977
         SUBS    R8, #4
998 978
         BGT     C_downsampler_loop
999 979
 
980
+    ADR     R1, V_noise_shape
1000 981
     ADR     R0, (C_downsampler_return+1)
1001 982
     BX      R0
1002 983
 
@@ -1006,6 +987,10 @@ C_downsampler_loop:
1006 987
     .thumb
1007 988
 
1008 989
 C_downsampler_return:
990
+    LSR     R4, #16
991
+    STRB    R4, [R1, #0]
992
+    LSR     R5, #16
993
+    STRB    R5, [R1, #1]
1009 994
     LDR     R0, [SP, #ARG_PCM_STRUCT]
1010 995
     LDR     R3, mixer_finished_status           @ this is used to indicate the interrupt handler the rendering was finished properly
1011 996
     STR     R3, [R0]