public override void OnStarted()
    {
      int channelBitwidth = base.ChannelBitwidth;
      switch (channelBitwidth)
      {
        case 0x20:
          this._streamFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
          this._streamFlags |= BASSFlag.BASS_SAMPLE_FLOAT;
          channelBitwidth = 4;
          break;

        case 8:
          this._streamFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
          this._streamFlags |= BASSFlag.BASS_SAMPLE_8BITS;
          channelBitwidth = 1;
          break;

        default:
          this._streamFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
          this._streamFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
          channelBitwidth = 2;
          break;
      }
      this._streamBuffer = new BASSBuffer(2f, base.ChannelSampleRate, base.ChannelNumChans, channelBitwidth);
      this._stream = Un4seen.Bass.Bass.BASS_StreamCreate(base.ChannelSampleRate, base.ChannelNumChans, this._streamFlags,
                                                         null, IntPtr.Zero);
      Un4seen.Bass.Bass.BASS_ChannelSetLink(base.ChannelHandle, this._stream);
      if (Un4seen.Bass.Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
      {
        Bass.BASS_ChannelPlay(this._stream, false);
      }
    }
        /// <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);
        }
Exemple #3
0
 public BASS_SAMPLE(int Freq, float Volume, float Pan, BASSFlag Flags, int Length, int Max, int OrigRes, int Chans, int MinGap, BASS3DMode Flag3D, float MinDist, float MaxDist, int IAngle, int OAngle, float OutVol, BASSVam FlagsVam, int Priority)
 {
     freq = 0xac44;
     volume = 1f;
     max = 1;
     chans = 2;
     outvol = 1f;
     vam = BASSVam.BASS_VAM_HARDWARE;
     freq = Freq;
     volume = Volume;
     pan = Pan;
     flags = Flags;
     length = Length;
     max = Max;
     origres = OrigRes;
     chans = Chans;
     mingap = MinGap;
     mode3d = Flag3D;
     mindist = MinDist;
     maxdist = MaxDist;
     iangle = IAngle;
     oangle = OAngle;
     outvol = OutVol;
     vam = FlagsVam;
     priority = Priority;
 }
        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
                using (lfra.EnsureLocalFileSystemAccess())
                    handle = Bass.BASS_MusicLoad(lfra.LocalFileSystemPath, 0, 0, flags, 0);
            }

            if (handle == BassConstants.BassInvalidHandle)
            {
                throw new BassLibraryException("BASS_MusicLoad");
            }

            _bassStream = BassStream.Create(handle);
        }
Exemple #6
0
        public override void OnStarted()
        {
            int channelBitwidth = base.ChannelBitwidth;

            switch (channelBitwidth)
            {
            case 0x20:
                _streamFlags   &= ~BASSFlag.BASS_SAMPLE_8BITS;
                _streamFlags   |= BASSFlag.BASS_SAMPLE_FLOAT;
                channelBitwidth = 4;
                break;

            case 8:
                _streamFlags   &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                _streamFlags   |= BASSFlag.BASS_SAMPLE_8BITS;
                channelBitwidth = 1;
                break;

            default:
                _streamFlags   &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                _streamFlags   &= ~BASSFlag.BASS_SAMPLE_8BITS;
                channelBitwidth = 2;
                break;
            }
            _streamBuffer = new BASSBuffer(2f, base.ChannelSampleRate, base.ChannelNumChans, channelBitwidth);
            _stream       = Bass.BASS_StreamCreate(base.ChannelSampleRate, base.ChannelNumChans, _streamFlags,
                                                   null, IntPtr.Zero);
            Bass.BASS_ChannelSetLink(base.ChannelHandle, _stream);
            if (Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelPlay(_stream, false);
            }
        }
Exemple #7
0
 public int CreateStream(string pathToAudioFile, BASSFlag flags)
 {
     lock (lockObject)
     {
         return(Bass.BASS_StreamCreateFile(pathToAudioFile, 0, 0, flags));
     }
 }
 public DSP_BufferStream()
 {
     _configBuffer = 500;
     _isOutputBuffered = true;
     _bufferStreamFlags = BASSFlag.BASS_MUSIC_DECODE;
     ConfigBuffer = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_BUFFER);
     _streamProc = new STREAMPROC(BassStreamProc);
 }
Exemple #9
0
 public DSP_BufferStream()
 {
     _configBuffer      = 500;
     _isOutputBuffered  = true;
     _bufferStreamFlags = BASSFlag.BASS_MUSIC_DECODE;
     ConfigBuffer       = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_BUFFER);
     _streamProc        = new STREAMPROC(BassStreamProc);
 }
Exemple #10
0
 public DSP_BufferStream(int channel, int priority) : base(channel, priority, IntPtr.Zero)
 {
     _configBuffer      = 500;
     _isOutputBuffered  = true;
     _bufferStreamFlags = BASSFlag.BASS_MUSIC_DECODE;
     ConfigBuffer       = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_BUFFER);
     _streamProc        = new STREAMPROC(BassStreamProc);
 }
        /// <summary>
        /// 开始录音
        /// </summary>
        /// <param name="freq">录音采样率,默认48000</param>
        /// <param name="chans">声道数[1-6],默认1</param>
        /// <param name="period">录音数据输出间隔,单位/毫秒,默认100.最小值5ms,the maximum the maximum is half the BASS_CONFIG_REC_BUFFER setting.
        /// If the period specified is outside this range, it is automatically capped. The default is 100ms</param>
        /// <param name="sampleType">采样类型,建议默认值16位</param>
        public void Start(int freq = 48000, int chans = 1, int period = 100, SampleType sampleType = SampleType.Sample16Bit)
        {
            BASSFlag flags = this.SampleTypeToBASSFlag(sampleType);

            this._recordFlag = true;
            this._handle     = RecordHelper.RecordStart(freq, chans, flags, period, this._recordPro, IntPtr.Zero);
            WavHelper.ChannelPlay(this._handle, false);
        }
 public DSP_BufferStream(int channel, int priority)
     : base(channel, priority, IntPtr.Zero)
 {
     _configBuffer = 500;
     _isOutputBuffered = true;
     _bufferStreamFlags = BASSFlag.BASS_MUSIC_DECODE;
     ConfigBuffer = Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_BUFFER);
     _streamProc = new STREAMPROC(BassStreamProc);
 }
Exemple #13
0
        public static int BASS_MusicLoad(string file, long offset, int lenght, BASSFlag flags, int freq)
        {

            IntPtr ptr = Marshal.StringToHGlobalAnsi(file);
            int handle = BASS_ML(false, ptr, offset, lenght, flags, freq);
            Marshal.FreeHGlobal(ptr);

            return handle;
        }
Exemple #14
0
        public int OpenFile(string loc, BASSFlag flags)
        {
            int chan = Bass.BASS_StreamCreateFile(loc, 0, 0, flags | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE);

            if (chan == 0)
            {
                GetBassErrorTrow("Could not open file: " + loc);
            }
            return(chan);
        }
