You are currently browsing the archive for the Minim category.
Minim on Github
The project with Numediart has gotten off to a great start. I’m excited about the additional music programming capabilities that will result from that work. However, the beginning of the project has already brought a much needed improvement to Minim: a better way for people to contribute to the project. I’ve been developing Minim pretty much solo and working in an undisclosed Subversion repository. My intent had been to eventually make that repository publicly known, but I had not figured out a good way to review changes that people might make before committing them. Github was suggested to me as a good site for managing this sort of thing and we decided to try the process out by using Github for the Numediart project. My initial experience with it has been fantastic, so I plan to keep Minim there. Visit the project page to see what it’s all about:
If you would like to contribute to the development of Minim, all you need to do is create a Github account and click the Fork button on the Minim project page. This will create a branch of the project that you can push to. When you’ve fixed a bug that’s been bothering you, or create a new feature that you think is worthy of being included, you simply send me a pull request and I will be able to review your patch and accept it or not. Totally sweet, I say.
Building Minim
I develop Minim in Eclipse, so the repository is structured such that you can clone it into your Eclipse workspace and then import it as an already existing project. Here are the instructions for acquiring and building Minim, if you fork the project, you’d follow these same instructions but use the “Your Clone URL” from the fork you create. Keep in mind that Eclipse doesn’t support two projects with the same name in the same workspace.
What you will need:
What you will do:
- From your workspace directory, clone the github Minim repo. On the command line that’d be this command:
git clone git://github.com/ddf/Minim.git
This should create a local git repo in a directory named Minim. - Then go into Eclipse, right click in the Package Explorer and choose “Import…”
- Under “General” choose “Existing Projects into Workspace”
- Click “Next”
- With “Select Root Directory” selected, choose “Browse…” and browse to the the directory that git just created.
- Click “Finish”. You should now have a browsable and buildable project named “Minim” in your package explorer.
- Create the folder libraries/minim/library inside of you sketchbook folder.
- Export the packages ddf.minim, ddf.minim.analysis, ddf.minim.effects, and ddf.minim.signals, as a single jar file named minim.jar into the folder you just created.
- Export the package ddf.minim.javasound as a jar file named jsminim.jar to the same folder.
- Export the package ddf.minim.spi as a jar file named minim-spi.jar to the same folder.
- Copy all of the jar files in the lib directory of the project, except for core.jar, into the same directory you exported the first three jars into.
- Run Processing and sketches that use Minim will use the build you just made, instead of the build that Processing comes with.
I am happy to announce the release of Minim 2.0.2! Download and installation instructions are available on the project page. Here’s what’s fixed and new, which you will also find in the changelog.txt file included with the distribution:
Fixed Bugs:
- filenames were being parsed incorrectly by createRecorder.
- fixed audio processing routines for AudioPlayer and AudioSnippet so that they don’t spend cycles doing nothing while not in the “play” state.
- fixed the zombie thread bug, which kept audio processing Threads from exiting when close() was called.
- fixed out-of-memory problems that could occur when large files were played. this does come at the cost of slower seek times.
- fixed the isEnabled(AudioEffect) function, which, uh, wasn’t working.
- fixed the pan() function, which was returning the BALANCE control.
New Features:
- added functions to FFT for doing forward transforms with an offset: forward(float[] samples, offset) and forward(AudioBuffer samples, offset)
- added a freqToIndex(float freq) method to FFT for finding out the index of the spectrum band that contains the passed in frequency.
- added a stop() method to AudioSample, so that playing samples can be immediately silenced.
- added setPanNoGlide(float pan) to Controller, which will snap the panning setting of a sound to the provided value.
- added setInputMixer(Mixer) and setOutputMixer(Mixer), which allow you to specify which Java Mixer object should be used when obtaining inputs (AudioInput) and outputs (AudioOuput, AudioPlayer, AudioSnippet, AudioSample).
I am close close close to releasing 2.0.2! Today I wrote a couple new examples to demonstrate a couple additional features that have been added and I made sure the javadocs all looked good. Then I got sidetracked by writing a song. Well, so it goes, one doesn’t say no to songwriting when inspiration strikes. So! I plan to do the release tomorrow. As mentioned, there won’t be a whole lot new in this release, but a number of nasty bugs have been fixed. A full run down of what’s been fixed and what’s new will be provided with the release.
Among all of the things that I have learned while working as a professional game dev, two very important things are 1) how to document and test bug fixes and 2) the importance of having a sane build process. I didn’t have a terribly good handle on either of these things when I first created Minim and as a result pushing out a release was a very painful process.
Bug Fixing
I’ve not always been good about keeping track of exactly which bugs I’ve fixed in a release, or which new features I’ve added. No longer! The past two days have seen verbose comments in my check-ins, which means I should be able to create a pretty exact changelog for the next release. Here’s my most recent check-in comment, to give you an idea of the kinds of things coming up:
FourierTransform:
- added freqToIndex method for converting a frequency to an index (duh)
- added getAverageCenterFrequency to get the center frequency of an average band from an index
- added forward(float[], int) and forward(AudioBuffer,int) so an offset into the array of floats can be provided, in case a user has a large buffer they want to analyze only parts of.
JSMinim:
- added setInputMixer(Mixer) so users can specify which Mixer to use when getting TargetDataLines
- added setOutputMixer(Mixer) so users can specify which Mixer to use when getting SourceDataLines
Minim:
- added getServiceProvider() so that you can get a handle on the implementation being used by Minim.
- added createSample functions to get an AudioSample using a buffer(s) of floats.
MinimServiceProvider:
- added getAudioSample(float[], AudioFormat, int) and getAudioSample(float[], float[], AudioFormat, int) interface functions for requesting AudioSamples with buffers instead of from files.
Build Process
Creating and uploading new JAR files is not the hard part of doing a release. No, the hard part is making sure all of my online examples are up-to-date and making sure the Manual reflects any additions or changes to the API. The biggest pain with the examples is that the directory structure that I use on the website does not match the local directory structure, so it’s not just an easy drag-and-drop. I have my examples set up as a subdirectory in my Processing sketch folder, but what actually gets uploaded to the website are the contents of the applet directory that is generated for each sketch when I export it. Man, I would love to know a way to tell Processing to export an applet to a location other than the sketch folder, because then I could export to a directory structure that is the same as what’s on the web.
In any event, that’s a pain, and I need to figure that out, but I also finally got around to creating a subversion repository for all of the example source files. This will at least make it easier for me to tell at a glace which sketches need to have applets re-exported and uploaded. Maybe I can even figure out how to create an automated process for this. But, one thing I had to do before I could commit all of the examples, was delete all of the applet directories. To do that, I googled around and found this totally helpful batch file:
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q %%G
That particular code will delete all subdirectories that match the name “*.svn*” under the directory it is executed in. All I had to do was change the name to match to “applet”. It’s all really clearly explained in this forum post and worked liked a charm.
So, that’s at least one part of my build process that’s been sanitized (by which I mean: made sane)!
Recently had this neat little interview with Andrew Bayazkus pop up in my feed reader. He’s made some pretty cool audio-visual sketches in Processing using Minim for the audio end of things. Check them out at his site Kosmotrope. I love seeing this kind of stuff and am glad that people have been able to use Minim to make it!
I’m working on adding the ability to do frequency modulation in Minim. I didn’t figure it was a very complicated thing. I knew that I’d have to do it while generating each sample, so it couldn’t be done as an AudioEffect. But when I went looking online about how to do it, I found a number of articles that described the technique in words, with somewhat dense equations, but none that had easy to understand code examples. I did find this article, but the code in it is some form of Lisp, a language I am not familiar with. I thought I had it figured out a couple times, but every time I tried something new I still wasn’t achieving the correct result.
So today I asked my friend The Mysterious H how it works because he’s a smart guy and builds synths out of Atari sound chips and shit like that. He goes, “Oh it’s easy.”
Every time you want to generate a sample of the signal you are modulating (the carrier), generate a sample of your modulator and add that to the phase you use to generate your carrier sample.
Said another way: Say you’ve got a signal called f. At every time step t (which is your phase), you generate a sample s by evaluating f(t). If you want to modulate the frequency of f with a modulator called m, then at every t you will do this:
s = f(t + m(t))
The speed of the modulation is determined by the frequency of your modulator and the amount of the modulation (how many hertz above and below the frequency of your carrier signal the audible signal will swing) is determined by the amplitude of the modulator. In my tests I found that the amplitude had to be around 0.001 to achieve what one would consider vibrato. Setting it to 0.1 made for some pretty intense alien sounds when the frequency of the modulator was up in audio signal range (20 Hz and up, say).
It’s lots of fun to play with and will be coming soon!
Tags: code, fm, frequency modulation
Reas kicked me in the ass (via e-mail), so I updated the Minim Manual to reflect the Minim 2.0 API. I need to give a shout-out to Urban Giraffe for their Wordpress plug-in Sniplets. This enabled me to pull all of the examples in the Manual directly from the online examples. This means that any time I update the online examples, they will be immediately reflected in the Manual. Rock, rock on, says I.
I’m pretty sure that I didn’t leave anything out, but if you spot any omissions, mistakes, or poorly written explanations, please let me know! I will endeavor to fix the problem as quickly as possible.
Also worth mentioning in this post is that Processing 1.0 is out! I can’t say I contributed much to its release, but its imminent release is what got me to finally cleanup and release Minim 2.0. One exciting detail I don’t think I’ve mentioned is that Minim is now one of the libraries that comes with the Processing download. I am very honored to have my library so closely tied to such an awesome project and I hope that people find working with Minim as easy as it is to work with the core Processing API.
While writing the example that I just posted, I discovered a couple nasty bugs that would have made a lot of people unhappy. For the curious, they were that the getChannel method was not returning the correct channel when using BufferedAudio.LEFT and BufferedAudio.RIGHT, and that stereo AudioSamples were only playing the left channel. All my tests thus far have used mono files, so that one just slipped past me. I’ve packed up a new release and updated the download page.
Kyle says, “Like what if I want to load up a sound and remove certain portions that fit some criteria or rearrange it (i.e., non-real-time processing)?”
What you want to do is currently possible to a certain degree using AudioSample. It now has a method called getChannel(int), which comes from the BufferedAudio interface. This method returns in a float array the actual samples being used by the object when you trigger it. You can then manipulate those values and hear the change when you trigger it.
Example (view online)
import ddf.minim.*; Minim minim; AudioSample jingle; void setup() { size(512, 200, P3D); minim = new Minim(this); jingle = minim.loadSample("jingle.mp3", 2048); // get the left channel of the audio as a float array // getChannel is defined in the interface BuffereAudio, // which also defines two constants to use as an argument // BufferedAudio.LEFT and BufferedAudio.RIGHT float[] leftChannel = jingle.getChannel(BufferedAudio.LEFT); // now we are just going to reverse the left channel float[] reversed = reverse(leftChannel); arraycopy(reversed, 0, leftChannel, 0, leftChannel.length); } void draw() { background(0); stroke(255); for(int i = 0; i < jingle.bufferSize() - 1; i++) { line(i, 50 - jingle.left.get(i)*50, i+1, 50 - jingle.left.get(i+1)*50); line(i, 150 - jingle.right.get(i)*50, i+1, 150 - jingle.right.get(i+1)*50); } } void keyPressed() { jingle.trigger(); } void stop() { // always close Minim audio classes when you finish with them jingle.close(); minim.stop(); super.stop(); }

