示例#1
0
    void OnDisable()
    {
        Debug.Log("BASS ERRROR CODE: " + Bass.BASS_ErrorGetCode().ToString());

        Bass.BASS_Stop();
        Bass.BASS_Free();
    }
示例#2
0
        public void Dispose()
        {
            if (_disposedMixerStream)
            {
                return;
            }

            lock (this)
            {
                _disposedMixerStream = true;

                Log.Debug("BASS: Disposing Mixer Stream");

                try
                {
                    if (!Bass.BASS_StreamFree(_mixer))
                    {
                        Log.Error("BASS: Error freeing mixer: {0}", Bass.BASS_ErrorGetCode());
                    }
                    _mixer = 0;
                }
                catch (Exception ex)
                {
                    Log.Error("BASS: Exception disposing mixer - {0}. {1}", ex.Message, ex.StackTrace);
                }
            }
        }
示例#3
0
        static void Main()
        {
            //passing a path argument sets the working directory of the exe to that file's directory; bypass it
            Directory.SetCurrentDirectory(Application.ExecutablePath.Replace(Path.GetFileName(Application.ExecutablePath), ""));

            if (!File.Exists("bass.dll"))
            {
                MessageBox.Show("bass.dll not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Properties.Settings.Default.RegEmail == "" || Properties.Settings.Default.RegCode == "")
            {
                MessageBox.Show("You haven't set your BASS.NET registration details. A splash screen will be shown.\nYou can set details in app.config.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            BassNet.Registration(Properties.Settings.Default.RegEmail, Properties.Settings.Default.RegCode);

            if (init())
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());

                Bass.BASS_Free();
            }
            else
            {
                MessageBox.Show("Init error: " + Bass.BASS_ErrorGetCode(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        /// <summary>
        /// Register the Fade out Event
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="fadeOutMS"></param>
        /// <returns></returns>
        private int RegisterCrossFadeEvent(int stream)
        {
            int    syncHandle     = 0;
            long   len            = Bass.BASS_ChannelGetLength(stream);          // length in bytes
            double totaltime      = Bass.BASS_ChannelBytes2Seconds(stream, len); // the total time length
            double fadeOutSeconds = 0;

            if (Config.CrossFadeIntervalMs > 0)
            {
                fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            }

            long bytePos = Bass.BASS_ChannelSeconds2Bytes(stream, totaltime - fadeOutSeconds);

            syncHandle = Bass.BASS_ChannelSetSync(stream,
                                                  BASSSync.BASS_SYNC_POS,
                                                  bytePos, _playbackCrossFadeProcDelegate,
                                                  IntPtr.Zero);

            if (syncHandle == 0)
            {
                Log.Debug("BASS: RegisterCrossFadeEvent of stream {0} failed with error {1}", stream,
                          Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
            }
            return(syncHandle);
        }
    public override bool Play(float playPoint = 0, bool restart = false)
    {
        base.Play(playPoint, restart);

        int channel = Bass.BASS_SampleGetChannel(audioHandle, false);

        bool isPlaying = Bass.BASS_ChannelIsActive(channel) != BASSActive.BASS_ACTIVE_STOPPED && Bass.BASS_ChannelIsActive(channel) != BASSActive.BASS_ACTIVE_PAUSED;

        if (onlyPlayIfStopped && isPlaying)
        {
            return(false);
        }

        if (channel != 0)
        {
            Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_VOL, volume);
            Bass.BASS_ChannelSetAttribute(channel, BASSAttribute.BASS_ATTRIB_PAN, pan);

            Bass.BASS_ChannelPlay(channel, restart);
            return(true);
        }
        else
        {
            UnityEngine.Debug.LogError("Error when playing sample stream: " + Bass.BASS_ErrorGetCode() + ", " + audioHandle);
        }

        return(false);
    }
示例#6
0
        private void buttonStreamCreate_Click(object sender, System.EventArgs e)
        {
            Bass.BASS_StreamFree(_stream);
            this.textBox1.Text = "";

            // test BASS_StreamCreate
            if (_fileName != String.Empty)
            {
                // open any file supported by BASS...
                _fs = File.OpenRead(_fileName);
                this.textBox1.Text += "Open file: " + _fs.Name + Environment.NewLine;

                // create the stream
                _stream             = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero);
                this.textBox1.Text += "StreamCreateUser: "******"ChannelPlay: playing" + Environment.NewLine;
                }
                else
                {
                    this.textBox1.Text += String.Format("Error: {0}\n", Bass.BASS_ErrorGetCode());
                }
            }
        }
示例#7
0
        public override int Decode(ref byte[] Dest, long offset)
        {
            #region [ decode ]
            int    LEN  = 65536;
            byte[] data = new byte[LEN];             // 2 x 16-bit and length in is bytes
            int    len  = 0;
            long   p    = 0;
            do
            {
                len = Bass.BASS_ChannelGetData(stream_in, data, LEN);
                if (len < 0)
                {
                    BASSError be = Bass.BASS_ErrorGetCode();
                    Trace.TraceInformation("Cmp3: BASS_ChannelGetData Error: " + be.ToString());
                }
                Array.Copy(data, 0, Dest, p, len);
                p += len;
            } while (p < nTotalPCMSize);
            #endregion

//SaveWav(filename, Dest);

            data = null;
            return(0);
        }
示例#8
0
文件: BassLib.cs 项目: tynidev/BPM
        public void GetBassErrorTrow(string msg)
        {
            var err = Bass.BASS_ErrorGetCode();

            //BassException e = new BassException(err, msg);
            Console.WriteLine(err.ToString() + " " + msg);
        }
示例#9
0
        public static void RegisterBASS()
        {
            if (!bassRegistered)
            {
                BassNet.Registration(StringUtil.Convert(StringUtil.Seq1), StringUtil.Convert(StringUtil.Seq2));
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

                plugInRefs = new List <int>();
                plugInRefs.Add(Bass.BASS_PluginLoad("basswma.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bassflac.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bass_aac.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bass_alac.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bass_mpc.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("basswv.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bass_ac3.dll"));
                plugInRefs.Add(Bass.BASS_PluginLoad("bass_ape.dll"));

                userAgentPtr = Marshal.StringToHGlobalAnsi(userAgent);
                Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, userAgentPtr);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF, 0); // so that we can display the buffering%
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 1);

                if (Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_WMA_PREBUF, 0) == false)
                {
                    Console.WriteLine("ERROR: " + Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                }

                bassRegistered = true;
            }
        }
示例#10
0
        public static void Encode(string file)
        {
            if (File.Exists(file))
            {
                var encoderLAME = new EncoderLAME(0)
                {
                    LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_192,
                    LAME_Mode    = EncoderLAME.LAMEMode.Default,
                    LAME_Quality = EncoderLAME.LAMEQuality.Quality
                };

                var resp = BaseEncoder.EncodeFile(
                    inputFile: file,
                    outputFile: file + "_small.mp3",
                    encoder: encoderLAME,
                    proc: null,
                    overwriteOutput: true,
                    deleteInput: false,
                    updateTags: false,
                    fromPos: 5.0f,
                    toPos: 10.0f
                    );
                var e = Bass.BASS_ErrorGetCode();
                Console.WriteLine(resp);
                Console.WriteLine(e);
            }
        }
        public void PreLoad(byte[] data)
        {
            if (data == null)
            {
                return;
            }
            this.UnLoad();

            try
            {
                IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
                hStream = Bass.BASS_StreamCreateFile(pData, 0, data.Length, BASSFlag.BASS_DEFAULT);
            }
            catch
            {
                hStream = 0;
            }

            if (hStream != 0)
            {
                this.Volume = this.Volume;//调节音量到设定值
                this.Loop   = this.Loop;
                this.data   = data;
                if (this.autoPlay)
                {
                    this.Play();
                }
            }
            else
            {
                var lastErr = Bass.BASS_ErrorGetCode();
            }
        }
示例#12
0
 public BassHelper(int deviceId, int rate, BASSInit bassInit, IntPtr intPtr)
 {
     if (!Bass.BASS_Init(deviceId, rate, bassInit, intPtr))
     {
         throw new ApplicationException(" Bass初始化出错! " + Bass.BASS_ErrorGetCode().ToString());
     }
 }
示例#13
0
        public override int Decode(int nHandle, IntPtr pDest, uint szDestSize, int bLoop)
        {
            var ms_out = new MemoryStream();
            var bw_out = new BinaryWriter(ms_out);

            #region [ decode ]
            int    LEN  = 65536;
            byte[] data = new byte[LEN];             // 2 x 16-bit and length in is bytes
            int    len  = 0;
            do
            {
                len = Bass.BASS_ChannelGetData(stream_in, data, LEN);
                if (len < 0)
                {
                    BASSError be = Bass.BASS_ErrorGetCode();
                    Trace.TraceInformation("Cmp3: BASS_ChannelGetData Error: " + be.ToString());
                }
                bw_out.Write(data, 0, len);
            } while (len == LEN);
            #endregion

            wavdata = ms_out.ToArray();

            bw_out.Dispose(); bw_out = null;
            ms_out.Dispose(); ms_out = null;

            Marshal.Copy(wavdata, 0, pDest, wavdata.Length);

//SaveWav(filename);

            return(0);
        }
示例#14
0
        /// <summary>
        /// Recode the file
        /// </summary>
        /// <param name="fileName">Initial file</param>
        /// <param name="outFileName">Target file</param>
        /// <param name="targetSampleRate">Target sample rate</param>
        public void RecodeTheFile(string fileName, string outFileName, int targetSampleRate)
        {
            int      stream = Bass.BASS_StreamCreateFile(fileName, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_FLOAT);
            TAG_INFO tags   = new TAG_INFO();

            BassTags.BASS_TAG_GetFromFile(stream, tags);
            int mixerStream = BassMix.BASS_Mixer_StreamCreate(targetSampleRate, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_FLOAT);

            if (BassMix.BASS_Mixer_StreamAddChannel(mixerStream, stream, BASSFlag.BASS_MIXER_FILTER))
            {
                WaveWriter waveWriter = new WaveWriter(outFileName, mixerStream, true);
                const int  length     = 5512 * 10 * 4;
                float[]    buffer     = new float[length];
                while (true)
                {
                    int bytesRead = Bass.BASS_ChannelGetData(mixerStream, buffer, length);
                    if (bytesRead == 0)
                    {
                        break;
                    }
                    waveWriter.Write(buffer, bytesRead);
                }
                waveWriter.Close();
            }
            else
            {
                throw new Exception(Bass.BASS_ErrorGetCode().ToString());
            }
        }
        public override void Play()
        {
            if ((Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PAUSED) || (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_STOPPED))
            {
                Bass.BASS_StreamFree(_stream);

                _stream = Bass.BASS_StreamCreateFile(_source, 0, 0, BASSFlag.BASS_DEFAULT);
                //_stream = Bass.BASS_StreamCreateFile(_source, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                if (_stream != 0)
                {
                    //костыли
                    Bass.BASS_ChannelGetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, ref vol);
                    //костыли
                    Volume = vol * 100F;
                    //костыли
                    Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, (float)_volume);
                    Bass.BASS_ChannelPlay(_stream, false); //2й параметр это луп (рестарт)
                    //   MessageBox.Show(vol.ToString());
                }
                else
                {
                    MessageBox.Show("Error= " + Bass.BASS_ErrorGetCode().ToString());
                }
            }
            else
            {
                Bass.BASS_ChannelPlay(_stream, false);
            }

            //       MessageBox.Show(Duration.ToString());
//
            // Position = TimeSpan.Parse("00:01:00");// 40000;
        }
示例#16
0
        /// <summary>
        /// Play the MP3 song stored in the buffer lameEncodedBytes
        /// </summary>
        /// <param name="buffer"></param>
        private void PlayByteBlog(byte[] buffer)
        {
            if (_blogStreamHandle == 0 || Bass.BASS_ChannelIsActive(_blogStreamHandle) != BASSActive.BASS_ACTIVE_PLAYING)
            {
                // create a handle to the buffer and pin it, so that the Garbage Collector will not remove it
                GCHandle hGC = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                // create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
                _blogStreamHandle = Bass.BASS_StreamCreateFile(hGC.AddrOfPinnedObject(), 0, buffer.Length, BASSFlag.BASS_DEFAULT);

                //...let it play...

                if (buffer != null && buffer.Length > 0)
                {
                    if (_blogStreamHandle != 0 && Bass.BASS_ChannelPlay(_blogStreamHandle, false))
                    {
                        Msg("Lame MP3 playback started");
                        Msg("MP3 has " + lameEncodedBytes.Length + " bytes");
                    }
                    else
                    {
                        BASSError error = Bass.BASS_ErrorGetCode();
                        Msg(Enum.GetName(typeof(BASSError), error));
                    }
                }
                hGC.Free();
            }
            else
            {
                Msg("Mp3 data is still playing");
            }
        }
示例#17
0
        private void buttonStreamCreateUser_Click(object sender, System.EventArgs e)
        {
            Bass.BASS_StreamFree(_stream);
            this.textBox1.Text = "";

            // test BASS_StreamCreateUser
            if (_fileName != String.Empty)
            {
                // open the file...
                _fs = File.OpenRead(_fileName);
                this.textBox1.Text += "Open file: " + _fs.Name + Environment.NewLine;

                // create the stream
                // Note: The BASS_STREAM_PRESCAN flag is only used to demo what is happening when set.
                //       As it generates a lot of output at the beginning you might remove it.
                _stream             = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_AUTOFREE, _myStreamCreateUser, IntPtr.Zero);
                this.textBox1.Text += "StreamCreate: " + _stream.ToString() + Environment.NewLine;
                // play the stream
                if (_stream != 0 && Bass.BASS_ChannelPlay(_stream, false))
                {
                    this.textBox1.Text += "ChannelPlay: playing" + Environment.NewLine;
                }
                else
                {
                    this.textBox1.Text += String.Format("Error: {0}\n", Bass.BASS_ErrorGetCode());
                }
            }
        }
示例#18
0
        static void Main(string[] args)
        {
            // init BASS using the default output device
            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                // create a stream channel from a file
                int stream = Bass.BASS_StreamCreateFile("test.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);
                if (stream != 0)
                {
                    // play the channel
                    Bass.BASS_ChannelPlay(stream, false);
                }
                else
                {
                    // error
                    Console.WriteLine("Stream error: {0}", Bass.BASS_ErrorGetCode());
                }

                // wait for a key
                Console.WriteLine("Press any key to exit");
                Console.ReadKey(false);

                // free the stream
                Bass.BASS_StreamFree(stream);
                // free BASS
                Bass.BASS_Free();
            }
        }
示例#19
0
        public override int Open(string filename)
        {
            bool r = Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            stream_in = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_DECODE);
            // BASS_DEFAULT: output 32bit (16bit stereo)
            if (stream_in == 0)
            {
                BASSError be = Bass.BASS_ErrorGetCode();
                Trace.TraceInformation("Cmp3ogg: StreamCreateFile error: " + be.ToString());
            }
            nTotalPCMSize = Bass.BASS_ChannelGetLength(stream_in);

            #region [ Getting WAVEFORMEX info ]
            var chinfo = Bass.BASS_ChannelGetInfo(stream_in);
            wfx = new CWin32.WAVEFORMATEX(
                (ushort)1,                                              // wFormatTag
                (ushort)chinfo.chans,                                   // nChannels
                (uint)chinfo.freq,                                      // nSamplesPerSec
                (uint)(chinfo.freq * 2 * chinfo.chans),                 // nAvgBytesPerSec
                (ushort)(2 * chinfo.chans),                             // nBlockAlign
                16,                                                     // wBitsPerSample
                0                                                       // cbSize
                );
            #endregion

            //string fn = Path.GetFileName(filename);
            //Trace.TraceInformation("filename=" + fn + ", size=(decode): " + wavdata.Length + ", channelgetlength=" + _TotalPCMSize2 + ", " + _TotalPCMSize) ;

            return(0);
        }
示例#20
0
        public unsafe int Read(float[] buffer, int offset, int count)
        {
            lock (Lock)
            {
                fixed(float *buff = buffer)
                {
                    var obuff = buff + offset;
                    int ret   = Bass.BASS_ChannelGetData(Handle, (IntPtr)obuff, (count * 4) | (int)BASSData.BASS_DATA_FLOAT);

                    if (ret == 0)
                    {
                        BASSError BE = Bass.BASS_ErrorGetCode();
                        if (BE != BASSError.BASS_ERROR_ENDED)
                        {
                            Debug.ShowMsgBox(
                                "Data parsing error",
                                "An error has occured while parsing the audio data from the BASS stream.",
                                null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        Debug.PrintToConsole("wrn", BE.ToString());
                    }

                    return(ret / 4);
                }
            }
        }
示例#21
0
        /// <summary>
        /// Creates audio stream.
        /// Locks file.
        /// </summary>
        public void CreateStream()
        {
            if (!(State == ReadyState.Started || State == ReadyState.ClosedStream))
            {
                throw new InvalidOperationException("Not ready.");
            }

            // Create stream.
            stream = Bass.BASS_StreamCreateFile(filePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
            if (stream == 0)
            {
                throw new Exception(Bass.BASS_ErrorGetCode().ToString());
            }

            // Set number of frames.
            long trackLengthInBytes = Bass.BASS_ChannelGetLength(stream);
            long frameLengthInBytes = Bass.BASS_ChannelSeconds2Bytes(stream, 0.01d);

            NumFrames = (int)Math.Round(1f * trackLengthInBytes / frameLengthInBytes);
#if DEBUG
            Console.WriteLine(stream);
            BASS_CHANNELINFO info = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(stream, info);
            Console.WriteLine(info.ToString());
            Console.WriteLine($"track length in bytes from waveformgenerator.cs: {trackLengthInBytes}");
            Console.WriteLine($"how many bytes in 20 ms from waveformgenerator.cs: {frameLengthInBytes}");
            Console.WriteLine($"NumFrames: {NumFrames}");
#endif

            // Change state.
            State = ReadyState.CreatedStream;
        }
示例#22
0
        public BASSMIDI(WaveFormat WF)
        {
            lock (Lock)
            {
                WaveFormat = WF;
                InitializeSettings();

                Handle = BassMidi.BASS_MIDI_StreamCreate(16, Flags, WaveFormat.SampleRate);
                if (!CheckError(Handle, "Unable to create stream."))
                {
                    ErroredOut = true;
                    return;
                }
                if (Handle == 0)
                {
                    BASSError ERR = Bass.BASS_ErrorGetCode();

                    Debug.ShowMsgBox(
                        "BASSMIDI error",
                        String.Format("Unable to create stream.\n\nError encountered: {0}", ERR),
                        null, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    ErroredOut = true;
                    return;
                }
                Debug.PrintToConsole("ok", String.Format("{0} - Stream is open.", UniqueID));

                Int32 Tracks = BassMidi.BASS_MIDI_StreamGetTrackCount(Handle);
                Debug.PrintToConsole("ok", String.Format("{0} - Total tracks = {1}", UniqueID, Tracks));

                SetSoundFonts();
            }
        }
示例#23
0
 public bool Enable(int deviceIndex)
 {
     if (!_enabled)
     {
         if (!_initialized)
         {
             bool result = BassWasapi.BASS_WASAPI_Init(deviceIndex, 0, 0,
                                                       BASSWASAPIInit.BASS_WASAPI_BUFFER,
                                                       1f, 0.05f,
                                                       _process, IntPtr.Zero);
             if (!result)
             {
                 var error = Bass.BASS_ErrorGetCode();
                 Console.WriteLine(error.ToString());
                 return(false);
             }
             else
             {
                 _initialized = true;
             }
         }
         BassWasapi.BASS_WASAPI_Start();
     }
     else
     {
         return(false);
     }
     System.Threading.Thread.Sleep(500);
     _t.IsEnabled = true;
     return(true);
 }
示例#24
0
        public DirectXOutputDevice(Controller controller)
            : base(controller)
        {
            _streamWriteProcDelegate = OutputStreamWriteProc;
            _deviceNo = GetDeviceNo();

            // TODO: move to SetStream?
            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().DirectSoundBufferSizeMilliSecs);

            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");
            }
        }
示例#25
0
        /// <summary>
        /// Attach a stream to the Mixer
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public bool AttachStream(MusicStream stream)
        {
            Bass.BASS_ChannelLock(_mixer, true);

            // Set SynyPos at end of stream
            SetSyncPos(stream, 0.0);

            bool result = BassMix.BASS_Mixer_StreamAddChannel(_mixer, stream.BassStream,
                                                              BASSFlag.BASS_MIXER_NORAMPIN | BASSFlag.BASS_MIXER_BUFFER |
                                                              BASSFlag.BASS_MIXER_MATRIX | BASSFlag.BASS_MIXER_DOWNMIX |
                                                              BASSFlag.BASS_STREAM_AUTOFREE);

            if (!result)
            {
                Log.Error("BASS: Error attaching stream to mixer. {0}", Bass.BASS_ErrorGetCode());
            }

            Bass.BASS_ChannelLock(_mixer, false);

            if (result && _mixingMatrix != null)
            {
                Log.Debug("BASS: Setting mixing matrix...");
                result = BassMix.BASS_Mixer_ChannelSetMatrix(stream.BassStream, _mixingMatrix);
                if (!result)
                {
                    Log.Error("BASS: Error attaching Mixing Matrix. {0}", Bass.BASS_ErrorGetCode());
                }
            }

            return(result);
        }
示例#26
0
        public void StartMusic(string title)
        {
            UnityEngine.Debug.Log("Start " + title);

            if (!_IsEnabled)
            {
                return;
            }

            UnityEngine.Debug.Log("Engine is started");

            if (_CurrentStream != 0)
            {
                Bass.BASS_ChannelStop(_CurrentStream);
                _CurrentStream = 0;
            }

            int stream = Bass.BASS_StreamCreateFile(title, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT);

            if (stream != 0)
            {
                UnityEngine.Debug.Log("Start streaming");
                Bass.BASS_ChannelPlay(stream, false);
                _CurrentStream = stream;
                long len = Bass.BASS_ChannelGetLength(_CurrentStream, BASSMode.BASS_POS_BYTES);
                _CurrentStreamTime = Bass.BASS_ChannelBytes2Seconds(_CurrentStream, len);
                _CurrentTime       = 0.0d;
            }
            else
            {
                UnityEngine.Debug.Log("Cannot start music " + Bass.BASS_ErrorGetCode());
                Bass.BASS_ChannelStop(_CurrentStream);
                _CurrentStream = 0;
            }
        }
示例#27
0
        public bool StartDevice(int deviceIndex)
        {
            var result2 = false;
            var result  = false;

            if (!_initialized)
            {
                devindex = deviceIndex;

                result2 = Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                if (!result2)
                {
                    var error = Bass.BASS_ErrorGetCode();
                    //MessageBox.Show(error.ToString());
                }
                result = BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero);
                if (!result)
                {
                    var error = Bass.BASS_ErrorGetCode();
                    //MessageBox.Show(error.ToString());
                }
                if (result && result2)
                {
                    _initialized = true;
                    var started = BassWasapi.BASS_WASAPI_Start();
                    timer.IsEnabled = true;
                }
            }

            return(result && result2);
        }
        public LabirintoEletronico()
        {
            InitializeComponent();

            txtbSentidoDescricao.Visibility = Visibility.Collapsed;
            txtbSentido.Visibility          = Visibility.Collapsed;
            recImagemDisp.Visibility        = Visibility.Collapsed;
            txtbTempo.Visibility            = Visibility.Collapsed;
            txtbToques.Visibility           = Visibility.Collapsed;
            txtbPosicao.Visibility          = Visibility.Collapsed;

            dTmr          = new DispatcherTimer();
            dTmr.Interval = TimeSpan.FromMilliseconds(10);
            dTmr.Tick    += dTmr_Tick;

            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                streamBeep = Bass.BASS_StreamCreateFile("Beep.wav", 0, 0, BASSFlag.BASS_DEFAULT);
            }
            else
            {
                MessageBox.Show(Bass.BASS_ErrorGetCode().ToString());
            }

            IniciaJoystick();

            LeArquivoRecords();
        }
示例#29
0
 public static AudioFX loadFromFile(String path, bool sfx)
 {
     initBass();
     try
     {
         if (Loaded[path] != null && !sfx)
         {
             return(Loaded[path]);
         }
     }
     catch (Exception)
     { //just means wasn't in dict yet
     }
     if (File.Exists(path))
     {
         //int h = Bass.BASS_StreamCreateFile(path, 0L, 0, BASSFlag.BASS_DEFAULT);
         int h = Bass.BASS_StreamCreateFile(path, 0L, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
         h = BassFx.BASS_FX_TempoCreate(h, BASSFlag.BASS_MUSIC_PRESCAN);
         //Bass.BASS_ChannelSetAttribute(h, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, frequency);
         if (h == 0)
         {
             Console.WriteLine(Bass.BASS_ErrorGetCode());
         }
         AudioFX fx = new AudioFX(h, path, sfx);
         if (!sfx)
         {
             Loaded.Add(path, fx);
         }
         return(fx);
     }
     Console.WriteLine("Could not find " + path);
     return(new AudioFX()); //so game doesnt get nullpointerexceptions, no audio plays though
 }
示例#30
0
        public void LoadMusic(string musicPath)
        {
            //释放之前的
            Stop();
            Bass.BASS_StreamFree(CurrentMusicHandle);

            switch (MusicHelper.GetMusicType(musicPath))
            {
            case MusicHelper.MusicType.MOD:
                //MOD音乐获取长度要求在BASS_MusicLoad(String,Int64,Int32,BASSFlag,Int32)调用中使用BASS_MUSIC_PRESCAN标志
                //BASS_MusicLoad 用来加载MOD音乐文件-MO3 / IT / XM / S3M / MTM / MOD / UMX格式。
                //方法说明:文件路径   偏移   数据长度 0使用所有数据
                CurrentMusicHandle = Bass.BASS_MusicLoad(musicPath, 0L, 0, BASSFlag.BASS_MUSIC_PRESCAN, 0);
                break;

            case MusicHelper.MusicType.Stream:
                //BASS_StreamCreateFile 用来加载MP3,MP2,MP1,OGG,WAV,AIFF或插件支持的文件创建示例流
                CurrentMusicHandle = Bass.BASS_StreamCreateFile(musicPath, 0L, 0, BASSFlag.BASS_DEFAULT);
                break;

            case MusicHelper.MusicType.None:
                Debug.LogError("check file");
                return;
            }
            Play();
            BASS_CHANNELINFO info      = Bass.BASS_ChannelGetInfo(CurrentMusicHandle);
            BASSError        bASSError = Bass.BASS_ErrorGetCode();

            Debug.Log($"Load Music Success!!! \ncurrentMusicHandle:{CurrentMusicHandle}\nTotletime(s):{GetMusicTotleTime()}\nInfo:{info.ToString()}\nerror:{bASSError}\n\n");
        }