Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. % Alexandre JADIN - Frederic KACZYNSKI
  2. % -----------
  3. % Version 3.0.0.0.1-prealpha-b10056 pa
  4.  
  5. local Mix Interprete Projet CWD ToNote ToDuree Bourdon Etirer Duree Transpose GetH in
  6. % CWD contient le chemin complet vers le dossier contenant le fichier 'code.oz'
  7. % modifiez sa valeur pour correspondre à votre système.
  8. CWD = {Property.condGet 'testcwd' '/home/justice/Documents/Projet2014/'}
  9.  
  10. % Si vous utilisez Mozart 1.4, remplacez la ligne précédente par celle-ci :
  11. % [Projet] = {Link ['Projet2014_mozart1.4.ozf']}
  12. %
  13. % Projet fournit quatre fonctions :
  14. % {Projet.run Interprete Mix Music 'out.wav'} = ok OR error(...)
  15. % {Projet.readFile FileName} = AudioVector OR error(...)
  16. % {Projet.writeFile FileName AudioVector} = ok OR error(...)
  17. % {Projet.load 'music_file.dj.oz'} = La valeur oz contenue dans le fichier chargé (normalement une <musique>).
  18. %
  19. % et une constante :
  20. % Projet.hz = 44100, la fréquence d'échantilonnage (nombre de données par seconde)
  21. [Projet] = {Link [CWD#'Projet2014_mozart2.ozf']}
  22.  
  23. local
  24. Audio = {Projet.readFile CWD#'wave/animaux/cow.wav'}
  25. in
  26. % Mix prends une musique et doit retourner un vecteur audio.
  27. fun {Mix Interprete Music}
  28. local Result in
  29. Result = {Interprete Music.1.1}
  30.  
  31. {Browse Result}
  32. Audio
  33. end
  34. end % fun
  35.  
  36.  
  37. fun{GetH Note}
  38. H in
  39. case Note of note(nom:Nom octave:Octave alteration:none) then
  40. case Nom
  41. of a then H=0
  42. [] b then H=2
  43. [] c then H=~8
  44. [] d then H=~6
  45. [] e then H=~4
  46. [] f then H=~3
  47. [] g then H=~2
  48. end
  49. H+48-12*Octave
  50. [] note(nom:Nom octave:Octave alteration:'# ') then
  51. case Nom
  52. of c then H=~7
  53. [] d then H=~5
  54. [] f then H=~3
  55. [] g then H=~1
  56. [] a then H=1
  57. end
  58. H+48-12*Octave
  59. end %case
  60. end %fun
  61.  
  62. fun {Bourdon ListEchants Note}
  63. case ListEchants
  64. of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then
  65. case Note
  66. of silence then
  67. silence(duree:Duree)|{Bourdon T Note}
  68. else
  69. % TODO Appliquer ToHauteur à Note
  70. echantillon(hauteur:Hauteur-2 duree:Duree instrument:Instrument)|{Bourdon T Note}
  71. end
  72. [] silence(duree:Duree)|T then
  73. silence(duree:Duree)|{Bourdon T Note}
  74. [] nil then
  75. nil
  76. end
  77. end
  78.  
  79. fun {Etirer L Facteur}
  80. case L
  81. of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then
  82. echantillon(hauteur:Hauteur duree:(Duree*Facteur) instrument:Instrument)|{Etirer T Facteur}
  83. [] silence(duree:Duree)|T then
  84. silence(duree:(Duree*Facteur))|{Etirer T Facteur}
  85. [] nil then
  86. nil
  87. end % case
  88. end % fun
  89.  
  90. fun {Duree L Secondes DureeTotale}
  91. case L of echantillon(hauteur:Hauteur duree:DureeEchant instrument:Instrument)|T then
  92. echantillon(hauteur:Hauteur duree:(DureeEchant*Secondes/DureeTotale) instrument:Instrument)|{Duree T Secondes DureeTotale}
  93. [] nil then
  94. nil
  95. [] silence(duree:DureeSilence)|T then
  96. silence(duree:(DureeSilence*Secondes/DureeTotale))|{Duree T Secondes DureeTotale}
  97. [] E then
  98. {Duree [E] Secondes DureeTotale} % TODO
  99. end
  100. end
  101.  
  102. fun {ToNote Note}
  103. case Note
  104. of Nom#Octave then
  105. note(nom:Nom octave:Octave alteration:'# ')
  106. [] Atom then
  107. case {AtomToString Atom}
  108. of [ N ] then
  109. note(nom:Atom octave:4 alteration:none)
  110. [] [N O] then
  111. note(nom:{StringToAtom [N]} octave:{StringToInt [O]} alteration:none)
  112. end
  113. end
  114. end
  115.  
  116. fun{ToDuree EchList}
  117. local ToDuree2 in
  118. fun{ToDuree2 EchantList Acc}
  119. case EchantList of H|T then
  120. Acc=Acc+H.duree
  121. {ToDuree T}
  122. [] nil then
  123. Acc
  124. end %case
  125. end %fun
  126. {ToDuree2 EchList 0}
  127. end %local
  128. end %fun
  129.  
  130. fun{Transpose EchList DemiTons}
  131. case EchList
  132. of echantillon(hauteur:Hauteur duree:Duree instrument:Instrument)|T then
  133. echantillon(hauteur:Hauteur+DemiTons duree:Duree instrument:Instrument)|{Transpose T DemiTons}
  134. [] silence(duree:Duree)|T then
  135. silence(duree:Duree)|{Transpose T DemiTons}
  136. [] nil then
  137. nil
  138. end
  139. end
  140.  
  141.  
  142.  
  143. % Interprete doit interpréter une partition
  144. fun {Interprete Partition}
  145. case Partition
  146. of H|T then
  147. {Append {Interprete H} {Interprete T}}
  148. [] etirer(1:PartitionIn facteur:Facteur) then
  149. {Etirer {Interprete PartitionIn} Facteur}
  150. [] muet(1:PartitionIn) then
  151. {Bourdon {Interprete PartitionIn} silence}
  152. [] duree(1:PartitionIn secondes:Secondes) then
  153. local
  154. ListEchants = {Interprete PartitionIn}
  155. DureeTotale = {ToDuree ListEchants}
  156. in
  157. {Duree ListEchants Secondes DureeTotale}
  158. end
  159. [] bourdon(1:PartitionIn note:Note) then
  160. {Bourdon {Interprete PartitionIn} Note}
  161. [] transpose(1:PartitionIn demitons:Demitons) then
  162. {Transpose {Interprete PartitionIn} Demitons}
  163. [] nil then
  164. nil
  165. [] E then
  166. % TODO Appliquer ToHauteur
  167. local
  168. Note = {ToNote E}
  169. in
  170. [echantillon(hauteur:{GetH Note} duree:1.0 instrument: none)]
  171. end
  172. end % case
  173. end % fun
  174.  
  175. local
  176. Music = {Projet.load CWD#'joie.dj.oz'}
  177. in
  178. % Votre code DOIT appeler Projet.run UNE SEULE fois. Lors de cet appel,
  179. % vous devez mixer une musique qui démontre les fonctionalités de votre
  180. % programme.
  181. %
  182. % Si votre code devait ne pas passer nos tests, cet exemple serait le
  183. % seul qui ateste de la validité de votre implémentation.
  184. {Browse {Projet.run Mix Interprete Music CWD#'out.wav'}}
  185. end
  186. end
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement