Mercurial > hg > may
changeset 2:51c7fea7d805
Matrix bits & bobs
author | Chris Cannam |
---|---|
date | Sun, 02 Dec 2012 12:09:32 +0000 |
parents | 7aedeab67b08 |
children | 29e39209360b |
files | audio.yeti matrix.yeti |
diffstat | 2 files changed, 35 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/audio.yeti Fri Nov 30 18:06:47 2012 +0000 +++ b/audio.yeti Sun Dec 02 12:09:32 2012 +0000 @@ -6,6 +6,8 @@ import java.io: File, IOException; +mat = load matrix; + openAudioFile name is string -> 'a = (f = new File(name); stream = AudioSystem#getAudioInputStream(f); @@ -15,11 +17,15 @@ read file n is { .format is ~AudioFormat, .stream is ~AudioInputStream } -> number -> 'a = (ch = file.format#getChannels(); - b = new byte[n * ch]; - f = new float[ch][n]; - f); + bbuf = new byte[n * ch * file.format#sampleSizeInBits() / 8]; + fbuf = new float[n * ch]; + file.f#read(bbuf); + //!!! magic here + mat.uninterleave ch fbuf; + ); { - openAudioFile + openAudioFile, + read }
--- a/matrix.yeti Fri Nov 30 18:06:47 2012 +0000 +++ b/matrix.yeti Sun Dec 02 12:09:32 2012 +0000 @@ -1,10 +1,30 @@ module matrix; -zeros n = - map \0 [1..n]; +zeros n = array(map \0 [1..n]); +ones n = array(map \1 [1..n]); -matrix rows cols = - array (map \(new double[cols]) [1..rows]); +generateMatrix f rows cols = array + (map do row: array + (map (f row) [0..cols-1]) + done [0..rows-1]); -{ matrix } +constMatrix n = generateMatrix do row col: n done; +randomMatrix = generateMatrix do row col: Math#random() done; + +zeroMatrix = constMatrix 0; +identityMatrix = constMatrix 1; + +width m = if length m > 0 then length m[0] else 0 fi; + +height m = length m; + +transposed m = array + (map do n: array + (map do a: a[n-1] done m) + done [1..width m]); + +interleaved m = array(concat(transposed m)); + +{ generateMatrix, constMatrix, randomMatrix, zeroMatrix, identityMatrix, interleaved, width, height, zeros, ones, transposed } +