Mercurial > hg > cmdp
view src/uk/ac/qmul/eecs/depic/daw/Chunk.java @ 2:c0412c81d274
Added documentation
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Thu, 18 Feb 2016 18:35:26 +0000 |
parents | 629262395647 |
children |
line wrap: on
line source
/* Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation. Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package uk.ac.qmul.eecs.depic.daw; import uk.ac.qmul.eecs.depic.patterns.MathUtils; import uk.ac.qmul.eecs.depic.patterns.Range; /** * * A Chunk is a set of contiguous audio samples. It is used in the visual representation of a sound wave where only the maximum * and minimum values of all the samples are taken into account. In the sound wave a chuck would be drawn as a vertical * line at a specific x position, all the contiguous chunks make the sound wave as usually drawn. * */ public class Chunk extends Range<Float> { public static final Chunk SILENCE = new Chunk((short)0,(short)0); private float normalizedStart; private float normalizedEnd; public Chunk(Chunk chunk1, Chunk chunk2) { super(chunk1, chunk2); normalizedStart = Math.min(chunk1.getNormStart(), chunk2.getNormStart()); normalizedEnd = Math.max(chunk1.getNormEnd(), chunk2.getNormEnd()); } public Chunk(Short s1, Short s2) { normalizedStart = (s1-Short.MIN_VALUE)/(float)domain(); normalizedEnd = (s2-Short.MIN_VALUE)/(float)domain(); MathUtils.Scale scale = new MathUtils.Scale(0.0f, 1.0f, -1.0f, 1.0f); start = scale.linear(normalizedStart); end = scale.linear(normalizedEnd); } public static int domain() { return Short.MAX_VALUE - Short.MIN_VALUE; } public float getNormStart(){ return normalizedStart; } public float getNormEnd(){ return normalizedEnd; } @Override public String toString(){ return "Chunk - range:["+getStart()+","+getEnd()+"] normalized range ["+getNormStart()+","+getNormEnd()+"]" ; } }