Ejemplo n.º 1
0
        /// <summary>
        /// Sets up a synchronizer on a MOD music, stream or recording channel.
        /// </summary>
        /// <param name="handle">The channel handle... a HMUSIC, HSTREAM or HRECORD. </param>
        /// <param name="type">The type of sync (see the table below). The following flags may also be used.
        /// BASS_SYNC_MIXTIME Call the sync function immediately when the sync is triggered, instead of delaying the call until the sync event is actually heard. This is automatic with some sync types (see table below), and always with decoding and recording channels, as they cannot be played/heard.
        /// BASS_SYNC_ONETIME Call the sync only once and then remove it from the channel.
        /// BASS_SYNC_THREAD Call the sync asynchronously in the dedicated sync thread.This only affects mixtime syncs (except BASS_SYNC_FREE syncs) and allows the callback function to safely call BASS_StreamFree or BASS_MusicFree on the same channel handle.</param>
        /// <param name="param">The sync parameter. Depends on the sync type... see the table below. </param>
        /// <param name="proc">The callback function. </param>
        /// <param name="user">User instance data to pass to the callback function. </param>
        /// <returns>If successful, then the new synchronizer's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code. </returns>
        public static int ChannelSetSync(int handle, BASSSync type, long param, SYNCPROC proc, IntPtr user)
        {
            int result = NativeMethods.BASS_ChannelSetSync(handle, type, param, proc, user);

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

            return(result);
        }
Ejemplo n.º 2
0
        public Sync(ChannelHandle channelHandle, BASSSync syncType, Action <int, int, int, IntPtr> sync)
        {
            ChannelHandle = channelHandle;

            if (!ChannelHandle.Valid)
            {
                throw new ArgumentException("Invalid handle provided for sync.");
            }

            SyncType       = syncType;
            _syncProcedure = new SYNCPROC(sync);

            Handle = Bass.BASS_ChannelSetSync(ChannelHandle.Handle, syncType, 0, _syncProcedure, IntPtr.Zero);

            if (!Valid)
            {
                throw new Exception($"Couldn't set sync procedure for channel handle {ChannelHandle.Handle.ToString("X8")}, file name {ChannelHandle.FileName}.");
            }
        }
Ejemplo n.º 3
0
 public static extern int BASS_ChannelSetSync(int handle, BASSSync type, long param, SYNCPROC proc, IntPtr user);
Ejemplo n.º 4
0
        /// <summary>
        /// Sets a synchronization callback.
        /// </summary>
        /// <param name="type">Sync type</param>
        /// <param name="param">Parameter (depends on sync type)</param>
        /// <param name="syncProc">Instance of the synchronization callback</param>
        /// <returns>Synchronization callback handle</returns>
        public int SetSync(BASSSync type, long param, SYNCPROC syncProc)
        {
            // Set sync
            int syncHandle = Bass.BASS_ChannelSetSync(handle, type, param, syncProc, IntPtr.Zero);

            // Check for error
            if (syncHandle == 0)
            {
                Base.CheckForError();
            }

            return syncHandle;
        }
