can not add audio onto processing - processing

I added an audio file in processing, but when I ran it the program just reminded:
Could not run the sketch (Target VM failed to initialize). Make sure
that you haven't set the maximum available memory too high.
The size of the file I added was only 266KB and the format was wav. What confused me was I had add an audio file named love.mp3 whose size is 4.01MB and the program ran normally.
Here is the code:
Minim minim;
AudioPlayer player;
AudioInput input;
void setup(){
size(400,400);
minim = new Minim(this);
player = minim.loadFile("transformer.wav");
input = minim.getLineIn();
}
void draw(){ }
void mousePressed(){
player.play();
}
void mouseReleased(){
player.close();
player = minim.loadFile("transformer.wav");
}

Related

Music Visualizer using Processing

I'm trying to create a music visualizer using Processing. My idea is to have a line, across the entire screen, that moves accordingly with a song.
This is what I have, right now
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer track;
AudioInput input;
FFT fft;
//AudioIn in;
String audioFileName = "dune.mp3";
void setup()
{
//size(480, 320);
fullScreen();
noCursor();
minim = new Minim(this);
track = minim.loadFile(audioFileName, 2048);
input = minim.getLineIn();
fft = new FFT(input.bufferSize(), input.sampleRate());
}
void draw()
{
background(0);
stroke(255);
fft.forward(input.mix);
for (int i = 0; i < fft.specSize(); i++)
{
ellipse(i, 200, 7, fft.getBand(i)*10);
//line(0, 200, 200, fft.getBand(i));
}
}
So, my problems are:
the music that I'm loading, it's not working. (String audioFileName). Only the input, so when I talk to the microphone, works
I can't get a line, only the ellipse like the code
Does anyone knows how to solve this? Or has a good tutorial that I can follow?
Thank you
Your demo crashes on my Mac and will take me a while to debug. Perhaps the following demo which I copied from the web will get you started (see file header): http://code.compartmental.net/minim/minim_class_minim.html . It is heavily commented with several 'println' calls to hopefully give you some idea of how it works. You will need to create a 'data' folder in your Processing sketch folder and place a file named 'groove.mp3' inside the data folder in order to run it. I've tested it on my system and it seems to work ok. Does not use FFT.
/*
This sketch demonstrates how to play a file with Minim using an AudioPlayer.
It's also a good example of how to draw the waveform of the audio. Full documentation
for AudioPlayer can be found at http://code.compartmental.net/minim/audioplayer_class_audioplayer.html
For more information about Minim and additional features, visit http://code.compartmental.net/minim/
*/
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup() {
size(512, 200);
// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);
println("minim = ", minim);
// loadFile will look in all the same places as loadImage does.
// this means you can find files that are in the data folder and the
// sketch folder. you can also pass an absolute path, or a URL.
player = minim.loadFile("groove.mp3");
println("player = ", player);
}
void draw() {
background(0);
stroke(255);
// draw the waveforms
// the values returned by left.get() and right.get() will be between -1 and 1,
// so we need to scale them up to see the waveform
// note that if the file is MONO, left.get() and right.get() will return the same value
for (int i = 0; i < player.bufferSize() - 1; i++) {
float x1 = map( i, 0, player.bufferSize(), 0, width );
float x2 = map( i+1, 0, player.bufferSize(), 0, width );
line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 );
line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 );
}
// draw a line to show where in the song playback is currently located
float posx = map(player.position(), 0, player.length(), 0, width);
stroke(0, 200, 0);
line(posx, 0, posx, height);
if ( player.isPlaying() ) {
text("Press any key to pause playback.", 10, 20 );
} else {
text("Press any key to start playback.", 10, 20 );
}
}
void keyPressed() {
if ( player.isPlaying() ) {
player.pause();
}
// if the player is at the end of the file,
// we have to rewind it before telling it to play again
else if ( player.position() == player.length() ) {
player.rewind();
player.play();
} else {
player.play();
}
}
The following is a revision of your initial post along with the reference that I used to debug it. 'Input' is the microphone and 'track' is the file; you had it set up to use the microphone and I switched it to the file. Just like the example above you will need to create a data folder in the Processing sketch folder and insert a file named 'groove.mp3'.
/*
Reference: https://github.com/ddf/Minim/blob/v2.2.2/examples/Analysis/SoundSpectrum/SoundSpectrum.pde
*/
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer track;
AudioInput input;
FFT fft;
String audioFileName = "groove.mp3";
void setup() {
size(480, 320);
noCursor();
minim = new Minim(this);
track = minim.loadFile(audioFileName, 1024);
input = minim.getLineIn();
fft = new FFT(track.bufferSize(), track.sampleRate());
println(fft);
track.loop();
}
void draw() {
background(0);
stroke(255);
fft.forward(track.mix);
for (int i = 0; i < fft.specSize(); i++) {
ellipse(i, 200, 7, fft.getBand(i)*10);
// line(0, 200, 200, fft.getBand(i)); //Unable to get this to work
}
}

how to solve meaningless characters on serial montior Arduino

Hi i am new at Arduino Uno , i am trying to use imu sensor and read datas from it so i installed mpu9500 lib from arduino website and run one example from its lib. However as i open the serial monitor, it displays strange characters . I check the pin configuration many times and load different libs and examples but i could not fix it.
Here is the codes i run.
#include "MPU9250.h"
MPU9250 mpu;
void setup() {
Serial.begin(115200);
Wire.begin();
delay(2000);
if (!mpu.setup(0x68)) { // change to your own address
while (1) {
Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
delay(5000);
}
}
}
void loop() {
if (mpu.update()) {
static uint32_t prev_ms = millis();
if (millis() > prev_ms + 25) {
print_roll_pitch_yaw();
prev_ms = millis();
}
}
}
void print_roll_pitch_yaw() {
Serial.print("Yaw, Pitch, Roll: ");
Serial.print(mpu.getYaw(), 2);
Serial.print(", ");
Serial.print(mpu.getPitch(), 2);
Serial.print(", ");
Serial.println(mpu.getRoll(), 2);
}
And this is what i get also i changed value of boud but nothing changed
01:10:23.688 -> ⸮7в⸮⸮⸮⸮⸮⸮`f⸮⸮⸮⸮⸮f⸮⸮⸮~⸮⸮xxf⸮~⸮⸮fx⸮⸮⸮⸮⸮⸮怘⸮
Try running simple Serial print code at the same baud rate(115200) and check if your board is alright. Then run the following code once:
#include "MPU9250.h"
MPU9250 mpu; // You can also use MPU9255 as is
void setup() {
Serial.begin(115200);
Wire.begin();
delay(2000);
mpu.setup(0x68); // change to your own address
}
void loop() {
if (mpu.update()) {
Serial.print(mpu.getYaw()); Serial.print(", ");
Serial.print(mpu.getPitch()); Serial.print(", ");
Serial.println(mpu.getRoll());
}
}

Unicast image transmission using Xbee

community
I've been working on image transmission using xbee s2b pro modules and Arduino Mega. Main task is to transmit an jpg image taken by a jpeg serial camera at the transmitter and send it to a microSD memory at the receiver, but I've been dealing with one unique trouble, I need a delay of 2 seconds to send and receive succesfully 1 byte, if I set less seconds I lose information and receipt image get corrupted. Here you will see my codes:
Transmitter code:
byte ZERO = 0x00;
byte incomingbyte;
long int a=0x0000,j=0,k=0,count=0,i=0;
uint8_t MH,ML;
boolean EndFlag=0;
void SendResetCmd();
void SetBaudRateCmd();
void SetImageSizeCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial1.begin(38400);
}
void loop()
{
byte a[32];
int ii;
SendResetCmd();
delay(4000);
SendTakePhotoCmd();
delay(1000);
while(Serial1.available()>0)
{
incomingbyte=Serial1.read();
}
while(!EndFlag)
{
j=0;
k=0;
count=0;
SendReadDataCmd();
delay(20);
while(Serial1.available()>0)
{
incomingbyte=Serial1.read();
k++;
if((k>5)&&(j<32)&&(!EndFlag))
{
a[j]=incomingbyte;
if((a[j-1]==0xFF)&&(a[j]==0xD9)) //tell if the picture is finished
EndFlag=1;
j++;
count++;
}
}
for(j=0;j<count;j++)
{
Serial.write(a[j]);
delay(2000);// observe the image through serial port
}
i++;
}
while(1);
}
void SendResetCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x26);
Serial1.write(ZERO);
}
void SetImageSizeCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x31);
Serial1.write(0x05);
Serial1.write(0x04);
Serial1.write(0x01);
Serial1.write(ZERO);
Serial1.write(0x19);
Serial1.write(0x11);
}
void SetBaudRateCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x24);
Serial1.write(0x03);
Serial1.write(0x01);
Serial1.write(0x2A);
Serial1.write(0xC8);
}
void SendTakePhotoCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x36);
Serial1.write(0x01);
Serial1.write(ZERO);
}
void SendReadDataCmd()
{
MH=a/0x100;
ML=a%0x100;
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x32);
Serial1.write(0x0c);
Serial1.write(ZERO);
Serial1.write(0x0a);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(MH);
Serial1.write(ML);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(ZERO);
Serial1.write(0x20);
Serial1.write(ZERO);
Serial1.write(0x0a);
a+=0x20;
}
void StopTakePhotoCmd()
{
Serial1.write(0x56);
Serial1.write(ZERO);
Serial1.write(0x36);
Serial1.write(0x01);
Serial1.write(0x03);
}
Receiver code:
#include <SD.h>
#include <SPI.h>
File myFile;
int pinCS = 53; // Pin 10 on Arduino Uno
void setup()
{
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
if (!SD.begin()) {
return;
}
}
void loop() {
byte buf[5000];
if (Serial.available()>0)
{
myFile = SD.open("imgrx.jpg", FILE_WRITE);
Serial.readBytes(buf,sizeof(buf));
Serial.println((byte)*buf);
myFile.write((byte)*buf);
while(Serial.available()>0) Serial.read();
}
else{
myFile.close();
}
}
I've tried a MicroSD -> XBEE -> MicroSD also and that trouble continued there, maybe I've passed through something and I'd like to tell me where. Let me add these methods give me images identical to the ones I send, so even slowly, it's very effective. I changed baudrates without any success. Xbee adresses are connected as unicast. I also tried using only Serial.readBytes and I got Bytes faster but as decimal values and is unreadable.
I would really appreciate any information or experience approach to solve this problem. Ask me anything you don't understand about my question. Thanks
Some starting recommendations:
Increase your baud rate to 115200 to increase throughput to/from the XBee.
Add hardware flow control to your setup so you know when the XBee module is "full" of queued data and not receiving.
Switch to API mode on your XBee modules, and generate API frames using the maximum payload size.
Wait for the Transmit Status response on your outbound Transmit frames before sending your next packet.
XBee 802.15.4 modules (including Zigbee and DigiMesh) weren't designed for high throughput. They're low-power, long range devices where you'll be lucky to get 10kbytes/second.

Kinect - Play & Pause music in Processing

I'm trying to play music when I move my hand forward and pause music when I move my hand background as in this video.
I can play music when I move forward. But I can't see how to pause my player when I move background.
import ddf.minim.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
int closestValue;
int closestX;
int closestY;
PImage img;
AudioPlayer player;
Minim minim;
void setup() {
size(640, 480);
img = loadImage("background.jpg");
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
image(img, 0, 0);
minim = new Minim(this);
player = minim.loadFile("music.mp3");
}
void draw() {
closestValue = 600;
kinect.update();
int[] depthValues = kinect.depthMap();
// this breaks our array down into rows
for (int y = 0; y < 480; y++ ) {
// this breaks our array down into specific pixels in each row
for (int x = 0; x < 640; x++) {
// this pulls out the specific array position
int i = x + y * 640;
int current = depthValues[i];
//now we're on to comparing them!
if ( current > 0 && current < closestValue) {
closestValue = current;
closestX = x;
closestY = y;
player.play();
}
/// I made this else if in order to make the pause when the current value is superior or equal to the closest value ///
/// but it doesn't play the player, it seems that it directly pauses the player. ///
/*else if ( current > 0 && current >= closestValue) {
player.pause();
}*/
}
}
// draw the depth image on the screen
image(kinect.depthImage(), 0, 0);
// draw that swanky red circle identifying it
fill(255, 0, 0); //This sets the colour to red
ellipse(closestX, closestY, 25, 25);
}
Try to player.pause(); in the play code segment and see what happens. If it pauses. then it's because of the expression you are using for the else if statement.

Dynamical drawing images in Cinder (Windows)

I have used Cinder about few weeks and i have some problem.
I am using method "drag-and-drop" in my program :
void TutorialApp::fileDrop(FileDropEvent drop){ /// drop are images
for(size_t i=0; i<drop.getNumFiles();++i){
Vertex imageVertex = Vertex((Vec2i(drop.getPos().x, drop.getPos().y+200)));
imageVertex.path = drop.getFiles()[i];
and next my step is draw Vertex with associeted image. So that is question: how to add resources in this case, or maybe there is more easy solution? Thank
Straight to the point:
First of all,you want to keep images (i.e gl::Texture) in your objects, that you want to draw. So in your class Vertex, add this gl::Texture as member. And then I suggest to use this function to load image and edit constructor, to take gl::Texture as parameter.
So you end up with something like this:
class testVertex
{
public:
testVertex(Vec2i _pos, gl::Texture image);
void draw(){
gl::draw(texture, pos);
}
private:
gl::Texture texture;
Vec2i pos;
};
///constructor
testVertex::testVertex(Vec2i _pos, gl::Texture image)
{
pos = _pos;
texture = image;
}
class BasicApp : public AppNative {
public:
void setup();
void mouseMove( MouseEvent event );
void mouseUp( MouseEvent event );
void keyUp(KeyEvent event);
void fileDrop(FileDropEvent event);
void update();
void draw();
//// create container for testVertex
vector <testVertex> mVertices;
}
/// To load images via drop...
void BasicApp::fileDrop(FileDropEvent event){
gl::Texture fileTexture = loadImage(event.getFile(0));
mVertices.push_back(testVertex(Vec2i(event.getX(), event.getY()), fileTexture));
}
/// To draw images...
void BasicApp::draw(){
for (int i = 0; i < mVertices.size(); i++)
{
mVertices[i].draw();
}
}
///

Resources