public SoundSystem(SoundManager manager) { _manager = manager; var config = new AudioDeviceConfiguration(); Logger.Trace <SoundSystem>($"Creating Sound System using {nameof(XAudio2Device)} with {config.NumberOfSounds} channels for SFX."); _device = new XAudio2Device(config); }
public XAudio2Device(AudioDeviceConfiguration config) { // TODO: what flags and processor should we use? CheckAndThrow(XAudio2Common.XAudio2Create(_xAudio2, 0U, XAUDIO2_PROCESSOR.XAUDIO2_USE_DEFAULT_PROCESSOR), nameof(XAudio2Common.XAudio2Create)); // TODO: check the flags and arguments fixed(IXAudio2MasteringVoice **pMasteringVoice = &_masteringVoice) { CheckAndThrow(_xAudio2.Get()->CreateMasteringVoice(pMasteringVoice), nameof(IXAudio2.CreateMasteringVoice)); } _sourceVoices = new SourceVoice[config.NumberOfSounds]; _maxVoices = (int)config.NumberOfSounds; // TODO: how should this be configured? var format = new WAVEFORMATEX { nBlockAlign = 4, //nBlockAlign = 1, //nBlockAlign = 2, wFormatTag = 1, wBitsPerSample = 16, //wBitsPerSample = 8, nSamplesPerSec = 44100, nChannels = 2, //nChannels = 1, cbSize = (WORD)sizeof(WAVEFORMATEX) }; format.nAvgBytesPerSec = ((uint)format.wBitsPerSample * format.nChannels * format.nSamplesPerSec) / 8; for (var i = 0; i < config.NumberOfSounds; ++i) { _sourceVoices[i] = new SourceVoice(_xAudio2, format); } }