PitchDetectionResult.java (3621B)
1 /* 2 * _______ _____ _____ _____ 3 * |__ __| | __ \ / ____| __ \ 4 * | | __ _ _ __ ___ ___ ___| | | | (___ | |__) | 5 * | |/ _` | '__/ __|/ _ \/ __| | | |\___ \| ___/ 6 * | | (_| | | \__ \ (_) \__ \ |__| |____) | | 7 * |_|\__,_|_| |___/\___/|___/_____/|_____/|_| 8 * 9 * ------------------------------------------------------------- 10 * 11 * TarsosDSP is developed by Joren Six at IPEM, University Ghent 12 * 13 * ------------------------------------------------------------- 14 * 15 * Info: http://0110.be/tag/TarsosDSP 16 * Github: https://github.com/JorenSix/TarsosDSP 17 * Releases: http://0110.be/releases/TarsosDSP/ 18 * 19 * TarsosDSP includes modified source code by various authors, 20 * for credits and info, see README. 21 * 22 */ 23 24 package be.tarsos.dsp.pitch; 25 26 27 /** 28 * A class with information about the result of a pitch detection on a block of 29 * audio. 30 * 31 * It contains: 32 * 33 * <ul> 34 * <li>The pitch in Hertz.</li> 35 * <li>A probability (noisiness, (a)periodicity, salience, voicedness or clarity 36 * measure) for the detected pitch. This is somewhat similar to the term voiced 37 * which is used in speech recognition. This probability should be calculated 38 * together with the pitch. The exact meaning of the value depends on the detector used.</li> 39 * <li>A way to calculate the RMS of the signal.</li> 40 * <li>A boolean that indicates if the algorithm thinks the signal is pitched or 41 * not.</li> 42 * </ul> 43 * 44 * The separate pitched or unpitched boolean can coexist with a defined pitch. 45 * E.g. if the algorithm detects 220Hz in a noisy signal it may respond with 46 * 220Hz "unpitched". 47 * 48 * <p> 49 * For performance reasons the object is reused. Please create a copy of the object 50 * if you want to use it on an other thread. 51 * 52 * 53 * @author Joren Six 54 */ 55 public class PitchDetectionResult { 56 /** 57 * The pitch in Hertz. 58 */ 59 private float pitch; 60 61 private float probability; 62 63 private boolean pitched; 64 65 public PitchDetectionResult(){ 66 pitch = -1; 67 probability = -1; 68 pitched = false; 69 } 70 71 /** 72 * A copy constructor. Since PitchDetectionResult objects are reused for performance reasons, creating a copy can be practical. 73 * @param other 74 */ 75 public PitchDetectionResult(PitchDetectionResult other){ 76 this.pitch = other.pitch; 77 this.probability = other.probability; 78 this.pitched = other.pitched; 79 } 80 81 82 /** 83 * @return The pitch in Hertz. 84 */ 85 public float getPitch() { 86 return pitch; 87 } 88 89 public void setPitch(float pitch) { 90 this.pitch = pitch; 91 } 92 93 /* (non-Javadoc) 94 * @see java.lang.Object#clone() 95 */ 96 public PitchDetectionResult clone(){ 97 return new PitchDetectionResult(this); 98 } 99 100 /** 101 * @return A probability (noisiness, (a)periodicity, salience, voicedness or 102 * clarity measure) for the detected pitch. This is somewhat similar 103 * to the term voiced which is used in speech recognition. This 104 * probability should be calculated together with the pitch. The 105 * exact meaning of the value depends on the detector used. 106 */ 107 public float getProbability() { 108 return probability; 109 } 110 111 public void setProbability(float probability) { 112 this.probability = probability; 113 } 114 115 /** 116 * @return Whether the algorithm thinks the block of audio is pitched. Keep 117 * in mind that an algorithm can come up with a best guess for a 118 * pitch even when isPitched() is false. 119 */ 120 public boolean isPitched() { 121 return pitched; 122 } 123 124 public void setPitched(boolean pitched) { 125 this.pitched = pitched; 126 } 127 }