Audio Fade in/out with minim
in
Core Library Questions
•
1 year ago
Hi everyone,
I have just started using processing and minim and i would like some advice from more advanced people.
I am trying to make a small program using minim to crossfade 2 songs ( 1 song is playing and after an event, the previous song fade out and the next sound fade in, the previous and the next song can be the same song ) and i got some problem with it. I am using AudioPlayer object and the method ShiftGain.
First one is that when I use the method
shiftGain(float from,float to,int millis) to make the fade in or the fade out, the transition is quite rough and I would like to know if there is any way to improve the transition.
The second one is that when I am trying to crossfade the same sound, it doesn't work. The song ( the previous one ) just shut down and there is only the fade in of the next song ) and but it kind of works with different sounds. I would like to know where my code is wrong.
P.S I know where my code is wrong, before the fade out is finished, I rewind the player associated to the song. i dont want to duplicate with another AudioPlayer Object. is there anyway to fix this ?
The last one My songs are mono(left) and when I using processing and minim, I have some noise on my right which quite annoying. Can i suppress this noise?
This is my following code
- import ddf.minim.*;
- Minim minim;
- AudioPlayer [] player;
- int numberOfsong; // number of songs
- int currPlayer; // integer to know which song is playing
- void setup()
- {
- size(100, 100);
- minim = new Minim(this);
- numberOfsong = 2;
- currPlayer = 0;
- player = new AudioPlayer[numberOfsong];
- player[0] = minim.loadFile("sample_1.WAV");
- player[1] = minim.loadFile("sample_2.WAV");
- }
- void draw()
- {
- background(0);
- }
- void keyPressed()
- {
- switch (key)
- {
- case 'e':
- if ( player[currPlayer].isPlaying() ) // if any song is playing
- {
- player[currPlayer].shiftGain(0, -50, 2000); // fade out of the playing song
- currPlayer = 0; // update the integer
- player[currPlayer].rewind(); // rewind from the beginning of the song
- player[currPlayer].setGain(0); // set the gain of the next song
- player[currPlayer].play(); // play the next song
- player[currPlayer].shiftGain(-50,0, 2000); // Fade in of the next song
- }
- else // no song is playing
- {
- currPlayer = 0; // update the integer
- player[currPlayer].rewind(); // rewind from the beginning of the song
- player[currPlayer].setGain(0); // set the gain of the next song
- player[currPlayer].play(); // play the song
- player[currPlayer].shiftGain(-50,0, 2000); // Fade in of the song
- }
- break;
- case 'r':
- if ( player[currPlayer].isPlaying() )
- {
- println("crossfade");
- player[currPlayer].shiftGain(0, -50, 2000);
- currPlayer = 1;
- player[currPlayer].rewind();
- player[currPlayer].setGain(0);
- player[currPlayer].play();
- player[currPlayer].shiftGain(-50,0, 1000);
- }
- else
- {
- currPlayer = 1;
- player[currPlayer].rewind();
- player[currPlayer].setGain(0);
- player[currPlayer].play();
- player[currPlayer].shiftGain(-50,0, 500);
- }
- break;
- }
- }
- void stop()
- {
- player[0].close();
- player[1].close();
- minim.stop();
- super.stop();
- }
2