/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassAudioFileInputSource.Initialize()"); BASSFlag flags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; int handle; ILocalFsResourceAccessor lfra = _accessor as ILocalFsResourceAccessor; if (lfra == null) { // Build stream reading procs for the resource's input stream flags |= BASSFlag.BASS_STREAM_PRESCAN; _streamInput = new StreamInput(_accessor.OpenRead()); handle = Bass.BASS_StreamCreateFileUser( BASSStreamSystem.STREAMFILE_NOBUFFER, flags, _streamInput.FileProcs, IntPtr.Zero); } else { // Optimize access to local filesystem resource using (lfra.EnsureLocalFileSystemAccess()) handle = Bass.BASS_StreamCreateFile(lfra.LocalFileSystemPath, 0, 0, flags); } if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreateFile"); } _BassStream = BassStream.Create(handle); }
public void SetInputStream(BassStream stream, bool passThrough) { if (_deviceState != DeviceState.Stopped) { throw new BassPlayerException("Device state is not 'DeviceState.Stopped'"); } _inputStream = stream; Log.Debug("Creating output stream"); const BASSFlag flags = BASSFlag.BASS_SAMPLE_FLOAT; int handle = Bass.BASS_StreamCreate( _inputStream.SampleRate, _inputStream.Channels, flags, _streamWriteProcDelegate, IntPtr.Zero); if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreate"); } _outputStream = BassStream.Create(handle); if (passThrough) { _fader = new BassStreamFader(_inputStream, Controller.GetSettings().FadeDuration); } ResetState(); }
/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassMODFileInputSource.Initialize()"); const BASSFlag flags = BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MUSIC_AUTOFREE | BASSFlag.BASS_MUSIC_PRESCAN; int handle; ILocalFsResourceAccessor lfra = _accessor as ILocalFsResourceAccessor; if (lfra == null) { // Build stream reading procs for the resource's input stream Stream inputStream = _accessor.OpenRead(); int length = (int)inputStream.Length; byte[] audioData = new byte[length]; inputStream.Read(audioData, 0, length); handle = Bass.BASS_MusicLoad(audioData, 0, length, flags, 0); } else { // Optimize access to local filesystem resource handle = Bass.BASS_MusicLoad(lfra.LocalFileSystemPath, 0, 0, flags, 0); } if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_MusicLoad"); } _bassStream = BassStream.Create(handle); }
/// <summary> /// Creates the visualization Bass stream. /// </summary> private void CreateVizStream() { BASSFlag streamFlags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; int handle = Bass.BASS_StreamCreate( _inputStream.SampleRate, _inputStream.Channels, streamFlags, _vizRawStreamWriteProcDelegate, IntPtr.Zero); if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreate"); } _vizRawStream = BassStream.Create(handle); // Todo: apply AGC streamFlags = BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE; handle = BassMix.BASS_Mixer_StreamCreate(_inputStream.SampleRate, 2, streamFlags); if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreate"); } _vizStream = BassStream.Create(handle); streamFlags = BASSFlag.BASS_MIXER_NORAMPIN | BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_MATRIX; if (!BassMix.BASS_Mixer_StreamAddChannel(_vizStream.Handle, _vizRawStream.Handle, streamFlags)) { throw new BassLibraryException("BASS_Mixer_StreamAddChannel"); } // TODO Albert 2010-02-27: What is this? if (_inputStream.Channels == 1) { float[,] mixMatrix = new float[2, 1]; mixMatrix[0, 0] = 1; mixMatrix[1, 0] = 1; if (!BassMix.BASS_Mixer_ChannelSetMatrix(_vizRawStream.Handle, mixMatrix)) { throw new BassLibraryException("BASS_Mixer_ChannelSetMatrix"); } } }
/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassWebStreamInputSource.Initialize()"); const BASSFlag flags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; _handle = Bass.BASS_StreamCreateURL(_url, 0, flags, null, new IntPtr()); if (_handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreateURL"); } _bassStream = BassStream.Create(_handle); }
private void CreateOutputStream() { const BASSFlag flags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE; int handle = Bass.BASS_StreamCreate( _inputStream.SampleRate, _inputStream.Channels, flags, _streamWriteProcDelegate, IntPtr.Zero); if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreate"); } _outputStream = BassStream.Create(handle); }
protected bool Initialize(IInputSource inputSource) { if (_state != SessionState.Reset) { return(false); } if (!MatchesInputSource(inputSource)) { return(false); } _currentInputSource = inputSource; Log.Debug("PlaybackSession: Creating output stream"); const BASSFlag flags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE; int handle = Bass.BASS_StreamCreate( _currentInputSource.OutputStream.SampleRate, _currentInputSource.OutputStream.Channels, flags, _streamWriteProcDelegate, IntPtr.Zero); if (handle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_StreamCreate"); } _outputStream = BassStream.Create(handle); _state = SessionState.Initialized; _upDownMixer.SetInputStream(_outputStream); _vstProcessor.SetInputStream(_upDownMixer.OutputStream); _winAmpDSPProcessor.SetInputStream(_vstProcessor.OutputStream); _playbackBuffer.SetInputStream(_winAmpDSPProcessor.OutputStream); _controller.OutputDeviceManager.SetInputStream(_playbackBuffer.OutputStream, _outputStream.IsPassThrough); return(true); }
/// <summary> /// Create a mixer to be used as Output stream. /// We currently need this in case of Up- or Downmixing /// </summary> private void CreateMixer(int channels) { _mixerHandle = BassMix.BASS_Mixer_StreamCreate(_inputStream.SampleRate, channels, MIXER_FLAGS); if (_mixerHandle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_Mixer_StreamCreate"); } _mixerStream = BassStream.Create(_mixerHandle); // Now Attach the Input Stream to the mixer try { Bass.BASS_ChannelLock(_mixerHandle, true); bool result = BassMix.BASS_Mixer_StreamAddChannel(_mixerHandle, _inputStream.Handle, BASSFlag.BASS_MIXER_NORAMPIN | BASSFlag.BASS_MIXER_BUFFER | BASSFlag.BASS_MIXER_MATRIX | BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE ); if (!result) { throw new BassLibraryException("BASS_UpDownMix_StreamAddChannel"); } } finally { Bass.BASS_ChannelLock(_mixerHandle, false); } if (_mixingMatrix != null) { bool result = BassMix.BASS_Mixer_ChannelSetMatrix(_inputStream.Handle, _mixingMatrix); if (!result) { throw new BassLibraryException("BASS_UpDownMix_SetMixingMatrix"); } } }
/// <summary> /// Initializes a new instance. /// </summary> private void Initialize() { Log.Debug("BassCDTrackInputSource.Initialize()"); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_CD_FREEOLD, false); const BASSFlag flags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT; int bassDrive = BassUtils.Drive2BassID(_drive); int handle = BassCd.BASS_CD_StreamCreate(bassDrive, BassTrackNo, flags); if (handle == 0) { if (Bass.BASS_ErrorGetCode() == BASSError.BASS_ERROR_ALREADY) { // Drive is already playing - stream must be lazily initialized return; } throw new BassLibraryException("BASS_CD_StreamCreate"); } _bassStream = BassStream.Create(handle); }
public override void SetInputStream(BassStream stream, bool passThrough) { if (_deviceState != DeviceState.Stopped) { throw new BassPlayerException("Device state is not 'DeviceState.Stopped'"); } _inputStream = stream; _flags = BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT | BASSWASAPIInit.BASS_WASAPI_BUFFER; // If Exclusive mode is used, check, if that would be supported, otherwise init in shared mode bool isExclusive = Controller.GetSettings().WASAPIExclusiveMode; if (isExclusive) { _flags |= BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE; BASSWASAPIFormat wasapiFormat = BassWasapi.BASS_WASAPI_CheckFormat(_deviceNo, _inputStream.SampleRate, _inputStream.Channels, BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE); if (wasapiFormat == BASSWASAPIFormat.BASS_WASAPI_FORMAT_UNKNOWN) { Log.Info("BASS: WASAPI exclusive mode not directly supported for samplerate of {0} and {1} channels", _inputStream.SampleRate, _inputStream.Channels); isExclusive = false; } } retry: if (!isExclusive) { Log.Debug("BASS: Init WASAPI shared mode with Event driven system enabled."); _flags &= ~BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE; _flags |= BASSWASAPIInit.BASS_WASAPI_SHARED | BASSWASAPIInit.BASS_WASAPI_EVENT; } Log.Debug("BASS: Try to init WASAPI with a samplerate of {0} and {1} channels", _inputStream.SampleRate, _inputStream.Channels); bool result = BassWasapi.BASS_WASAPI_Init(_deviceNo, _inputStream.SampleRate, _inputStream.Channels, _flags, 0.5f, 0f, _streamWriteProcDelegate, IntPtr.Zero); BASSError?bassInitErrorCode = result ? null : new BASSError?(Bass.BASS_ErrorGetCode()); if (bassInitErrorCode.HasValue) { if (bassInitErrorCode.Value == BASSError.BASS_ERROR_ALREADY) { if (!BassWasapi.BASS_WASAPI_SetDevice(_deviceNo)) { throw new BassLibraryException("BASS_WASAPI_SetDevice"); } } else if (isExclusive) { // Allow one retry in shared mode Log.Warn("BASS: Failed to initialize WASAPI exclusive mode for samplerate of {0} and {1} channels. Trying fallback to shared mode.", _inputStream.SampleRate, _inputStream.Channels); isExclusive = false; goto retry; } else { throw new BassLibraryException("BASS_WASAPI_Init"); } } // If the GetDeviceNo() method returned BassConstants.BassDefaultDevice, we must request the actual device number // of the choosen default device _deviceNo = BassWasapi.BASS_WASAPI_GetDevice(); CollectDeviceInfo(_deviceNo); BASS_WASAPI_INFO wasapiInfo = BassWasapi.BASS_WASAPI_GetInfo(); Log.Debug("BASS: ---------------------------------------------"); Log.Debug("BASS: Buffer Length: {0}", wasapiInfo.buflen); Log.Debug("BASS: Channels: {0}", wasapiInfo.chans); Log.Debug("BASS: Frequency: {0}", wasapiInfo.freq); Log.Debug("BASS: Format: {0}", wasapiInfo.format.ToString()); Log.Debug("BASS: InitFlags: {0}", wasapiInfo.initflags.ToString()); Log.Debug("BASS: Exclusive: {0}", wasapiInfo.IsExclusive.ToString()); Log.Debug("BASS: ---------------------------------------------"); Log.Info("BASS: WASAPI Device successfully initialised"); // For shared mode we require a mixer to change the sampling rates of input stream to device output stream. if (!wasapiInfo.IsExclusive) { // Recreate Mixer with new value Log.Debug("BASS: Creating new {0} channel mixer for frequency {1}", wasapiInfo.chans, wasapiInfo.freq); _mixerHandle = BassMix.BASS_Mixer_StreamCreate(wasapiInfo.freq, wasapiInfo.chans, MIXER_FLAGS); if (_mixerHandle == BassConstants.BassInvalidHandle) { throw new BassLibraryException("BASS_Mixer_StreamCreate"); } _mixer = BassStream.Create(_mixerHandle); AttachStream(); } 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"); } if (passThrough) { _fader = new BassStreamFader(_inputStream, Controller.GetSettings().FadeDuration); } ResetState(); }