cutcutcodec 1.0.post3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cutcutcodec might be problematic. Click here for more details.

Files changed (233) hide show
  1. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__init__.py +6 -0
  2. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__main__.py +38 -0
  3. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/c_build.py +33 -0
  4. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/__init__.py +3 -0
  5. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/__init__.py +3 -0
  6. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/_helper_properties.py +52 -0
  7. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/__init__.py +3 -0
  8. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/__init__.py +3 -0
  9. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/duration.py +83 -0
  10. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/ffprobe.py +637 -0
  11. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/__init__.py +3 -0
  12. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/find.py +82 -0
  13. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/time_backprop.py +68 -0
  14. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/__init__.py +3 -0
  15. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_audio.py +239 -0
  16. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_video.py +97 -0
  17. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/shape.py +107 -0
  18. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/time_backprop.py +183 -0
  19. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/__init__.py +3 -0
  20. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/__init__.py +3 -0
  21. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/duration.py +162 -0
  22. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/nb_frames.py +159 -0
  23. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/rate.py +102 -0
  24. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/timestamps.py +194 -0
  25. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/__init__.py +3 -0
  26. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/container.py +40 -0
  27. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/encoder.py +152 -0
  28. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/filter.py +33 -0
  29. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame.py +127 -0
  30. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_audio.py +205 -0
  31. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_video.py +322 -0
  32. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/layout.py +206 -0
  33. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/meta_filter.py +41 -0
  34. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/muxer.py +184 -0
  35. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/node.py +164 -0
  36. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream.py +182 -0
  37. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_audio.py +130 -0
  38. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_video.py +193 -0
  39. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/__init__.py +7 -0
  40. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/ast_to_file.py +125 -0
  41. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/__init__.py +6 -0
  42. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/compatibility.py +734 -0
  43. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/default.py +99 -0
  44. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/encodec.py +40 -0
  45. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/muxer.py +8 -0
  46. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/rate.py +133 -0
  47. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_ast.py +477 -0
  48. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_json.py +104 -0
  49. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_tree.py +190 -0
  50. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/json_to_graph.py +114 -0
  51. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/parse.py +123 -0
  52. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/__init__.py +15 -0
  53. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/dynamic.py +544 -0
  54. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/lambdify.py +612 -0
  55. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/preprocess.py +698 -0
  56. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/printer.py +926 -0
  57. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/tree_to_graph.py +168 -0
  58. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/__init__.py +3 -0
  59. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/decision/__init__.py +8 -0
  60. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/__init__.py +3 -0
  61. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/add.py +73 -0
  62. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/remove.py +476 -0
  63. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/exceptions.py +60 -0
  64. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/__init__.py +3 -0
  65. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/__init__.py +3 -0
  66. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/add.py +170 -0
  67. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cat.py +60 -0
  68. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cut.py +112 -0
  69. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/delay.py +85 -0
  70. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/equation.py +261 -0
  71. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/fir.py +231 -0
  72. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/identity.py +48 -0
  73. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/resample.py +451 -0
  74. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/subclip.py +91 -0
  75. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/cut.py +74 -0
  76. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/__init__.py +3 -0
  77. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/audio_cast.py +208 -0
  78. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/video_cast.py +197 -0
  79. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/subclip.py +53 -0
  80. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/__init__.py +3 -0
  81. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/add.py +331 -0
  82. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cat.py +60 -0
  83. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cut.py +113 -0
  84. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/delay.py +84 -0
  85. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/equation.py +265 -0
  86. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/identity.py +48 -0
  87. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/pad.py +99 -0
  88. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/subclip.py +91 -0
  89. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/__init__.py +3 -0
  90. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/__init__.py +3 -0
  91. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/empty.py +73 -0
  92. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/equation.py +56 -0
  93. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/noise.py +243 -0
  94. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/__init__.py +3 -0
  95. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/c_fractal.cpython-312-x86_64-linux-gnu.so +0 -0
  96. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/empty.py +69 -0
  97. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/equation.py +109 -0
  98. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/__init__.py +3 -0
  99. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/fractal.c +116 -0
  100. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/geometry.py +100 -0
  101. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/mandelbrot.py +176 -0
  102. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/noise.py +112 -0
  103. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/__init__.py +3 -0
  104. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/seedable.py +82 -0
  105. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/__init__.py +3 -0
  106. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_ffmpeg.py +904 -0
  107. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_svg.py +145 -0
  108. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/scheduler.py +356 -0
  109. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/write.py +340 -0
  110. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/__init__.py +3 -0
  111. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/__init__.py +3 -0
  112. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/basic.py +35 -0
  113. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/__init__.py +3 -0
  114. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/graph.py +80 -0
  115. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/__init__.py +3 -0
  116. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/graph.py +81 -0
  117. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/singleton.py +47 -0
  118. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cuda/__init__.py +3 -0
  119. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/__init__.py +5 -0
  120. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/proba.py +189 -0
  121. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/__init__.py +5 -0
  122. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/delay_to_fir.py +88 -0
  123. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/graph.py +17 -0
  124. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/__init__.py +3 -0
  125. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/buffer.py +90 -0
  126. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/utils.py +34 -0
  127. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/audio_5.1_narration.oga +0 -0
  128. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/intro.webm +0 -0
  129. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/logo.svg +13 -0
  130. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/project.json +226 -0
  131. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/video.mp4 +0 -0
  132. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__init__.py +8 -0
  133. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__main__.py +25 -0
  134. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/actions.py +63 -0
  135. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/__init__.py +3 -0
  136. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/app.py +248 -0
  137. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/base.py +50 -0
  138. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/__init__.py +3 -0
  139. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/__init__.py +3 -0
  140. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/container_input_ffmpeg.py +90 -0
  141. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_delay.py +9 -0
  142. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_equation.py +45 -0
  143. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_fir.py +58 -0
  144. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_subclip.py +9 -0
  145. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_cut.py +82 -0
  146. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_delay.py +20 -0
  147. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_subclip.py +21 -0
  148. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_delay.py +9 -0
  149. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_equation.py +53 -0
  150. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_subclip.py +9 -0
  151. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_equation.py +14 -0
  152. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_noise.py +19 -0
  153. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_equation.py +13 -0
  154. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_mandelbrot.py +60 -0
  155. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_noise.py +18 -0
  156. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/base.py +99 -0
  157. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/default.py +27 -0
  158. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/documentation.py +47 -0
  159. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/general.py +71 -0
  160. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/interface.py +305 -0
  161. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/loader.py +41 -0
  162. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/main.py +62 -0
  163. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edition_tabs.py +34 -0
  164. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/__init__.py +3 -0
  165. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/base.py +122 -0
  166. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/filters.py +42 -0
  167. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/generators.py +42 -0
  168. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry_tabs.py +46 -0
  169. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/__init__.py +3 -0
  170. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/_helper.py +54 -0
  171. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/container.py +226 -0
  172. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/doc.py +67 -0
  173. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/encodec.py +289 -0
  174. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/main.py +173 -0
  175. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/__init__.py +3 -0
  176. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/edge_properties.py +56 -0
  177. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/main.py +280 -0
  178. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/node.py +44 -0
  179. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/main.py +151 -0
  180. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/menu.py +21 -0
  181. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/__init__.py +3 -0
  182. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/audio_settings.py +183 -0
  183. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/main.py +41 -0
  184. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/video_settings.py +257 -0
  185. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/run.py +71 -0
  186. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/__init__.py +3 -0
  187. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/main.py +30 -0
  188. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/slider.py +286 -0
  189. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/track.py +97 -0
  190. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/view.py +90 -0
  191. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/toolbar.py +29 -0
  192. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/tools.py +23 -0
  193. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/__init__.py +3 -0
  194. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/audio_player.py +103 -0
  195. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/control.py +96 -0
  196. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/frame_extractor.py +254 -0
  197. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/main.py +115 -0
  198. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__init__.py +8 -0
  199. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__main__.py +27 -0
  200. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/coding_style.py +49 -0
  201. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/generation.py +52 -0
  202. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/install.py +72 -0
  203. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/run.py +58 -0
  204. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/abstract.py +215 -0
  205. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_cast.py +35 -0
  206. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_equation.py +71 -0
  207. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/c_memory.py +132 -0
  208. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compatibility.py +27 -0
  209. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compile.py +42 -0
  210. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/encoder.py +23 -0
  211. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_cut.py +107 -0
  212. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_delay.py +71 -0
  213. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_empty.py +40 -0
  214. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/fir.py +143 -0
  215. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/hashes.py +23 -0
  216. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/initialisation.py +24 -0
  217. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/muxer.py +22 -0
  218. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/nan_snapshot.py +39 -0
  219. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/read.py +192 -0
  220. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/serialization_equality.py +50 -0
  221. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/snapshot_shape.py +21 -0
  222. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/sympy_to_torch.py +135 -0
  223. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/thread_safe.py +77 -0
  224. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/time_range.py +55 -0
  225. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/video_equation.py +77 -0
  226. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/write.py +95 -0
  227. cutcutcodec-1.0.post3.data/platlib/cutcutcodec/utils.py +40 -0
  228. cutcutcodec-1.0.post3.dist-info/LICENSE +7 -0
  229. cutcutcodec-1.0.post3.dist-info/METADATA +271 -0
  230. cutcutcodec-1.0.post3.dist-info/RECORD +233 -0
  231. cutcutcodec-1.0.post3.dist-info/WHEEL +5 -0
  232. cutcutcodec-1.0.post3.dist-info/entry_points.txt +6 -0
  233. cutcutcodec-1.0.post3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,451 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """Resample an audio signal."""
4
+
5
+ from fractions import Fraction
6
+ import math
7
+ import numbers
8
+ import typing
9
+
10
+ import numpy as np
11
+ import torch
12
+
13
+ from cutcutcodec.core.classes.frame_audio import FrameAudio
14
+ from cutcutcodec.core.classes.stream import Stream
15
+ from cutcutcodec.core.classes.stream_audio import StreamAudio
16
+ from cutcutcodec.core.filters.audio.fir import FilterAudioFIR
17
+
18
+
19
+ def anti_aliasing(
20
+ rate: numbers.Integral,
21
+ cutoff: numbers.Real,
22
+ band: typing.Optional[numbers.Real] = None,
23
+ attenuation: numbers.Real = 120.0,
24
+ ) -> np.ndarray:
25
+ """Find the best type 1 impulse response that perfectly matchs the constraints.
26
+
27
+ Search the low pass symetric odd filter filter as possible.
28
+ This filter introduces a linear phase shift, with a time delay equal to ``len(rif)/(2*rate)``.
29
+
30
+ Parameters
31
+ ----------
32
+ rate : int
33
+ The sampling rate of the filter in time domain in Hz.
34
+ cutoff : float
35
+ The cut-off absolute frequency in Hz. It has to be < rate/2.
36
+ It is not the -3 dB but the ``-attenuation`` dB frequency.
37
+ band : float, optional
38
+ The absolute width of the transition band in Hz.
39
+ If not provide, the value is compute for an audio application that
40
+ correspond to the perceptive frequency hearing threshold resolution.
41
+ It is based on a MEL cut-off of 5 musical cents, or 5 `mel_cent`.
42
+ One cent is define by b = a * 2**(1/1200).
43
+ attenuation : float, default=120
44
+ The attenuation in the stopband in dB.
45
+ Transmitted to ``cutcutcodec.core.filters.audio.resample.kaiser``.
46
+
47
+ Returns
48
+ -------
49
+ rif : np.ndarray
50
+ The 1d symetric odd finite response that matche the given constraints.
51
+
52
+ Examples
53
+ --------
54
+ >>> import numpy as np
55
+ >>> from cutcutcodec.core.filters.audio.resample import anti_aliasing
56
+ >>> fir = anti_aliasing(48000, 8000)
57
+ >>> np.round(fir, 6)
58
+ array([-1.8e-05, -2.7e-05, -9.0e-06, ..., -9.0e-06, -2.7e-05, -1.8e-05])
59
+ >>>
60
+ >>> # import matplotlib.pyplot as plt
61
+ >>> # fig, (ax_t, ax_f) = plt.subplots(ncols=2)
62
+ >>> # _ = fig.suptitle("FIR filter design")
63
+ >>> # _ = ax_f.set_title("Frequency domain response")
64
+ >>> # _ = ax_f.set_xlabel("freq [Hz]")
65
+ >>> # _ = ax_f.set_ylabel("gain [dB]")
66
+ >>> # _ = ax_t.set_title("Temporal domain response")
67
+ >>> # _ = ax_t.set_xlabel("time [s]")
68
+ >>> # _ = ax_t.set_ylabel("magnitude")
69
+ >>> # _ = ax_t.plot(np.arange(len(fir))/48000, fir, "o-")
70
+ >>> # _ = ax_f.plot(
71
+ >>> # np.linspace(-24000, 24000, 128*len(fir)+1),
72
+ >>> # 20*np.log10(abs(np.fft.fftshift(np.fft.fft(fir, n=128*len(fir)+1)/48000))))
73
+ >>> # fig.tight_layout()
74
+ >>> # plt.show()
75
+ >>>
76
+ """
77
+ assert isinstance(rate, numbers.Integral), rate.__class__.__name__
78
+ assert rate > 0, rate
79
+ rate = int(rate)
80
+ assert isinstance(cutoff, numbers.Real), cutoff.__class__.__name__
81
+ cutoff = float(cutoff)
82
+ if band is not None:
83
+ assert isinstance(band, numbers.Real), band.__class__.__name__
84
+ band = float(band)
85
+ assert band > 0, band
86
+ assert cutoff < .5*rate, cutoff
87
+
88
+ if band is None:
89
+ band = 1127.0 * math.log(1.0 + cutoff/700.0) # mel scale
90
+ band *= (2.0**(1.0/240.0) - 1.0) # 5 cents
91
+ cutoff -= .5*band
92
+ win = kaiser(cutoff/rate, band/rate, attenuation)
93
+ times = np.arange(-(len(win)-1)//2, (len(win)+1)//2, dtype=float) / rate
94
+ rif = 2.0*cutoff*np.sinc(2.0*cutoff*times)
95
+ rif *= win
96
+ return rif
97
+
98
+
99
+ def kaiser(
100
+ cutoff: numbers.Real, band: numbers.Real, attenuation: numbers.Real
101
+ ) -> np.ndarray:
102
+ """Design a kaiser window with some frequencial properties.
103
+
104
+ Parameters
105
+ ----------
106
+ cutoff : float
107
+ The cutoff frequency as a fraction of the sampling rate in ]0, 0.5[.
108
+ band : float
109
+ Transition band, as a fraction of the sampling rate in ]0, 0.5[.
110
+ attenuation : float
111
+ The attenuation in the stopband in dB.
112
+
113
+ Returns
114
+ -------
115
+ window : torch.Tensor
116
+ The 1d symetric odd window.
117
+
118
+ Examples
119
+ --------
120
+ >>> import numpy as np
121
+ >>> from cutcutcodec.core.filters.audio.resample import kaiser
122
+ >>> np.round(kaiser(0.25, 0.05, 80), 5)
123
+ array([0.00267, 0.00453, 0.00692, 0.00991, 0.01359, 0.01803, 0.02331,
124
+ 0.02951, 0.03671, 0.04499, 0.05443, 0.06508, 0.07702, 0.0903 ,
125
+ 0.10497, 0.12107, 0.13863, 0.15766, 0.17817, 0.20016, 0.22359,
126
+ 0.24845, 0.27467, 0.30219, 0.33093, 0.3608 , 0.39168, 0.42346,
127
+ 0.45599, 0.48912, 0.5227 , 0.55654, 0.59048, 0.62431, 0.65784,
128
+ 0.69088, 0.72321, 0.75464, 0.78496, 0.81398, 0.84149, 0.86731,
129
+ 0.89127, 0.91319, 0.93292, 0.95033, 0.96527, 0.97765, 0.98737,
130
+ 0.99437, 0.99859, 1. , 0.99859, 0.99437, 0.98737, 0.97765,
131
+ 0.96527, 0.95033, 0.93292, 0.91319, 0.89127, 0.86731, 0.84149,
132
+ 0.81398, 0.78496, 0.75464, 0.72321, 0.69088, 0.65784, 0.62431,
133
+ 0.59048, 0.55654, 0.5227 , 0.48912, 0.45599, 0.42346, 0.39168,
134
+ 0.3608 , 0.33093, 0.30219, 0.27467, 0.24845, 0.22359, 0.20016,
135
+ 0.17817, 0.15766, 0.13863, 0.12107, 0.10497, 0.0903 , 0.07702,
136
+ 0.06508, 0.05443, 0.04499, 0.03671, 0.02951, 0.02331, 0.01803,
137
+ 0.01359, 0.00991, 0.00692, 0.00453, 0.00267])
138
+ """
139
+ # verifs
140
+ assert isinstance(cutoff, numbers.Real), attenuation.__class__.__name__
141
+ assert 0 < cutoff < 0.5, cutoff
142
+ assert isinstance(band, numbers.Real), band.__class__.__name__
143
+ assert 0 < band < 0.5, band
144
+ assert isinstance(attenuation, numbers.Real), attenuation.__class__.__name__
145
+ cutoff = float(cutoff)
146
+ band = float(band)
147
+ attenuation = abs(float(attenuation))
148
+
149
+ # parameters
150
+ if not (nb_samples := math.ceil((attenuation - 8) / (2.285 * 2 * math.pi * band)) + 1) % 2:
151
+ nb_samples += 1 # make sure is odd
152
+ if attenuation < 21:
153
+ beta = 0.0
154
+ elif attenuation <= 50:
155
+ beta = 0.5842 * (attenuation-21)**0.4 + 0.07886 * (attenuation-21)
156
+ else:
157
+ beta = 0.1102 * (attenuation-8.7)
158
+
159
+ # compute window
160
+ win = np.kaiser(nb_samples, beta)
161
+ # win *= 1/np.sum(win) # normalize to get unity gain
162
+ return win
163
+
164
+
165
+ def sinc_continuous(
166
+ frame: FrameAudio, timestamp: Fraction, rate: int, samples: int, *, win: int = 256
167
+ ) -> FrameAudio:
168
+ """Resample the signal by the exact continuous function.
169
+
170
+ It process in two steps:
171
+ 1) Discrete to continuous signal. Convolute by a cardinal sinus.
172
+ 2) Continus to dicrete. Eval the continuous signal on some points.
173
+
174
+ There is no anti-aliasing filter for downsampeling.
175
+ We assume that the signal doese not contains any frequecies other `rate/2`.
176
+ The temporal and spacial complexity is o(samples*win).
177
+
178
+ Parameters
179
+ ----------
180
+ frame : cutcutcodec.core.classes.fream_audio.FrameAudio
181
+ The reference frame to resample.
182
+ timestamp : Fraction
183
+ The starting time the new resampled frame.
184
+ For more information, see ``cutcutcodec.core.classes.stream_audio.StreamAudio.snapshot``.
185
+ rate : int
186
+ The new sample rate.
187
+ For more information, see ``cutcutcodec.core.classes.stream_audio.StreamAudio.snapshot``.
188
+ samples : int
189
+ The number of samples in the new resampled frame.
190
+ For more information, see ``cutcutcodec.core.classes.stream_audio.StreamAudio.snapshot``.
191
+ win : int, optinal
192
+ The maximum half width of the sliding windows.
193
+ It correspond to the number of samples in the source frame
194
+ that contribute to compute one sample in the destination frame.
195
+ Bigger it is, slowler is the computation o(n), but more is accurate. Has to be odd number.
196
+
197
+ Returns
198
+ -------
199
+ new_frame : cutcutcodec.core.classes.fream_audio.FrameAudio
200
+ The resampled frame.
201
+
202
+ Examples
203
+ --------
204
+ >>> from fractions import Fraction
205
+ >>> import torch
206
+ >>> from cutcutcodec.core.filters.audio.resample import sinc_continuous
207
+ >>> from cutcutcodec.core.classes.frame_audio import FrameAudio
208
+ >>> frame = FrameAudio(1, 8000, "mono", torch.empty(1, 512))
209
+ >>> frame[:, :] = torch.sin(2*torch.pi*3960*frame.timestamps).reshape(1, -1) # 1% to shannon
210
+ >>> frame[:, :] *= torch.blackman_window(frame.samples, periodic=False).reshape(1, -1)
211
+ >>> new_frame = sinc_continuous(frame, 1-Fraction(16, 8000), 96000, 96000*544//8000)
212
+ >>>
213
+ >>> torch.round(frame, decimals=3)
214
+ FrameAudio(1, 8000, 'mono', [[-0. , 0. , -0. , 0. , -0. ,
215
+ 0. , -0. , 0. , -0. , 0. ,
216
+ -0. , 0.001, -0.001, 0.001, -0.001,
217
+ 0.001, -0.002, 0.002, -0.002, 0.003,
218
+ -0.003, 0.004, -0.004, 0.005, -0.006,
219
+ 0.006, -0.007, 0.008, -0.009, 0.009,
220
+ -0.01 , 0.011, -0.012, 0.013, -0.015,
221
+ 0.016, -0.017, 0.018, -0.02 , 0.021,
222
+ -0.022, 0.024, -0.025, 0.027, -0.028,
223
+ 0.03 , -0.032, 0.033, -0.035, 0.037,
224
+ -0.038, 0.04 , -0.042, 0.043, -0.045,
225
+ 0.047, -0.048, 0.05 , -0.052, 0.053,
226
+ -0.055, 0.056, -0.058, 0.059, -0.06 ,
227
+ 0.062, -0.063, 0.064, -0.065, 0.066,
228
+ -0.066, 0.067, -0.067, 0.068, -0.068,
229
+ 0.068, -0.068, 0.068, -0.067, 0.067,
230
+ -0.066, 0.065, -0.064, 0.062, -0.061,
231
+ 0.059, -0.057, 0.054, -0.052, 0.049,
232
+ -0.046, 0.042, -0.039, 0.035, -0.031,
233
+ 0.026, -0.022, 0.017, -0.011, 0.006,
234
+ -0. , -0.006, 0.012, -0.019, 0.026,
235
+ -0.034, 0.041, -0.049, 0.057, -0.065,
236
+ 0.074, -0.083, 0.091, -0.101, 0.111,
237
+ -0.121, 0.13 , -0.141, 0.152, -0.161,
238
+ 0.173, -0.183, 0.195, -0.206, 0.218,
239
+ -0.229, 0.24 , -0.252, 0.263, -0.275,
240
+ 0.286, -0.298, 0.31 , -0.321, 0.332,
241
+ -0.343, 0.355, -0.366, 0.377, -0.388,
242
+ 0.398, -0.408, 0.418, -0.428, 0.438,
243
+ -0.447, 0.456, -0.464, 0.472, -0.48 ,
244
+ 0.487, -0.493, 0.5 , -0.505, 0.511,
245
+ -0.515, 0.519, -0.523, 0.526, -0.528,
246
+ 0.53 , -0.531, 0.531, -0.531, 0.529,
247
+ -0.528, 0.526, -0.522, 0.518, -0.513,
248
+ 0.508, -0.501, 0.494, -0.488, 0.478,
249
+ -0.469, 0.458, -0.448, 0.437, -0.423,
250
+ 0.41 , -0.395, 0.381, -0.365, 0.35 ,
251
+ -0.333, 0.314, -0.296, 0.276, -0.257,
252
+ 0.235, -0.214, 0.193, -0.17 , 0.148,
253
+ -0.124, 0.101, -0.075, 0.051, -0.026,
254
+ 0. , 0.025, -0.054, 0.08 , -0.106,
255
+ 0.133, -0.16 , 0.188, -0.215, 0.245,
256
+ -0.272, 0.299, -0.327, 0.354, -0.384,
257
+ 0.408, -0.438, 0.464, -0.49 , 0.517,
258
+ -0.542, 0.57 , -0.594, 0.62 , -0.643,
259
+ 0.666, -0.69 , 0.712, -0.736, 0.756,
260
+ -0.777, 0.796, -0.815, 0.835, -0.851,
261
+ 0.868, -0.884, 0.898, -0.912, 0.924,
262
+ -0.937, 0.948, -0.958, 0.966, -0.974,
263
+ 0.981, -0.987, 0.991, -0.995, 0.997,
264
+ -0.998, 0.998, -0.997, 0.995, -0.992,
265
+ 0.988, -0.982, 0.976, -0.969, 0.959,
266
+ -0.95 , 0.939, -0.928, 0.915, -0.901,
267
+ 0.886, -0.87 , 0.854, -0.835, 0.819,
268
+ -0.8 , 0.778, -0.758, 0.736, -0.715,
269
+ 0.69 , -0.667, 0.643, -0.618, 0.593,
270
+ -0.567, 0.541, -0.512, 0.486, -0.459,
271
+ 0.43 , -0.403, 0.372, -0.345, 0.315,
272
+ -0.287, 0.259, -0.229, 0.201, -0.17 ,
273
+ 0.142, -0.112, 0.085, -0.057, 0.027,
274
+ 0. , -0.028, 0.055, -0.08 , 0.108,
275
+ -0.133, 0.161, -0.185, 0.21 , -0.233,
276
+ 0.255, -0.28 , 0.3 , -0.323, 0.343,
277
+ -0.364, 0.382, -0.4 , 0.42 , -0.436,
278
+ 0.453, -0.467, 0.484, -0.496, 0.508,
279
+ -0.522, 0.532, -0.543, 0.552, -0.561,
280
+ 0.57 , -0.576, 0.583, -0.588, 0.593,
281
+ -0.596, 0.599, -0.602, 0.603, -0.604,
282
+ 0.603, -0.603, 0.601, -0.599, 0.596,
283
+ -0.592, 0.588, -0.583, 0.577, -0.571,
284
+ 0.564, -0.557, 0.549, -0.54 , 0.532,
285
+ -0.522, 0.512, -0.502, 0.492, -0.481,
286
+ 0.469, -0.458, 0.446, -0.434, 0.422,
287
+ -0.409, 0.397, -0.383, 0.37 , -0.358,
288
+ 0.344, -0.331, 0.317, -0.304, 0.291,
289
+ -0.277, 0.265, -0.251, 0.238, -0.224,
290
+ 0.212, -0.199, 0.187, -0.174, 0.161,
291
+ -0.15 , 0.137, -0.126, 0.115, -0.104,
292
+ 0.093, -0.082, 0.072, -0.062, 0.052,
293
+ -0.043, 0.033, -0.025, 0.016, -0.008,
294
+ -0. , 0.007, -0.014, 0.022, -0.028,
295
+ 0.034, -0.04 , 0.046, -0.051, 0.055,
296
+ -0.06 , 0.064, -0.068, 0.072, -0.076,
297
+ 0.079, -0.081, 0.084, -0.086, 0.088,
298
+ -0.089, 0.091, -0.092, 0.093, -0.094,
299
+ 0.094, -0.094, 0.094, -0.094, 0.094,
300
+ -0.093, 0.093, -0.092, 0.091, -0.09 ,
301
+ 0.088, -0.087, 0.086, -0.084, 0.082,
302
+ -0.081, 0.079, -0.077, 0.075, -0.073,
303
+ 0.071, -0.069, 0.066, -0.064, 0.062,
304
+ -0.06 , 0.058, -0.055, 0.053, -0.051,
305
+ 0.049, -0.047, 0.044, -0.042, 0.04 ,
306
+ -0.038, 0.036, -0.034, 0.032, -0.03 ,
307
+ 0.028, -0.027, 0.025, -0.023, 0.022,
308
+ -0.02 , 0.019, -0.017, 0.016, -0.015,
309
+ 0.013, -0.012, 0.011, -0.01 , 0.009,
310
+ -0.008, 0.007, -0.006, 0.006, -0.005,
311
+ 0.004, -0.004, 0.003, -0.003, 0.002,
312
+ -0.002, 0.002, -0.001, 0.001, -0.001,
313
+ 0.001, -0. , 0. , -0. , 0. ,
314
+ 0. , -0. , 0. , -0. , 0. ,
315
+ -0. , 0. , -0. , 0. , -0. ,
316
+ 0. , 0. ]])
317
+ >>> middle = new_frame.samples//2
318
+ >>> torch.round(new_frame[:, middle-32:middle+32], decimals=3).numpy()
319
+ array([[ 0.588, 0.359, 0.109, -0.151, -0.398, -0.619, -0.8 , -0.927,
320
+ -0.992, -0.99 , -0.923, -0.793, -0.612, -0.39 , -0.139, 0.118,
321
+ 0.371, 0.595, 0.781, 0.915, 0.988, 0.995, 0.935, 0.813,
322
+ 0.635, 0.417, 0.172, -0.088, -0.339, -0.571, -0.761, -0.901,
323
+ -0.982, -0.997, -0.946, -0.83 , -0.66 , -0.444, -0.201, 0.056,
324
+ 0.312, 0.544, 0.742, 0.889, 0.976, 0.999, 0.956, 0.848,
325
+ 0.683, 0.474, 0.231, -0.025, -0.28 , -0.518, -0.719, -0.873,
326
+ -0.969, -1. , -0.964, -0.864, -0.707, -0.501, -0.263, -0.009]],
327
+ dtype=float32)
328
+ >>>
329
+ >>> # import matplotlib.pyplot as plt
330
+ >>> # plt.xlabel("time (s)"); plt.ylabel("magnitude")
331
+ >>> # plt.plot(frame.timestamps.numpy(), frame.transpose(0, 1).numpy(), marker="o")
332
+ >>> # plt.plot(new_frame.timestamps.numpy(), new_frame.transpose(0, 1).numpy(), marker="o")
333
+ >>> # plt.show()
334
+ >>>
335
+ """
336
+ assert isinstance(frame, FrameAudio), frame.__class__.__name__
337
+ assert isinstance(timestamp, Fraction), timestamp.__class__.__name__
338
+ assert isinstance(rate, int), rate.__class__.__name__
339
+ assert isinstance(samples, int), samples.__class__.__name__
340
+ assert isinstance(win, int), win.__class__.__name__
341
+
342
+ # initialisation of the empty new frame
343
+ dst_frame = FrameAudio(
344
+ timestamp,
345
+ rate,
346
+ frame.layout,
347
+ torch.empty((frame.channels, samples), dtype=frame.dtype, device=frame.device),
348
+ )
349
+
350
+ # precompute and cache some useful values
351
+ src_t = frame.timestamps # shape (frame.samples,)
352
+ dst_t = dst_frame.timestamps # shape (samples,)
353
+
354
+ # For the dst sample i, j=indexs[i] corresponds to the src sample j, with the time matching
355
+ indexs = dst_t - float(frame.time) # copy, shape (samples,)
356
+ indexs *= frame.rate
357
+ indexs = indexs.to(dtype=torch.int32, copy=False)
358
+ indexs = ((dst_t - float(frame.time)) * frame.rate).to(torch.int32)
359
+ win = min(win, (frame.samples-1)//2)
360
+ indexs = torch.clip(indexs, win, frame.samples-1-win, out=indexs)
361
+
362
+ # the cardinal sinuns to convolve
363
+ sinc_conv = torch.empty(
364
+ (samples, 2*win+1), dtype=frame.dtype, device=frame.device
365
+ ) # shape (samples, 2*win+1)
366
+ for i in range(2*win+1):
367
+ sinc_conv[:, i] = src_t[indexs-win+i] # src_t
368
+ sinc_conv -= dst_t.unsqueeze(1) # src_t - dst_t
369
+ sinc_conv *= frame.rate # src_rate * (src_t - dst_t), pi is included in the sinc torch function
370
+ sinc_conv = torch.sinc(sinc_conv, out=sinc_conv) # sin(x)/x, x = pi*src_rate*(src_t-dst_t)
371
+
372
+ # the cardinal sinuns magnitude
373
+ magnitude = torch.empty(
374
+ (frame.channels, samples, 2*win+1), dtype=frame.dtype, device=frame.device
375
+ ) # shape (nbr_channels, samples, 2*win+1)
376
+ for i in range(2*win+1):
377
+ magnitude[:, :, i] = frame[:, indexs-win+i]
378
+
379
+ # final dot product
380
+ values = torch.mul(magnitude, sinc_conv.unsqueeze(0), out=magnitude)
381
+ del sinc_conv
382
+ values = torch.sum(values, dim=2, keepdim=False) # shape (nbr_channels, samples, 2*win+1)
383
+ dst_frame[:, :] = values
384
+
385
+ return dst_frame
386
+
387
+
388
+ class FilterAudioAntiAliasing(FilterAudioFIR):
389
+ """Anti-aliasing filter for audio subsampling.
390
+
391
+ This filter is a class 1 finite impulse response linear phase low-pass filter.
392
+
393
+ Attributes
394
+ ----------
395
+ cutoff : float
396
+ The cutoff frequency in Hz (readonly).
397
+ delay : Fraction
398
+ The delay introduced by the filter in seconds (readonly).
399
+
400
+ Examples
401
+ --------
402
+ >>> from cutcutcodec.core.filters.audio.resample import FilterAudioAntiAliasing
403
+ >>> from cutcutcodec.core.generation.audio.equation import GeneratorAudioEquation
404
+ >>> (audio_a4,) = GeneratorAudioEquation("sin(2*pi*440*t)").out_streams
405
+ >>> (audio_a5,) = GeneratorAudioEquation("sin(2*pi*880*t)").out_streams
406
+ >>> out_a4, out_a5 = FilterAudioAntiAliasing([audio_a4, audio_a5], 622).out_streams
407
+ >>>
408
+ """
409
+
410
+ def __init__(self, in_streams: typing.Iterable[StreamAudio], cutoff: numbers.Real):
411
+ """Initialise and create the class.
412
+
413
+ Parameters
414
+ ----------
415
+ in_streams : typing.Iterable[Stream]
416
+ Transmitted to ``cutcutcodec.core.filters.audio.fir.FilterAudioFIR``.
417
+ cutoff : float
418
+ The cut-off frequency in Hz. For the Shannon criteria, it is the half sample rate.
419
+ The margin, the band with and the attenuation have been automatically chosen
420
+ for the earing sensibility in the case of an audio application.
421
+ """
422
+ assert isinstance(cutoff, numbers.Real), cutoff.__class__.__name__
423
+ assert cutoff > 0, cutoff
424
+ self._cutoff = float(cutoff)
425
+ fir_rate = math.floor(2*self._cutoff) + 1
426
+ fir = torch.from_numpy(anti_aliasing(fir_rate, cutoff))
427
+ super().__init__(in_streams, fir, fir_rate)
428
+
429
+ def _getstate(self) -> dict:
430
+ return {
431
+ "cutoff": self.cutoff,
432
+ }
433
+
434
+ def _setstate(self, in_streams: typing.Iterable[Stream], state: dict) -> None:
435
+ assert state.keys() == {"cutoff"}, set(state)
436
+ FilterAudioAntiAliasing.__init__(self, in_streams, state["cutoff"])
437
+
438
+ @property
439
+ def cutoff(self) -> Fraction:
440
+ """Return the cutoff frequency in Hz."""
441
+ return self._cutoff
442
+
443
+ @classmethod
444
+ def default(cls):
445
+ """Provide a minimalist example of an instance of this node."""
446
+ return cls([], 8000)
447
+
448
+ @property
449
+ def delay(self) -> Fraction:
450
+ """Return the delay introduced by the filter in seconds."""
451
+ return Fraction(len(self._fir)-1, 2*self._fir_rate)
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """Selects a time slice of an audio stream."""
4
+
5
+ from fractions import Fraction
6
+ import math
7
+ import numbers
8
+ import typing
9
+
10
+ from cutcutcodec.core.classes.meta_filter import MetaFilter
11
+ from cutcutcodec.core.classes.node import Node
12
+ from cutcutcodec.core.classes.stream import Stream
13
+ from cutcutcodec.core.compilation.parse import parse_to_number
14
+ from cutcutcodec.core.filters.audio.cut import FilterAudioCut
15
+ from cutcutcodec.core.filters.audio.identity import FilterAudioIdentity
16
+ from cutcutcodec.core.filters.subclip import FilterSubclip
17
+
18
+
19
+ class FilterAudioSubclip(FilterSubclip, MetaFilter):
20
+ """Extract a segment from an audio stream.
21
+
22
+ It is a particular case of ``cutcutcodec.core.filters.audio.cut.FilterAudioCut``.
23
+ Allows to start a flow after the beginning and or finish it before the end.
24
+
25
+ Examples
26
+ --------
27
+ >>> from cutcutcodec.core.filters.audio.subclip import FilterAudioSubclip
28
+ >>> from cutcutcodec.core.generation.audio.noise import GeneratorAudioNoise
29
+ >>>
30
+ >>> (s_a,) = GeneratorAudioNoise(0).out_streams
31
+ >>> (s_b,) = GeneratorAudioNoise(0).out_streams
32
+ >>> s_subclip_a, s_subclip_b = FilterAudioSubclip([s_a, s_b], 10, 20).out_streams
33
+ >>>
34
+ >>> s_subclip_a.beginning
35
+ Fraction(10, 1)
36
+ >>> s_subclip_a.duration
37
+ Fraction(20, 1)
38
+ >>> s_subclip_b.beginning
39
+ Fraction(10, 1)
40
+ >>> s_subclip_b.duration
41
+ Fraction(20, 1)
42
+ >>>
43
+ """
44
+
45
+ def __init__(
46
+ self,
47
+ in_streams: typing.Iterable[Stream],
48
+ delay: numbers.Real = Fraction(0),
49
+ duration_max: numbers.Real = math.inf,
50
+ ):
51
+ """Initialise and create the class.
52
+
53
+ Parameters
54
+ ----------
55
+ in_streams : typing.Iterable[Stream]
56
+ Transmitted to ``cutcutcodec.core.classes.filter.Filter``.
57
+ delay: numbers.Real, default=0
58
+ Transmitted to ``cutcutcodec.core.filters.subclip.FilterSubClip``.
59
+ duration_max : numbers.Real, default=inf
60
+ Transmitted to ``cutcutcodec.core.filters.subclip.FilterSubClip``.
61
+ """
62
+ FilterSubclip.__init__(self, delay, duration_max)
63
+ MetaFilter.__init__(self, in_streams)
64
+
65
+ def _compile(self, in_streams: tuple[Stream]) -> Node:
66
+ if self.delay:
67
+ if math.isfinite(self.duration_max):
68
+ sub_streams = FilterAudioCut(
69
+ in_streams, self.delay, self.delay+self.duration_max
70
+ ).out_streams[len(in_streams):2*len(in_streams)]
71
+ else:
72
+ sub_streams = FilterAudioCut(in_streams, self.delay).out_streams[len(in_streams):]
73
+ else:
74
+ if math.isfinite(self.duration_max):
75
+ sub_streams = FilterAudioCut(
76
+ in_streams, self.delay+self.duration_max
77
+ ).out_streams[:len(in_streams)]
78
+ else:
79
+ sub_streams = in_streams
80
+ return FilterAudioIdentity(sub_streams)
81
+
82
+ def _setstate(self, in_streams: typing.Iterable[Stream], state: dict) -> None:
83
+ assert state.keys() == {"delay", "duration_max"}, set(state)
84
+ FilterAudioSubclip.__init__(
85
+ self, in_streams, Fraction(state["delay"]), parse_to_number(state["duration_max"])
86
+ )
87
+
88
+ @classmethod
89
+ def default(cls):
90
+ """Provide a minimalist example of an instance of this node."""
91
+ return cls([], 0, math.inf)
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """The common part for ``FilterAudioCut`` and ``FilterVideoCut``."""
4
+
5
+ from fractions import Fraction
6
+ import math
7
+ import numbers
8
+ import typing
9
+
10
+ from cutcutcodec.core.classes.stream import Stream
11
+
12
+
13
+ class FilterCut:
14
+ """Splits the stream at the given positions.
15
+
16
+ Attributes
17
+ ----------
18
+ limits : list[Fraction]
19
+ The ordered limits of each slices in seconds (readonly).
20
+ """
21
+
22
+ def init(self, in_streams: typing.Iterable[Stream], stream_cls: type, *limits: numbers.Real):
23
+ """Initialise and create the class.
24
+
25
+ Parameters
26
+ ----------
27
+ in_streams : typing.Iterable[Stream]
28
+ Transmitted to ``cutcutcodec.core.classes.filter.Filter``.
29
+ stream_cls : type
30
+ A subclass of ``cutcutcodec.core.classes.stream.Stream``.
31
+ It is the constructor of the `out_streams` of self.
32
+ limits : numbers.Real
33
+ The temporal limits between the differents slices.
34
+ The timings are like a duration relative to the beginning of the first stream.
35
+
36
+ Returns
37
+ -------
38
+ _limits : list[Fraction]
39
+ The verificated limits.
40
+ out_streams : list[cutcutcodec.core.classes.stream.Stream]
41
+ The instanciated out streams
42
+ """
43
+ assert issubclass(stream_cls, Stream), stream_cls.__name__
44
+ assert all(
45
+ isinstance(lim, numbers.Real) and math.isfinite(lim) and lim >= 0 for lim in limits
46
+ )
47
+
48
+ _limits = list(map(Fraction, limits))
49
+ assert sorted(_limits) == _limits, f"limits are not sorted, {limits}"
50
+ assert len(set(_limits)) == len(_limits), f"some limits are equal, {limits}"
51
+
52
+ if not in_streams:
53
+ return _limits, []
54
+
55
+ beginning = min(s.beginning for s in in_streams)
56
+ abs_limits = [lim + beginning for lim in _limits]
57
+ abs_limits_min = [-math.inf] + abs_limits
58
+ abs_limits_max = abs_limits + [math.inf]
59
+ return (
60
+ _limits,
61
+ [
62
+ stream_cls(self, index, l_min, l_max)
63
+ for l_min, l_max in zip(abs_limits_min, abs_limits_max)
64
+ for index in range(len(in_streams))
65
+ ],
66
+ )
67
+
68
+ def _getstate(self) -> dict:
69
+ return {"limits": list(map(str, self.limits))}
70
+
71
+ @property
72
+ def limits(self):
73
+ """Return the ordered limits of each slices in seconds."""
74
+ return self._limits.copy()
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """Change the number of channels."""