 #   T h i s   s c r i p t   g o e s   t h r o u g h   s o u n d   a n d   T e x t G r i d   f i l e s   i n   a   d i r e c t o r y , 
 #   o p e n s   e a c h   p a i r   o f   S o u n d   a n d   T e x t G r i d ,   c a l c u l a t e s   t h e   d u r a t i o n 
 #   o f   e a c h   l a b e l e d   i n t e r v a l   i n   t h e   p h o n e   t i e r ,   
 #   t h e   p i t c h   m a x i m u m   a t   t h e   c e n t e r   o f   t h e   p h o n e ,   a n d 
 #   t h e   d u r a t i o n   o f   t h e   c o r r e s p o n d i n g   i n t e r v a l   i n   t h e   s y l l a b l e   t i e r ,   
 #   a n d   t h e n   s a v e s   t h e   r e s u l t s   t o   a   t e x t   f i l e . 
 # 
 #   T o   m a k e   s o m e   o t h e r   o r   a d d i t i o n a l   a n a l y s e s ,   y o u   c a n   m o d i f y   t h e   s c r i p t 
 #   y o u r s e l f . . .   i t   s h o u l d   b e   r e a s o n a b l y   w e l l   c o m m e n t e d !   ; ) 
 # 
 #   T h i s   s c r i p t   i s   d i s t r i b u t e d   u n d e r   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e . 
 #   C o p y r i g h t   2 5 . 1 1 . 2 0 0 4   M i e t t a   L e n n e s 
 
 f o r m   A n a l y z e   d u r a t i o n s   o f   p h o n e s   a n d   t h e   c o r r e s p o n d i n g   s y l l a b l e s 
 	 c o m m e n t   D i r e c t o r y   o f   s o u n d   f i l e s 
 	 #   t e x t   s o u n d _ d i r e c t o r y   / h o m e / l e n n e s / k y s y m y k s e t /   # 
 
 #   P F A D   F  R   P C : 
 	 #   t e x t   s o u n d _ d i r e c t o r y   D : \ W e i r i c h \ Z A S \ L e h r e \ P r a a t _ W o r k s h o p \ a u d i o \ 
 
 # # # # # # #   H I E R   D E N   P F A D   Z U   D E N   A U D I O   F I L E S   A N P A S S E N :     # # # # # # # # # # # # # # # # # # # # # # # # 
 
 # P F A D   F  R   M A C S 
 t e x t   s o u n d _ d i r e c t o r y   / U s e r s / s t e f / D e s k t o p / d a t a / e i n z e l n e _ f i l e s / 
 
 
 	 #   s e n t e n c e   S o u n d _ f i l e _ e x t e n s i o n   . a i f 
                     s e n t e n c e   S o u n d _ f i l e _ e x t e n s i o n   . w a v 
 	 c o m m e n t   D i r e c t o r y   o f   T e x t G r i d   f i l e s 
 	 #   t e x t   t e x t G r i d _ d i r e c t o r y   / h o m e / l e n n e s / k y s y m y k s e t /   # 
 
 #   P F A D   F  R   P C : 
 	 #   t e x t   t e x t G r i d _ d i r e c t o r y   D : \ W e i r i c h \ Z A S \ L e h r e \ P r a a t _ W o r k s h o p \ a u d i o \ 
 
 # # # # # # #   H I E R   D E N   P F A D   Z U   D E N   T E X T G R I D S   A N P A S S E N     # # # # # # # # # # # # # # # # # # # # # # # # # # 
 
 # P F A D   F  R   M A C S 
 t e x t   t e x t G r i d _ d i r e c t o r y   / U s e r s / s t e f / D e s k t o p / d a t a / e i n z e l n e _ f i l e s / 
 
 
 
 	 #   s e n t e n c e   T e x t G r i d _ f i l e _ e x t e n s i o n   . T e x t G r i d 
 	     s e n t e n c e   T e x t G r i d _ f i l e _ e x t e n s i o n   . T e x t G r i d 
 	 c o m m e n t   F u l l   p a t h   o f   t h e   r e s u l t i n g   t e x t   f i l e : 
 	 #   t e x t   r e s u l t f i l e   / h o m e / l e n n e s / k y s y m y k s e t / p i t c h r e s u l t s . t x t   # 
 
 #   P F A D   F  R   P C : 
 	 #   t e x t   r e s u l t f i l e   D : \ W e i r i c h \ Z A S \ L e h r e \ P r a a t _ W o r k s h o p \ a u d i o \ t e s t . t x t 
 
 # # # # # # #   H I E R   D E N   P F A D   Z U M   R E S U L T A T E - F I L E   A N P A S S E N     # # # # # # # # # # # # # # # # # # # # # # # # # 
 
 # P F A D   F  R   M A C S 
 t e x t   r e s u l t f i l e   / U s e r s / s t e f / D e s k t o p / d a t a / e i n z e l n e _ f i l e s / d a u e r _ r e s u l t a t e . t x t 
 
 	 c o m m e n t   W h i c h   t i e r   c o n t a i n s   t h e   s p e e c h   s o u n d   s e g m e n t s ? 
 	 #   s e n t e n c e   P h o n e _ t i e r   p h o n e   # 
 	     s e n t e n c e   P h o n e _ t i e r   S e g m e n t e 
 	 c o m m e n t   W h i c h   t i e r   c o n t a i n s   t h e   s y l l a b l e   s e g m e n t s ? 
 	 #   s e n t e n c e   S y l l a b l e _ t i e r   s y l l a b l e 
 	 #     s e n t e n c e   S y l l a b l e _ t i e r   W  r t e r 
 	 c o m m e n t   P i t c h   a n a l y s i s   p a r a m e t e r s 
 	   r e a l   T i m e _ s t e p   0 . 0   ( = a u t o ) 
 	   p o s i t i v e   M i n i m u m _ p i t c h   7 5 
 	   p o s i t i v e   M a x i m u m _ p i t c h   5 0 0 
 e n d f o r m 
 
 #   H e r e ,   y o u   m a k e   a   l i s t i n g   o f   a l l   t h e   s o u n d   f i l e s   i n   a   d i r e c t o r y . 
 #   T h e   e x a m p l e   g e t s   f i l e   n a m e s   e n d i n g   w i t h   " . a i f "   f r o m   C : \ k y s y m y k s e t \ 
 
 C r e a t e   S t r i n g s   a s   f i l e   l i s t . . .   l i s t   ' s o u n d _ d i r e c t o r y $ ' * ' s o u n d _ f i l e _ e x t e n s i o n $ ' 
 n u m b e r O f F i l e s   =   G e t   n u m b e r   o f   s t r i n g s 
 
 #   C h e c k   i f   t h e   r e s u l t   f i l e   e x i s t s : 
 i f   f i l e R e a d a b l e   ( r e s u l t f i l e $ ) 
 	 p a u s e   T h e   r e s u l t   f i l e   ' r e s u l t f i l e $ '   a l r e a d y   e x i s t s !   D o   y o u   w a n t   t o   o v e r w r i t e   i t ? 
 	 f i l e d e l e t e   " ' r e s u l t f i l e $ ' " 
 e n d i f 
 
 #   W r i t e   a   r o w   w i t h   c o l u m n   t i t l e s   t o   t h e   r e s u l t   f i l e : 
 #   ( r e m e m b e r   t o   e d i t   t h i s   i f   y o u   a d d   o r   c h a n g e   t h e   a n a l y s e s ! ) 
 
 t i t l e l i n e $   =   " F i l e n a m e 	 P h o n e   l a b e l 	 S t a r t i n g   p o i n t 	 E n d   p o i n t 	 D u r a t i o n 	 p i t c h   m a x 	 ' n e w l i n e $ ' " 
 f i l e a p p e n d   " ' r e s u l t f i l e $ ' "   ' t i t l e l i n e $ ' 
 
 #   G o   t h r o u g h   a l l   t h e   s o u n d   f i l e s ,   o n e   b y   o n e : 
 
 f o r   i f i l e   t o   n u m b e r O f F i l e s 
 	 f i l e n a m e $   =   G e t   s t r i n g . . .   i f i l e 
 	 #   A   s o u n d   f i l e   i s   o p e n e d   f r o m   t h e   l i s t i n g : 
 	 R e a d   f r o m   f i l e . . .   ' s o u n d _ d i r e c t o r y $ ' ' f i l e n a m e $ ' 
 	 #   S t a r t i n g   f r o m   h e r e ,   y o u   c a n   a d d   e v e r y t h i n g   t h a t   s h o u l d   b e   
 	 #   r e p e a t e d   f o r   e v e r y   s o u n d   f i l e   t h a t   w a s   o p e n e d : 
 	 s o u n d n a m e $   =   s e l e c t e d $   ( " S o u n d " ,   1 ) 
 	 #   O p e n   a   T e x t G r i d   b y   t h e   s a m e   n a m e : 
 	 g r i d f i l e $   =   " ' t e x t G r i d _ d i r e c t o r y $ ' ' s o u n d n a m e $ ' ' t e x t G r i d _ f i l e _ e x t e n s i o n $ ' " 
 	 i f   f i l e R e a d a b l e   ( g r i d f i l e $ ) 
 	 	 R e a d   f r o m   f i l e . . .   ' g r i d f i l e $ ' 
 	 	 #   F i n d   t h e   t i e r   n u m b e r   t h a t   h a s   t h e   l a b e l   g i v e n   i n   t h e   f o r m : 
 	 	 c a l l   G e t T i e r   ' p h o n e _ t i e r $ '   p h o n e _ t i e r 
 	 	 #   c a l l   G e t T i e r   ' s y l l a b l e _ t i e r $ '   s y l l a b l e _ t i e r 
 	 	 i f   p h o n e _ t i e r   >   0   
 	 	 #   a n d   s y l l a b l e _ t i e r   >   0 
 	 	 	 n u m b e r O f I n t e r v a l s   =   G e t   n u m b e r   o f   i n t e r v a l s . . .   p h o n e _ t i e r 
 	 	 	 p r e c e d i n g _ l a b e l $   =   " " 
 	 	 	 s e l e c t   S o u n d   ' s o u n d n a m e $ ' 
 	 	         T o   P i t c h . . .   t i m e _ s t e p   m i n i m u m _ p i t c h   m a x i m u m _ p i t c h 
 	 	 	 s e l e c t   T e x t G r i d   ' s o u n d n a m e $ ' 
 	 	 	 #   P a s s   t h r o u g h   a l l   i n t e r v a l s   i n   t h e   s e l e c t e d   p h o n e   t i e r : 
 	 	 	 f o r   i n t e r v a l   t o   n u m b e r O f I n t e r v a l s 
 	 	 	 	 l a b e l $   =   G e t   l a b e l   o f   i n t e r v a l . . .   p h o n e _ t i e r   i n t e r v a l 
 	 	 	 	 i f   l a b e l $   < >   " " 
 	 	 	 	 	 #   i f   t h e   i n t e r v a l   h a s   a n   u n e m p t y   l a b e l ,   g e t   i t s   s t a r t   a n d   e n d : 
 	 	 	 	 	 s t a r t   =   G e t   s t a r t i n g   p o i n t . . .   p h o n e _ t i e r   i n t e r v a l 
 	 	 	 	 	 e n d   =   G e t   e n d   p o i n t . . .   p h o n e _ t i e r   i n t e r v a l 
 	 	 	 	 	 #   g e t   t h e   d u r a t i o n   o f   t h e   p h o n e   s e g m e n t 
 	 	 	 	 	     p h o n e d u r   =   e n d   -   s t a r t 
 	 	 	 	 	 #   g e t   t h e   t i m e   a t   t h e   m i d d l e   o f   t h e   p h o n e : 
 	 	 	 	 	     p h o n e c e n t e r   =   ( s t a r t   +   e n d )   /   2 
 	 	 	 	           s e l e c t   P i t c h   ' s o u n d n a m e $ ' 
 	 	 	 	           p i t c h m a x   =   G e t   m a x i m u m . . .   s t a r t   e n d   H e r t z   P a r a b o l i c 
 	 	 	 	 	 s e l e c t   T e x t G r i d   ' s o u n d n a m e $ ' 
 	 	 	 	 	 #   g e t   t h e   s y l l a b l e   i n t e r v a l   n u m b e r   a t   t h e   p h o n e   c e n t e r : 
 	 	 	 	 	 #     s y l l a b l e   =   G e t   i n t e r v a l   a t   t i m e . . .   s y l l a b l e _ t i e r   p h o n e c e n t e r 
 	 	 	 	                 #   g e t   t h e   l a b e l   o f   t h a t   s y l l a b l e : 
 	 	 	 	 	 #     s y l l a b l e _ l a b e l $   =   G e t   l a b e l   o f   i n t e r v a l . . .   s y l l a b l e _ t i e r   s y l l a b l e 
 	 	 	 	 	 #     s y l l s t a r t   =   G e t   s t a r t i n g   p o i n t . . .   s y l l a b l e _ t i e r   s y l l a b l e 
 	 	 	 	 	 #     s y l l e n d   =   G e t   e n d   p o i n t . . .   s y l l a b l e _ t i e r   s y l l a b l e 
 	 	 	 	 	 #   g e t   t h e   d u r a t i o n   o f   t h e   s y l l a b l e   s e g m e n t : 
 	 	 	 	 	 #     s y l l a b l e d u r   =   s y l l e n d   -   s y l l s t a r t 
 	 	 	 	 	 #   S a v e   r e s u l t   t o   t e x t   f i l e : 
 	 	 	 	 	 r e s u l t l i n e $   =   " ' s o u n d n a m e $ ' 	 ' l a b e l $ ' 	 ' s t a r t ' 	 ' e n d ' 	 ' p h o n e d u r ' 	 ' p i t c h m a x ' 	 ' n e w l i n e $ ' " 
 	 	 	 	 	 f i l e a p p e n d   " ' r e s u l t f i l e $ ' "   ' r e s u l t l i n e $ ' 
 	 	 	 	 	 s e l e c t   T e x t G r i d   ' s o u n d n a m e $ ' 
 	 	 	 	 e n d i f 
 	 	 	 	 p r e c e d i n g _ l a b e l $   =   l a b e l $ 
 	 	 	 e n d f o r 
 	 	 	   # R e m o v e   t h e   P i t c h   o b j e c t 
 	 	           s e l e c t   P i t c h   ' s o u n d n a m e $ ' 
 	 	           R e m o v e 
 	 	 e n d i f 
 	 	   # R e m o v e   t h e   T e x t G r i d   o b j e c t   f r o m   t h e   o b j e c t   l i s t 
 	 	 s e l e c t   T e x t G r i d   ' s o u n d n a m e $ ' 
 	 	 R e m o v e 
 	 e n d i f 
 	 #   R e m o v e   t h e   s o u n d   o b j e c t   f r o m   t h e   o b j e c t   l i s t 
 	 s e l e c t   S o u n d   ' s o u n d n a m e $ ' 
 	 R e m o v e 
 	 s e l e c t   S t r i n g s   l i s t 
 	 #   a n d   g o   o n   w i t h   t h e   n e x t   s o u n d   f i l e ! 
 e n d f o r 
 
 R e m o v e 
 
 
 # - - - - - - - - - - - - - 
 #   T h i s   p r o c e d u r e   f i n d s   t h e   n u m b e r   o f   a   t i e r   t h a t   h a s   a   g i v e n   l a b e l . 
 
 p r o c e d u r e   G e t T i e r   n a m e $   v a r i a b l e $ 
                 n u m b e r O f T i e r s   =   G e t   n u m b e r   o f   t i e r s 
                 i t i e r   =   1 
                 r e p e a t 
                                 t i e r $   =   G e t   t i e r   n a m e . . .   i t i e r 
                                 i t i e r   =   i t i e r   +   1 
                 u n t i l   t i e r $   =   n a m e $   o r   i t i e r   >   n u m b e r O f T i e r s 
                 i f   t i e r $   < >   n a m e $ 
                                 ' v a r i a b l e $ '   =   0 
                 e l s e 
                                 ' v a r i a b l e $ '   =   i t i e r   -   1 
                 e n d i f 
 
 	 i f   ' v a r i a b l e $ '   =   0 
 	 	 p r i n t l i n e   T h e   t i e r   c a l l e d   ' n a m e $ '   i s   m i s s i n g   f r o m   t h e   f i l e   ' s o u n d n a m e $ ' ! 
 	 e n d i f 
 
 e n d p r o c 
