public DirectXOutputDevice(Controller controller) { _controller = controller; _DeviceState = DeviceState.Stopped; _StreamWriteProcDelegate = new STREAMPROC(OutputStreamWriteProc); _Silence = new Silence(); _DeviceNo = GetDeviceNo(); BASSInit flags = BASSInit.BASS_DEVICE_DEFAULT; // Because all deviceinfo is saved in a static dictionary, // we need to determine the latency only once. if (!_DeviceInfos.ContainsKey(_DeviceNo)) flags |= BASSInit.BASS_DEVICE_LATENCY; bool result = Bass.BASS_Init( _DeviceNo, 44100, //Only relevant for -> pre-XP (VxD drivers) flags, IntPtr.Zero); BASSError? bassInitErrorCode = result ? null : new BASSError?(Bass.BASS_ErrorGetCode()); // If the GetDeviceNo() method returned BassConstants.BassDefaultDevice, we must request the actual device number // of the choosen default device _DeviceNo = Bass.BASS_GetDevice(); if (bassInitErrorCode.HasValue) { if (bassInitErrorCode.Value == BASSError.BASS_ERROR_ALREADY) { if (!Bass.BASS_SetDevice(_DeviceNo)) throw new BassLibraryException("BASS_SetDevice"); bassInitErrorCode = null; } } if (bassInitErrorCode.HasValue) throw new BassLibraryException("BASS_Init", bassInitErrorCode.Value); CollectDeviceInfo(_DeviceNo); int ms = Convert.ToInt32(Controller.GetSettings().DirectSoundBufferSize.TotalMilliseconds); if (!Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, ms)) throw new BassLibraryException("BASS_SetConfig"); // Enable update thread while the output device is active if (!Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, ms / 4)) throw new BassLibraryException("BASS_SetConfig"); }
public PlaybackBuffer(Controller controller) { _controller = controller; _silence = new Silence(); BassPlayerSettings settings = Controller.GetSettings(); _bufferSize = settings.PlaybackBufferSize; _streamWriteProcDelegate = new STREAMPROC(OutputStreamWriteProc); _vizRawStreamWriteProcDelegate = new STREAMPROC(VizRawStreamWriteProc); _notifyBufferUpdateThread = new AutoResetEvent(false); _updateThreadFinished = new AutoResetEvent(false); }