We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › minim setGain(); problem
Page Index Toggle Pages: 1
minim setGain(); problem (Read 1017 times)
minim setGain(); problem
Feb 24th, 2008, 1:05pm
 
hi,

im working on a sketch with multiple minim AudioPlayers. The user can switch to other samples. i call play() and pause() to switch listening between the samples.

with controlp5 i built a simple slider, to change the volume(figured out it had to be gain here) of the samples playing.

when i now regulate the slider the volume stays the same, but i hear nasty sound lags. is there a way to solve this problem? or a way to do everything much better?

thank you
Re: minim setGain(); problem
Reply #1 - Feb 24th, 2008, 9:18pm
 
I'd have to see the code you are using to do this before I can give a good suggestion. Based on your description, it sounds like it should just work.
Re: minim setGain(); problem
Reply #2 - Feb 25th, 2008, 12:34pm
 
here is part of my code. when i run it it runs @ 60% of my cpu capacity. can this be a limiting factor.
(running 10 SampleMachines at once)

Quote:


import ddf.minim.*;
import ddf.minim.analysis.*;
import processing.opengl.*;
import controlP5.*;

AudioPlayer[] track;
SampleMachine[] SM;
Slider[] s;

BeatDetect beat;
ControlP5 controlP5;
int beatcount;
int CurrentTrack;
int num;
int rad;
int volzume;


void setup(){
 size(800,800);
 Minim.start(this);
 smooth();

 num = 7;
 rad = 200;

 SM = new SampleMachine[num];
 s = new Slider[num];
 controlP5 = new ControlP5(this);

 SM[0] = new SampleMachine(0,"2.mp3",50,50,SM);
 SM[1] = new SampleMachine(1,"1.mp3",600,750,SM);

 SM[5].play();
 background(0);
 Slider s = controlP5.addSlider("volzume",-500,500,0.8,300,700,10,40);
}

void draw()
{
 background(0);
 for (int i=0;i<SM.length;i++){
   SM[i].update();
   SM[i].display();
   SM[i].processor();
 }
}

void mouseReleased()
{
 for (int i=0 ; i< SM.length; i++){
   SM[i].mouseRelease();
 }
}

class SampleMachine{
 int ID;
 int x, y;
 int vol;
 int volume;
 int myColorRect;
 int myColorBackground;
 String name;
 boolean mouseOver;
 boolean mousePress;
 boolean locked = false;
 boolean otherslocked = false;
 boolean othersplayed = false;
 boolean play = false;
 boolean pause = false;
 boolean optionized;
 SampleMachine[] others;
 AudioPlayer song;
 BeatDetect beat;
 int beats = 0;
 int startCut;
 int endCut;
 SampleMachine(int id, String n, int ix, int iy, SampleMachine[] o){
   ID = id;
   name = n;
   x = ix;
   y = iy;
   others = o;
   song = Minim.loadFile(name);
   startCut = 0;
   endCut = song.length();

   beat = new BeatDetect();
   beat.detectMode(BeatDetect.FREQ_ENERGY);
   beat.setSensitivity(500);
   
   s[ID] = controlP5.addSlider("vol",-800,10,9,100,700,10,40);

   size = 25;
 }
 
Re: minim setGain(); problem
Reply #3 - Feb 25th, 2008, 12:34pm
 
Quote:

void update()
 {
   println(s[ID].value());
   println(song.getGain());
   song.setGain(s[ID].value());
       
   boxX = x-size/2;
   boxY = y-size/2;

   for(int i=0;i<others.length; i++){
     if(others[i].locked){
       otherslocked = true;
       break;
     }
     else{
       otherslocked = false;
     }

   }

   if (!otherslocked){  
     mouseOver();
     mousePress();
   }

   if ( mousePress && !collide()){
     x = mouseX;
     y = mouseY;

   }
   
   song.setGain(vol);
 }

 void mouseOver()
 {
   if ( overRect(boxX,boxY,size,size) ){
     mouseOver = true;
   }
   else{
     mouseOver = false;
   }
 }  

 void mousePress()
 {
   if (mouseOver && mousePressed || locked) {
     mousePress = true;
     locked = true;

     if(mouseButton == RIGHT){
       if(!play){
         play = true;
       }
       else{
         play = false;
       }    
     }
     
     if(mouseButton == CENTER){
       if(!optionized){
         optionized = true;
       }
       else{
         optionized = false;
       }
     }
     
   }
   else{
     mousePress = false;
   }
 }

 void mouseRelease()
 {
   locked = false;
 }

 void display()
 {
   
   stroke(255);
   strokeWeight(3);
   fill(20,70,170);

   
   if (optionized){
    s[ID].show();
   }
   else{
     s[ID].hide();
   }
 }
   
}

Re: minim setGain(); problem
Reply #4 - Feb 26th, 2008, 3:38am
 
So, the last thing you do is update is set the gain using the vol variable in the class. You may think this is being updated by the slider you create, named "vol", but I don't believe that is the case. If you remove that line, it should work properly, as you are already setting the gain from the value of the slider that you get using your cached ID.
Re: minim setGain(); problem
Reply #5 - Feb 26th, 2008, 12:44pm
 
jah i see what u mean, tried it with either of the two setgain lines, but nothing works. when i only use one line, there are no sound lags, but volume stays the same. i dont know why either. the setgain example from minim worx without problems

edit: worx now. had other wrong code artifacts somewhere in the sourcecode. just too long. need to switch to other editor. ill try eclipse
thanks ddf
Page Index Toggle Pages: 1