Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .syntax unified
- .global main
- //Ass-1-P-2
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- @ the audio framework has two functions:
- @
- @ 1. init_audio (call this once at the start of your program)
- @
- @ 2. play audio_sample (sends the low 16 bits of r0 out the
- @ headphone jack - call this repeatedly in your main loop)
- @
- @ the rest is up to you!
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- main:
- @ your code goes here
- bl init_audio //Init Audio, self explanatory
- mov r0, #0 //Init the register to 0. This is possibly uneccesary
- mov r8, #0 //Our future loop counter for the period, init here
- mov r9, #0 //Our Ascending/Descending boolean flag, starting at 0, for ascend
- mov r10, #480 //Upper (technically lower) limit. Interchangeable, results may be less interesting.
- mov r11, #48 //Lower (technically upper) limit.
- mov r12, #218 //Our current frequency register, starting at 218 (440Hz on 192kHZ Board/2)
- @@@@@@@@@@@@@--TOP WAVE--@@@@@@@@@@@@@@@@@@@@@@@@
- init_top:
- mov r8, #0 //Reset period counter
- play_top:
- cmp r8, r12 //If counter has surpassed Frequency in R2 (Hz/2) return 0
- beq init_bottom //If 0 returned, move to bottom wave
- mov r0, 0x00006000 //Amplitude of the Wave
- adds r8, #1 //Increment period counter
- bl play_audio_sample //Play
- b play_top //Repeat
- @@@@@@@@@@@@@@@--BOTTOM WAVE--@@@@@@@@@@@@@@@@@@
- init_bottom:
- mov r8, #0 //Reset Period counter
- play_bottom:
- cmp r8, r12 //If counter has surpassed Frequency in R2 (Hz/2) return 0
- beq modify_sound //If 0 returned, move to modifying the signal
- mov r0, 0x0000A000 //Inverse of 4000 from Top
- adds r8, #1 //Increment period counter
- bl play_audio_sample //Play
- b play_bottom //Repeat
- @@@@@@@@@@@@@@@--Handle Changes--@@@@@@@@@@@@@@@@@@
- modify_sound:
- cmp r12, r10 //Compare Frequency with defind upper limit
- beq set_ascend //If it's at the upper limit, begin ascent
- cmp r12, r11 //If at bottom limit
- beq set_descend //then begin descent
- return_point: //Return here from toggling flag
- cmp r9, #0 //Check flag
- beq descend //Jump to descend when 0
- b ascend //Otherwise jump to ascend
- set_ascend:
- mov r9, #0 //Set Flag to Ascend
- b return_point //Return to Execution
- set_descend:
- mov r9, #1 //Set Flag to Descend
- b return_point //Return to Execution
- ascend:
- adds r12, #2 //Add to the Frequency counter
- b repeat //Jump to the loop point
- descend:
- subs r12, #2 //Subtracts from the Frequency counter
- b repeat //Jump to the loop point
- repeat:
- b init_top //Return to top and begin again
- end:
- nop //This is probably not needed, but there for redundancy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement