Skip to content

Commit

Permalink
SoundFile:toCSV method
Browse files Browse the repository at this point in the history
  • Loading branch information
danstowell committed Apr 4, 2008
1 parent d8d40ba commit 56f1750
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions build/ChangeLog
@@ -1,5 +1,18 @@
//////////// change log /////////////

// user-visible changes after SC v3.2:

// HEADLINES:

// BUGFIXES:

// OTHER ADDITIONS/IMPROVEMENTS:
* 2008-04-04 SoundFile:toCSV - ds



///////////////////////////// SuperCollider v3.2 released 2008-02-21 /////////////////////////////

// user-visible changes in preparing SC v3.2, SuperCollider book release:

// HEADLINES:
Expand Down
33 changes: 33 additions & 0 deletions build/SCClassLibrary/Common/Files/SoundFile.sc
Expand Up @@ -366,4 +366,37 @@ SoundFile {

}

toCSV { |outpath, headers, delim=",", append=false, func, action|

var outfile, dataChunk;

// Prepare input
if(this.openRead(this.path).not){
^"SoundFile:toCSV could not open the sound file".error
};
dataChunk = FloatArray.newClear(this.numChannels * min(this.numFrames, 1024));

// Prepare output
if(outpath.isNil){ outpath = path.splitext.at(0) ++ ".csv" };
outfile = File(outpath, if(append, "a", "w"));
if(headers.notNil){
if(headers.isString){
outfile.write(headers ++ Char.nl);
}{
outfile.write(headers.join(delim) ++ Char.nl);
}
};

// Now do it
while{this.readData(dataChunk); dataChunk.size > 0}{
dataChunk.clump(this.numChannels).do{|row|
outfile.write(if(func.isNil, {row}, {func.value(row)}).join(delim) ++ Char.nl)
};
};
outfile.close;
this.close;

action.value(outpath);
}

}

0 comments on commit 56f1750

Please sign in to comment.