Changeset 6853
- Timestamp:
- 10/11/06 00:55:36 (5 years ago)
- Location:
- trunk/Jav_Audio/com/scenari/s/audio
- Files:
-
- 2 edited
-
Util.java (modified) (4 diffs)
-
transform/TransformerSox.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jav_Audio/com/scenari/s/audio/Util.java
r6850 r6853 5 5 import java.util.StringTokenizer; 6 6 7 import org.w3c.dom.Element; 8 import org.w3c.dom.Node; 9 7 10 public class Util { 8 11 12 /** Mode d'une track : track vide (aucun segment). */ 13 public static final String TRACKMODE_EMPTY = "empty"; 14 15 /** Mode d'une track : contigue : une seule source, segments adjacents. */ 16 public static final String TRACKMODE_CONTIGUOUS = "contiguous"; 17 9 18 /** 10 * Parsing d'un timeCode.11 * TODO Format à décider.19 * Mode d'une track : contigue : une seule source, mais segments 20 * discontinus. 12 21 */ 13 public static float parseTc(String pTc, float pDefault){ 22 public static final String TRACKMODE_DISCONTINUOUS = "discontinuous"; 23 24 /** Mode d'une track : assemblage de différentes sources. */ 25 public static final String TRACKMODE_ASSEMB = "assemb"; 26 27 /** Mode d'une track : track d'auto-segmentation. */ 28 public static final String TRACKMODE_SELFSEG = "selfSeg"; 29 30 /** 31 * Parsing d'un timeCode. TODO Format à décider. 32 */ 33 public static float parseTc(String pTc, float pDefault) { 14 34 try { 15 35 return Float.parseFloat(pTc); 16 } catch (NumberFormatException e) {36 } catch (NumberFormatException e) { 17 37 return pDefault; 18 38 } 19 39 } 20 40 21 41 /** 22 42 * Parsing d'un float (volume). 23 43 */ 24 public static float parseFloat(String pFloat, float pDefault) {44 public static float parseFloat(String pFloat, float pDefault) { 25 45 try { 26 46 return Float.parseFloat(pFloat); 27 } catch (NumberFormatException e) {47 } catch (NumberFormatException e) { 28 48 return pDefault; 29 49 } 30 50 } 51 31 52 /** 32 53 * Sérialize d'un timeCode. 33 54 */ 34 public static String serializeTc(float pTc) {35 if (pTc == 0) return "0";55 public static String serializeTc(float pTc) { 56 if (pTc == 0) return "0"; 36 57 return Float.toString(pTc); 37 58 } 38 59 39 60 /** 40 61 * Parsing d'un float (volume). 41 62 */ 42 public static String serializeFloat(float pFloat) {43 if (pFloat == 0) return "0";44 if (pFloat == 1) return "1";63 public static String serializeFloat(float pFloat) { 64 if (pFloat == 0) return "0"; 65 if (pFloat == 1) return "1"; 45 66 return Float.toString(pFloat); 46 67 } 47 48 68 49 69 /** 50 * Gestion des listes de codes de tracks 51 * Construit un tableau. 70 * Gestion des listes de codes de tracks Construit un tableau. 52 71 */ 53 72 public static List split(String pVal) { … … 68 87 69 88 /** 70 * Gestion des listes de codes de tracks 71 * intersection de 2 listes de tracks. 89 * Gestion des listes de codes de tracks intersection de 2 listes de tracks. 72 90 */ 73 91 public static List intersect(List p1, List p2) { … … 83 101 84 102 /** 85 * Gestion des listes de codes de tracks : 86 * reconstruit une sous-liste de pValues en fonction des entrées dans pList correspondant aux keys de pKeys. 103 * Gestion des listes de codes de tracks : reconstruit une sous-liste de 104 * pValues en fonction des entrées dans pList correspondant aux keys de 105 * pKeys. 87 106 */ 88 107 public static String joinMap(List pList, List pKeys, List pValues) { … … 98 117 return vBuf.toString(); 99 118 } 119 120 public static String getTrackMode(Node pNode) { 121 String vPreviousUri = null; 122 String vPreviousEnd = null; 123 boolean vIsEmpty = true; 124 boolean vIsSameSrc = true; 125 boolean vIsContiguous = true; 126 for (Node vNode = pNode; vNode != null; vNode = vNode.getNextSibling()) { 127 if (vNode.getNodeName().equals("selfSeg")) { 128 return TRACKMODE_SELFSEG; 129 } else if (vNode.getNodeName().equals("seg")) { 130 if (vPreviousUri != null) { 131 if (vIsSameSrc) { 132 String vUri = ((Element) vNode).getAttribute("refUri"); 133 if (vUri != null && vUri.length() > 0) { 134 if (!vUri.equals(vPreviousUri)) { 135 vIsSameSrc = false; 136 continue; 137 } 138 if (vIsContiguous) { 139 String vStart = ((Element) vNode).getAttribute("start"); 140 if (vPreviousEnd == null || vStart == null || !vPreviousEnd.equals(vStart)) vIsContiguous = false; 141 vPreviousEnd = ((Element) vNode).getAttribute("end"); 142 } 143 } 144 } 145 } else { 146 // 1er segment 147 if (vIsEmpty) vIsEmpty = false; 148 vPreviousUri = ((Element) vNode).getAttribute("refUri"); 149 String vStart = ((Element) vNode).getAttribute("start"); 150 if (parseTc(vStart, 0) != 0) vIsContiguous = false; 151 vPreviousEnd = ((Element) vNode).getAttribute("end"); 152 } 153 } 154 } 155 if (vIsEmpty) return TRACKMODE_EMPTY; 156 if (!vIsSameSrc) return TRACKMODE_ASSEMB; 157 return vIsContiguous ? TRACKMODE_CONTIGUOUS : TRACKMODE_DISCONTINUOUS; 158 } 159 160 /** 161 * Pour les tracks de type TRACKMODE_DISCONTINUOUS ou TRACKMODE_CONTIGUOUS, 162 * retourne la source unique. 163 */ 164 public static String getTrackRefUri(Node pNode) { 165 for (Node vNode = pNode; vNode != null; vNode = vNode.getNextSibling()) { 166 if (vNode.getNodeName().equals("seg")) { 167 String vUri = ((Element) vNode).getAttribute("refUri"); 168 if (vUri != null && vUri.length() > 0) return vUri; 169 } 170 } 171 return ""; 172 } 100 173 } -
trunk/Jav_Audio/com/scenari/s/audio/transform/TransformerSox.java
r6850 r6853 95 95 ArrayList vCmds = new ArrayList(32); 96 96 vCmds.add(new File(sUrlExe).getCanonicalPath()); 97 if(pVolume>=0 && pVolume < 1) { 98 vCmds.add("-v"); 99 vCmds.add(Float.toString(pVolume)); 100 } 97 101 vCmds.add(pSrc.getCanonicalPath()); 98 102 vTmp = setParamDst(vCmds, vEncod, pDst); 103 104 if(pStart > 0 || pEnd >= 0) { 105 vCmds.add("trim"); 106 vCmds.add(serializeSoxTc(pStart)); 107 if(pEnd >= pStart) vCmds.add(serializeSoxTc(pEnd - pStart)); 108 } 109 110 if(pFadeIn>0 || (pFadeOut > 0 && pEnd >= 0) ) { 111 vCmds.add("fade"); 112 vCmds.add("q"); 113 vCmds.add(serializeSoxTc(pFadeIn)); 114 if(pFadeOut > 0) { 115 vCmds.add(serializeSoxTc(pEnd - pStart)); 116 vCmds.add(serializeSoxTc(pFadeOut)); 117 } 118 } 119 99 120 100 121 String[] vCommands = (String[])vCmds.toArray(new String[vCmds.size()]); … … 114 135 } 115 136 } 137 } 138 139 140 /** 141 * Sérialize d'un timeCode. 142 */ 143 public static String serializeSoxTc(float pTc){ 144 if(pTc == 0) return "0"; 145 String vH = null; 146 if(pTc>3600){ 147 vH = Integer.toString((int) (pTc / 3600)); 148 pTc = pTc % 3600; 149 } 150 String vM = null; 151 if(pTc>60){ 152 vM = Integer.toString((int) (pTc / 60)); 153 pTc = pTc % 60; 154 } 155 if(vH == null && vM == null) return Float.toString(pTc); 156 StringBuffer vBuf = new StringBuffer(12); 157 if(vH != null) { 158 vBuf.append(vH); 159 vBuf.append(':'); 160 } 161 if(vM != null) { 162 vBuf.append(vM); 163 vBuf.append(':'); 164 } 165 vBuf.append(Float.toString(pTc)); 166 return vBuf.toString(); 116 167 } 117 168
Note: See TracChangeset
for help on using the changeset viewer.