Skip to content
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

コールバックで音声を受け取る SoraAudioStreamSink の追加 #32

Merged
merged 13 commits into from
Aug 28, 2023

Conversation

tnoho
Copy link
Contributor

@tnoho tnoho commented Aug 27, 2023

現在用意されている SoraAudioSink は SoraAudioSinkImpl 内のバッファに受け取った音声データを溜め込み、任意のタイミングで音声を取り出すことができるようにしてあります。

これは、SoraVideoSink のように AudioTrack から音声データを受け取るたびにコールバックを呼び出す形で実装すると 10ms という非常に短い間隔でコールバックが呼び出されるために Python 側で実装に配慮が必要になることを想定しそのようにしました。

しかしながら SoraVideoSink 同様に AudioTrack から音声データを受け取るたびにコールバックで呼び出す形の SoraAudioSink もあった方がリアルタイム処理などでの利便性が高いと考えたことから、これを実装した SoraAudioStreamSink を追加したいと思います。

SoraAudioSink にも同じ形を実装しようとしたコードがあるのですが、 1 つのクラスに 2 つの機能は難しいと考え分けることとしました、これがマージされた後に SoraAudioSink の当該部分は削除したいと思います。

前述のコールバックが非常に短くなる点への配慮として、コールバックにより渡される SoraAudioFrame は pickle できるようになっており、 multiprocessing.Queue などで別プロセスへのオフロードが可能になっています。

必須ではない割と大きめの機能追加なので、フォークしたリポジトリからの PR としました。レビューいただければと思います。

@tnoho tnoho requested review from voluntas, sile and melpon August 27, 2023 04:36
@tnoho tnoho self-assigned this Aug 27, 2023
@voluntas
Copy link
Member

SoraAudioSink2 という名前が良くないので変更をお願い。

@tnoho tnoho changed the title コールバックで音声を受け取る SoraAudioSink2 の追加 コールバックで音声を受け取る SoraAudioStreamSink の追加 Aug 27, 2023
@tnoho
Copy link
Contributor Author

tnoho commented Aug 27, 2023

SoraAudioStreamSink に改名しました!

@voluntas
Copy link
Member

@tnoho ドキュメントも PR ください。

@voluntas voluntas merged commit c817940 into shiguredo:develop Aug 28, 2023
@@ -44,6 +47,22 @@ PyType_Slot audio_sink_slots[] = {
{Py_tp_traverse, (void*)audio_sink_tp_traverse},
{0, nullptr}};

int audio_sink2_tp_traverse(PyObject* self, visitproc visit, void* arg) {
Copy link
Member

Choose a reason for hiding this comment

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

ここの sink2 は変更もれでしょうか?(stream_sink になるべき?)

SoraTrackInterface* track_;
const int output_sample_rate_;
const size_t output_channels_;
// ACMResampler の前に std::unique_ptr がなんでも良いので無いと何故かビルドが通らない
Copy link
Member

Choose a reason for hiding this comment

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

🤔

@@ -0,0 +1,201 @@
#ifndef SORA_AUDIO_SINK2_H_
Copy link
Member

Choose a reason for hiding this comment

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

ここも "SINK2" になってますね

Copy link
Member

@sile sile left a comment

Choose a reason for hiding this comment

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

LGTM with nits

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.

3 participants