Changeset 6853


Ignore:
Timestamp:
10/11/06 00:55:36 (5 years ago)
Author:
sys
Message:

ModelingSound...

Location:
trunk/Jav_Audio/com/scenari/s/audio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Audio/com/scenari/s/audio/Util.java

    r6850 r6853  
    55import java.util.StringTokenizer; 
    66 
     7import org.w3c.dom.Element; 
     8import org.w3c.dom.Node; 
     9 
    710public 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 
    918        /** 
    10          * Parsing d'un timeCode. 
    11          * TODO Format à décider. 
     19         * Mode d'une track : contigue : une seule source, mais segments 
     20         * discontinus. 
    1221         */ 
    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) { 
    1434                try { 
    1535                        return Float.parseFloat(pTc); 
    16                 }catch (NumberFormatException e) { 
     36                } catch (NumberFormatException e) { 
    1737                        return pDefault; 
    1838                } 
    1939        } 
    20          
     40 
    2141        /** 
    2242         * Parsing d'un float (volume). 
    2343         */ 
    24         public static float parseFloat(String pFloat, float pDefault){ 
     44        public static float parseFloat(String pFloat, float pDefault) { 
    2545                try { 
    2646                        return Float.parseFloat(pFloat); 
    27                 }catch (NumberFormatException e) { 
     47                } catch (NumberFormatException e) { 
    2848                        return pDefault; 
    2949                } 
    3050        } 
     51 
    3152        /** 
    3253         * Sérialize d'un timeCode. 
    3354         */ 
    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"; 
    3657                return Float.toString(pTc); 
    3758        } 
    38          
     59 
    3960        /** 
    4061         * Parsing d'un float (volume). 
    4162         */ 
    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"; 
    4566                return Float.toString(pFloat); 
    4667        } 
    47          
    4868 
    4969        /** 
    50          * Gestion des listes de codes de tracks 
    51          * Construit un tableau. 
     70         * Gestion des listes de codes de tracks Construit un tableau. 
    5271         */ 
    5372        public static List split(String pVal) { 
     
    6887 
    6988        /** 
    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. 
    7290         */ 
    7391        public static List intersect(List p1, List p2) { 
     
    83101 
    84102        /** 
    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. 
    87106         */ 
    88107        public static String joinMap(List pList, List pKeys, List pValues) { 
     
    98117                return vBuf.toString(); 
    99118        } 
     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        } 
    100173} 
  • trunk/Jav_Audio/com/scenari/s/audio/transform/TransformerSox.java

    r6850 r6853  
    9595                ArrayList vCmds = new ArrayList(32); 
    9696            vCmds.add(new File(sUrlExe).getCanonicalPath()); 
     97                if(pVolume>=0 && pVolume < 1) { 
     98                        vCmds.add("-v"); 
     99                        vCmds.add(Float.toString(pVolume)); 
     100                } 
    97101            vCmds.add(pSrc.getCanonicalPath()); 
    98102            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             
    99120             
    100121            String[] vCommands = (String[])vCmds.toArray(new String[vCmds.size()]); 
     
    114135                        } 
    115136        } 
     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(); 
    116167        } 
    117168         
Note: See TracChangeset for help on using the changeset viewer.