SinOsc to play through an IntList

edited April 2018 in Library Questions

Hi, I'm trying to get SinOsc to play through an IntList. The IntList values will be mapped so that their values change the frequency output. I would like to be able to control the timing of the sounds (e.g., one sound per second). However, I'm running into all sorts of problems, starting with map() as it will only accept floats. Never mind trying to make it play through the IntList.

The following is the code I have that works so far (all failed attempts at playing the sounds have been omitted):

import processing.sound.*;
IntList luxSample1;
final int sampleSize=10;
Table table;
TableRow row;
float luxData;
float luxNoise1;
PFont font;
int RowCount; //total rows
int index; // random starting point
int end = index+9;
int [] randomLux1 = new int [10];
int minLux1, maxLux1;
SinOsc sine1;
String date;


void setup() {
  processData();
  size(640, 600); 
  background(0);
  font = createFont("Arial", 14, true);

  //Processing sound
  sine1 = new SinOsc(this);
  sine1.play();
}

void draw () {
  background(0);
  fill(255);
  textFont(font);
  textAlign(LEFT);
  date = table.getString(1, 0);
  text(date, 20, 20);
}
void processData() {
  table = loadTable("sample.csv", "header"); //change file here
  RowCount = table.getRowCount();

  index = int(random(RowCount-sampleSize));

  int[] randomLux1 = int(table.getStringColumn("lux"));
  luxSample1 = new IntList();
  luxSample1.append(subset(randomLux1, index, sampleSize));
  println(luxSample1);
  minLux1 = min(subset(randomLux1, index, sampleSize));
  maxLux1 = max(subset(randomLux1, index, sampleSize));
  println(minLux1, maxLux1);
}

The data is taken from a .csv file. Here is a sample: date,time,lux 02.08.2016,9:27:28,866 02.08.2016,9:27:29,635 02.08.2016,9:27:30,949 02.08.2016,9:27:31,986 02.08.2016,9:27:33,987 02.08.2016,9:27:34,992 02.08.2016,9:27:40,980 02.08.2016,9:27:44,987 02.08.2016,9:27:45,981 02.08.2016,9:27:46,977 02.08.2016,9:27:47,977 02.08.2016,9:27:48,974

Any pointers or help as to where I am going wrong or what I should look into will be greatly appreciated. Thanks!

Answers

  • could you please format the data like you did with your code?

  • I tried, but it keeps on putting it on a continuous line. Sorry. I don't know how else to do it. If you do, please let me know. Thanks.

  • Paste it in, then highlight and use Ctrl-o to indent four spaces.

    date,time,lux
    02.08.2016,9:27:28,866
    02.08.2016,9:27:29,635
    02.08.2016,9:27:30,949
    02.08.2016,9:27:31,986
    02.08.2016,9:27:33,987
    02.08.2016,9:27:34,992
    02.08.2016,9:27:40,980
    02.08.2016,9:27:44,987
    02.08.2016,9:27:45,981
    02.08.2016,9:27:46,977
    02.08.2016,9:27:47,977
    02.08.2016,9:27:48,974
    
  •     date,time,lux 
        02.08.2016,9:27:28,866 
        02.08.2016,9:27:29,635 
        02.08.2016,9:27:30,949 
        02.08.2016,9:27:31,986 
        02.08.2016,9:27:33,987 
        02.08.2016,9:27:34,992 
        02.08.2016,9:27:40,980 
        02.08.2016,9:27:44,987 
        02.08.2016,9:27:45,981 
        02.08.2016,9:27:46,977 
        02.08.2016,9:27:47,977 
        02.08.2016,9:27:48,974
    

    I'm on a Mac. Ctrl-O tries to open a file.

Sign In or Register to comment.