# HG changeset patch # User Chris Cannam # Date 1354450172 0 # Node ID 51c7fea7d8055d1e135340776b7e449c29302e60 # Parent 7aedeab67b08743bf5af37fe5feba99af61d10f8 Matrix bits & bobs diff -r 7aedeab67b08 -r 51c7fea7d805 audio.yeti --- 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 } diff -r 7aedeab67b08 -r 51c7fea7d805 matrix.yeti --- 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 } +