Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. .syntax unified
  2. .global main
  3.  
  4. //Ass-1-P-2
  5.  
  6. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  7. @ the audio framework has two functions:
  8. @
  9. @ 1. init_audio (call this once at the start of your program)
  10. @
  11. @ 2. play audio_sample (sends the low 16 bits of r0 out the
  12. @ headphone jack - call this repeatedly in your main loop)
  13. @
  14. @ the rest is up to you!
  15. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  16.  
  17. main:
  18. @ your code goes here
  19.  
  20. bl init_audio //Init Audio, self explanatory
  21.  
  22. mov r0, #0 //Init the register to 0. This is possibly uneccesary
  23.  
  24. mov r8, #0 //Our future loop counter for the period, init here
  25. mov r9, #0 //Our Ascending/Descending boolean flag, starting at 0, for ascend
  26.  
  27. mov r10, #480 //Upper (technically lower) limit. Interchangeable, results may be less interesting.
  28. mov r11, #48 //Lower (technically upper) limit.
  29. mov r12, #218 //Our current frequency register, starting at 218 (440Hz on 192kHZ Board/2)
  30.  
  31. @@@@@@@@@@@@@--TOP WAVE--@@@@@@@@@@@@@@@@@@@@@@@@
  32.  
  33. init_top:
  34. mov r8, #0 //Reset period counter
  35.  
  36. play_top:
  37. cmp r8, r12 //If counter has surpassed Frequency in R2 (Hz/2) return 0
  38. beq init_bottom //If 0 returned, move to bottom wave
  39. mov r0, 0x00006000 //Amplitude of the Wave
  40. adds r8, #1 //Increment period counter
  41. bl play_audio_sample //Play
  42. b play_top //Repeat
  43.  
  44. @@@@@@@@@@@@@@@--BOTTOM WAVE--@@@@@@@@@@@@@@@@@@
  45.  
  46. init_bottom:
  47. mov r8, #0 //Reset Period counter
  48.  
  49. play_bottom:
  50. cmp r8, r12 //If counter has surpassed Frequency in R2 (Hz/2) return 0
  51. beq modify_sound //If 0 returned, move to modifying the signal
  52. mov r0, 0x0000A000 //Inverse of 4000 from Top
  53. adds r8, #1 //Increment period counter
  54. bl play_audio_sample //Play
  55. b play_bottom //Repeat
  56.  
  57. @@@@@@@@@@@@@@@--Handle Changes--@@@@@@@@@@@@@@@@@@
  58.  
  59. modify_sound:
  60. cmp r12, r10 //Compare Frequency with defind upper limit
  61. beq set_ascend //If it's at the upper limit, begin ascent
  62. cmp r12, r11 //If at bottom limit
  63. beq set_descend //then begin descent
  64. return_point: //Return here from toggling flag
  65. cmp r9, #0 //Check flag
  66. beq descend //Jump to descend when 0
  67. b ascend //Otherwise jump to ascend
  68.  
  69. set_ascend:
  70. mov r9, #0 //Set Flag to Ascend
  71. b return_point //Return to Execution
  72.  
  73. set_descend:
  74. mov r9, #1 //Set Flag to Descend
  75. b return_point //Return to Execution
  76.  
  77. ascend:
  78. adds r12, #2 //Add to the Frequency counter
  79. b repeat //Jump to the loop point
  80.  
  81. descend:
  82. subs r12, #2 //Subtracts from the Frequency counter
  83. b repeat //Jump to the loop point
  84.  
  85. repeat:
  86. b init_top //Return to top and begin again
  87.  
  88. end:
  89. nop //This is probably not needed, but there for redundancy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement