私は、この問題に対する良い解決策を見つけようとして、ひどい時間を過ごしています.
電話でコンテンツとしてマークされた 3 つの効果音がありますが、すべて同じビットレートです。
- サウンド1.wav
- サウンド2.wav
- sound3.wav
ユーザーが任意の順序で、または好きなだけ wav ファイルの再生順序を選択し、その選択に基づいて新しい wav ファイルを生成できるようにしたいと考えています。隔離されたストレージ。
これThank You Walt Ritscher
までのところ助けを借りていますが、最終的には、私のコーディングスキルがせいぜい断片化されていることがわかります. 次のコードで伝えようとしているのは、ユーザーがタップ イベントで任意またはすべてのサウンドを選択するように求められ、ユーザーの選択によって新しいサウンドエフェクトがどのように聞こえるか (順序など) が決まるということです。ただし、私が知らないことはまだたくさんありますが、ここに私が思いついたコードがあります(私のコーディングコンピューターではありません)。
//SO I have this master list of sounds to use, indicated in this block of code:
//sound1.wav, sound2.wav, sound3.wav
// my wav files are marked as resources
// get the wav file from the DLL
var streamInfo1 = Application.GetResourceStream(
new Uri(sound1.wav, UriKind.Relative));
var streamInfo2 = Application.GetResourceStream(
new Uri(sound2.wav, UriKind.Relative));
var streamInfo3 = Application.GetResourceStream(
new Uri(sound3.wav, UriKind.Relative));
//With the above declarations made, I run each one as a stream as a variable.
var stream1 = streamInfo1.Stream as UnmanagedMemoryStream;
var stream2 = streamInfo2.Stream as UnmanagedMemoryStream;
var stream3 = streamInfo3.Stream as UnmanagedMemoryStream;
//The user can choose the sounds in any order, and repeat if desired.
//Let us assume the user chose in this order:
//sound1.wav + sound1.wav + sound2.wav +sound3.wav
for (int i = 0; i < 10; i++)
{
var bytesA = new byte[stream1.Length];
var bytesB = new byte[stream1.Length];
var bytesC = new byte[stream2.Length];
}
// read the bytes from the stream into the array
stream1.Read(bytesA, 0, (int)stream1.Length);
stream2.Read(bytesB, 0, (int)stream1.Length);
stream3.Read(bytesC, 0, (int)stream2.Length);
var combined = new byte[bytesA.Length + bytesA.Length + bytesB.Length] + bytesC.Length]];
// copy the bytes into the combined array
System.Buffer.BlockCopy(bytesA, 0, combined, 0, bytesA.Length);
System.Buffer.BlockCopy(bytesB, 0, combined, bytesA.Length, bytesB.Length);
var outputStream = new MemoryStream();
outputStream.Write(combined, 0, combined.Length);
// substitute your own sample rate
var effect = new SoundEffect(
buffer: outputStream.ToArray(),
sampleRate: 48000,
channels: AudioChannels.Mono);
var instance = effect.CreateInstance();
instance.Play();
// save stream to IsolatedStorage