Exemple #15
0
        public static int BASS_MusicLoad(byte[] file, long offset, int lenght, BASSFlag flags, int freq)
        {
            IntPtr ptr = Marshal.AllocHGlobal(file.Length);
            Marshal.Copy(file, 0, ptr, file.Length);

            int handle = BASS_ML(true, ptr , offset, file.Length, flags, freq);
            Marshal.FreeHGlobal(ptr);

            return handle;
        }
        /// <summary>
        /// Creates a user sample stream.
        /// </summary>
        /// <param name="freq">The default sample rate. The sample rate can be changed using BASS_ChannelSetAttribute. </param>
        /// <param name="chans">The number of channels... 1 = mono, 2 = stereo, 4 = quadraphonic, 6 = 5.1, 8 = 7.1. </param>
        /// <param name="flags">A combination of these flags.</param>
        /// <param name="proc">The user defined stream writing function, or one of the following.
        /// STREAMPROC_DEVICE Create a "dummy" stream for the device's final output mix. This allows DSP/FX to be applied to all channels that are playing on the device,
        /// rather than individual channels. DSP/FX parameter change latency is also reduced because channel playback buffering is avoided. The stream is created with the device's current output sample format;
        /// the freq, chans, and flags parameters are ignored.It will always be floating-point except on platforms/architectures that do not support floating-point (see BASS_CONFIG_FLOAT), where it will be 16-bit instead.
        /// STREAMPROC_DUMMY Create a "dummy" stream. A dummy stream does not have any sample data of its own, but a decoding dummy stream (with BASS_STREAM_DECODE flag) can be used to apply DSP/FX processing to any sample data, by setting DSP/FX on the stream and feeding the data through BASS_ChannelGetData. The dummy stream should have the same sample format as the data being fed through it.
        /// STREAMPROC_PUSH Create a "push" stream.Instead of BASS pulling data from a STREAMPROC function, data is pushed to BASS via BASS_StreamPutData.</param>
        /// <param name="user">User instance data to pass to the callback function. Unused when creating a dummy or push stream. </param>
        /// <returns>If successful, the new stream's handle is returned, else throw WavException</returns>
        public static int StreamCreate(int freq, int chans, BASSFlag flags, STREAMPROC proc, IntPtr user)
        {
            int handle = NativeMethods.BASS_StreamCreate(freq, chans, flags, proc, IntPtr.Zero);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
        /// <summary>
        /// Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file.
        /// </summary>
        /// <param name="memory">An unmanaged pointer to the memory location as an IntPtr</param>
        /// <param name="offset">Offset to begin streaming from (unused for memory streams, set to 0). </param>
        /// <param name="length">Data length (needs to be set to the length of the memory stream in bytes which should be played)</param>
        /// <param name="flags">A combination of these flags.</param>
        /// <returns>If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code</returns>
        public static int StreamCreateFile(IntPtr memory, long offset, long length, BASSFlag flags)
        {
            int handle = NativeMethods.BASS_StreamCreateFileMemory(true, memory, offset, length, flags);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
        /// <summary>
        /// Creates a user sample stream.
        /// </summary>
        /// <param name="freq">The default sample rate. The sample rate can be changed using BASS_ChannelSetAttribute. </param>
        /// <param name="chans">The number of channels... 1 = mono, 2 = stereo, 4 = quadraphonic, 6 = 5.1, 8 = 7.1. </param>
        /// <param name="flags">A combination of these flags.</param>
        /// <param name="proc">The user defined stream writing function, or one of the following.
        /// STREAMPROC_DEVICE Create a "dummy" stream for the device's final output mix. This allows DSP/FX to be applied to all channels that are playing on the device,
        /// rather than individual channels. DSP/FX parameter change latency is also reduced because channel playback buffering is avoided. The stream is created with the device's current output sample format;
        /// the freq, chans, and flags parameters are ignored.It will always be floating-point except on platforms/architectures that do not support floating-point (see BASS_CONFIG_FLOAT), where it will be 16-bit instead.
        /// STREAMPROC_DUMMY Create a "dummy" stream. A dummy stream does not have any sample data of its own, but a decoding dummy stream (with BASS_STREAM_DECODE flag) can be used to apply DSP/FX processing to any sample data, by setting DSP/FX on the stream and feeding the data through BASS_ChannelGetData. The dummy stream should have the same sample format as the data being fed through it.
        /// STREAMPROC_PUSH Create a "push" stream.Instead of BASS pulling data from a STREAMPROC function, data is pushed to BASS via BASS_StreamPutData.</param>
        /// <param name="user">User instance data to pass to the callback function. Unused when creating a dummy or push stream. </param>
        /// <returns>If successful, the new stream's handle is returned, else throw WavException</returns>

        public static int StreamCreate(int freq, int chans, BASSFlag flags, BASSStreamProc proc)
        {
            int handle = NativeMethods.BASS_StreamCreatePtr(freq, chans, flags, new IntPtr((int)proc), IntPtr.Zero);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
        /// <summary>
        /// Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file via user callback functions.
        /// </summary>
        /// <param name="system">File system to use, one of the following. </param>
        /// <param name="flags">A combination of these flags.</param>
        /// <param name="procs">The user defined file functions. </param>
        /// <param name="user">User instance data to pass to the callback functions. </param>
        /// <returns>If successful, the new stream's handle is returned, else throw WavException.</returns>
        public static int StreamCreateFileUser(BASSStreamSystem system, BASSFlag flags, BASS_FILEPROCS procs, IntPtr user)
        {
            int handle = NativeMethods.BASS_StreamCreateFileUser(system, flags, procs, user);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
Exemple #20
0
        /// <summary>
        /// Starts recording.
        /// </summary>
        /// <param name="freq">The sample rate to record at... 0 = device's current sample rate. </param>
        /// <param name="chans">The number of channels... 1 = mono, 2 = stereo, etc. 0 = device's current channel count</param>
        /// <param name="flags">A combination of these flags.
        /// BASS_SAMPLE_8BITS Use 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flag are specified, then the recorded data is 16-bit.
        /// BASS_SAMPLE_FLOAT Use 32-bit floating-point sample data.See Floating-point channels for info.
        /// BASS_RECORD_PAUSE Start the recording paused.
        /// The HIWORD - use MAKELONG(flags, period) - can be used to set the period(in milliseconds) between calls to the callback function.
        ///              The minimum period is 5ms, the maximum is half the BASS_CONFIG_REC_BUFFER setting. If the period specified is outside this range, it is automatically capped. The default is 100ms.
        /// </param>
        /// <param name="period">Set the period(in milliseconds) between calls to the callback function(Un4seen.Bass.RECORDPROC).
        /// The minimum period is 5ms, the maximum the maximum is half the BASS_CONFIG_REC_BUFFER setting.
        /// If the period specified is outside this range, it is automatically capped. The default is 100ms</param>
        /// <param name="proc">The user defined function to receive the recorded sample data... can be NULL if you do not wish to use a callback. </param>
        /// <param name="user">User instance data to pass to the callback function. </param>
        /// <returns>If successful, the new recording's handle is returned, else throw WavException. </returns>
        public static int RecordStart(int freq, int chans, BASSFlag flags, int period, RECORDPROC proc, IntPtr user)
        {
            int handle = NativeMethods.BASS_RecordStart(freq, chans, (BASSFlag)Utils.MakeLong((int)flags, period), proc, user);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
Exemple #21
0
        /// <summary>
        /// Открыть файл для проигрывания из файла.
        /// </summary>
        /// <param name="FileName">Имя файла для открытия</param>
        /// <param name="repeate">Повторять ли звук после окончания</param>
        public void Open(string FileName, bool repeate = false)
        {
            SetDevice(SoundCard);
            Repeate = repeate;
            BASSFlag Loop = repeate
                ? BASSFlag.BASS_MUSIC_LOOP
                : BASSFlag.BASS_DEFAULT;

            Channel = Bass.BASS_StreamCreateFile(FileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | Loop | AudioChannel);
            SetOpenParameters();
        }
Exemple #22
0
        /// <summary>
        /// Modifies and retrieves a channel's flags
        /// </summary>
        /// <param name="handle">The channel handle... a HCHANNEL, HMUSIC, HSTREAM. </param>
        /// <param name="flags">A combination of these flags.
        /// BASS_SAMPLE_LOOP Loop the channel.
        /// BASS_STREAM_AUTOFREE Automatically free the channel when playback ends.Note that the BASS_MUSIC_AUTOFREE flag is identical to this flag. (HSTREAM/HMUSIC only)
        /// BASS_STREAM_RESTRATE Restrict the download rate. (HSTREAM)
        /// BASS_MUSIC_NONINTER Use non-interpolated sample mixing. (HMUSIC)
        /// BASS_MUSIC_SINCINTER Use sinc interpolated sample mixing. (HMUSIC)
        /// BASS_MUSIC_RAMP Use "normal" ramping. (HMUSIC)
        /// BASS_MUSIC_RAMPS Use "sensitive" ramping. (HMUSIC)
        /// BASS_MUSIC_SURROUND Use surround sound. (HMUSIC)
        /// BASS_MUSIC_SURROUND2 Use surround sound mode 2. (HMUSIC)
        /// BASS_MUSIC_FT2MOD Use FastTracker 2 .MOD playback. (HMUSIC)
        /// BASS_MUSIC_PT1MOD Use ProTracker 1 .MOD playback. (HMUSIC)
        /// BASS_MUSIC_POSRESET Stop all notes when seeking. (HMUSIC)
        /// BASS_MUSIC_POSRESETEX Stop all notes and reset BPM/etc when seeking. (HMUSIC)
        /// BASS_MUSIC_STOPBACK Stop when a backward jump effect is played. (HMUSIC)
        /// BASS_SPEAKER_xxx Speaker assignment flags. (HSTREAM/HMUSIC)
        /// other flags may be supported by add-ons, see the documentation. </param>
        /// <param name="mask">The flags (as above) to modify. Flags that are not included in this are left as they are, so it can be set to 0 in order to just retrieve the current flags. To modify the speaker flags, any of the BASS_SPEAKER_xxx flags can be used in the mask (no need to include all of them). </param>
        /// <returns>If successful, the channel's updated flags are returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.</returns>
        public static BASSFlag ChannelFlags(int handle, BASSFlag flags, BASSFlag mask)
        {
            int result = NativeMethods.BASS_ChannelFlags(handle, flags, mask);

            if (result == -1)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return((BASSFlag)result);
        }
Exemple #23
0
        static int StreamCreateFile(string file, long offset, long length, BASSFlag flags)
        {
            int audioStreamHandle = Bass.BASS_StreamCreateFile(file, offset, length, flags);

            if (audioStreamHandle == 0)
            {
                // Try an opus stream instead as a fallback
                audioStreamHandle = BassOpus.BASS_OPUS_StreamCreateFile(file, offset, length, flags);
            }

            return(audioStreamHandle);
        }
Exemple #24
0
        public static int BASS_AAC_StreamCreateURL(string url, int offset, BASSFlag flags, DOWNLOADPROC proc, IntPtr user)
        {
            flags |= BASSFlag.BASS_UNICODE;
            int num = BassAac.BASS_AAC_StreamCreateURLUnicode(url, offset, flags, proc, user);

            if (num == 0)
            {
                flags &= (BASSFlag.BASS_SAMPLE_8BITS | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_LOOP | BASSFlag.BASS_SAMPLE_3D | BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_MUTEMAX | BASSFlag.BASS_SAMPLE_VAM | BASSFlag.BASS_SAMPLE_FX | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_RECORD_PAUSE | BASSFlag.BASS_RECORD_ECHOCANCEL | BASSFlag.BASS_RECORD_AGC | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_STREAM_RESTRATE | BASSFlag.BASS_STREAM_BLOCK | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_STATUS | BASSFlag.BASS_SPEAKER_FRONT | BASSFlag.BASS_SPEAKER_REAR | BASSFlag.BASS_SPEAKER_REAR2 | BASSFlag.BASS_SPEAKER_LEFT | BASSFlag.BASS_SPEAKER_RIGHT | BASSFlag.BASS_SPEAKER_PAIR8 | BASSFlag.BASS_ASYNCFILE | BASSFlag.BASS_SAMPLE_OVER_VOL | BASSFlag.BASS_WV_STEREO | BASSFlag.BASS_AC3_DOWNMIX_2 | BASSFlag.BASS_AC3_DOWNMIX_4 | BASSFlag.BASS_AC3_DYNAMIC_RANGE | BASSFlag.BASS_AAC_FRAME960);
                num    = BassAac.BASS_AAC_StreamCreateURLAscii(url, offset, flags, proc, user);
            }
            return(num);
        }
Exemple #25
0
        /// <summary>
        /// Starts recording.
        /// </summary>
        /// <param name="freq">The sample rate to record at... 0 = device's current sample rate. </param>
        /// <param name="chans">The number of channels... 1 = mono, 2 = stereo, etc. 0 = device's current channel count</param>
        /// <param name="flags">A combination of these flags.
        /// BASS_SAMPLE_8BITS Use 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flag are specified, then the recorded data is 16-bit.
        /// BASS_SAMPLE_FLOAT Use 32-bit floating-point sample data.See Floating-point channels for info.
        /// BASS_RECORD_PAUSE Start the recording paused.
        /// The HIWORD - use MAKELONG(flags, period) - can be used to set the period(in milliseconds) between calls to the callback function.
        ///              The minimum period is 5ms, the maximum is half the BASS_CONFIG_REC_BUFFER setting. If the period specified is outside this range, it is automatically capped. The default is 100ms.
        /// </param>
        /// <param name="proc">The user defined function to receive the recorded sample data... can be NULL if you do not wish to use a callback. </param>
        /// <param name="user">User instance data to pass to the callback function. </param>
        /// <returns>If successful, the new recording's handle is returned, else throw WavException. </returns>
        public static int RecordStart(int freq, int chans, BASSFlag flags, RECORDPROC proc, IntPtr user)
        {
            int flagRet = (int)flags + 20 << 8;
            int handle  = NativeMethods.BASS_RecordStart(freq, chans, flags, proc, user);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
        private int CreateStream(string pathToFile, BASSFlag flags)
        {
            // create streams for re-sampling
            int stream = bassServiceProxy.CreateStream(pathToFile, flags);

            if (stream == 0)
            {
                throw new BassAudioServiceException(bassServiceProxy.GetLastError());
            }

            return(stream);
        }
        /// <summary>
        /// Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file.
        /// </summary>
        /// <param name="mem">TRUE = stream the file from memory(true:流;false:文件)</param>
        /// <param name="file">Filename (mem = FALSE) or a memory location (mem = TRUE).</param>
        /// <param name="offset">File offset to begin streaming from (only used if mem = FALSE). </param>
        /// <param name="length">Data length... 0 = use all data up to the end of the file (if mem = FALSE)</param>
        /// <param name="flags">A combination of these flags.</param>
        /// <returns>If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code</returns>
        public static int StreamCreateFile(string file, long offset, long length, BASSFlag flags)
        {
            flags |= BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE;
            int handle = NativeMethods.BASS_StreamCreateFileUnicode(false, file, offset, length, flags);

            if (handle == 0)
            {
                throw new WavException(BassErrorCode.GetErrorInfo());
            }

            return(handle);
        }
Exemple #28
0
        public static BASSActive BASS_Mixer_ChannelIsActive(int handle)
        {
            BASSFlag bassflag = BassMix.BASS_Mixer_ChannelFlags(handle, BASSFlag.BASS_STREAM_PRESCAN, BASSFlag.BASS_DEFAULT);

            if (bassflag < BASSFlag.BASS_DEFAULT)
            {
                return(BASSActive.BASS_ACTIVE_STOPPED);
            }
            if ((bassflag & BASSFlag.BASS_STREAM_PRESCAN) != BASSFlag.BASS_DEFAULT)
            {
                return(BASSActive.BASS_ACTIVE_PAUSED);
            }
            return(BASSActive.BASS_ACTIVE_PLAYING);
        }
        /// <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");
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// Установка баланса
        /// </summary>
        /// <param name="balance"></param>
        public void SetBalance(int balance)
        {
            Balance = balance;
            Bass.BASS_ChannelSetAttribute(Channel, BASSAttribute.BASS_ATTRIB_PAN, Balance);
            AudioChannel = BASSFlag.BASS_SPEAKER_FRONT;

            /*switch (Balance)
             * {
             *  case -1: AudioChannel = BASSFlag.BASS_SPEAKER_FRONTLEFT; break;
             *  case 0: AudioChannel = BASSFlag.BASS_SPEAKER_FRONT; break;
             *  case 1: AudioChannel = BASSFlag.BASS_SPEAKER_FRONTRIGHT; break;
             *
             * }*/
        }
        /// <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);
        }
Exemple #32
0
        /// <summary>
        /// Открыть файл для проигрывания из массива байтов (byte[]).
        /// </summary>
        /// <param name="ByteStream">массива байтов</param>
        /// <param name="repeate">Повторять ли звук после окончания</param>
        public void Open(byte[] ByteStream, bool repeate = false)
        {
            SetDevice(SoundCard);
            GCHandle _hGCFile;

            Repeate = repeate;
            BASSFlag Loop = repeate
                ? BASSFlag.BASS_MUSIC_LOOP
                : BASSFlag.BASS_DEFAULT;

            _hGCFile = GCHandle.Alloc(ByteStream, GCHandleType.Pinned);
            // create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
            Channel = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(),
                                                 0L, ByteStream.Length, BASSFlag.BASS_SAMPLE_FLOAT | Loop | AudioChannel);
            SetOpenParameters();
        }
Exemple #33
0
        public static int MixerStreamCreate(int samplerate)
        {
            BASSFlag mixerFlags = BASSFlag.BASS_SAMPLE_FLOAT;

            if (Player.IsAsioInitialized || Player.IsWasapiInitialized)
            {
                mixerFlags |= BASSFlag.BASS_STREAM_DECODE;
            }

            m_mixerChannel = BassMix.BASS_Mixer_StreamCreate(samplerate, 2, mixerFlags);

            Console.WriteLine("Player.IsBassInitialized " + Player.IsBassInitialized);
            Console.WriteLine("Player.IsAsioInitialized " + Player.IsAsioInitialized);
            Console.WriteLine("Player.IsWasapiInitialized " + Player.IsWasapiInitialized);

            return(m_mixerChannel);
        }
Exemple #34
0
        public static int PlugChannelToMixer(int handle, int freq, int chans, int res)
        {
            BASSFlag bassFlag = BASSFlag.BASS_STREAM_DECODE;

            if (res == 8)
            {
                bassFlag |= BASSFlag.BASS_SAMPLE_8BITS;
            }

            // this will be the final mixer output stream being played
            int mixer = BassMix.BASS_Mixer_StreamCreate(freq, chans, bassFlag);

            // add channel to mixer
            bool isMixerGood = BassMix.BASS_Mixer_StreamAddChannel(mixer, handle, BASSFlag.BASS_MIXER_NORAMPIN);

            return(mixer);
        }
        internal AudioTrackBass(Stream data, bool quick = false, bool loop = false)
        {
            procs = new BASS_FILEPROCS(ac_Close, ac_Length, ac_Read, ac_Seek);

            Preview = quick;
            Looping = loop;

            BASSFlag flags = Preview ? 0 : (BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);

            if (data == null)
            {
                throw new AudioNotLoadedException();
            }
            else
            {
                //encapsulate incoming stream with async buffer if it isn't already.
                DataStream = data as AsyncBufferStream;
                if (DataStream == null)
                {
                    DataStream = new AsyncBufferStream(data, quick ? 8 : -1);
                }

                audioStreamPrefilter = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, flags, procs, IntPtr.Zero);
            }

            if (Preview)
            {
                audioStream = audioStreamForwards = audioStreamPrefilter;
            }
            else
            {
                audioStream          = audioStreamForwards = BassFx.BASS_FX_TempoCreate(audioStreamPrefilter, loop ? BASSFlag.BASS_MUSIC_LOOP : BASSFlag.BASS_DEFAULT);
                audioStreamBackwards = BassFx.BASS_FX_ReverseCreate(audioStreamPrefilter, 5f, BASSFlag.BASS_DEFAULT);

                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_USE_QUICKALGO, Bass.TRUE);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 4);
                Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 30);
            }

            Length = (Bass.BASS_ChannelBytes2Seconds(audioStream, Bass.BASS_ChannelGetLength(audioStream)) * 1000);
            Bass.BASS_ChannelGetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_FREQ, ref initialAudioFrequency);
            currentAudioFrequency = initialAudioFrequency;

            AudioEngine.RegisterTrack(this);
        }
        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);
        }
