-
Notifications
You must be signed in to change notification settings - Fork 12
Added 21_midi2 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added 21_midi2 #19
Conversation
sago35
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR ありがとうございます。
いくつかコメントしました。 @mi-bear
sago35
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
さらに指摘を追加。
だいぶ安定度が増して、演奏しやすくなるはず。
21_midi2/main.go
Outdated
| } | ||
| } | ||
|
|
||
| func redraw(d ssd1306.Device, state State) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この行で heap allocs があるので、 ssd1306.Device を global 変数にしたほうが良いです。
音は、画面描画にできるだけ影響されないようにしたいので。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おお...なるほど、勉強になります!
21_midi2/main.go
Outdated
| colPins[1].Low() | ||
| colPins[2].Low() | ||
| colPins[3].Low() | ||
| time.Sleep(1 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの time.Sleep() を削ると 1 回あたり 3ms 減らせれるのでかなり演奏が安定します。
参考ソースを以下に起きました。
関数全体を置き換えでよいと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.Sleep が必要なんだと思い込んでた。結果軽快になった感じがします。
| case off2on: | ||
| ret = off2on2 | ||
| case off2on2: | ||
| ret = off2on3 | ||
| case off2on3: | ||
| ret = off2on4 | ||
| case off2on4: | ||
| ret = off2onX | ||
| case off2onX: | ||
| ret = on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回は楽器なので off から on にするときは反応早く、 on から off にするときは反応がルーズでもよい、
ただし、少しだけチャタリング対策したい、という形にするとよいです。
現状のソースで off2on は反応が速いので良し。
しかし on2off のタイミングで NoteOff() してるけど、それはチャタリングしている場合は良くない動きになってしまいます。
なので、 on2off は off が連続で何回か続いたとき、という形にするとよいです。
こちらも参考ソースを置きました。
関数全体の置き換えでもよさそう。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、こうしたほうが良いのか。
書き換えました!めちゃ学びや。
sago35
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
やったぜー! |
技術書典の記事を書くために日本語のコメントいっぱい入っております。