예제 #1
0
        /// <summary>
        /// Creates a user sample stream.
        /// </summary>
        /// <param name="Frequency">The default sample rate. The sample rate can be changed using <see cref="ChannelSetAttribute(int, ChannelAttribute, float)" />.</param>
        /// <param name="Channels">The number of channels... 1 = mono, 2 = stereo, 4 = quadraphonic, 6 = 5.1, 8 = 7.1. More than stereo requires WDM drivers, and the Speaker flags are ignored.</param>
        /// <param name="Flags">A combination of <see cref="BassFlags"/>.</param>
        /// <param name="Procedure">The user defined stream writing function (see <see cref="StreamProcedure" />).</param>
        /// <param name="User">User instance data to pass to the callback function.</param>
        /// <returns>If successful, the new stream's handle is returned, else 0 is returned. Use <see cref="LastError" /> to get the error code.</returns>
        /// <remarks>
        /// <para>
        /// Sample streams allow any sample data to be played through Bass, and are particularly useful for playing a large amount of sample data without requiring a large amount of memory.
        /// If you wish to play a sample format that BASS does not support, then you can create a stream and decode the sample data into it.
        /// </para>
        /// <para>
        /// Bass can automatically stream MP3, MP2, MP1, OGG, WAV and AIFF files, using <see cref="CreateStream(string,long,long,BassFlags)" />, and also from HTTP and FTP servers,
        /// using <see cref="CreateStream(string,int,BassFlags,DownloadProcedure,IntPtr)" />, <see cref="CreateStream(StreamSystem,BassFlags,FileProcedures,IntPtr)" /> allows streaming from other sources too.
        /// </para>
        /// <para>However, the callback method must deliver PCM sample data as specified, so opening an MP3 file and just passing that file data will not work here.</para>
        /// <para>
        /// Unlike Bass.Net, a reference to <paramref name="Procedure"/> doesn't need to be held by you manually.
        /// ManagedBass automatically holds a reference and frees it when the Channel is freed.
        /// </para>
        /// </remarks>
        /// <exception cref="Errors.Init"><see cref="Init" /> has not been successfully called.</exception>
        /// <exception cref="Errors.NotAvailable">Only decoding channels (<see cref="BassFlags.Decode"/>) are allowed when using the <see cref="NoSoundDevice"/> device. The <see cref="BassFlags.AutoFree"/> flag is also unavailable to decoding channels.</exception>
        /// <exception cref="Errors.SampleFormat">The sample format is not supported by the device/drivers. If the stream is more than stereo or the <see cref="BassFlags.Float"/> flag is used, it could be that they are not supported.</exception>
        /// <exception cref="Errors.Speaker">The specified Speaker flags are invalid. The device/drivers do not support them, they are attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled.</exception>
        /// <exception cref="Errors.Memory">There is insufficient memory.</exception>
        /// <exception cref="Errors.No3D">Could not initialize 3D support.</exception>
        /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
        public static int CreateStream(int Frequency, int Channels, BassFlags Flags, StreamProcedure Procedure, IntPtr User = default(IntPtr))
        {
            var h = BASS_StreamCreate(Frequency, Channels, Flags, Procedure, User);

            if (h != 0)
            {
                ChannelReferences.Add(h, 0, Procedure);
            }

            return(h);
        }
예제 #2
0
        public UserStream(UserStreamCallback callback, PlaybackDevice Device, Resolution BufferKind = Resolution.Short, bool IsMono = false)
            : base(BufferKind)
        {
            call      = callback;
            Procedure = new StreamProcedure(Callback);

            // Stream Flags
            BassFlags Flags = BufferKind.ToBassFlag();

            // Set Mono
            if (IsMono)
            {
                Flags |= BassFlags.Mono;
            }

            Handle = Bass.CreateStream(44100, 2, Flags, Procedure, IntPtr.Zero);

            Bass.ChannelSetDevice(Handle, Device.DeviceIndex);
        }
예제 #3
0
        public Player(string filepath, double volume, bool streaming)
        {
            this.FilePath = filepath;
            Ended         = false;
            if (streaming)
            {
                this.reader = new MusicFileReaderStreaming(filepath);
            }
            else
            {
                this.reader = new MusicFileReader(filepath);
            }

            this.IsLoop = !string.IsNullOrEmpty(reader.Tags.GetTag("LOOPSTART")) && (!string.IsNullOrEmpty(reader.Tags.GetTag("LOOPLENGTH")) || !string.IsNullOrEmpty(reader.Tags.GetTag("LOOPEND")));
            if (this.IsLoop)
            {
                LoopStart = long.Parse(reader.Tags.GetTag("LOOPSTART"));
                if (!string.IsNullOrEmpty(reader.Tags.GetTag("LOOPLENGTH")))
                {
                    LoopEnd = LoopStart + long.Parse(reader.Tags.GetTag("LOOPLENGTH"));
                }
                else
                {
                    LoopEnd = long.Parse(reader.Tags.GetTag("LOOPEND"));
                }
            }
            else
            {
                LoopStart = 0;
                LoopEnd   = reader.TotalSamples;
            }

            this.tSTREAMPROC  = new StreamProcedure(this.StreamProc);
            this.tSYNCPROC    = new SyncProcedure(this.EndProc);
            this.StreamHandle = Bass.CreateStream(reader.SampleRate, reader.Channels, BassFlags.Float, this.tSTREAMPROC);
            ChangeVolume(volume);
            Bass.ChannelSetSync(this.StreamHandle, SyncFlags.Stalled, 0, this.tSYNCPROC);

            Bass.ChannelPlay(this.StreamHandle);
        }
예제 #4
0
 static extern int BASS_StreamCreate(int Frequency, int Channels, BassFlags Flags, StreamProcedure Procedure, IntPtr User);
예제 #5
0
 public extern static int CreateStream(int Frequency, int Channels, BassFlags Flags, StreamProcedure Procedure, IntPtr User = default(IntPtr));
예제 #6
0
 public static extern int BASS_StreamCreate(DWORD freq, DWORD chans, DWORD flags, StreamProcedure proc, IntPtr user);