Exemple #37
0
 private static extern int BASS_SampleLoadMemory([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory,
                                                 long offset, int length, int max, BASSFlag flags);
Exemple #38
0
 public static int BASS_SampleLoad(IntPtr memory, long offset, int length, int max, BASSFlag flags)
 {
     return BASS_SampleLoadMemory(true, memory, offset, length, max, flags);
 }
Exemple #39
0
 public static int BASS_RecordStart(int freq, int chans, BASSFlag flags, int period, RECORDPROC proc, IntPtr user)
 {
     return BASS_RecordStart(freq, chans, (BASSFlag) Utils.MakeLong((int) flags, period), proc, user);
 }
Exemple #40
0
 public static int BASS_MusicLoad(byte[] memory, long offset, int length, BASSFlag flags, int freq)
 {
     return BASS_MusicLoadMemory(true, memory, offset, length, flags, freq);
 }
Exemple #41
0
 public static extern BASSFlag BASS_ChannelFlags(int handle, BASSFlag flags, BASSFlag mask);
Exemple #42
0
 private static extern int BASS_StreamCreateFileUnicode([MarshalAs(UnmanagedType.Bool)] bool mem,
                                                        [In, MarshalAs(UnmanagedType.LPWStr)] string file,
                                                        long offset, long length, BASSFlag flags);
Exemple #43
0
 public static int BASS_StreamCreateFile(string file, long offset, long length, BASSFlag flags)
 {
     flags |= BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE;
     return BASS_StreamCreateFileUnicode(false, file, offset, length, flags);
 }
Exemple #44
0
 public static int BASS_StreamCreateFile(IntPtr memory, long offset, long length, BASSFlag flags)
 {
     return BASS_StreamCreateFileMemory(true, memory, offset, length, flags);
 }
Exemple #45
0
 public static int BASS_StreamCreateDummy(int freq, int chans, BASSFlag flags, IntPtr user)
 {
     return BASS_StreamCreatePtr(freq, chans, flags, IntPtr.Zero, user);
 }
Exemple #46
0
 public static extern int BASS_StreamCreate(int freq, int chans, BASSFlag flags, STREAMPROC proc, IntPtr user);
 internal int StreamCreate(int freq, int chans, BASSFlag Flags, STREAMPROC proc, IntPtr user)
 {
   lock (_syncRoot)
   {
     return Bass.BASS_StreamCreate(freq, chans, Flags, proc, user);
   }
 }
Exemple #48
0
 private static extern int BASS_SampleLoadUnicode([MarshalAs(UnmanagedType.Bool)] bool mem,
                                                  [In, MarshalAs(UnmanagedType.LPWStr)] string file, long offset,
                                                  int length, int max, BASSFlag flags);
Exemple #49
0
 private static extern int BASS_StreamCreateFileMemory([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory,
                                                       long offset, long length, BASSFlag flags);
Exemple #50
0
 public static extern int BASS_StreamCreateFileUser(BASSStreamSystem system, BASSFlag flags, BASS_FILEPROCS procs,
                                                    IntPtr user);
Exemple #51
0
 private static extern int BASS_StreamCreatePtr(int freq, int chans, BASSFlag flags, IntPtr procPtr, IntPtr user);
Exemple #52
0
 public static int BASS_StreamCreatePush(int freq, int chans, BASSFlag flags, IntPtr user)
 {
     return BASS_StreamCreatePtr(freq, chans, flags, new IntPtr(-1), user);
 }
Exemple #53
0
 public static int BASS_MusicLoad(string file, long offset, int length, BASSFlag flags, int freq)
 {
     flags |= BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE;
     return BASS_MusicLoadUnicode(false, file, offset, length, flags, freq);
 }
Exemple #54
0
 public static extern int BASS_StreamCreateURL([In, MarshalAs(UnmanagedType.LPStr)] string url, int offset,
                                               BASSFlag flags, DOWNLOADPROC proc, IntPtr user);
Exemple #55
0
 public static extern int BASS_RecordStart(int freq, int chans, BASSFlag flags, RECORDPROC proc, IntPtr user);
Exemple #56
0
 private static extern int BASS_MusicLoadMemory([MarshalAs(UnmanagedType.Bool)] bool mem, byte[] memory,
                                                long offset, int length, BASSFlag flags, int freq);
Exemple #57
0
 public static extern int BASS_SampleCreate(int length, int freq, int chans, int max, BASSFlag flags);
Exemple #58
0
 private static extern int BASS_MusicLoadUnicode([MarshalAs(UnmanagedType.Bool)] bool mem,
                                                 [In, MarshalAs(UnmanagedType.LPWStr)] string file, long offset,
                                                 int length, BASSFlag flags, int freq);
Exemple #59
0
 public static int BASS_SampleLoad(string file, long offset, int length, int max, BASSFlag flags)
 {
     flags |= BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE;
     return BASS_SampleLoadUnicode(false, file, offset, length, max, flags);
 }
Exemple #60
0
 private static extern int BASS_PluginLoadUnicode([In, MarshalAs(UnmanagedType.LPWStr)] string file,
                                                  BASSFlag flags);