Ejemplo n.º 5
0
        public void LoadFile(string file)
        {
            ChannelType = CHANNEL_TYPE.STREAM;

            this.Stop();

            int stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE);

            if (stream == Bass.FALSE)
            {
                stream = Bass.BASS_MusicLoad(file, 0L, 0, BASSFlag.BASS_MUSIC_DECODE | BASSFlag.BASS_MUSIC_FLOAT | BASSFlag.BASS_MUSIC_PRESCAN | BASSFlag.BASS_MUSIC_POSRESETEX | BASSFlag.BASS_MUSIC_RAMP, 0);

                if (stream != Bass.FALSE)
                {
                    ChannelType = CHANNEL_TYPE.MUSIC;
                }
            }

            if (stream == Bass.FALSE)
            {
                stream = Bass.BASS_StreamCreateURL(file, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_STATUS, downloadProc, IntPtr.Zero);
                if (stream != Bass.FALSE)
                {
                    ChannelType = CHANNEL_TYPE.REMOTE_URL;
                }
            }

            TAG_INFO         tagInfo     = new TAG_INFO(file);
            BASS_CHANNELINFO channelInfo = stream != Bass.FALSE ?
                                           Bass.BASS_ChannelGetInfo(stream) :
                                           new BASS_CHANNELINFO();

            this.Stream = stream;

            if (stream != Bass.FALSE)
            {
                bool isTagAvailable = ChannelType == CHANNEL_TYPE.REMOTE_URL ? BassTags.BASS_TAG_GetFromURL(stream, tagInfo) : BassTags.BASS_TAG_GetFromFile(stream, tagInfo);

                this.LengthInBytes   = Bass.BASS_ChannelGetLength(stream);
                this.LengthInSeconds = Bass.BASS_ChannelBytes2Seconds(stream, this.LengthInBytes);
            }

            this.TagInfo = tagInfo;

            this.ChannelInfo = channelInfo;

            if (ChannelType == CHANNEL_TYPE.REMOTE_URL)
            {
                BASSTag tagType = TagInfo.tagType;

                BASSSync syncFlag = syncFlag = BASSSync.BASS_SYNC_META;

                if (tagType == BASSTag.BASS_TAG_WMA)
                {
                    syncFlag = BASSSync.BASS_SYNC_WMA_META;
                }

                bool isWMA = false;

                if (channelInfo.ctype == BASSChannelType.BASS_CTYPE_STREAM_WMA)
                {
                    isWMA = true;
                }
                // ok, do some pre-buffering...
                System.Diagnostics.Debug.WriteLine("Buffering...");
                if (!isWMA)
                {
                    // display buffering for MP3, OGG...
                    while (true)
                    {
                        long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
                        if (len == -1)
                        {
                            break; // typical for WMA streams
                        }
                        // percentage of buffer filled
                        float progress = (
                            Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) -
                            Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
                            ) * 100f / len;

                        if (progress > 75f)
                        {
                            break; // over 75% full, enough
                        }

                        System.Diagnostics.Debug.WriteLine(String.Format("Buffering... {0}%", progress));
                    }
                }
                else
                {
                    // display buffering for WMA...
                    while (true)
                    {
                        long len = Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER);
                        if (len == -1L)
                        {
                            break;
                        }
                        // percentage of buffer filled
                        if (len > 75L)
                        {
                            break; // over 75% full, enough
                        }

                        System.Diagnostics.Debug.WriteLine(String.Format("Buffering... {0}%", len));
                    }
                }

                // get the meta tags (manually - will not work for WMA streams here)
                string[] icy = Bass.BASS_ChannelGetTagsICY(stream);
                if (icy == null)
                {
                    // try http...
                    icy = Bass.BASS_ChannelGetTagsHTTP(stream);
                }
                if (icy != null)
                {
                    foreach (string tag in icy)
                    {
                        System.Diagnostics.Debug.WriteLine("ICY: " + tag);
                    }
                }
                // get the initial meta data (streamed title...)
                icy = Bass.BASS_ChannelGetTagsMETA(stream);
                if (icy != null)
                {
                    foreach (string tag in icy)
                    {
                        System.Diagnostics.Debug.WriteLine("Meta: " + tag);
                    }
                }
                else
                {
                    // an ogg stream meta can be obtained here
                    icy = Bass.BASS_ChannelGetTagsOGG(stream);
                    if (icy != null)
                    {
                        foreach (string tag in icy)
                        {
                            System.Diagnostics.Debug.WriteLine("Meta: " + tag);
                        }
                    }
                }

                syncMetaUpdated = new SYNCPROC(SyncMetaCallback);

                mySyncHandleMetaUpdate = Bass.BASS_ChannelSetSync(stream, syncFlag, 0, syncMetaUpdated, IntPtr.Zero);
            }

            OnStreamCreated(stream);
        }
Ejemplo n.º 6
0
 public static extern UInt32 ChannelSetSync(UInt32 handle, BASSSync type, UInt64 param, SyncProc proc, IntPtr user);
Ejemplo n.º 7
0
 public static extern int BASS_ChannelSetSync(int handle, BASSSync type, long param, SYNCPROC proc, IntPtr user);
Ejemplo n.º 8
0
 public static extern UInt32 ChannelSetSync(UInt32 handle, BASSSync type, UInt64 param, SyncProc proc, IntPtr user);
Ejemplo n.º 9
0
 public static int BASS_Mixer_ChannelSetSyncEx(int handle, BASSSync type, long param, SYNCPROCEX proc, IntPtr user)
 {
     type |= (BASSSync)16777216;
     return(BassMix.BASS_Mixer_ChannelSetSync(handle, type, param, proc, user));
 }
Ejemplo n.º 10
0
 private static extern int BASS_Mixer_ChannelSetSync(int handle, BASSSync type, long param, SYNCPROCEX proc, IntPtr user);