Advertisement
Guest User

Untitled

a guest
May 1st, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.40 KB | None | 0 0
  1. .syntax unified
  2. .global main
  3.  
  4. .type main, %function
  5. main:
  6.   bl init
  7.   b restart
  8.  
  9. restart:
  10.   mov r0,0        @initialize r0 to be played
  11.   mov r4,0        @a reference register as the current peak
  12.  
  13.   ldr r6, =array  @Loading the array location
  14.   ldr r7, [r6, 4] @Loading the first element on the array
  15.   mov r5, r7      @Use r5 as a reference from the first element
  16.   ldr r8, [r6]    @Size of the array
  17.   mov r9, 1     @Array Counter
  18.   mov r10, 12000@Duration for 0.25
  19.   mov r11, 0    @Duration Counter
  20.  
  21.   b positive_peak
  22.  
  23. positive_peak:    @Label that change r6 to positive peak
  24.  
  25.   ldr r4, =0x7fff @Setting the positive peak at 0x7fff
  26.   mov r0, r4      @Putting the positive peak value to r0 to be played
  27.   add r11, 1
  28.   cmp r10, r11
  29.   beq change_pitch
  30.   sub r7, 1        @Adding 1 to the counter
  31.   cmp r7, 0      @Because the Period = 1/f and the BSP is 48khz then to get the period for 1/440HZ we multiply is by 48khz
  32.                   @which will reslted with 109.090909
  33.                   @But we need the point for half of a period because each peak is only half a period
  34.                   @which is 54.5 but since we can't use float in integer then we use 55
  35.  beq negative_peak @This will change the peak to negative peak if high peak has reach the half period
  36.  bl BSP_AUDIO_OUT_Play_Sample @This will play the sound at the particular value of r0
  37.  
  38. b positive_peak  
  39.  
  40. negative_peak:  @Label that change r6 to positive peak
  41.  
  42.  ldr r4, =0x8000 @Setting the negative peak at 0x7fff
  43.  mov r0, r4      @Putting the negative peak value to r0 to be played
  44.  add r11, 1
  45.  cmp r10, r11
  46.  beq change_pitch
  47.  add r7, 1      @Substracting 1 to the counter
  48.  cmp r7, r5
  49.  @ bleq change
  50.                  @when the subs reach 0 then the negative peak has reach half of the period which is 55 then we change it to positive
  51.  beq positive_peak
  52.  bl BSP_AUDIO_OUT_Play_Sample
  53.  
  54. b negative_peak
  55.  
  56.  
  57. change_pitch:
  58.  add r9, 1
  59.  cmp r8, r9
  60.  beq restart
  61.  mov r12, 4
  62.  mul r3, r9, r12
  63.  ldr r7, [r6,r3]
  64.  mov r10, 12000@Duration for 0.25
  65.  mov r11, 0    @Duration Counter
  66.  b positive_peak
  67.  
  68. .data
  69. array:
  70.  .word 27
  71.  .word 82, 0, 69, 0, 61, 61, 0, 82, 0, 69, 0, 58, 61, 61, 0, 0, 82, 0, 69, 0, 61, 61 , 0, 69, 0, 82, 0
  72.  
  73.  
  74. @ print(cal(293.66));
  75. @ print(cal(349.23));
  76. @ print(cal(392));
  77. @ print(cal(415.30));
  78.  
  79.  
  80. @ 81.72716747258734
  81. @ 68.72261833175844
  82. @ 61.22448979591836
  83. @ 57.78954972309174
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement