Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Un4seen.Bass.BassNet.Registration("*****@*****.**", "2X113281839322");
            Un4seen.Bass.BassNet.OmitCheckVersion = true;
            bool bassinit = Un4seen.Bass.Bass.BASS_Init(0, sampleRate, Un4seen.Bass.BASSInit.BASS_DEVICE_DEFAULT, System.IntPtr.Zero);

            if (bassinit)
            {
                streamCreate = new STREAMPROC(WaveformProc);
                channel      = Bass.BASS_StreamCreate(sampleRate, 2, BASSFlag.BASS_DEFAULT, streamCreate, IntPtr.Zero);
                if (channel != 0)
                {
                    bufferLength = Bass.BASS_ChannelSeconds2Bytes(channel, (double)Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_BUFFER) / 1000d);
                    data         = new short[bufferLength];

                    playSine();
                }
                else
                {
                    Un4seen.Bass.BASSError error = Un4seen.Bass.Bass.BASS_ErrorGetCode();
                    Console.WriteLine(error.ToString());
                }
            }
            else
            {
                Console.WriteLine("FAIL");
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public void Play(List <string> albumTracksUrls)
        {
            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                int stream1 = Bass.BASS_StreamCreateURL(albumTracksUrls[0], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);
                int stream2 = Bass.BASS_StreamCreateURL(albumTracksUrls[1], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);
                int stream3 = Bass.BASS_StreamCreateURL(albumTracksUrls[2], 0, BASSFlag.BASS_SAMPLE_MONO, null, IntPtr.Zero);

                Bass.BASS_ChannelSetPosition(stream1, Bass.BASS_ChannelSeconds2Bytes(stream1, 0.01), BASSMode.BASS_POS_BYTES);
                Bass.BASS_ChannelSlideAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream1, false);
                VolumeUpSlow(stream1);
                Bass.BASS_ChannelSlideAttribute(stream1, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Thread.Sleep(2500);
                Bass.BASS_ChannelSetPosition(stream2, Bass.BASS_ChannelSeconds2Bytes(stream2, 0.5), BASSMode.BASS_POS_BYTES);
                Bass.BASS_ChannelSlideAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream2, false);
                Bass.BASS_StreamFree(stream1);
                VolumeUpSlow(stream2);
                Thread.Sleep(3000);
                Bass.BASS_ChannelSlideAttribute(stream2, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Bass.BASS_ChannelSlideAttribute(stream3, BASSAttribute.BASS_ATTRIB_VOL, 0, 0);
                Bass.BASS_ChannelPlay(stream3, false);
                VolumeUpSlow(stream3);
                Bass.BASS_StreamFree(stream2);
                Thread.Sleep(5000);
                Bass.BASS_ChannelSlideAttribute(stream3, BASSAttribute.BASS_ATTRIB_VOL, 0, 3000);//volume down
                Thread.Sleep(3000);
                Bass.BASS_StreamFree(stream3);
                // free BASS
                Bass.BASS_Free();
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets a SyncPos on the mixer stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timePos"></param>
        public void SetSyncPos(MusicStream stream, double timePos)
        {
            double fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            double totalStreamLen = Bass.BASS_ChannelBytes2Seconds(stream.BassStream, Bass.BASS_ChannelGetLength(stream.BassStream, BASSMode.BASS_POS_BYTES));
            long   mixerPos       = Bass.BASS_ChannelGetPosition(_mixer, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
            long   syncPos        = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixer, totalStreamLen - timePos - fadeOutSeconds);

            if (_syncProc != 0)
            {
                Bass.BASS_ChannelRemoveSync(_mixer, _syncProc);
            }

            // We might have stored the pinned object already, because we are skipping
            // Only store object it, when it doesn't exist
            if (!_pinnedObjects.ContainsKey(stream.BassStream))
            {
                Log.Debug("BASS: Updating Dictionary for GCHandle for stream {0}", stream.BassStream);
                // Add the pinned object to the global dictionary, so that we can free it later in the Sync End Proc
                _pinnedObjects.Add(stream.BassStream, GCHandle.Alloc(stream));
            }

            _syncProc = Bass.BASS_ChannelSetSync(_mixer,
                                                 BASSSync.BASS_SYNC_ONETIME | BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
                                                 syncPos, _playbackEndProcDelegate,
                                                 new IntPtr(stream.BassStream));
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
 // Token: 0x060000B5 RID: 181 RVA: 0x0001A734 File Offset: 0x00018934
 public void method_36(float float_1)
 {
     if (!this.isSongLoaded)
     {
         return;
     }
     this.PauseSong();
     if (float_1 < 0f)
     {
         float_1 = 0f;
     }
     if ((double)float_1 > this.double_1)
     {
         this.bool_2 = true;
         return;
     }
     this.bool_2 = false;
     for (int i = 0; i < this.stemChannels.Length; i++)
     {
         if (this.stemChannels[i] != 0)
         {
             long num = Bass.BASS_ChannelGetLength(this.stemChannels[i]);
             if (Bass.BASS_ChannelSeconds2Bytes(this.stemChannels[i], (double)float_1) < num)
             {
                 Bass.BASS_ChannelSetPosition(this.stemChannels[i], (double)float_1);
             }
         }
     }
 }
Ejemplo n.º 7
0
        private void buttonSetEnvelope_Click(object sender, EventArgs e)
        {
            if (_currentTrack.Channel != 0)
            {
                BASS_MIXER_NODE[] nodes =
                {
                    new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 10d), 1f),
                    new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 13d), 0f),
                    new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 17d), 0f),
                    new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(_mixer, 20d), 1f)
                };
                BassMix.BASS_Mixer_ChannelSetEnvelope(_currentTrack.Channel, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes);
                // already align the envelope position to the current playback position
                // pause mixer
                Bass.BASS_ChannelLock(_mixer, true);
                long pos = BassMix.BASS_Mixer_ChannelGetPosition(_currentTrack.Channel);
                // convert source pos to mixer pos
                long envPos = Bass.BASS_ChannelSeconds2Bytes(_mixer, Bass.BASS_ChannelBytes2Seconds(_currentTrack.Channel, pos));
                BassMix.BASS_Mixer_ChannelSetEnvelopePos(_currentTrack.Channel, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, envPos);
                // resume mixer
                Bass.BASS_ChannelLock(_mixer, false);

                // and show it in our waveform
                _WF.DrawVolume = WaveForm.VOLUMEDRAWTYPE.Solid;
                foreach (BASS_MIXER_NODE node in nodes)
                {
                    _WF.AddVolumePoint(node.pos, node.val);
                }
                DrawWave();
            }
        }
Ejemplo n.º 8
0
        public void SetPosition(int iPositionInSecond)
        {
            double pos = System.Convert.ToDouble(iPositionInSecond);

            this._positionInByte = Bass.BASS_ChannelSeconds2Bytes(this._stream, pos);
            Bass.BASS_ChannelSetPosition(this._stream, this._positionInByte);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 再生位置を変更する
 /// </summary>
 /// <param name="ms"></param>
 public void setPosition(uint ms)
 {
     if (sound[PlayerController.MainChannel] != 0)
     {
         long position = Bass.BASS_ChannelSeconds2Bytes(sound[PlayerController.MainChannel], (double)((double)ms / 1000));
         Bass.BASS_ChannelSetPosition(sound[PlayerController.MainChannel], position);
     }
 }
Ejemplo n.º 10
0
 void MixTrack(int pMixer, Track pTrack, Dictionary <AudioSample, int> pSamples)
 {
     foreach (Note n in pTrack.Notes)
     {
         //TODO: Maybe use another length instead of 0
         long start = Bass.BASS_ChannelSeconds2Bytes(pMixer, PositionOfNote(n));
         BassMix.BASS_Mixer_StreamAddChannelEx(pMixer, pSamples[n.Sample], 0, start, 0);
     }
 }
Ejemplo n.º 11
0
 private void setGain(int deck, float gain)
 {
     // annoying dsp code to write
     // each node is like a (value,time) pair
     BASS_MIXER_NODE[] nodes =
     {
         new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(deck, 0d), gain),
     };
     BassMix.BASS_Mixer_ChannelSetEnvelope(deck, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Sets the position of the player
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool SetPos(double value)
 {
     try {
         var sec = (value / 100) * SoundCloudCore.Tracks[Tracks[TrackIndex]].Duration.TotalSeconds;
         var pos = Bass.BASS_ChannelSeconds2Bytes(channel, sec);
         Bass.BASS_ChannelSetPosition(channel, pos);
         return(true);
     }
     catch { return(false); }
 }
Ejemplo n.º 13
0
        public void Run()
        {
            Logger.Info("Starting ...");
            Bass.BASS_ChannelSetPosition(_soundStream, Bass.BASS_ChannelSeconds2Bytes(_soundStream, 0.0), BASSMode.BASS_POS_BYTES);
            Bass.BASS_ChannelPlay(_soundStream, false);

            _stopwatch.Start();
            _globalTime.Start();

            RenderLoop.Run(_form, () => Update());
        }
Ejemplo n.º 14
0
        public void SetPosSeconds(int chan, double seconds)
        {
            long curPos = Bass.BASS_ChannelGetPosition(chan);
            long pos    = Bass.BASS_ChannelSeconds2Bytes(chan, seconds);



            if (!Bass.BASS_ChannelSetPosition(chan, pos, BASSMode.BASS_POS_BYTES))
            {
                GetBassErrorTrow("Could not seek to " + seconds);
            }
        }
Ejemplo n.º 15
0
 public bool Seek(double seconds)
 {
     if (State == ChannelStates.Playing || State == ChannelStates.Paused)
     {
         var bytes = Bass.BASS_ChannelSeconds2Bytes(Stream, seconds);
         return(Bass.BASS_ChannelSetPosition(Stream, bytes, BASSMode.BASS_POS_BYTE));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
        private void SetEnvelopePos(int source, long newPos)
        {
            // pause mixer
            Bass.BASS_ChannelLock(_mixer, true);
            BassMix.BASS_Mixer_ChannelSetPosition(source, newPos);
            // convert source pos to mixer pos
            long envPos = Bass.BASS_ChannelSeconds2Bytes(_mixer, Bass.BASS_ChannelBytes2Seconds(source, newPos));

            BassMix.BASS_Mixer_ChannelSetEnvelopePos(source, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, envPos);
            // resume mixer
            Bass.BASS_ChannelLock(_mixer, false);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Set the end position of a song inside a CUE file
        /// </summary>
        /// <param name="startPos"></param>
        /// <param name="endPos"></param>
        public void SetCueTrackEndPos(float startPos, float endPos)
        {
            if (_cueTrackEndEventHandler != 0)
            {
                Bass.BASS_ChannelRemoveSync(_stream, _cueTrackEndEventHandler);
            }

            Bass.BASS_ChannelSetPosition(_stream, Bass.BASS_ChannelSeconds2Bytes(_stream, startPos));
            if (endPos > startPos)
            {
                _cueTrackEndEventHandler = RegisterCueTrackEndEvent(Bass.BASS_ChannelSeconds2Bytes(_stream, endPos));
            }
        }
Ejemplo n.º 18
0
 public DSP_IIRDelay(int channel, int priority, float maxDelay) : base(channel, priority, IntPtr.Zero)
 {
     if (maxDelay > 60f)
     {
         maxDelay = 60f;
     }
     else if (maxDelay < 0.001f)
     {
         maxDelay = 0.001f;
     }
     this._maxDelay = maxDelay;
     this.MAX_DELAY = (int)(Bass.BASS_ChannelSeconds2Bytes(base.ChannelHandle, (double)maxDelay) / (long)(base.ChannelBitwidth / 8));
     this.buffer    = new double[this.MAX_DELAY];
 }
Ejemplo n.º 19
0
        //开始
        public void Start()
        {
            if (_fileName != String.Empty)
            {
                if (_stream != 0)
                {
                    playPause = false;
                    // used in RMS
                    _30mslength = (int)Bass.BASS_ChannelSeconds2Bytes(_stream, 0.03); // 30ms window                                                                                 // latency from milliseconds to bytes
                    _deviceLatencyBytes = (int)Bass.BASS_ChannelSeconds2Bytes(_stream, _deviceLatencyMS / 1000.0);

                    if (WF2 != null && WF2.IsRendered)
                    {
                        // make sure playback and wave form are in sync, since
                        // we rended with 16-bit but play here with 32-bit
                        WF2.SyncPlayback(_stream);

                        //long cuein = WF2.GetMarker("CUE");
                        long cueout = WF2.GetMarker("END");

                        //int cueinFrame = WF2.Position2Frames(cuein);
                        //int cueoutFrame = WF2.Position2Frames(cueout);
                        //Console.WriteLine("CueIn at {0}sec.; CueOut at {1}sec.", WF2.Frame2Seconds(cueinFrame), WF2.Frame2Seconds(cueoutFrame));

                        //if (cuein >= 0)
                        //{
                        //    Bass.BASS_ChannelSetPosition(_stream, cuein);
                        //}
                        if (cueout >= 0)
                        {
                            Bass.BASS_ChannelRemoveSync(_stream, _syncer);
                            _syncer = Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_POS, cueout, _sync, IntPtr.Zero);
                        }
                    }

                    if (_stream != 0 && Bass.BASS_ChannelPlay(_stream, false))
                    {
                        _updateTimer.Start();
                    }
                    else
                    {
                        Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
                    }

                }

            }
        }
Ejemplo n.º 20
0
        // calculates the level of a stereo signal between 0 and 65535
        // where 0 = silent, 32767 = 0dB and 65535 = +6dB
        private void GetLevel(int channel, out int peakL, out int peakR)
        {
            float maxL = 0f;
            float maxR = 0f;

            // length of a 20ms window in bytes
            int length20ms = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.02);
            // the number of 32-bit floats required (since length is in bytes!)
            int l4 = length20ms / 4; // 32-bit = 4 bytes

            // create a data buffer as needed
            float[] sampleData = new float[l4];

            int length = Bass.BASS_ChannelGetData(channel, sampleData, length20ms);

            // the number of 32-bit floats received
            // as less data might be returned by BASS_ChannelGetData as requested
            l4 = length / 4;

            for (int a = 0; a < l4; a++)
            {
                float absLevel = Math.Abs(sampleData[a]);

                // decide on L/R channel
                if (a % 2 == 0)
                {
                    // Left channel
                    if (absLevel > maxL)
                    {
                        maxL = absLevel;
                    }
                }
                else
                {
                    // Right channel
                    if (absLevel > maxR)
                    {
                        maxR = absLevel;
                    }
                }
            }

            // limit the maximum peak levels to +6bB = 65535 = 0xFFFF
            // the peak levels will be int values, where 32767 = 0dB
            // and a float value of 1.0 also represents 0db.
            peakL = (int)Math.Round(32767f * maxL) & 0xFFFF;
            peakR = (int)Math.Round(32767f * maxR) & 0xFFFF;
        }
Ejemplo n.º 21
0
 public void ReSync()
 {
     if (!base.IsAssigned)
     {
         return;
     }
     if (this._isOutputBuffered && this.TargetMixerStream != 0 && this.SourceMixerStream != 0)
     {
         Bass.BASS_ChannelLock(this.SourceMixerStream, true);
         int num = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
         if (num > 0)
         {
             num = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num));
             if (!this._isSourceMixerNonstop && this._isTargetMixerNonstop)
             {
                 this._streamCopyDelay = num;
                 BassMix.BASS_Mixer_ChannelSetPosition(this._streamCopy, 0L);
             }
             else if (!this._isTargetMixerNonstop)
             {
                 int num2 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                 num2 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num2));
                 if (num2 > num)
                 {
                     byte[] buffer = new byte[num2 - num];
                     Bass.BASS_StreamPutData(this._streamCopy, buffer, num2 - num);
                 }
             }
         }
         else if (this._isSourceMixerNonstop)
         {
             int num3 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
             num3 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num3));
             int num4 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, (double)this._outputLatency / 1000.0);
             if (num3 > num4)
             {
                 BassMix.BASS_Mixer_ChannelSetPosition(this._streamCopy, 0L);
                 byte[] buffer2 = new byte[num3 - num4];
                 Bass.BASS_StreamPutData(this._streamCopy, buffer2, num3 - num4);
             }
         }
         if (this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
         {
             Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
         }
         Bass.BASS_ChannelLock(this.SourceMixerStream, false);
     }
 }
Ejemplo n.º 22
0
        private int BassStreamProc(int handle, IntPtr buffer, int length, IntPtr user)
        {
            if (base.IsBypassed)
            {
                return(0);
            }
            DSP_BufferStream obj;

            if (this.OutputHandle != 0)
            {
                int num = Bass.BASS_ChannelGetData(this.OutputHandle, IntPtr.Zero, 0);
                num = (int)Bass.BASS_ChannelSeconds2Bytes(handle, Bass.BASS_ChannelBytes2Seconds(this.OutputHandle, (long)num));
                if (num > this._bufferLength)
                {
                    num = this._bufferLength;
                }
                else if (num < 0)
                {
                    num = 0;
                }
                if (length > num)
                {
                    length = num;
                }
                obj = this;
                lock (obj)
                {
                    Marshal.Copy(this._buffer, this._bufferLength - num, buffer, length);
                    return(length);
                }
            }
            if (this._lastPos + length > this._bufferLength)
            {
                length = this._bufferLength - this._lastPos;
            }
            obj = this;
            lock (obj)
            {
                Marshal.Copy(this._buffer, this._lastPos, buffer, length);
                this._lastPos += length;
                if (this._lastPos > this._bufferLength)
                {
                    this._lastPos = this._bufferLength;
                }
            }
            return(length);
        }
Ejemplo n.º 23
0
        public static bool BASSPlayBackEngineRT(Double[] CustomFramerates, ref Int64 pos, ref Int64 es)
        {
            double fpssim = MainWindow.FPSSimulator.NextDouble() * (CustomFramerates[0] - CustomFramerates[1]) + CustomFramerates[1];
            int    length = Convert.ToInt32(Bass.BASS_ChannelSeconds2Bytes(MainWindow.KMCGlobals._recHandle, fpssim));

            byte[] buffer = new byte[length];

            for (int i = 0; i <= 15; i++)
            {
                BassMidi.BASS_MIDI_StreamEvent(MainWindow.KMCGlobals._recHandle, i, BASSMIDIEvent.MIDI_EVENT_MIXLEVEL, MainWindow.KMCStatus.ChannelsVolume[i]);
            }

            while (es < MainWindow.KMCGlobals.eventc && MainWindow.KMCGlobals.events[es].pos < pos + length)
            {
                BassMidi.BASS_MIDI_StreamEvent(MainWindow.KMCGlobals._recHandle, MainWindow.KMCGlobals.events[es].chan, MainWindow.KMCGlobals.events[es].eventtype, MainWindow.KMCGlobals.events[es].param);
                es++;
            }

            if (MainWindow.VSTs.VSTInfo[0].isInstrument)
            {
                Bass.BASS_ChannelGetData(MainWindow.VSTs._VSTiHandle, buffer, length);
            }
            int got = Bass.BASS_ChannelGetData(MainWindow.KMCGlobals._recHandle, buffer, length);

            if (got < 0)
            {
                MainWindow.KMCGlobals.CancellationPendingValue = MainWindow.KMCConstants.CONVERSION_ENDED;
                return(false);
            }

            pos += got;
            if (es == MainWindow.KMCGlobals.eventc)
            {
                BassMidi.BASS_MIDI_StreamEvent(MainWindow.KMCGlobals._recHandle, 0, BASSMIDIEvent.MIDI_EVENT_END, 0);
            }

            float fpsstring = 1 / (float)fpssim;

            IntPtr UnmanagedBuffer = Marshal.AllocHGlobal(buffer.Length);

            Marshal.Copy(buffer, 0, UnmanagedBuffer, buffer.Length);
            BassWasapi.BASS_WASAPI_PutData(UnmanagedBuffer, length);
            Marshal.FreeHGlobal(UnmanagedBuffer);

            return(true);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Create a Fingerprint and lookup the Recordings
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private async Task <List <Recording> > GetRecordings(string file)
        {
            var stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE);
            var chInfo = Bass.BASS_ChannelGetInfo(stream);

            var bufLen = (int)Bass.BASS_ChannelSeconds2Bytes(stream, 120.0);
            var buf    = new short[bufLen];

            var chromaContext = new ChromaContext();

            chromaContext.Start(chInfo.freq, chInfo.chans);

            var length = Bass.BASS_ChannelGetData(stream, buf, bufLen);

            chromaContext.Feed(buf, length / 2);

            chromaContext.Finish();

            var fingerPrint = chromaContext.GetFingerprint();

            Configuration.ClientKey = "mfbgmu2P";
            var lookupSvc = new LookupService();

            var len  = Bass.BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTE);
            var time = Bass.BASS_ChannelBytes2Seconds(stream, len);

            Bass.BASS_StreamFree(stream);

            //var result = await lookupSvc.GetAsync(fingerPrint, Convert.ToInt32(time), new[] { "recordingids", "releases", "artists" });
            var trackIds = await lookupSvc.GetAsync(fingerPrint, Convert.ToInt32(time), new[] { "recordingids" });

            var recordings = new List <Recording>();

            foreach (var trackId in trackIds.Results)
            {
                foreach (var rec in trackId.Recordings)
                {
                    System.Threading.Thread.Sleep(400);
                    var recording = await Recording.GetAsync(rec.Id, new[] { "releases", "artists", "media", "discids" });

                    recordings.Add(recording);
                }
            }
            return(recordings);
        }
Ejemplo n.º 25
0
 public void StopFile(int handle, bool fadeOut, int fadeOutTime, bool isCrossFade)
 {
     if (!fadeOut || fadeOutTime == 0)
     {
         Bass.BASS_ChannelStop(handle); // no error handling, unimportant
         FileFinished(handle, true);
     }
     else
     {
         long pos           = Bass.BASS_ChannelGetPosition(handle);
         long length        = Bass.BASS_ChannelGetLength(handle);
         long remaining     = length - pos;
         long fadeOutLength = Bass.BASS_ChannelSeconds2Bytes(handle, 0.001 * fadeOutTime);
         if (fadeOutLength == -1)
         {
             // on error, just stop the file
             Bass.BASS_ChannelStop(handle);
             FileFinished(handle, true);
             return;
         }
         if (pos == -1 || length == -1 || remaining <= 0)
         {
             // web radio doesn't have a length
             remaining = fadeOutLength;
         }
         if (fadeOutLength > remaining)
         {
             fadeOutLength = remaining;
         }
         // if (Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_POS, pos + fadeOutLength, m_StopSync, new IntPtr(0)) == 0)
         if (Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_SLIDE | BASSSync.BASS_SYNC_ONETIME, 0, m_StopSync, new IntPtr(handle)) == 0)
         {
             // on error, just stop the file
             Bass.BASS_ChannelStop(handle);
             FileFinished(handle, true);
             return;
         }
         FadeOut(handle, fadeOutTime);
         if (isCrossFade)
         {
             // call finished immediately to start the next file
             FileFinished(handle, false);
         }
     }
 }
Ejemplo n.º 26
0
 private int BassStreamProc(int handle, IntPtr buffer, int length, IntPtr user)
 {
     if (base.IsBypassed)
     {
         return(0);
     }
     if (OutputHandle != 0)
     {
         int num = Bass.BASS_ChannelGetData(OutputHandle, IntPtr.Zero, 0);
         num =
             (int)
             Bass.BASS_ChannelSeconds2Bytes(handle, Bass.BASS_ChannelBytes2Seconds(OutputHandle, (long)num));
         if (num > _bufferLength)
         {
             num = _bufferLength;
         }
         else if (num < 0)
         {
             num = 0;
         }
         if (length > num)
         {
             length = num;
         }
         lock (this)
         {
             Marshal.Copy(_buffer, _bufferLength - num, buffer, length);
             return(length);
         }
     }
     if ((_lastPos + length) > _bufferLength)
     {
         length = _bufferLength - _lastPos;
     }
     lock (this)
     {
         Marshal.Copy(_buffer, _lastPos, buffer, length);
         _lastPos += length;
         if (_lastPos > _bufferLength)
         {
             _lastPos = _bufferLength;
         }
     }
     return(length);
 }
Ejemplo n.º 27
0
        private void Encode(string filename)
        {
            // Отключаем кнопки
            playButton.Enabled   = false;
            saveButton.Enabled   = false;
            selectButton.Enabled = false;

            encodeProgress.Visible = true;

            // Энкодим в мп3
            ThreadPool.QueueUserWorkItem(w =>
            {
                int encoder = BassEnc.BASS_Encode_Start(fxStream, "lame -b192 - \"" + filename + "\"", 0, null, IntPtr.Zero /*this.Handle*/);

                long i          = 0;
                long chanLenght = Bass.BASS_ChannelGetLength(fxStream);
                while (i < chanLenght - 1)
                {
                    // Так как буфер в 1сек, то и записываем по одной секунде данных в проход
                    Bass.BASS_ChannelSetPosition(fxStream, i, BASSMode.BASS_POS_BYTES);
                    long len = Bass.BASS_ChannelSeconds2Bytes(fxStream, 1);
                    Bass.BASS_ChannelUpdate(fxStream, 1000);

                    i += len;

                    this.Invoke((MethodInvoker) delegate
                    {
                        encodeProgress.Value = (int)(i * 100 / chanLenght);
                        debugInfo.Text       = Bass.BASS_ErrorGetCode().ToString() + "\n" + len + "\n" + i + "\n" + Bass.BASS_ChannelGetLength(fxStream);
                    });
                }

                // ехал инвок через инвок
                this.Invoke((MethodInvoker) delegate
                {
                    encodeProgress.Visible = false;

                    playButton.Enabled   = true;
                    saveButton.Enabled   = true;
                    selectButton.Enabled = true;
                });

                BassEnc.BASS_Encode_Stop(encoder);
            });
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Sets a SyncPos on the mixer stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timePos"></param>
        public void SetSyncPos(MusicStream stream, double timePos)
        {
            double fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            double totalStreamLen = Bass.BASS_ChannelBytes2Seconds(stream.BassStream, Bass.BASS_ChannelGetLength(stream.BassStream, BASSMode.BASS_POS_BYTES));
            long   mixerPos       = Bass.BASS_ChannelGetPosition(_mixer, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
            long   syncPos        = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixer, totalStreamLen - timePos - fadeOutSeconds);

            if (_syncProc != 0)
            {
                Bass.BASS_ChannelRemoveSync(_mixer, _syncProc);
            }

            GCHandle pFilePath = GCHandle.Alloc(stream);

            _syncProc = Bass.BASS_ChannelSetSync(_mixer,
                                                 BASSSync.BASS_SYNC_ONETIME | BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
                                                 syncPos, _playbackEndProcDelegate,
                                                 GCHandle.ToIntPtr(pFilePath));
        }
Ejemplo n.º 29
0
        public List <MusicBrainzTrack> GetMusicBrainzTrack(string fileName)
        {
            log.Debug("Identify: Creating Fingerprint");
            // Create a Decoding Channel
            int channel = Bass.BASS_StreamCreateFile(fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE);

            if (channel == 0)
            {
                return(null);
            }

            // Now get information about channel and retrieve length
            BASS_CHANNELINFO chinfo;

            chinfo = Bass.BASS_ChannelGetInfo(channel);


            // Get 135 Seconds of the file to be used for the fingerprint
            int sampleLength = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 135);

            byte[] samples = new byte[sampleLength];
            sampleLength = Bass.BASS_ChannelGetData(channel, samples, sampleLength);
            lengthInMS   = (int)Bass.BASS_ChannelBytes2Seconds(channel, Bass.BASS_ChannelGetLength(channel)) * 1000;
            Bass.BASS_StreamFree(channel);

            // Get Fingerprint
            puid = "";
            StringBuilder fp = new StringBuilder(758);

            if (NativeMethods.ofa_create_print(fp, samples, 0, sampleLength / 2, chinfo.freq, chinfo.chans == 2 ? true : false))
            {
                fingerprint = fp.ToString();
                puid        = GetPuid();
            }

            if (puid == "")
            {
                return(null);
            }

            return(RetrieveMusicBrainzTrack(puid));
        }
