You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

1

Thursday, June 12th 2014, 3:28pm

Beads Audio Library Question

I've been having some luck with the Beads library, which was built for audio DSP in Java/Processing. It compares with other libraries like Minim, and really simplifies the process of synthesis, analysis and recording.

Beads is located here:

http://www.beadsproject.net/

There's a great ebook called Sonifying Processing that gives many examples of Beads in use. The website for this ebook seems to be offline at the moment but it's archived here:

https://web.archive.org/web/201305100810…ds_Tutorial.pdf


Anyway, I have had some success with it - porting the granular sampler, basic sine wave synthesis and reverb examples - all of which seem to work well.

I have hit a brick wall however when it comes to implementing the custom function unit generator. I had a similar problem with Jsyn, about which I posted recently. I'm just not sure how to go about implementing it and any help/examples would be great.

In particular, I am trying to get the short Frequency Modulation example on page 25 of the ebook to work but am not sure how to do this in Jabaco:


Function frequencyModulation = new Function(modulator)
{
public float calculate() {
// return x[0], which is the original value of the
// modulator signal (a sine wave)
// multiplied by 50 to make the sine
// vary between -50 and 50
// then add 200, so that it varies from 150 to 250
return (x[0] * 50.0) + 200.0;
}


JavaDocs for beads are here: http://www.beadsproject.net/doc/

and information on the Beads Function Ugen is here: http://www.beadsproject.net/doc/net/bead…s/Function.html

Thanks in advance for any help.

Benjamin

This post has been edited 1 times, last edit by "vpr" (Jun 15th 2014, 10:21pm)


theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Sunday, December 21st 2014, 9:21pm

It is only a snippet of code, which itself don't work. So I can not creating a working example with it, because I don't want to read the complete tutorial.
But I can port your snippet to Jabaco:

At first loading all jar-files in the Beads.zip to your classpath.
Then go to the right top of the IDE to the "Project"-area and click there on "Add File..". Adding a "Class Module" there.
Go to the "Properties"-area of the IDE. You see now the properties of the new class file. Let the name as "Class1", but change the superclass to "net/beadsproject/beads/ugens/Function". You can do it by browing to it: Click on the "..." right beside of the text-filed of "(SuperClass)". Choosing the beads.jar-file and browse to the directory "net" -> "beadsproject" -> "beads" -> "ugens" and there choosing the file "Function.class".

Now go to the text-filed of the IDE and write the following code to Class1:

Jabaco Source

1
2
3
4
5
6
7
8
Public Sub Class1(a As net#beadsproject#beads#core#UGen)

End Sub

Public Function calculate() As Single
  Dim x As Single = 7
  calculate = (x * 50.0) + 200.0
End Function


Changing now to the Module1-file and write there:

Jabaco Source

1
2
3
Public Sub main(ByJava args() As String)
  Dim frequencyModulation As New Class1(modulator)
End Sub


Thats the port.
Jabaco don't find "modulator"? Right. But that is't defined in the snipped, too.

But I hope. that this port to Jabaco helps even though.

Greatings
theuserbl

vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

3

Wednesday, December 24th 2014, 3:38am

Thank you. I'm having some luck with this. I understand the syntax for doing this in Jabaco now and although it produces sound using the method that you have described, it is not doing FM synthesis. This variable "x" is a protected float array that is part of the Beads Function UGEN. "An array representing the current values from the array of input UGens".

You can see the source here for it here:

https://github.com/orsjb/beads/blob/mast…s/Function.java

As the Beads website says:

Inside the calculate() method, users access the samples from the list of input UGens using an array ‘x’. For example, if you instantiated a new Function with arguments a, b, c (where a, b and c are UGens), then the expression
return x[0] + x[1] / x[2];
would be equivalent to the operation (a + b / c) on the outputs of the UGens a, b and c.

So, in the example code you give, I need to write: calculate = (x(0) * 50.0) + 200.0

This doesn't work however. I can't seem to get access to the array. Might this be something to do with the way Jabaco handles protected variables, arrays, functions, etc... I say this because I searched for the word 'protected' on the forum and found someone with an issue on this thread:

Jabaco app that sends email over SSL, how?

I can upload the sample project that I'm working with if that might help diagnose the problem.

Thanks.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

4

Thursday, December 25th 2014, 1:30pm


This doesn't work however. I can't seem to get access to the array. Might this be something to do with the way Jabaco handles protected variables, arrays, functions, etc...


Yes. That is the reason. Jabaco knows only "public" and "private". And "protected" Jabaco handles as "private".

The easiest way, is to download this modified beads.jar and use it instead of the original beads.jar:
[ http://www.file-upload.net/download-10047838/beads.jar.html ]
The only difference is, that

Jabaco Source

1
protected float[] x;
is changed to

Jabaco Source

1
public float[] x;


That is currently the easiest way to give you a working solution.

Because it is a normal array, be sure to not use it direct:

Jabaco Source

1
2
3
Dim myX() As Single
myX = x
calculate = (myX(0) * 50.0) + 200.0


Hope it works and helps.

Greatings
theuserbl

vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

5

Friday, December 26th 2014, 3:27pm

Great :) That works perfectly, and has also given me some insight into the way Jabaco works. I owe you a drink :)

Now, the other thing that I've been having trouble with for a while is filling a buffer. This seems like it should be a simple task (and probably is in Java or Processing) but I have had no luck doing it in Jabaco despite trying many different methods.

Here's someone asking the very same question on the Beads forum:[url]https://groups.google.com/forum/#!searchin/beadsproject/buf/beadsproject/dK9jVEcimD8/n2PGOzuhbEMJ[/url]

The answer is easy enough in Java:

Jabaco Source

1
2
3
4
5
int size = 512;
Buffer myBuf = new Buffer(size);
for(int i = 0; i < size; i++) {        
        myBuf.buf[i] = ???;
}


I can't fill the buffer (a float array) in Jabaco. The output, when I view it with system.out.println(myBuf) is just 0.0 0.0 0.0 0.0 0.0 0.0....

I can use the built in buffers (there's buffers with sine waves, sawtooth waves, etc...) but I want to be able to create custom buffers.

You can see how simple it should be in this example:

https://github.com/moumar/beads/blob/mas…singBuffer.java

There are two classes that pertain to the use and generation of buffers.

Buffer:

Javadoc: http://www.beadsproject.net/doc/net/bead…ata/Buffer.html
Source: https://github.com/orsjb/beads/blob/mast…ata/Buffer.java

and BufferFactory:

Javadoc: http://www.beadsproject.net/doc/net/bead…ferFactory.html
Source: https://github.com/orsjb/beads/blob/mast…ferFactory.java

Any help would be much appreciated.

vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

6

Friday, December 26th 2014, 3:36pm

There is some information on working with custom buffers on page 126 of this tutorial, that I'm re-reading now:

http://www.computermusicblog.com/Sonifyi…ds_Tutorial.pdf

And a sine buffer class, which basically illustrates how filling a buffer should work, I think:

https://github.com/moumar/beads/blob/mas…SineBuffer.java

This post has been edited 1 times, last edit by "vpr" (Dec 26th 2014, 4:10pm)


Rate this thread
WoltLab Burning Board