ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > irrKlang
Trying to make a smooth transition/crossfade
Author Text

Darty
Guest
Quote
2017-10-14 17:07:43

Hello, I need some help with the following issue.

Intro:
I've created an application that uses soundeffects on certain buttons and events and while the converting-task is working, it's playing a music "loop". As the file format isn't a module, looping is done with custom crossfade. The beginning and end of the short music is the same.
I've managed to get this working in Windows Media Player, but I wanted to change to another audio library that can handle the sounds (.ogg) better/faster.
So far it works everywhere, except at the crossfade code.

Code background:
* I use a crossfadetimer that starts as soon as converting process starts.
This timer simply counts an index till x, activates the volumefadetimer and resets x. This keeps looping till convertion is done.
Volumefadetimer is the code that should rise/lower the volumes of both ISound objects (from same Engine).
* I've tested many different values, in many situations it either plays the song once and goes silent, or it does a transition, but you hear a 'crack' at beginning of play and at the end. This also seems to get out of sync over time...

Below is the code I used, which worked with WMP. The only difference I noticed was the Volume value being max 1 (where WMP had 100).
I tried using the values needed for the same fade duration, tried different fade locations/durations, but it hasn't been smooth yet.
It's the last thing I need to get working if I want to keep this audio library. Any suggestions?

Actual code (with testvolume values):
private void tCrossFade_Tick(object sender, EventArgs e) //1000ms
{
if (i == 0) { tVolFade.Start(); } // Start Track and set Current irrPlayer.
if (i == 24) { i = -24; tVolFade.Start(); } // (Cross)Fade.
i++;
}
private void tVolFade_Tick(object sender, EventArgs e) // TIMER to Switch between 2 players (100ms)
{
// BackGround Audio during Conversion.
if (curirr == bgaudio1)
{
if (change == true) { bgaudio2 = irrEngine.Play2D(sBGAudio, false); change = false; } // Start new Player.
if (bgaudio1.Volume != 0) { bgaudio1.Volume = bgaudio1.Volume - 0.1f; bgaudio2.Volume = bgaudio2.Volume + 0.1f; } // FadeOut/-In Players.
else { tVolFade.Stop(); change = true; curirr = bgaudio2; }
}
else if (curirr == bgaudio2)
{
if (change == true) { bgaudio1 = irrEngine.Play2D(sBGAudio, false); change = false; }
if (bgaudio2.Volume != 0) { bgaudio2.Volume = bgaudio2.Volume - 0.1f; bgaudio1.Volume = bgaudio1.Volume + 0.1f; } // FadeOut/-In Players.
else { tVolFade.Stop(); change = true; curirr = bgaudio1; }
}
}


Darty
Guest
Quote
2017-10-15 17:15:03

I've rebuild my code to behave differently.
I've removed the VolumeFade timer and removed the code to adapt volume of any irrKlang related object.
As the song I want to loop is the same, I've edited the audiofile itself to fade in and out. I changed the code to play the track and close to fadelocation play the next, so they "crossfade" nicely without any damage or even sync problems.
I was hoping the fading would work by code, but this works for sure.
As I'm not creating a musicplayer with crossfade options but just try to continuously play 1 short "looped" music file, this solution works for me.

Final code:
private void tCrossFade_Tick(object sender, EventArgs e) // 300ms
{
if (i == 0) // Start Track and set Current irrPlayer.
{
if (curirr == bgaudio1) { bgaudio1 = irrEngine.Play2D(sBGAudio, false); curirr = bgaudio2; }
else if (curirr == bgaudio2) { bgaudio2 = irrEngine.Play2D(sBGAudio, false); curirr = bgaudio1; }
}
if (i == 78) // CrossFade.
{
i = -78;
if (curirr == bgaudio1) { bgaudio1 = irrEngine.Play2D(sBGAudio, false); curirr = bgaudio2; }
else if (curirr == bgaudio2) { bgaudio2 = irrEngine.Play2D(sBGAudio, false); curirr = bgaudio1; }
}
i++;
}


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2019 Nikolaus Gebhardt, Ambiera e.U.