问题
Is it possible to dynanmically generate sounds with XNA C# code?
I looked into this some time ago when XNA was first released. At that time it was only possible to playback sound resources included in the compiled code.
Have there been any changes or new features added since XNA 1.0 that would allow an XNA application to generate and playback audio on the fly?
回答1:
Yes.
XNA 4.0 added support for dynamic audio that allows you to:
- Create a regular immutable sound effect from a raw buffer using the SoundEffect.FromStream method.
- Create a DynamicSoundEffectInstance object then modify the audio data of this new streaming sound effect object dynamically.
Read more in the blog entry What’s “Dynamic” about this SoundEffectInstance? and in the AppHub article Dynamic Audio.
回答2:
I think you can do this in XNA with DirectSound. Here's a link with code that seems to do what you want:
http://forums.create.msdn.com/forums/t/40361.aspx
回答3:
Depends how dynamic you want to get. I know that XACT will let you change pitch and such, which, when combined with using cues in a programmatic fashion, can give some nice results.
If you want to generate your own waveform, you're out of luck. There's always the option of dropping below the framework and doing it yourself.
来源:https://stackoverflow.com/questions/5032450/how-to-play-dynamic-sounds-in-xna