Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.90 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        @ 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 for reference to compare to r7
  16.   ldr r8, [r6]    @ Size of the array
  17.   mov r9, 1       @ Array Index
  18.   ldr r10, =duration  @ Loading the array location
  19.   ldr r11, [r10, 4] @ Loading the first element on the array
  20.   mov r3, r11      @ Use r5 for reference to compare to r7
  21.  
  22.  
  23.   b positive_peak
  24.  
  25. positive_peak:    
  26.  
  27.   ldr r4, =0x7fff  
  28.   mov r0, r4      @ Putting the positive peak value to r0 to be played
  29.   sub r11, 1      @ Checking the duration counter
  30.   cmp r11, 0    @ Comparing it to 12000 to change pitch
  31.   beq change_pitch
  32.   sub r7, 1       @ Adding 1 to the counter
  33.   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
  34.                   @ But we need the point for half of a period because each peak is only half a period
  35.                   @ Which is 54.5 but since we can't use float in integer then we use
  36.  beq negative_peak   @This will change the peak to negative peak if high peak has reach the half period
  37.  bl BSP_AUDIO_OUT_Play_Sample
  38.  
  39. b positive_peak  
  40.  
  41. negative_peak:  
  42.  
  43.  ldr r4, =0x8000
  44.  mov r0, r4      
  45.  sub r11, 1
  46.  cmp r11, 0
  47.  beq change_pitch
  48.  add r7, 1      @Substracting 1 to the counter
  49.  cmp r7, r5
  50.                  @ bleq change
  51.                  @when the subs reach 0 then the negative peak has reach half of the period which is 55 then we change it to positive
  52.  beq positive_peak
  53.  bl BSP_AUDIO_OUT_Play_Sample @This will play the sound at the particular value of r0
  54.  
  55. b negative_peak
  56.  
  57.  
  58. change_pitch:
  59.  add r9, 1      @ Add the Array index
  60.  cmp r8, r9     @ Restart if it has reach the array limit
  61.  beq restart    
  62.  mov r12, 4    
  63.  mul r12, r9, r12 @ Multiply index with 4 to change the array index by *4 each loop
  64.  ldr r7, [r6,r12]
  65.  mov r5, r7      @ Change the reference pitch to the current pitch
  66.  ldr r11, [r10, r12] @ Loading the first element on the array
  67.  mov r3, r11      @ Use r5 for reference to compare to r7    
  68.  b positive_peak
  69.  
  70. .data
  71. array:
  72.  .word 26        @ Array Size
  73.  @.word 122, 130, 122, 122, 109, 109, 122, 122, 130, 130, 122, 122, 97, 97, 122, 0, 122, 130, 122, 122, 109, 0, 122, 0, 130, 0, 122, 0, 97, 97, 122, 0
  74.  .word 122, 130, 122, 122, 109, 122, 130, 122, 97, 122, 0, 122, 130, 122, 122, 109, 0, 122, 0, 130, 0, 122, 0, 97, 122, 0
  75.  
  76. duration:  
  77. .word 12000, 12000, 12000, 12000, 24000, 24000, 24000, 24000, 24000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 12000, 24000, 12000, 12000
  78. @196 , 185, 220, 246.94
  79. @122.448  ,  129.729  ,  109.0909  ,  97.189
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement