2016-05-09 22 views
0

私の現在のプロジェクトはこれまでのコードでは重かった。私はミニ(私はPCを使用しています)を使用してそれに音楽を追加したいと思いますが、メモリ不足のエラーでヒットを続けています。曲は動くが、極端に不安定になり、プログラムが使用できなくなる。私は好みの最大メモリを変更しましたが、運がないと4GBを試した後、これはうまく動作しないと考えました。誰も私のコードを見て、スペースを節約するために多分圧縮する方法を教えてもらえますか?私のプログラムをそのまま実行させる方法?ここメモリ不足エラー。これを修正するにはどうすればよいですか?

は、すべてのコードです:

import ddf.minim.*; 
import ddf.minim.analysis.*; 
import ddf.minim.effects.*; 
import ddf.minim.signals.*; 
import ddf.minim.spi.*; 
import ddf.minim.ugens.*; 


Minim minim; 
AudioPlayer player; 

final int stateMenu = 0; 
final int RedBox = 1; 
final int BlueBox = 2; 
final int GreenBox = 3; 
int state = stateMenu; 
    float x, y, r, g, b, radius; 
int timer; 

// 
// font 
PFont font; 
PFont Amatic; 
// 

// ---------------------------------------------------------------------- 
// main functions 

void setup() 
{ 
    // runs only once 
    // 
    size(800, 700); 
    smooth(); 
    minim = new Minim (this); 
    font = createFont("ARCARTER-78.vlw", 14); 
    textFont(font); 
    //Amatic = createFont("Amatic-Bold.ttf",60); 
    //textFont(Amatic); 
    frameRate(15); 
} // func 
// 
void draw() 
{ 
    // the main routine. It handels the states. 
    // runs again and again 
    switch (state) { 
    case stateMenu: 
    showMenu(); 
    break; 
    case RedBox: 
    handleRedBox(); 
    player = minim.loadFile("SuperLove.mp3"); 
    player.play(); 
    break; 
    case BlueBox: 
    handleBlueBox(); 
    break; 
    case GreenBox: 
    handleGreenBox(); 
    break; 
    default: 
    println ("Unknown state (in draw) " 
     + state 
     + " ++++++++++++++++++++++"); 
    exit(); 
    break; 
    } // switch 
    // 
} // func 
// ---------------------------------------------------------------- 
// keyboard functions 

void keyPressed() { 
    // keyboard. Also different depending on the state. 
    switch (state) { 
    case stateMenu: 
    keyPressedForStateMenu(); 
    break; 
    case RedBox: 
    keyPressedForRedBox(); 
    break; 
    case BlueBox: 
    keyPressedForBlueBox(); 
    break; 
    case GreenBox: 
    keyPressedForGreenBox(); 
    break; 
    default: 
    println ("Unknown state (in keypressed) " 
     + state 
     + " ++++++++++++++++++++++"); 
    exit(); 
    break; 
    } // switch 
    // 
} // func 
void keyPressedForStateMenu() { 
    // 
    switch(key) { 
    case '1': 
    state = RedBox; 
    break; 
    case '2': 
    state = BlueBox; 
     background(255); 
    break; 
    case '3': 
    state = GreenBox; 
    break; 
    case 'x': 
    case 'X': 
    // quit 
    exit(); 
    break; 
    default: 
    // do nothing 
    break; 
    }// switch 
    // 
} // func 
void keyPressedForRedBox() { 
    // any key is possible 
    switch(key) { 
    default: 
    state = stateMenu; 
    break; 
    } // switch 
    // 
} // func 
void keyPressedForBlueBox() { 
    // any key is possible 
    switch(key) { 
    default: 
    state = stateMenu; 
    break; 
    } // switch 
}// 
    void keyPressedForGreenBox(){ 
     switch(key) { 
    default: 
    state = stateMenu; 
    break; 
     } 
} // func 

// ---------------------------------------------------------------- 
// functions to show the menu and functions that are called from the menu. 
// They depend on the states and are called by draw(). 

void showMenu() { 
    background(255); 
    fill(0); 
    textSize(45); 
    //textFont(Amatic); 
    text(" Music Box ", 330, 250, 3); 
    textFont(font); 
    textSize(14); 
    text("Press 1 for Red ", 350, 300); 
    textSize(14); 
    text("Press 2 for Blue ", 350, 325); 
    textSize(14); 
    text("Press 3 for Green", 350, 350); 
    textSize(14); 
    // exit button 
    text("Press x to quit ", 350, 375); 
} 

void handleRedBox() { 
    background(255); 
    stroke(255,0,0); 
    color from = color(100,random(255),2); 
    color to = color(0,200,0); 
    color interA = lerpColor (to,from,.44); 
    int x = 100; 
    while (x < width/2 || x> width/2) { 
    int y = 100; 
    while (y <height/2 || y > height/2) { 
     blendMode(DIFFERENCE); 
     noStroke(); 
     fill(interA); 
     quadstuff(); 
     strokeWeight(5); 
     stroke(0,random(255),0); 
     line(width/2,height/2,mouseY,mouseX); 
     translate(width, height); 
     rotate(radians(frameCount)); 
     y = y + 50; 
    } 
    x = x + 50; 
    } 
ghostcirc(); 
ghostcirc2(); 
} 

void ghostcirc(){ 
    int w = 0; 
    while (w < width) { 
    int q = 0; 
    while (q <height) { 
     blendMode(ADD); 
     fill(random(61), random(90), random(250)); 
     ellipse(255,255,100,100);; 
     noStroke(); 
     translate(width, height); 
     rotate(radians(frameCount)); 
     q = q + 100; 
    } 
    w = w + 50; 
    } 
} 

void ghostcirc2(){ 
    for (int w= 0; w < width; w+=10) {  
     blendMode(ADD); 
     fill(random(61), random(90), random(250)); 
     ellipse(50,50,75,75);; 
     noStroke(); 
     translate(width, height); 
     rotate(radians(frameCount)); 
     //if (keyPressed == true){ 
     // fill(random(100), random(90), random(250)); 
     } 
    } 

void quadstuff() { 
    int rad = 60;  // Width of the shape 
    float xpos, ypos; // Starting position of shape  

    float xspeed = 2.8; // Speed of the shape 
    float yspeed = 2.2; // Speed of the shape 

    xpos = width/2; 
    ypos = height/2; 
    //ellipse(mouseX+x, mouseY+y, 100,100); 
    quad(xpos, ypos, rad, rad, mouseX+rad, mouseY+rad, xspeed, yspeed); 
    stroke(0); 
    strokeWeight(5); 
} 

void handleBlueBox() { 
    Zon(); 
} 

void Zon(){ 
    blendMode(REPLACE); 
    frameRate(75); 
    noStroke(); 
    smooth(); 
    color from = color(2,217,227); 
    color to = color(0,127,193); 
    color interA = lerpColor (from,to,.24); 
    // use frameCount to move x, use modulo to keep it within bounds 
    x = frameCount % width; 

    // use millis() and a timer to change the y every 2 seconds 
    if (millis() - timer >= 8000) { 
    y = random(height); 
    timer = millis(); 
    } 

    // use frameCount and noise to change the red color component 
    r = noise(frameCount * 0.01) * 60; 

    // use frameCount and modulo to change the green color component 
    g = frameCount % 1; 

    // use frameCount and noise to change the blue color component 
    b = 255 - noise(1 + frameCount * 0.025) * 255; 

    // use frameCount and noise to change the radius 
    radius = noise(frameCount * 0.01) * mouseX; 

    color c = color(r, g, b); 
    fill(c); 
    ellipse(x, y, radius, radius); 
} 

void Vert(){ 
    frameRate(45); 
    // use frameCount to move x, use modulo to keep it within bounds 
    x = frameCount % width; 

    // use millis() and a timer to change the y every 2 seconds 
    if (millis() - timer >= 8000) { 
    y = random(height); 
    timer = millis(); 
    } 

    // use frameCount and noise to change the red color component 
    r = noise(frameCount * 0.01) * 255; 

    // use frameCount and modulo to change the green color component 
    g = frameCount % 1; 

    // use frameCount and noise to change the blue color component 
    b = 255 - noise(1 + frameCount * 0.025) * 255; 

    // use frameCount and noise to change the radius 
    radius = noise(frameCount * 0.01) * mouseX; 

    color c = color(r, g, b); 
    fill(c); 
    ellipse(y, x, radius, radius); 
} 

void handleGreenBox() { 
    background(255); 
    fill(0); 
    textSize(32); 
    text(" Some stuff", 150, 100, 3); 
    textSize(14); 
    text("..... some text ", 100, 200); 
} 

答えて

1

あなたは一度だけ、あなたのサウンドファイルをロードする必要があります!

draw()機能は、毎秒60回呼び出され、その内部に、あなたはこのコードを持っている。この場合

case RedBox: 
    handleRedBox(); 
    player = minim.loadFile("SuperLove.mp3"); 

、サウンドファイルは1秒間に60回呼び出すことしようとしていること。それはあなたがしたいことではありません。

代わりにsetup()関数からすべてのサウンドファイルを読み込み、draw()関数内で参照してください。

関連する問題