Ejemplo n.º 30
0
        private void ProcessDecompressedData()
        {
            if (mixerHandle != 0)
            {
                int bytesRead = 0;
                do
                {
                    int bufferSizeInBytes = (int)Bass.BASS_ChannelSeconds2Bytes(mixerHandle, 1.0);
                    if (inSecBuffer == null)
                    {
                        inSecBuffer = new float[bufferSizeInBytes / 4]; // we hebben floats
                        inSecPtr    = 0;
                    }
                    else
                    {
                        bufferSizeInBytes = (inSecBuffer.Length - inSecPtr) * 4;
                    }

                    float[] buffer = new float[bufferSizeInBytes / 4];
                    bytesRead = Bass.BASS_ChannelGetData(mixerHandle, buffer, bufferSizeInBytes | (int)BASSData.BASS_DATA_FLOAT);
                    if (bytesRead <= 0)
                    {
                        return;
                    }

                    // nu data naar insecbuffer kopieren
                    Buffer.BlockCopy(buffer, 0, inSecBuffer, inSecPtr * 4, bytesRead);
                    inSecPtr += (int)(bytesRead / 4);

                    if (inSecPtr >= inSecBuffer.Length)
                    {
                        if (OnStreamUpdate != null)
                        {
                            DoCallback(OnStreamUpdate, this, new StreamUpdateEventArgs(inSecBuffer));
                        }
                        inSecBuffer = null;
                        inSecPtr    = 0;
                    }
                } while (bytesRead > 0);
            } //if basshandle valid
        }