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.