We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Split Audio file (Read 5190 times)
Split Audio file
Jun 6th, 2010, 12:12pm
 
Hello, I'm very new to Processing so bare with me.  I am trying to split an audio file into different files of equal length.  I have been looking at some of the audio libraries but none that I have seen help in this scenario.  Could some one guide me in the right direction.

My biggest issue is how do I pass the contents of an audio file into a byte array and loop.  
Any help would be greatly appreciated. This doesn't work but at least you can see what I am trying to do.

Code:

void setup(){
size(256,200);

byte b[] = loadBytes("resistance.mp3");
println("Song Byte Length: " + b.length);


// print each value, from 0 to 255
for (int i = 0; i < b.length; i++) {
byte[] c = new byte[1000000];
if(boolean(b[i])){
c[i] = (byte)(b[i]);
}
if( (i % 1000000) == 0){
saveBytes("First-" + i + ".mp3",c);
println(i + ": File");
}
}

// print a blank line at the end
println("Done");

Re: Split Audio file
Reply #1 - Jun 16th, 2010, 11:06pm
 
is this what you want

void setup(){
 size(256,200);
 byte b[] = loadBytes("_____________.mp3");        
 println("Song Byte Length: " + b.length);              
 // print each value, from 0 to 255      
// this part was moved      
byte[] c = new byte[10000000];
 for (int i = 0; i < b.length; i++) {

   if(boolean(b[i])){            
     c[i] = (byte)(b[i]);
   }      
   if( (i % 1000000) == 0){
     saveBytes("First-" + i + ".mp3",c);            
     println(i + ": File");      
   }        
 }
 // print a blank line at the end      
 println("Done");
}

//you were making an alot of arrays that was 1000000 . java
// doesn't like that
Page Index Toggle Pages: 1