# Using insert data to adjust volume (beads)

**URL:** https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062
**Category:** Libraries
**Created:** [September 22, 2020, 10:43pm UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062 "2020-09-22T22:43:16Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 22, 2020, 10:43pm UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/1 "2020-09-22T22:43:16Z")

</div>

I am trying to inset a table and use the data to adjust the volume in gains  
But I don’t know how to do it since they are in different methods but if i put them together, there will be an error

also, i’m using the library, beads

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f0b5b85fda5dc3a91778a4d733f67937ce875d8c.png)

import beads.\*;  
import java.util.Arrays;

Table windDirection;  
Table windSpeed;  
int index = 0;  
float y;

float speed\_y;  
int speedIndex = 0;

AudioContext ac;

void setup(){  
size(800, 800);  
smooth();

windSpeed = loadTable(“[https://eif-research.feit.uts.edu.au/api/csv/?rFromDate=2020-09-19T17%3A33%3A38&rToDate=2020-09-21T17%3A33%3A38&rFamily=weather&rSensor=IWS](https://eif-research.feit.uts.edu.au/api/csv/?rFromDate=2020-09-19T17%3A33%3A38&rToDate=2020-09-21T17%3A33%3A38&rFamily=weather&rSensor=IWS)”, “csv”);

ac = new AudioContext();  
selectInput(“Select an audio file:”, “fileSelected”);

frameRate(5);  
}

//===========================================================================================================================

void getSpeedData() {  
if (speedIndex \< windSpeed.getRowCount()) {  
// read the 2nd column (the 1), and read the row based on index which increments each draw()  
speed\_y = windSpeed.getInt(speedIndex, 1); // index is the row, 1 is the column with the data.  
speedIndex++;  
}  
else {  
speedIndex = 0;  
}  
}

//wind sound setting  
void fileSelected(File selection) {

//Choose audio file  
String audioFileName = selection.getAbsolutePath();  
//Creates a sample player and loads in the Sample.  
SamplePlayer player = new SamplePlayer(ac, SampleManager.sample(audioFileName));

//Modify the gain of a multi-channel audio signal  
//Parameters: AudioContext, #inputs = #outputs, gain level( 0: silence)  
Gain g = new Gain(ac, 2, );  
g.addInput(player);  
ac.out.addInput(g);  
ac.start();

}

void draw(){

}

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 23, 2020, 12:58am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/2 "2020-09-23T00:58:52Z")

</div>

if you could post your code it would help to try it out without having to retype it. sorry im lazy !

---

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 23, 2020, 2:04am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/3 "2020-09-23T02:04:04Z")

</div>

all good, sorry for that. I have upload the code and thanks

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 23, 2020, 6:27am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/4 "2020-09-23T06:27:28Z")

</div>

np.

first of all, the obvious mistake would the missing parameter in:

Gain g = new Gain(ac, 2, );

apparently that class expects 3 values not two.  
assuming that this is where you wanted to use speed\_y I put it in.  
maybe that is it ? code runs, but it seems the link to your data is refused.  
when I try with a browser I get some warning that this website is not safe. probable ignorable but that may be the reason why the sketch does not continue at this point.

but that would be the next step…

---

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 23, 2020, 6:32am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/5 "2020-09-23T06:32:53Z")

</div>

yes, the empty parameter is to put speed\_y

When I selected an audio, it remains silence

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 23, 2020, 6:42am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/6 "2020-09-23T06:42:07Z")

</div>

what’s the value range ? from the examples of the library it looks the use values in the rand of 0.1 to 1 (I figure zero to 100% volume (?)  
your dataset has values about 2020-09-21 16:32:37,4 -\> between 0 and 10 maybe

does it work if you put a fixed number like 0.3 for you ?

---

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 23, 2020, 6:44am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/7 "2020-09-23T06:44:28Z")

</div>

the value range is 0 - 16  
I tried to divide it but doesn’t help

If I put a number there, it works

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 23, 2020, 6:53am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/8 "2020-09-23T06:53:13Z")

</div>

ok, i also notice:

that your data is a csv, but in the dataset you only have the comma in strange places

2020-09-19 17:37:36,4 2020-09-19 17:42:36,3 2020-09-19 17:47:36,6 -\>

that would separate into:  
2020-09-19 17:37:36  
4 2020-09-19 17:42:36  
3 2020-09-19 17:47:36  
6 2020-09-19 17:52:36

so if I am not mistaken you say: take the first entry (which is 2020-09-19 17:37:36) and put it into speed\_y

but before that, you **never** execute getSpeedData() ! 😃  
so it stays 0 of course

---

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 23, 2020, 7:07am UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/9 "2020-09-23T07:07:34Z")

</div>

but I can’t do anything to alter the dataset, right?

---

<div class="post-metadata">

### Author: ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)
#### Post date: [September 23, 2020, 12:10pm UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/10 "2020-09-23T12:10:53Z")

</div>

you could…  
i didnt look into it in detail, but you can choose your separators differently and split the resulting entries again  
String [] one -\> split String with " " -\> [2020-09-19] [17:37:36,4] [2020-09-19] [17:42:36,3] …  
String [] two -\> split every other entry with “,” -\> [17:37:36] [4] [17:42:36] [3]  
IntList -\> append ever other entry  
(basically by: for (int i=1,i\<two.length; i+=2) so you take the 1,3,5th item)

or you could look for the index of the comma in a string and take the next character…

> **[String \\ Language (API) \\ Processing 3+](https://processing.org/reference/String.html)**

  
like:
1. find the first occurrence of a “,” in your string with indexOf()
2. get the value you need with charAt() - which is the index you just got +1
3. append it to an IntList
4. cut the “used” part away from the string with substring() from index 0 to the index of the value
5. repeat until your string is empty

---

<div class="post-metadata">

### Author: ![learningL](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@learningL](https://discourse.processing.org/u/learningL)
#### Post date: [September 23, 2020, 1:04pm UTC](https://discourse.processing.org/t/using-insert-data-to-adjust-volume-beads/24062/11 "2020-09-23T13:04:48Z")

</div>

thank you for helping
