Passing 16 bit data to AudioBuffer (as byte[]) #339
-
AudioBuffer takes a byte[] but typically data will be 16 bit? I'm not sure how to deal with this. Attempt 1: (language restriction)
Attempt 2: (language restriction)
Attempt 3: (performance cost)
Atttempt 4: (maybe, but too cumbersome)
What is the recommended way to pass 16 bit data in? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Monday I'll add generic data and span support. |
Beta Was this translation helpful? Give feedback.
-
NVM there was already present, take look here: https://github.com/amerkoleci/Vortice.Windows/blob/main/src/Vortice.XAudio2/AudioBuffer.cs#L75 |
Beta Was this translation helpful? Give feedback.
-
What is wrong with this.. // construct sound buffer
int seconds = 5;
int channels = 1;
int rate = 44100;
int samples = seconds * channels * rate;
short[] data = new short[samples];
for (int i = 0; i < samples; i++)
{
data[i] = (short)(Math.Sin(i*0.02f) * short.MaxValue);
}
ReadOnlySpan<short> span = new ReadOnlySpan<short>(data);
SoundBuffer = AudioBuffer.Create(span); // ** exception thrown **
|
Beta Was this translation helpful? Give feedback.
-
Version 2.1.26 has been released with those improvements. |
Beta Was this translation helpful? Give feedback.
NVM there was already present, take look here: https://github.com/amerkoleci/Vortice.Windows/blob/main/src/Vortice.XAudio2/AudioBuffer.cs#L75