capture_audio_video_to_a_file.html 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Capture Audio/Video to a File</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/capture_audio_video_to_a_file.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Capture Audio/Video to a File</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#simple-way">Simple Way</a></li><li><a href="#advanced-way">Advanced Way</a><ul class="sectlevel2"><li><a href="#basic-example">Basic Example</a></li><li><a href="#how-it-works">How it works</a></li><li><a href="#advanced-example">Advanced Example</a></li><li><a href="#using-advanced-features-to-record-from-more-than-one-perspective-at-once">Using Advanced features to Record from more than one perspective at once</a></li></ul></li><li><a href="#more-information">More Information</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>So you&#8217;ve made your cool new JMonkeyEngine3 game and you want to
  4. create a demo video to show off your hard work. Or maybe you want to
  5. make a cutscene for your game using the physics and characters in the
  6. game itself. Screen capturing is the most straightforward way to do
  7. this, but it can slow down your game and produce low-quality video and
  8. audio as a result. A better way is to record video and audio directly
  9. from the game while it is running using VideoRecorderAppState.</p></div>
  10. <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Combine this method with jMonkeyEngine&#8217;s
  11. <a href="../../jme3/advanced/cinematics.html">Cinematics</a>
  12. feature to record high-quality game trailers!</p></div></td></tr></table></div></div></div>
  13. <div class="sect1"><h2 id="simple-way">Simple Way</h2><div class="sectionbody"><div class="paragraph"><p>First off, if all you need is to record video at 30fps with no sound, then look
  14. no further than jMonkeyEngine 3&#8217;s built in <code>VideoRecorderAppState</code>
  15. class.</p></div>
  16. <div class="paragraph"><p>Add the following code to your <code>simpleInitApp()</code> method.</p></div>
  17. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">stateManager.attach(<span class="keyword">new</span> VideoRecorderAppState()); <span class="comment">//start recording</span></code></pre></div></div>
  18. <div class="paragraph"><p>The game will run slow, but the recording will be in high-quality and
  19. normal speed. Recording starts when the state is
  20. attached, and ends when the application quits or the state is detached.</p></div>
  21. <div class="paragraph"><p>The video files will be stored in your <strong>user home directory</strong>.
  22. If you want to save to another path, specify a File object in the
  23. VideoRecorderAppState constructor.</p></div>
  24. <div class="paragraph"><p>That&#8217;s all!</p></div></div></div>
  25. <div class="sect2"><h3 id="advanced-way">Advanced Way</h3><div class="admonitionblock note"><table><tr><td class="icon"><i class="fa icon-note" title="Note"></i></td><td class="content"><div class="paragraph"><p>This way of A/V recording is still in development.
  26. It works for all of jMonkeyEngine&#8217;s test cases.
  27. If you experience any problems or
  28. if something isn&#8217;t clear, please <a href="http://jmonkeyengine.org/members/bortreb/">let me know</a>. – bortreb</p></div></td></tr></table></div>
  29. <div class="paragraph"><p>If you want to record audio as well, record at different framerates,
  30. or record from multiple viewpoints at once, then there&#8217;s a full
  31. solution for doing this already made for you here:</p></div>
  32. <div class="paragraph"><p><a href="http://www.aurellem.com/releases/jmeCapture-latest.zip">http://www.aurellem.com/releases/jmeCapture-latest.zip</a></p></div>
  33. <div class="paragraph"><p><a href="http://www.aurellem.com/releases/jmeCapture-latest.tar.bz2">http://www.aurellem.com/releases/jmeCapture-latest.tar.bz2</a></p></div>
  34. <div class="paragraph"><p>Download the archive in your preferred format, extract,
  35. add the jars to your project, and you are ready to go.</p></div>
  36. <div class="paragraph"><p>The javadoc is here:
  37. <a href="http://www.aurellem.com/jmeCapture/docs/">http://www.aurellem.com/jmeCapture/docs/</a></p></div>
  38. <div class="paragraph"><p>To capture video and audio you use the
  39. <code>com.aurellem.capture.Capture</code> class, which has two methods,
  40. <code>captureAudio()</code> and <code>captureVideo()</code>, and the
  41. <code>com.aurellem.capture.IsoTimer</code> class, which sets the audio and
  42. video framerate.</p></div>
  43. <div class="paragraph"><p>The steps are:</p></div>
  44. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">yourApp.setTimer(<span class="keyword">new</span> IsoTimer(desiredFramesPerSecond));</code></pre></div></div>
  45. <div class="paragraph"><p>This causes jMonkeyEngine to take as much time as it needs to fully
  46. calculate every frame of the video and audio. You will see your game
  47. speed up and slow down depending on how computationally demanding your
  48. game is, but the final recorded audio and video will be perfectly
  49. sychronized and will run at exactly the fps which you specified.</p></div>
  50. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">captureVideo(yourApp, targetVideoFile);
  51. captureAudio(yourApp, targetAudioFile);</code></pre></div></div>
  52. <div class="paragraph"><p>These will cause the app to record audio and video when it is run.
  53. Audio and video will stop being recorded when the app stops. Your
  54. audio will be recorded as a 44,100 Hz linear PCM wav file, while the
  55. video will be recorded according to the following rules:</p></div>
  56. <div class="paragraph"><p>1.) (Preferred) If you supply an empty directory as the file, then
  57. the video will be saved as a sequence of .png files, one file per
  58. frame. The files start at 0000000.png and increment from there.
  59. You can then combine the frames into your preferred
  60. container/codec. If the directory is not empty, then writing
  61. video frames to it will fail, and nothing will be written.</p></div>
  62. <div class="paragraph"><p>2.) If the filename ends in “.avi then the frames will be encoded as
  63. a RAW stream inside an AVI 1.0 container. The resulting file
  64. will be quite large and you will probably want to re-encode it to
  65. your preferred container/codec format. Be advised that some
  66. video payers cannot process AVI with a RAW stream, and that AVI
  67. 1.0 files generated by this method that exceed 2.0GB are invalid
  68. according to the AVI 1.0 <abbr title="specification">spec</abbr> (but many programs can still deal
  69. with them.) Thanks to
  70. <a href="http://www.randelshofer.ch/blog/2008/08/writing-avi-videos-in-pure-java/">Werner Randelshofer</a>
  71. for his excellent work which made the AVI file writer option possible.</p></div>
  72. <div class="paragraph"><p>3.) Any non-directory file ending in anything other than “.avi will
  73. be processed through Xuggle. Xuggle provides the option to use
  74. many codecs/containers, but you will have to install it on your
  75. system yourself in order to use this option. Please visit
  76. <a href="http://www.xuggle.com/">http://www.xuggle.com/</a> to learn how to do this.</p></div>
  77. <div class="paragraph"><p>Note that you will not hear any sound if you choose to record sound to
  78. a file.</p></div>
  79. <div class="sect2"><h3 id="basic-example">Basic Example</h3><div class="paragraph"><p>Here is a complete example showing how to capture both audio and video
  80. from one of jMonkeyEngine3&#8217;s advanced demo applications.</p></div>
  81. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.io.File</span>;
  82. <span class="keyword">import</span> <span class="include">java.io.IOException</span>;
  83. <span class="keyword">import</span> <span class="include">jme3test.water.TestPostWater</span>;
  84. <span class="keyword">import</span> <span class="include">com.aurellem.capture.Capture</span>;
  85. <span class="keyword">import</span> <span class="include">com.aurellem.capture.IsoTimer</span>;
  86. <span class="keyword">import</span> <span class="include">com.jme3.app.SimpleApplication</span>;
  87. <span class="comment">/**
  88. * Demonstrates how to use basic Audio/Video capture with a
  89. * jMonkeyEngine application. You can use these techniques to make
  90. * high quality cutscenes or demo videos, even on very slow laptops.
  91. *
  92. * @author Robert McIntyre
  93. */</span>
  94. <span class="directive">public</span> <span class="type">class</span> <span class="class">Basic</span> {
  95. <span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> ignore) <span class="directive">throws</span> <span class="exception">IOException</span>{
  96. <span class="predefined-type">File</span> video = <span class="predefined-type">File</span>.createTempFile(<span class="string"><span class="delimiter">&quot;</span><span class="content">JME-water-video</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">.avi</span><span class="delimiter">&quot;</span></span>);
  97. <span class="predefined-type">File</span> audio = <span class="predefined-type">File</span>.createTempFile(<span class="string"><span class="delimiter">&quot;</span><span class="content">JME-water-audio</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">.wav</span><span class="delimiter">&quot;</span></span>);
  98. SimpleApplication app = <span class="keyword">new</span> TestPostWater();
  99. app.setTimer(<span class="keyword">new</span> IsoTimer(<span class="integer">60</span>));
  100. app.setShowSettings(<span class="predefined-constant">false</span>);
  101. Capture.captureVideo(app, video);
  102. Capture.captureAudio(app, audio);
  103. app.start();
  104. <span class="predefined-type">System</span>.out.println(video.getCanonicalPath());
  105. <span class="predefined-type">System</span>.out.println(audio.getCanonicalPath());
  106. }
  107. }</code></pre></div></div></div>
  108. <div class="sect2"><h3 id="how-it-works">How it works</h3><div class="paragraph"><p>A standard JME3 application that extends <code>SimpleApplication</code> or
  109. <code>Application</code> tries as hard as it can to keep in sync with
  110. <em>user-time</em>. If a ball is rolling at 1 game-mile per game-hour in the
  111. game, and you wait for one user-hour as measured by the clock on your
  112. wall, then the ball should have traveled exactly one game-mile. In
  113. order to keep sync with the real world, the game throttles its physics
  114. engine and graphics display. If the computations involved in running
  115. the game are too intense, then the game will first skip frames, then
  116. sacrifice physics accuracy. If there are particuraly demanding
  117. computations, then you may only get 1 fps, and the ball may tunnel
  118. through the floor or obstacles due to inaccurate physics simulation,
  119. but after the end of one user-hour, that ball will have traveled one
  120. game-mile.</p></div>
  121. <div class="paragraph"><p>When we&#8217;re recording video, we don&#8217;t care if the game-time syncs with
  122. user-time, but instead whether the time in the recorded video
  123. (video-time) syncs with user-time. To continue the analogy, if we
  124. recorded the ball rolling at 1 game-mile per game-hour and watched the
  125. video later, we would want to see 30 fps video of the ball rolling at
  126. 1 video-mile per <em>user-hour</em>. It doesn&#8217;t matter how much user-time it
  127. took to simulate that hour of game-time to make the high-quality
  128. recording.</p></div>
  129. <div class="paragraph"><p>The IsoTimer ignores real-time and always reports that the same amount
  130. of time has passed every time it is called. That way, one can put code
  131. to write each video/audio frame to a file without worrying about that
  132. code itself slowing down the game to the point where the recording
  133. would be useless.</p></div></div>
  134. <div class="sect2"><h3 id="advanced-example">Advanced Example</h3><div class="paragraph"><p>The package from aurellem.com was made for AI research and can do more
  135. than just record a single stream of audio and video. You can use it
  136. to:</p></div>
  137. <div class="paragraph"><p>1.) Create multiple independent listeners that each hear the world
  138. from their own perspective.</p></div>
  139. <div class="paragraph"><p>2.) Process the sound data in any way you wish.</p></div>
  140. <div class="paragraph"><p>3.) Do the same for visual data.</p></div>
  141. <div class="paragraph"><p>Here is a more advanced example, which can also be found along with
  142. other examples in the jmeCapture.jar file included in the
  143. distribution.</p></div>
  144. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">package</span> <span class="namespace">com.aurellem.capture.examples</span>;
  145. <span class="keyword">import</span> <span class="include">java.io.File</span>;
  146. <span class="keyword">import</span> <span class="include">java.io.IOException</span>;
  147. <span class="keyword">import</span> <span class="include">java.lang.reflect.Field</span>;
  148. <span class="keyword">import</span> <span class="include">java.nio.ByteBuffer</span>;
  149. <span class="keyword">import</span> <span class="include">javax.sound.sampled.AudioFormat</span>;
  150. <span class="keyword">import</span> <span class="include">org.tritonus.share.sampled.FloatSampleTools</span>;
  151. <span class="keyword">import</span> <span class="include">com.aurellem.capture.AurellemSystemDelegate</span>;
  152. <span class="keyword">import</span> <span class="include">com.aurellem.capture.Capture</span>;
  153. <span class="keyword">import</span> <span class="include">com.aurellem.capture.IsoTimer</span>;
  154. <span class="keyword">import</span> <span class="include">com.aurellem.capture.audio.CompositeSoundProcessor</span>;
  155. <span class="keyword">import</span> <span class="include">com.aurellem.capture.audio.MultiListener</span>;
  156. <span class="keyword">import</span> <span class="include">com.aurellem.capture.audio.SoundProcessor</span>;
  157. <span class="keyword">import</span> <span class="include">com.aurellem.capture.audio.WaveFileWriter</span>;
  158. <span class="keyword">import</span> <span class="include">com.jme3.app.SimpleApplication</span>;
  159. <span class="keyword">import</span> <span class="include">com.jme3.audio.AudioNode</span>;
  160. <span class="keyword">import</span> <span class="include">com.jme3.audio.Listener</span>;
  161. <span class="keyword">import</span> <span class="include">com.jme3.cinematic.MotionPath</span>;
  162. <span class="keyword">import</span> <span class="include">com.jme3.cinematic.events.AbstractCinematicEvent</span>;
  163. <span class="keyword">import</span> <span class="include">com.jme3.cinematic.events.MotionTrack</span>;
  164. <span class="keyword">import</span> <span class="include">com.jme3.material.Material</span>;
  165. <span class="keyword">import</span> <span class="include">com.jme3.math.ColorRGBA</span>;
  166. <span class="keyword">import</span> <span class="include">com.jme3.math.FastMath</span>;
  167. <span class="keyword">import</span> <span class="include">com.jme3.math.Quaternion</span>;
  168. <span class="keyword">import</span> <span class="include">com.jme3.math.Vector3f</span>;
  169. <span class="keyword">import</span> <span class="include">com.jme3.scene.Geometry</span>;
  170. <span class="keyword">import</span> <span class="include">com.jme3.scene.Node</span>;
  171. <span class="keyword">import</span> <span class="include">com.jme3.scene.shape.Box</span>;
  172. <span class="keyword">import</span> <span class="include">com.jme3.scene.shape.Sphere</span>;
  173. <span class="keyword">import</span> <span class="include">com.jme3.system.AppSettings</span>;
  174. <span class="keyword">import</span> <span class="include">com.jme3.system.JmeSystem</span>;
  175. <span class="comment">/**
  176. *
  177. * Demonstrates advanced use of the audio capture and recording
  178. * features. Multiple perspectives of the same scene are
  179. * simultaneously rendered to different sound files.
  180. *
  181. * A key limitation of the way multiple listeners are implemented is
  182. * that only 3D positioning effects are realized for listeners other
  183. * than the main LWJGL listener. This means that audio effects such
  184. * as environment settings will *not* be heard on any auxiliary
  185. * listeners, though sound attenuation will work correctly.
  186. *
  187. * Multiple listeners as realized here might be used to make AI
  188. * entities that can each hear the world from their own perspective.
  189. *
  190. * @author Robert McIntyre
  191. */</span>
  192. <span class="directive">public</span> <span class="type">class</span> <span class="class">Advanced</span> <span class="directive">extends</span> SimpleApplication {
  193. <span class="comment">/**
  194. * You will see three grey cubes, a blue sphere, and a path which
  195. * circles each cube. The blue sphere is generating a constant
  196. * monotone sound as it moves along the track. Each cube is
  197. * listening for sound; when a cube hears sound whose intensity is
  198. * greater than a certain threshold, it changes its color from
  199. * grey to green.
  200. *
  201. * Each cube is also saving whatever it hears to a file. The
  202. * scene from the perspective of the viewer is also saved to a
  203. * video file. When you listen to each of the sound files
  204. * alongside the video, the sound will get louder when the sphere
  205. * approaches the cube that generated that sound file. This
  206. * shows that each listener is hearing the world from its own
  207. * perspective.
  208. *
  209. */</span>
  210. <span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> args) {
  211. Advanced app = <span class="keyword">new</span> Advanced();
  212. AppSettings settings = <span class="keyword">new</span> AppSettings(<span class="predefined-constant">true</span>);
  213. settings.setAudioRenderer(AurellemSystemDelegate.SEND);
  214. JmeSystem.setSystemDelegate(<span class="keyword">new</span> AurellemSystemDelegate());
  215. app.setSettings(settings);
  216. app.setShowSettings(<span class="predefined-constant">false</span>);
  217. app.setPauseOnLostFocus(<span class="predefined-constant">false</span>);
  218. <span class="keyword">try</span> {
  219. Capture.captureVideo(app, <span class="predefined-type">File</span>.createTempFile(<span class="string"><span class="delimiter">&quot;</span><span class="content">advanced</span><span class="delimiter">&quot;</span></span>,<span class="string"><span class="delimiter">&quot;</span><span class="content">.avi</span><span class="delimiter">&quot;</span></span>));
  220. Capture.captureAudio(app, <span class="predefined-type">File</span>.createTempFile(<span class="string"><span class="delimiter">&quot;</span><span class="content">advanced</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">.wav</span><span class="delimiter">&quot;</span></span>));
  221. }
  222. <span class="keyword">catch</span> (<span class="exception">IOException</span> e) {e.printStackTrace();}
  223. app.start();
  224. }
  225. <span class="directive">private</span> Geometry bell;
  226. <span class="directive">private</span> Geometry ear1;
  227. <span class="directive">private</span> Geometry ear2;
  228. <span class="directive">private</span> Geometry ear3;
  229. <span class="directive">private</span> AudioNode music;
  230. <span class="directive">private</span> MotionTrack motionControl;
  231. <span class="directive">private</span> IsoTimer motionTimer = <span class="keyword">new</span> IsoTimer(<span class="integer">60</span>);
  232. <span class="directive">private</span> Geometry makeEar(Node root, Vector3f position){
  233. Material mat = <span class="keyword">new</span> Material(assetManager, <span class="string"><span class="delimiter">&quot;</span><span class="content">Common/MatDefs/Misc/Unshaded.j3md</span><span class="delimiter">&quot;</span></span>);
  234. Geometry ear = <span class="keyword">new</span> Geometry(<span class="string"><span class="delimiter">&quot;</span><span class="content">ear</span><span class="delimiter">&quot;</span></span>, <span class="keyword">new</span> <span class="predefined-type">Box</span>(<span class="float">1.0f</span>, <span class="float">1.0f</span>, <span class="float">1.0f</span>));
  235. ear.setLocalTranslation(position);
  236. mat.setColor(<span class="string"><span class="delimiter">&quot;</span><span class="content">Color</span><span class="delimiter">&quot;</span></span>, ColorRGBA.Green);
  237. ear.setMaterial(mat);
  238. root.attachChild(ear);
  239. <span class="keyword">return</span> ear;
  240. }
  241. <span class="directive">private</span> Vector3f<span class="type">[]</span> path = <span class="keyword">new</span> Vector3f<span class="type">[]</span>{
  242. <span class="comment">// loop 1</span>
  243. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  244. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, -<span class="integer">10</span>),
  245. <span class="keyword">new</span> Vector3f(-<span class="integer">2</span>, <span class="integer">0</span>, -<span class="integer">14</span>),
  246. <span class="keyword">new</span> Vector3f(-<span class="integer">6</span>, <span class="integer">0</span>, -<span class="integer">20</span>),
  247. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, -<span class="integer">26</span>),
  248. <span class="keyword">new</span> Vector3f(<span class="integer">6</span>, <span class="integer">0</span>, -<span class="integer">20</span>),
  249. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, -<span class="integer">14</span>),
  250. <span class="keyword">new</span> Vector3f(-<span class="integer">6</span>, <span class="integer">0</span>, -<span class="integer">20</span>),
  251. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, -<span class="integer">26</span>),
  252. <span class="keyword">new</span> Vector3f(<span class="integer">6</span>, <span class="integer">0</span>, -<span class="integer">20</span>),
  253. <span class="comment">// loop 2</span>
  254. <span class="keyword">new</span> Vector3f(<span class="integer">5</span>, <span class="integer">0</span>, -<span class="integer">5</span>),
  255. <span class="keyword">new</span> Vector3f(<span class="integer">7</span>, <span class="integer">0</span>, <span class="float">1.5f</span>),
  256. <span class="keyword">new</span> Vector3f(<span class="integer">14</span>, <span class="integer">0</span>, <span class="integer">2</span>),
  257. <span class="keyword">new</span> Vector3f(<span class="integer">20</span>, <span class="integer">0</span>, <span class="integer">6</span>),
  258. <span class="keyword">new</span> Vector3f(<span class="integer">26</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  259. <span class="keyword">new</span> Vector3f(<span class="integer">20</span>, <span class="integer">0</span>, -<span class="integer">6</span>),
  260. <span class="keyword">new</span> Vector3f(<span class="integer">14</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  261. <span class="keyword">new</span> Vector3f(<span class="integer">20</span>, <span class="integer">0</span>, <span class="integer">6</span>),
  262. <span class="keyword">new</span> Vector3f(<span class="integer">26</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  263. <span class="keyword">new</span> Vector3f(<span class="integer">20</span>, <span class="integer">0</span>, -<span class="integer">6</span>),
  264. <span class="keyword">new</span> Vector3f(<span class="integer">14</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  265. <span class="comment">// loop 3</span>
  266. <span class="keyword">new</span> Vector3f(<span class="integer">8</span>, <span class="integer">0</span>, <span class="float">7.5f</span>),
  267. <span class="keyword">new</span> Vector3f(<span class="integer">7</span>, <span class="integer">0</span>, <span class="float">10.5f</span>),
  268. <span class="keyword">new</span> Vector3f(<span class="integer">6</span>, <span class="integer">0</span>, <span class="integer">20</span>),
  269. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">26</span>),
  270. <span class="keyword">new</span> Vector3f(-<span class="integer">6</span>, <span class="integer">0</span>, <span class="integer">20</span>),
  271. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">14</span>),
  272. <span class="keyword">new</span> Vector3f(<span class="integer">6</span>, <span class="integer">0</span>, <span class="integer">20</span>),
  273. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">26</span>),
  274. <span class="keyword">new</span> Vector3f(-<span class="integer">6</span>, <span class="integer">0</span>, <span class="integer">20</span>),
  275. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">14</span>),
  276. <span class="comment">// begin ellipse</span>
  277. <span class="keyword">new</span> Vector3f(<span class="integer">16</span>, <span class="integer">5</span>, <span class="integer">20</span>),
  278. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">26</span>),
  279. <span class="keyword">new</span> Vector3f(-<span class="integer">16</span>, -<span class="integer">10</span>, <span class="integer">20</span>),
  280. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">14</span>),
  281. <span class="keyword">new</span> Vector3f(<span class="integer">16</span>, <span class="integer">20</span>, <span class="integer">20</span>),
  282. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span>, <span class="integer">26</span>),
  283. <span class="keyword">new</span> Vector3f(-<span class="integer">10</span>, -<span class="integer">25</span>, <span class="integer">10</span>),
  284. <span class="keyword">new</span> Vector3f(-<span class="integer">10</span>, <span class="integer">0</span>, <span class="integer">0</span>),
  285. <span class="comment">// come at me!</span>
  286. <span class="keyword">new</span> Vector3f(-<span class="float">28.00242f</span>, <span class="float">48.005623f</span>, -<span class="float">34.648228f</span>),
  287. <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span> , -<span class="integer">20</span>),
  288. };
  289. <span class="directive">private</span> <span class="type">void</span> createScene() {
  290. Material mat = <span class="keyword">new</span> Material(assetManager, <span class="string"><span class="delimiter">&quot;</span><span class="content">Common/MatDefs/Misc/Unshaded.j3md</span><span class="delimiter">&quot;</span></span>);
  291. bell = <span class="keyword">new</span> Geometry( <span class="string"><span class="delimiter">&quot;</span><span class="content">sound-emitter</span><span class="delimiter">&quot;</span></span> , <span class="keyword">new</span> Sphere(<span class="integer">15</span>,<span class="integer">15</span>,<span class="integer">1</span>));
  292. mat.setColor(<span class="string"><span class="delimiter">&quot;</span><span class="content">Color</span><span class="delimiter">&quot;</span></span>, ColorRGBA.Blue);
  293. bell.setMaterial(mat);
  294. rootNode.attachChild(bell);
  295. ear1 = makeEar(rootNode, <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span> ,-<span class="integer">20</span>));
  296. ear2 = makeEar(rootNode, <span class="keyword">new</span> Vector3f(<span class="integer">0</span>, <span class="integer">0</span> ,<span class="integer">20</span>));
  297. ear3 = makeEar(rootNode, <span class="keyword">new</span> Vector3f(<span class="integer">20</span>, <span class="integer">0</span> ,<span class="integer">0</span>));
  298. MotionPath track = <span class="keyword">new</span> MotionPath();
  299. <span class="keyword">for</span> (Vector3f v : path){
  300. track.addWayPoint(v);
  301. }
  302. track.setCurveTension(<span class="float">0.80f</span>);
  303. motionControl = <span class="keyword">new</span> MotionTrack(bell,track);
  304. <span class="comment">// for now, use reflection to change the timer...</span>
  305. <span class="comment">// motionControl.setTimer(new IsoTimer(60));</span>
  306. <span class="keyword">try</span> {
  307. <span class="predefined-type">Field</span> timerField;
  308. timerField = AbstractCinematicEvent.class.getDeclaredField(<span class="string"><span class="delimiter">&quot;</span><span class="content">timer</span><span class="delimiter">&quot;</span></span>);
  309. timerField.setAccessible(<span class="predefined-constant">true</span>);
  310. <span class="keyword">try</span> {timerField.set(motionControl, motionTimer);}
  311. <span class="keyword">catch</span> (<span class="exception">IllegalArgumentException</span> e) {e.printStackTrace();}
  312. <span class="keyword">catch</span> (<span class="exception">IllegalAccessException</span> e) {e.printStackTrace();}
  313. }
  314. <span class="keyword">catch</span> (<span class="exception">SecurityException</span> e) {e.printStackTrace();}
  315. <span class="keyword">catch</span> (<span class="exception">NoSuchFieldException</span> e) {e.printStackTrace();}
  316. motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
  317. motionControl.setRotation(<span class="keyword">new</span> Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
  318. motionControl.setInitialDuration(<span class="float">20f</span>);
  319. motionControl.setSpeed(<span class="float">1f</span>);
  320. track.enableDebugShape(assetManager, rootNode);
  321. positionCamera();
  322. }
  323. <span class="directive">private</span> <span class="type">void</span> positionCamera(){
  324. <span class="local-variable">this</span>.cam.setLocation(<span class="keyword">new</span> Vector3f(-<span class="float">28.00242f</span>, <span class="float">48.005623f</span>, -<span class="float">34.648228f</span>));
  325. <span class="local-variable">this</span>.cam.setRotation(<span class="keyword">new</span> Quaternion(<span class="float">0.3359635f</span>, <span class="float">0.34280345f</span>, -<span class="float">0.13281013f</span>, <span class="float">0.8671653f</span>));
  326. }
  327. <span class="directive">private</span> <span class="type">void</span> initAudio() {
  328. org.lwjgl.input.Mouse.setGrabbed(<span class="predefined-constant">false</span>);
  329. music = <span class="keyword">new</span> AudioNode(assetManager, <span class="string"><span class="delimiter">&quot;</span><span class="content">Sound/Effects/Beep.ogg</span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">false</span>);
  330. rootNode.attachChild(music);
  331. audioRenderer.playSource(music);
  332. music.setPositional(<span class="predefined-constant">true</span>);
  333. music.setVolume(<span class="float">1f</span>);
  334. music.setReverbEnabled(<span class="predefined-constant">false</span>);
  335. music.setDirectional(<span class="predefined-constant">false</span>);
  336. music.setMaxDistance(<span class="float">200.0f</span>);
  337. music.setRefDistance(<span class="float">1f</span>);
  338. <span class="comment">//music.setRolloffFactor(1f);</span>
  339. music.setLooping(<span class="predefined-constant">false</span>);
  340. audioRenderer.pauseSource(music);
  341. }
  342. <span class="directive">public</span> <span class="type">class</span> <span class="class">Dancer</span> <span class="directive">implements</span> SoundProcessor {
  343. Geometry entity;
  344. <span class="type">float</span> scale = <span class="integer">2</span>;
  345. <span class="directive">public</span> Dancer(Geometry entity){
  346. <span class="local-variable">this</span>.entity = entity;
  347. }
  348. <span class="comment">/**
  349. * this method is irrelevant since there is no state to cleanup.
  350. */</span>
  351. <span class="directive">public</span> <span class="type">void</span> cleanup() {}
  352. <span class="comment">/**
  353. * Respond to sound! This is the brain of an AI entity that
  354. * hears its surroundings and reacts to them.
  355. */</span>
  356. <span class="directive">public</span> <span class="type">void</span> process(<span class="predefined-type">ByteBuffer</span> audioSamples, <span class="type">int</span> numSamples, <span class="predefined-type">AudioFormat</span> format) {
  357. audioSamples.clear();
  358. <span class="type">byte</span><span class="type">[]</span> data = <span class="keyword">new</span> <span class="type">byte</span>[numSamples];
  359. <span class="type">float</span><span class="type">[]</span> out = <span class="keyword">new</span> <span class="type">float</span>[numSamples];
  360. audioSamples.get(data);
  361. FloatSampleTools.byte2floatInterleaved(data, <span class="integer">0</span>, out, <span class="integer">0</span>,
  362. numSamples/format.getFrameSize(), format);
  363. <span class="type">float</span> max = <span class="predefined-type">Float</span>.NEGATIVE_INFINITY;
  364. <span class="keyword">for</span> (<span class="type">float</span> f : out){<span class="keyword">if</span> (f &gt; max) max = f;}
  365. audioSamples.clear();
  366. <span class="keyword">if</span> (max &gt; <span class="float">0.1</span>){entity.getMaterial().setColor(<span class="string"><span class="delimiter">&quot;</span><span class="content">Color</span><span class="delimiter">&quot;</span></span>, ColorRGBA.Green);}
  367. <span class="keyword">else</span> {entity.getMaterial().setColor(<span class="string"><span class="delimiter">&quot;</span><span class="content">Color</span><span class="delimiter">&quot;</span></span>, ColorRGBA.Gray);}
  368. }
  369. }
  370. <span class="directive">private</span> <span class="type">void</span> prepareEar(Geometry ear, <span class="type">int</span> n){
  371. <span class="keyword">if</span> (<span class="local-variable">this</span>.audioRenderer <span class="keyword">instanceof</span> MultiListener){
  372. MultiListener rf = (MultiListener)<span class="local-variable">this</span>.audioRenderer;
  373. Listener auxListener = <span class="keyword">new</span> Listener();
  374. auxListener.setLocation(ear.getLocalTranslation());
  375. rf.addListener(auxListener);
  376. WaveFileWriter aux = <span class="predefined-constant">null</span>;
  377. <span class="keyword">try</span> {aux = <span class="keyword">new</span> WaveFileWriter(<span class="predefined-type">File</span>.createTempFile(<span class="string"><span class="delimiter">&quot;</span><span class="content">advanced-audio-</span><span class="delimiter">&quot;</span></span> + n, <span class="string"><span class="delimiter">&quot;</span><span class="content">.wav</span><span class="delimiter">&quot;</span></span>));}
  378. <span class="keyword">catch</span> (<span class="exception">IOException</span> e) {e.printStackTrace();}
  379. rf.registerSoundProcessor(auxListener,
  380. <span class="keyword">new</span> CompositeSoundProcessor(<span class="keyword">new</span> Dancer(ear), aux));
  381. }
  382. }
  383. <span class="directive">public</span> <span class="type">void</span> simpleInitApp() {
  384. <span class="local-variable">this</span>.setTimer(<span class="keyword">new</span> IsoTimer(<span class="integer">60</span>));
  385. initAudio();
  386. createScene();
  387. prepareEar(ear1, <span class="integer">1</span>);
  388. prepareEar(ear2, <span class="integer">1</span>);
  389. prepareEar(ear3, <span class="integer">1</span>);
  390. motionControl.play();
  391. }
  392. <span class="directive">public</span> <span class="type">void</span> simpleUpdate(<span class="type">float</span> tpf) {
  393. motionTimer.update();
  394. <span class="keyword">if</span> (music.getStatus() != AudioSource.Status.Playing){
  395. music.play();
  396. }
  397. Vector3f loc = cam.getLocation();
  398. Quaternion rot = cam.getRotation();
  399. listener.setLocation(loc);
  400. listener.setRotation(rot);
  401. music.setLocalTranslation(bell.getLocalTranslation());
  402. }
  403. }</code></pre></div></div>
  404. <div class="paragraph"><p><span class="image"><img src="http://www.youtube.com/v/oCEfK0yhDrY?.swf" alt="oCEfK0yhDrY?.swf" width="400" height=""></span></p></div></div>
  405. <div class="sect2"><h3 id="using-advanced-features-to-record-from-more-than-one-perspective-at-once">Using Advanced features to Record from more than one perspective at once</h3><div class="paragraph"><p><span class="image"><img src="http://www.youtube.com/v/WIJt9aRGusc?.swf" alt="WIJt9aRGusc?.swf" width="400" height=""></span></p></div></div></div>
  406. <div class="sect1"><h2 id="more-information">More Information</h2><div class="sectionbody"><div class="paragraph"><p>This is the old page showing the first version of this idea
  407. <a href="http://aurellem.org/cortex/html/capture-video.html">http://aurellem.org/cortex/html/capture-video.html</a></p></div>
  408. <div class="paragraph"><p>All source code can be found here:</p></div>
  409. <div class="paragraph"><p><a href="http://hg.bortreb.com/audio-send">http://hg.bortreb.com/audio-send</a></p></div>
  410. <div class="paragraph"><p><a href="http://hg.bortreb.com/jmeCapture">http://hg.bortreb.com/jmeCapture</a></p></div>
  411. <div class="paragraph"><p>More information on the modifications to OpenAL to support multiple
  412. listeners can be found here.</p></div>
  413. <div class="paragraph"><p><a href="http://aurellem.org/audio-send/html/ear.html">http://aurellem.org/audio-send/html/ear.html</a></p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  414. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  415. indexName: 'jmonkeyengine',
  416. inputSelector: '#doc-search',
  417. debug: false // Set debug to true if you want to inspect the dropdown
  418. });</script></body></html>