UWP プロジェクトがあり、Windows.Media.Audio API を使用してファイルを再生したいと考えています。FileInputNode を使用する代わりに、さまざまなタイミング プロパティを正確に判断できるように、ファイルをストリーミングしたいと考えています。
MediaStreamSource API を見つけ、16 ビット PCM 2 チャネルの .wav ファイルをデコードするために次のコードを作成しました。
public async Task<Windows.Storage.Streams.Buffer> GetBuffer()
{
// check if the sample requested byte offset is within the file size
if (byteOffset + BufferSize <= mssStream.Size)
{
inputStream = mssStream.GetInputStreamAt(byteOffset);
// create the MediaStreamSample and assign to the request object.
// You could also create the MediaStreamSample using createFromBuffer(...)
MediaStreamSample sample = await MediaStreamSample.CreateFromStreamAsync(inputStream, BufferSize, timeOffset);
sample.Duration = sampleDuration;
sample.KeyFrame = true;
// increment the time and byte offset
byteOffset += BufferSize;
timeOffset = timeOffset.Add(sampleDuration);
return sample.Buffer;
}
else
{
return null;
}
}
イベント システムを使用する代わりに、AudioFrameInputNode が新しい AudioFrame を必要とするたびに起動されるメソッドを作成しました。
MediaStreamSample の結果のバイト配列は、DataReader を使用して StorageFile を単純に読み取った場合とまったく同じようです。
MediaStreamSample.CreateFromStreamAsync は実際にオーディオ ファイルを float バイト配列にデコードしますか? それとも、サンプルを再生するときに MediaElement で行われますか?
もしそうなら、オーディオファイルをデコードして、結果のAudioBufferをFrameInputNodeに戻すにはどうすればよいですか?