Skip to content

Conversation

@sigprogramming
Copy link
Collaborator

内容

鍵盤クリック時とノート編集時に音を鳴らす機能を追加します。
また、以下も行います。

  • 鍵盤の描画をsymbolを使わない形に変更
  • ノートオン・ノートオフ周りの処理を修正
  • パラメーターの調整とリファクタリング

関連 Issue

VOICEVOX/voicevox_project#15

その他

@sigprogramming sigprogramming requested a review from a team as a code owner December 16, 2023 14:40
noteOn(contextTime: number) {
const t0 = contextTime;
const minContextTime = this.getMinContextTime(this.audioContext);
const t0 = Math.max(minContextTime, contextTime);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スケジュールが間に合わなかった場合(t0 < audioContext.currentTimeの場合)に音が鳴らなくなるので、スケジュールが間に合うようにt0を設定する処理を追加しました。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと違和感あったので、minContextTimecontextTimeをconsole.logしてみました。
contextTimeは0が渡されている一方、minContextTimeはcurrentTime+微小値が計算されていました!
どちらか意図と違いそう・・・?

あるいは「0やマイナス値を指定した場合は即座に音がなる」という意図した設計になっている感じでしょうか 👀
であればより意図がわかりやすいように、専用のリテラル文字を用意するとわかりやすいかもです!
こんな感じとか・・・?

  noteOn(contextTime: number | "immediately") {
    if (contextTime === "immediately") {
      contextTime = this.getMinContextTime(this.audioContext);
    }

Copy link
Collaborator Author

@sigprogramming sigprogramming Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「0やマイナス値を指定した場合は即座に音がなる」という意図した設計になっている感じでしょうか

OscillatorNode.start()は「currentTimeより前の時刻が指定されると即座に音がなる」ようになっていて、それに合わせています!

おっしゃる通り、0ではなく"immediately"を指定する形にすると分かりやすくなると思うので、
後で修正したいと思います!

Copy link
Member

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!

ドキュメント追加とシグネチャ変更の提案コメントをしてみました!
けど別に致命的ではないので、スピード優先でマージさせていただきます!!

};
// キーボードイベント
const handleNotesArrowUp = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleNotesArrowUphandleNotesArrowDown、処理共通化できそうに感じました!!

noteOn(contextTime: number) {
const t0 = contextTime;
const minContextTime = this.getMinContextTime(this.audioContext);
const t0 = Math.max(minContextTime, contextTime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと違和感あったので、minContextTimecontextTimeをconsole.logしてみました。
contextTimeは0が渡されている一方、minContextTimeはcurrentTime+微小値が計算されていました!
どちらか意図と違いそう・・・?

あるいは「0やマイナス値を指定した場合は即座に音がなる」という意図した設計になっている感じでしょうか 👀
であればより意図がわかりやすいように、専用のリテラル文字を用意するとわかりやすいかもです!
こんな感じとか・・・?

  noteOn(contextTime: number | "immediately") {
    if (contextTime === "immediately") {
      contextTime = this.getMinContextTime(this.audioContext);
    }

Comment on lines +731 to +739
private getMinContextTime(audioContext: BaseAudioContext) {
if (audioContext instanceof AudioContext) {
const renderQuantumSize = 128;
const latency = (renderQuantumSize + 10) / audioContext.sampleRate;
return audioContext.currentTime + latency;
} else {
return 0;
}
}
Copy link
Member

@Hiroshiba Hiroshiba Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMinContextTimeという関数名から「即座に音がなる一番近い時間」だということが伝わらないかもなので、ドキュメントがあると良いのかなと思いました!

あ、あとAudioContextでなくBaseAudioContextにもsampleRatecurrentTimeは生えているっぽいので、instanceofのifなくても良いかも?

@Hiroshiba Hiroshiba merged commit e3b7847 into VOICEVOX:project-s Dec 16, 2023
@sigprogramming sigprogramming deleted the preview_sound branch January 14, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants