How to set sample rate/frequency in Minim?

Hi,
Since I have problem using the Sound Library, I’ve been trying to use Minim but I am stuck on changing the rate of the sample. Unlike the Sound library, it seems like it won’t allow me access changing the rate.
How do I do this?

I’ve looked at this Minim library documentation: http://code.compartmental.net/minim/index.html

The section of my code where I tried changing it:

  file0.trigger();
  file0.sampleRate = 30000;  //This doesn't work!
  print(file0.sampleRate());  //Prints out current sample rate

My entire code:

import ddf.minim.*;

Minim minim;
AudioSample file0;
AudioSample file1;
AudioSample file2;
AudioSample file3;
AudioSample file4;
// This example code is in the public domain.

  import processing.serial.*;     // import the Processing serial library

  Serial myPort;                  // The serial port
int trigger; 

int numsounds = 5;  // Define the number of samples
float inByteX;
float inByteY;
float inByteZ;
// Define a variable to store the randomly generated background color in
int backgroundColor[] = {255, 255, 255};


float x;
float y;
float z;
float tempo;

  void setup() {
    size(640, 480);
    background(0);
    
  minim = new Minim(this);
  
    file0 = minim.loadSample((1 + ".aif"), 512);
    
    file1 = minim.loadSample((2 + ".aif"), 512);

    file2 = minim.loadSample((3 + ".aif"), 512);

    file3 = minim.loadSample((4 + ".aif"), 512);

    file4 = minim.loadSample((5 + ".aif"), 512);

  
    myPort = new Serial(this, Serial.list()[3], 9600);

    myPort.bufferUntil('\n');
    
    trigger = millis();


  }
  
float[] octave = {0.25, 0.5, 1.0, 2.0, 4.0};

  void draw() {
      // If the determined trigger moment in time matches up with the computer clock events get triggered.
      
      if (millis() > trigger) {
       float rate = octave[int(random(0, octave.length))];  //octave length = 5

       int thisFile = int(random(0,4));
       
       //Which sound file to play:
       switch(thisFile) {
        case 0: 
          file0.trigger();
          file0.sampleRate = 30000;  //This doesn't work!
          print(file0.sampleRate());  //Prints out current sample rate
          break;
        case 1: 
          file1.trigger();
          print(file1.sampleRate());
          break;
          case 2: 
          file2.trigger();
          print(file2.sampleRate());
          break;
          case 3: 
          file3.trigger();
          break;
          case 4: 
          file4.trigger();
          break;
          
      }



        for (int i = 0; i < 3; i++) {  //Change background colour when sound plays
            backgroundColor[i] = int(random(255));
        }     
        
        background(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
      
        float maximumTempo = max(inByteX, inByteY, inByteZ);   //Choose maximum input value/tempo
        maximumTempo = constrain(maximumTempo, 0, 100);
        tempo = map(maximumTempo, 0, 100, 300, 0);
 
        
        if (maximumTempo < 4){
          tempo = 2000;  //If accelerometer signal is under 4, play at 2000 ms interval
        };
        trigger = millis() + int(tempo);
    }
     
  } //End of draw


  void serialEvent(Serial myPort) {
    // read the serial buffer:
    String myString = myPort.readStringUntil('\n');
    // if you got any bytes other than the linefeed:
    myString = trim(myString);

    // split the string at the commas and convert the sections into integers:
    int sensors[] = int(split(myString, ','));

    // print out the values you got:
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }
    println();  //add a linefeed after all the sensor values are printed
    
      
    if (sensors.length > 1) {
      inByteX = map(sensors[0], 0, 1023, 0, 100);
      inByteY = map(sensors[1], 0, 1023, 0, 100);
      inByteZ = map(sensors[2], 0, 1023, 0, 100);
    }
    
    
    // send a byte to ask for more data:
    myPort.write("A");
    
    
  }

Thanks in advance :slight_smile: