内存不足错误。我该怎么做才能解决这个问题?
Out of memory error. What can I do to fix this?
到目前为止,我当前的项目在代码上很重要。我想使用 minim(我使用的是个人电脑)向其中添加音乐,但我一直遇到内存不足错误。这首歌会 运行 但非常不稳定,这使程序无法使用。我更改了首选项中的最大内存,但在尝试 4gb 但没有成功后,我认为这行不通。任何人都可以看看我的代码并告诉我一种压缩东西以节省 space 的方法吗?或者让我的程序 运行 保持原样的方法?
这是全部代码:
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);
}
您应该只加载一次声音文件![=14=]
draw()
函数每秒被调用 60 次,在其中有这段代码:
case RedBox:
handleRedBox();
player = minim.loadFile("SuperLove.mp3");
在这种情况下,该声音文件每秒将被调用 60 次。那不是你想做的。
相反,从 setup()
函数加载所有声音文件,然后在 draw()
函数中引用它们。
到目前为止,我当前的项目在代码上很重要。我想使用 minim(我使用的是个人电脑)向其中添加音乐,但我一直遇到内存不足错误。这首歌会 运行 但非常不稳定,这使程序无法使用。我更改了首选项中的最大内存,但在尝试 4gb 但没有成功后,我认为这行不通。任何人都可以看看我的代码并告诉我一种压缩东西以节省 space 的方法吗?或者让我的程序 运行 保持原样的方法?
这是全部代码:
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);
}
您应该只加载一次声音文件![=14=]
draw()
函数每秒被调用 60 次,在其中有这段代码:
case RedBox:
handleRedBox();
player = minim.loadFile("SuperLove.mp3");
在这种情况下,该声音文件每秒将被调用 60 次。那不是你想做的。
相反,从 setup()
函数加载所有声音文件,然后在 draw()
函数中引用它们。