2

Given an array (of changing length) of frequencies and amplitudes, can I generate a single audio buffer on a sample by sample basis that includes all the tones in the array? If not, what is the best way to generate multiple tones in a single audio unit? Have each note generate it's own buffer then sum those into an output buffer? Wouldn't that be the same thing as doing it all at once?

Working on an iOS app that generates notes from touches, considering using STK but don't want to have to send note off messages, would rather just generate sinusoidal tones for the notes I'm holding in an array. Each note actually needs to produce two sinusoids, with varying frequency and amplitude. One note may be playing the same frequency as a different note so a note off message at that frequency could cause problems. Eventually I want to manage amplitude (adsr) envelopes for each note outside of the audio unit. I also want response time to be as fast as possible so I'm willing to do some extra work/learning to keep the audio stuff as low level as I can.

I've been working with sine wave single tone generator examples. Tried essentially doubling one of these, something like:

Buffer[frame] = (sin(theta1) + sin(theta2))/2

Incrementing theta1/theta2 by frequency1/frequency2 over sample rate, (I realize this is not the most efficient calling sin() ) but get aliasing effects. I've yet to find an example with multiple frequencies or data sources other than reading audio from file.

Any suggestions/examples? I originally had each note generate its own audio unit, but that gave me too much latency from touch to note sounding (and seems inefficient too). I am newer to this level of programming than I am to digital audio in general, so please be gentle if I'm missing something obvious.

4

1 に答える 1

2

はい、もちろんできます。レンダー コールバック内で好きなことを行うことができます。この呼び出しを設定すると、オブジェクトへのポインターを渡すことができます。

そのオブジェクトには、各トーンのオン オフ状態が含まれる場合があります。実際、オブジェクトには、バッファをいっぱいにするメソッドが含まれている可能性があります。(オブジェクトがプロパティである場合は、オブジェクトが非アトミックであることを確認してください。そうしないと、ロックの問題によりアーティファクトが発生します)

正確に何を達成しようとしていますか?本当にオンザフライで生成する必要がありますか?

その場合、remoteIO オーディオ ユニットのレンダー コールバックが過負荷になるリスクがあり、グリッチやアーティファクトが発生します。

シミュレーターでそれを回避し、デバイスに移動すると、不思議なことに、50 分の 1 のプロセッサで実行されているため動作しなくなり、次のコールバックが到着する前に 1 つのコールバックを完了できないことに気付く場合があります。

とはいえ、多くのことを回避できます

任意の数の個別のトーンを同時に再生できる 12 トーン プレーヤーを作成しました。

私がしているのは、各トーンのリング バッファを用意することだけです (非常に複雑な波形を使用しているため、これには多くの時間がかかります。実際、アプリケーションを初めて実行するときに実際に計算し、その後ファイルからロードします)。各リングの読み取りヘッドと有効フラグ。

次に、レンダリング コールバックにすべてを追加すると、12 個すべてが一緒に再生されている場合でも、デバイス上で問題なく処理されます。ドキュメンテーションではこれを行わないように指示されていることは知っていますが、このコールバックを使用して 1 つのバッファーを別のバッファーから満たすことのみを推奨していますが、多くのことを回避できます。別のスレッドで。

于 2011-07-26T23:47:26.780 に答える