22 May '13 - 03:08 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: [BassFx] Tempo  (Read 370 times)
Samsa
Posts: 2


« on: 1 Jun '12 - 21:13 »
Reply with quoteQuote

Hello,

i have some trouble to change tempo on a source stream in C# project.
Here is my Tempo class :

public class Tempo : Effect
    {
        public const string KEY = "TEMPO";
        public override string Key
        {
            get { return KEY; }
        }

        protected float mValue = 0.0f;
        /// <summary>
        /// Tempo -95% to 5000%
        /// </summary>
        public float Value { get { return mValue; } set { if (value < -95.0f) value = -95.0f; else if (value > 5000.0f) value = 5000.0f; mValue = value; Update(); } }

        protected float mFrequency = 0.0f;
        /// <summary>
        /// Frequence -95% to 5000%
        /// </summary>
        public float Frequency { get { return mFrequency; } set { if (value < -95.0f) value = -95.0f; else if (value > 5000.0f) value = 5000.0f; mFrequency = value; Update(); } }

        protected float mPitch = 0.0f;
        /// <summary>
        /// Pitch -60 to 60
        /// </summary>
        public float Pitch { get { return mPitch; } set { if (value < -60.0f) value = -60.0f; else if (value > 60) value = 60.0f; mPitch = value; Update(); } }

        public Tempo()
        {
            CurrentStream = null;
            Value = 0.0f;
            Frequency = 0.0f;
            Pitch = 0.0f;
        }

        public override bool Update()
        {
            if (CurrentStream == null)
                return false;
            if (CurrentStream.HandleTempo == 0)
                return false;
            return SetTempo(Value) && SetTempoFreq(Frequency) && SetTempoPitch(Pitch);
        }

        public override bool AttachToStream(PlayStream stream, int priority)
        {
            if (stream == null)
                return false;

            CurrentStream = stream;
            return Update();
        }
        public override bool DetachFromStream()
        {
            if (CurrentStream == null)
                return false;

            if (SetTempo(0.0f))
            {
                if (SetTempoFreq(0.0f))
                {
                    if (SetTempoPitch(0.0f))
                    {
                        CurrentStream = null;
                        return true;
                    }
                    else
                        return false;
                }
                else
                    return false;
            }
            else
                return false;
        }

        #region Tempo
        protected bool GetTempo(ref float value)
        {
            return Bass.BASS_ChannelGetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO, ref value);
        }
        protected bool SetTempo(float tempo)
        {
            return Bass.BASS_ChannelSetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO, tempo);
        }
        protected bool GetTempoFreq(ref float value)
        {
            return Bass.BASS_ChannelGetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, ref value);
        }
        protected bool SetTempoFreq(float freq)
        {
            return Bass.BASS_ChannelSetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, freq);
        }
        protected bool GetTempoPitch(ref float value)
        {
            return Bass.BASS_ChannelGetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, ref value);
        }
        protected bool SetTempoPitch(float pitch)
        {
            return Bass.BASS_ChannelSetAttribute(CurrentStream.HandleTempo, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, pitch);
        }
        #endregion
    }

I create the source stream with BASS_MUSIC_DECODE and then create a Tempo stream :

...
Handle = Bass.BASS_StreamCreateFile(Song.FilePath, 0L, 0L, BASSFlag.BASS_MUSIC_DECODE);
if (Handle == 0)
    BassManager.CheckException();
else
{
    Parent.AddChannel(this);
    HandleTempo = BassFx.BASS_FX_TempoCreate(Handle, BASSFlag.BASS_SAMPLE_FX);
    if (HandleTempo == 0)
         BassManager.CheckException();
}
...

The CurrentStream is attach to a mixer stream (and this mixer stream is used with lame encoder and icecast broadcast objects).

I have no error but the stream isn't slow down or speed up, nothing happens.
And so i don't understand what i'm doing wrong.
Logged
radio42
Posts: 4012


« Reply #1 on: 4 Jun '12 - 08:47 »
Reply with quoteQuote

When adding a source stream to a Mixer, this source stream must be a decoding one (use the BASS_SAMPLE_FLOAT flag).
So in your case it looks, like the TempoStream isn't a decoding one.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines