-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from eeyrw/code-refactoring
Code refactoring
- Loading branch information
Showing
19 changed files
with
480 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 查找最后一个等于或者大于key的元素 | ||
def findLastEqualSmaller(arr, key): | ||
left = 0 | ||
right = len(arr) - 1 | ||
length = len(arr) | ||
|
||
# 这里必须是 <= | ||
while left <= right: | ||
mid = (left + right) // 2 | ||
if arr[mid] >= key: | ||
right = mid - 1 | ||
else: | ||
left = mid + 1 | ||
if left>=length: | ||
left=length-1 | ||
return left | ||
|
||
|
||
arr=[6,3,4,1,9] | ||
idx = findLastEqualSmaller(arr,11) | ||
print('Idx:',idx) | ||
print('Value:',arr[idx]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef __ASM_COMMON_H__ | ||
#define __ASM_COMMON_H__ | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __PERIOD_TIMER_H__ | ||
#define __PERIOD_TIMER_H__ | ||
|
||
#ifndef __ASSEMBLER__ | ||
extern void PIT_Task(void); | ||
|
||
#else | ||
|
||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "Player.h" | ||
#include "RegDefNv32.h" | ||
|
||
#define PeriodTimerHandler PIT_Ch0Isr_Override | ||
|
||
.syntax unified | ||
.section .text | ||
.thumb_func | ||
.global PeriodTimerHandler | ||
.func PeriodTimerHandler | ||
PeriodTimerHandler: | ||
push {r4-r7,lr} // r0-r3,r12 saved by hardware when expection happening | ||
ldr r0,=#PIT_TFLG0 | ||
ldr r1,[r0] | ||
ldr r2,=#PIT_TFLG_TIF_BIT | ||
orrs r1,r1,r2 | ||
str r1,[r0] | ||
|
||
ldr r5,=#GlobalPlayerPtr | ||
ldr r5,[r5] | ||
ldr r6,=#pSynthesizer | ||
adds r0,r5,r6 | ||
ldr r6,=#pScoreDecoder | ||
adds r1,r5,r6 | ||
#include "Synth.inc" | ||
#include "UpdateTick.inc" | ||
pop {r4-r7,pc} | ||
.endfunc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __REG_DEF_NV32_H__ | ||
#define __REG_DEF_NV32_H__ | ||
|
||
#define PWM_OUT1 0x4003A030 | ||
#define PWM_OUT2 0x4003A038 | ||
#define PIT_TFLG0 0x4003710C | ||
#define PIT_TFLG1 0x4003711C | ||
#define PIT_TFLG_TIF_BIT 0x01 | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "SynthCore.h" | ||
#include "AsmCommon.h" | ||
#include "RegDefNv32.h" | ||
|
||
.syntax unified | ||
.section .text | ||
SynthAsm: | ||
pSoundUnit .req r3 | ||
loopIndex .req r4 | ||
mixOut .req r2 | ||
|
||
movs loopIndex,#POLY_NUM | ||
movs mixOut,#0 | ||
movs pSoundUnit,r0 | ||
|
||
loopSynth: | ||
ldrh r7,[pSoundUnit,#pEnvelopeLevel] | ||
cmp r7,#0 | ||
beq loopSynthEnd | ||
ldr r5,[pSoundUnit,#pWaveTableAddress] | ||
ldr r6,[pSoundUnit,#pWavetablePos] | ||
lsrs r6,r6,#8 @wavetablePos /= 256 | ||
lsls r6,r6,#1 @wavetablePos *= 2 | ||
ldrsh r6,[r5,r6] @ Load signed 16bit sample to r6 | ||
#ifdef RUN_TEST | ||
strsh r6,[pSoundUnit,#pSampleVal] | ||
#endif | ||
muls r7,r6,r7 @sample*envelope/256 | ||
#ifdef RUN_TEST | ||
asrs r7,r7,#8 | ||
strsh r7,[pSoundUnit,#pVal] | ||
#endif | ||
adds mixOut,r7,mixOut @mixOut+=sample*envelope/256 | ||
|
||
ldr r6,[pSoundUnit,#pWavetablePos] | ||
ldr r5,[pSoundUnit,#pIncrement] | ||
adds r6,r5,r6 | ||
ldr r5,[pSoundUnit,#pWaveTableLen] | ||
lsls r5,r5,#8 @pWaveTableLen*=256 | ||
cmp r5,r6 | ||
bhi wavePosUpdateEnd @bhi : HI C = 1 ands Z = 0 Higher, unsigned | ||
ldr r5,[pSoundUnit,#pWaveTableLoopLen] | ||
lsls r5,r5,#8 @waveTableLoopLen*=256 | ||
subs r6,r6,r5 | ||
wavePosUpdateEnd: | ||
str r6,[pSoundUnit,#pWavetablePos] | ||
loopSynthEnd: | ||
|
||
adds pSoundUnit,pSoundUnit,#SoundUnitSize | ||
subs loopIndex,loopIndex,#1 @ set n = n-1 | ||
bne loopSynth | ||
movs pSoundUnit,r0 | ||
|
||
ldr r5,=#pMixOut | ||
adds r5,r5,pSoundUnit | ||
str mixOut,[r5] | ||
|
||
@ | ||
ldrh r5,[r5,#(pMainVolume-pMixOut)] | ||
asrs mixOut,mixOut,#8 | ||
muls mixOut,r5,mixOut | ||
asrs mixOut,mixOut,#(MAX_VOLUME_SHIFT_BIT+8) | ||
|
||
ldr r5,=#-128 | ||
cmp mixOut,r5 | ||
bge lowerBoundSatisfied | ||
movs mixOut,r5 | ||
lowerBoundSatisfied: | ||
ldr r5,=#127 | ||
cmp mixOut,r5 | ||
ble saturateEnd | ||
movs mixOut,r5 | ||
saturateEnd: | ||
|
||
@ mixOut: [-512,511] -> [0,1023] | ||
ldr r5,=#128 | ||
adds mixOut,mixOut,r5 | ||
ldr r5,=#PWM_OUT1 | ||
strh mixOut,[r5] | ||
ldr r5,=#PWM_OUT2 | ||
strh mixOut,[r5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.