Mercurial > hg > constant-q-cpp
diff yeti/cqt.yeti @ 72:642df7b3346f
Support returning a magnitude spectrum (dense) etc
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 20 Mar 2014 16:15:43 +0000 |
parents | 417489c0d9c2 |
children | be277d1367f4 |
line wrap: on
line diff
--- a/yeti/cqt.yeti Wed Mar 19 10:30:20 2014 +0000 +++ b/yeti/cqt.yeti Thu Mar 20 16:15:43 2014 +0000 @@ -33,6 +33,7 @@ cqtkernel = load cqtkernel; resample = load may.stream.resample; manipulate = load may.stream.manipulate; +mat = load may.matrix; cm = load may.matrix.complex; framer = load may.stream.framer; cplx = load may.complex; @@ -175,7 +176,36 @@ done { rows, columns }; ); - processOctaveLists octs = + assembleBlockSpectrogram bits = + (// As assembleBlock, but producing a dense magnitude + // spectrogram (rather than a complex output with zeros + // between the cell values in lower octaves). (todo: smoothing) + + //eprintln "assembleBlockSpectrogram: structure of bits is:"; + //eprintln (map length bits); + + rows = octaves * kdata.binsPerOctave; + columns = (pow 2 (octaves - 1)) * kdata.atomsPerFrame; + + mat.generate do row col: + + oct = int (row / binsPerOctave); + binNo = row % kdata.binsPerOctave; + + chunks = pow 2 oct; + colsPerAtom = int (columns / (chunks * kdata.atomsPerFrame)); + atomNo = int (col / colsPerAtom); + + if atomNo < length bits[oct] then + cplx.magnitude bits[oct][atomNo][binNo]; + else + 0 + fi; + + done { rows, columns }; + ); + + processOctaveLists assembler octs = case octs[0] of block::rest: (toAssemble = array @@ -189,7 +219,7 @@ array [] fi done (keys octs)); - assembleBlock toAssemble :. \(processOctaveLists octs)); + assembler toAssemble :. \(processOctaveLists assembler octs)); _: [] esac; @@ -218,7 +248,14 @@ done (reverse (list kdata.binFrequencies)) done [0..octaves-1]) }, - output = processOctaveLists octaveLists + octaves, + output type = + case type of + ComplexCQ (): + Complex (processOctaveLists assembleBlock octaveLists); + Spectrogram (): + Real (processOctaveLists assembleBlockSpectrogram octaveLists); + esac } );