<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lithium flowers bloom &#187; sound</title>
	<atom:link href="http://leejayxia.com/blog/tag/sound/feed/" rel="self" type="application/rss+xml" />
	<link>http://leejayxia.com/blog</link>
	<description>the weblog</description>
	<lastBuildDate>Sat, 15 May 2010 20:52:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Storytelling stickers update</title>
		<link>http://leejayxia.com/blog/storytelling-stickers-update/</link>
		<comments>http://leejayxia.com/blog/storytelling-stickers-update/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 22:28:27 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Toy Design]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[RFID]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[Spring 2009]]></category>
		<category><![CDATA[sticker]]></category>
		<category><![CDATA[toy]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=611</guid>
		<description><![CDATA[Wrapping up what&#8217;s happened to the storytelling stickers! THE READER The RFID reader is working! It took a while though. I did some search and ended up taking arduino codes from http://blog.formatlos.de/2008/12/08/arduino-id-12/ featuring the AF_SoftSerial library. It&#8217;s very well written and comprehensive. The scripts added a kicking off step and a disconnection detection as well. [...]]]></description>
			<content:encoded><![CDATA[<p>Wrapping up what&#8217;s happened to the <a href="http://leejayxia.com/blog/toy-design-proposal/">storytelling stickers</a>!</p>
<h3>THE READER</h3>
<p>The RFID reader is working! It took a while though. I did some search and ended up taking arduino codes from <a href="http://blog.formatlos.de/2008/12/08/arduino-id-12/">http://blog.formatlos.de/2008/12/08/arduino-id-12/</a> featuring the <a href="http://www.ladyada.net/make/eshield/AFSoftSerial.zip">AF_SoftSerial library</a>. It&#8217;s very well written and comprehensive. The scripts added a kicking off step and a disconnection detection as well. Great work! A simple processing sketch was made to display the identifier code. </p>
<p><object width="640" height="480"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3933690&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3933690&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="480"></embed></object></p>
<p>The tag needs to be really close to the reader to be recognized, which is fine in my project. But since I probably needs to get reading from both ends of a miniature trumpet/horn, that might not be good enough. I&#8217;m trying to build some antenna for the reader and see if it could extend the accessibility.  </p>
<h3>THE TAG</h3>
<p>The tags arrived too. I ordered 300 raw EM4001 RFID tags (meaning that they come with exposed coil antennae) and unfortunately a lot of them broke. A lot of soldering is ahead! But I got enough to start anyway, like a hundred.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image019.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image019-300x225.jpg" alt="image019" title="image019" width="300" height="225" class="alignnone size-medium wp-image-616" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image017.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image017-300x225.jpg" alt="image017" title="image017" width="300" height="225" class="alignnone size-medium wp-image-615" /></a>&nbsp;<a href="http://leejayxia.com/blog/wp-content/uploads/2009/04/image0251.jpg" rel="lightbox[611]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/04/image0251-300x225.jpg" alt="image0251" title="image0251" width="300" height="225" class="alignnone size-medium wp-image-617" /></a></p>
<h3>THE SOUND</h3>
<p>I got the <a href="http://www.ladyada.net/make/waveshield/">wave sound shield from Adafruit</a> and finished assembling while procrastinating. But I haven&#8217;t tried to use them because it doesn&#8217;t record to the card and I decided to fall back to use a computer in this phrase.</p>
<p>So now it works like this. Whenever a card/tag/sticker is seen/read, according to the mode an audio clip associated to the tag ID would be recorded or played, by the computer. All sound files are stored on the computer instead of any hardware/memory card as I previously planned. The processing sketch was adapted to keep track of a known card and pick the corresponding sound file to play/record. </p>
<p>[Videos to be uploaded soon]</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.signals.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.analysis.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ddf.minim.effects.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">processing.serial.*</span><span style="color: #339933;">;</span><br />
<br />
Serial myPort<span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> connected <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">String</span> activeTag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Waiting...&quot;</span><span style="color: #339933;">;</span><br />
PFont f <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Helvetica&quot;</span>, <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">Hashtable</span> cards<span style="color: #339933;">;</span><br />
Minim minim<span style="color: #339933;">;</span><br />
AudioInput in<span style="color: #339933;">;</span><br />
AudioRecorder recorder<span style="color: #339933;">;</span><br />
AudioPlayer player<span style="color: #339933;">;</span><br />
<br />
<span style="color: #003399;">String</span> previousCard <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">boolean</span> autoPilot <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connecting...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; myPort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Serial<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, Serial.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, <span style="color: #cc66cc;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; myPort.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; cards <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Hashtable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; loadCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; minim <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Minim<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; in <span style="color: #339933;">=</span> minim.<span style="color: #006633;">getLineIn</span><span style="color: #009900;">&#40;</span>Minim.<span style="color: #006633;">STEREO</span>, <span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">800</span>,<span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; textAlign<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; textFont<span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WAITING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>connected<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myPort.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span>activeTag,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PLAYING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RECORDING&quot;</span>,width <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>recorder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> player.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> in.<span style="color: #006633;">bufferSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">50</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">left</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line<span style="color: #009900;">&#40;</span>i, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span>, i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">150</span> <span style="color: #339933;">+</span> in.<span style="color: #006633;">right</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> player.<span style="color: #006633;">isPlaying</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>recorder <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #666666; font-style: italic;">/* &amp;&amp; recorder.isRecording()*/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">endRecord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> loadCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; cards.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>lines <span style="color: #339933;">=</span> loadStrings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;index.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lines <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> lines.<span style="color: #006633;">length</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> card <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>lines<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cards.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>card, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> dumpCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">PrintWriter</span> writer <span style="color: #339933;">=</span> createWriter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data/index.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Enumeration</span> e <span style="color: #339933;">=</span> cards.<span style="color: #006633;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> e.<span style="color: #006633;">hasMoreElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> card <span style="color: #339933;">=</span> e.<span style="color: #006633;">nextElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; writer.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>card<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; writer.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; writer.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>Serial port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003399;">String</span> myString <span style="color: #339933;">=</span> port.<span style="color: #006633;">readStringUntil</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myString <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>myString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connected <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;connected~!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>myString.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0000000000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; activeTag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Disconnected&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode <span style="color: #339933;">&amp;&amp;</span> player <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>previousCard <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Disconnect from playing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>previousCard <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Disconnect from recording&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousCard <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; activeTag <span style="color: #339933;">=</span> myString<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cards.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>activeTag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cards.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>activeTag,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dumpCards<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//auto switch to record &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: switch to record mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #666666; font-style: italic;">//found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//auto switch to play&nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: switch to play mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cards.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span>activeTag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Start playing new file, disconnect from previous &quot;</span> <span style="color: #339933;">+</span> previousCard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;loading &quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; to play&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player <span style="color: #339933;">=</span> minim.<span style="color: #006633;">loadFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data/&quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.wav&quot;</span>, <span style="color: #cc66cc;">2048</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.<span style="color: #006633;">loop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Not recorded yet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #666666; font-style: italic;">//record mode</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">!=</span> previousCard<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span>activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;: Start playing new file, disconnect from previous &quot;</span> <span style="color: #339933;">+</span> previousCard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder <span style="color: #339933;">=</span> minim.<span style="color: #006633;">createRecorder</span><span style="color: #009900;">&#40;</span>in, <span style="color: #0000ff;">&quot;data/&quot;</span> <span style="color: #339933;">+</span> activeTag <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.wav&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recorder.<span style="color: #006633;">beginRecord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousCard <span style="color: #339933;">=</span> activeTag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; in.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; closePlayer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; closeRecorder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; minim.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">void</span> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; playMode <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>playMode<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>playMode<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;play mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;record mode&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; autoPilot <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>autoPilot<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>autoPilot<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: ON&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Autopilot: OFF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h3>THE NAME</h3>
<p>Any thoughts on a name for the toy?</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/storytelling-stickers-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When you cannot sleep</title>
		<link>http://leejayxia.com/blog/when-you-cannot-sleep/</link>
		<comments>http://leejayxia.com/blog/when-you-cannot-sleep/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 04:44:37 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Redial:Interactive Telephony]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[insomnia]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[midterm]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[Spring 2009]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=504</guid>
		<description><![CDATA[It&#8217;s a shame I never wrote about Redial class since it really turned out to be my favorite this semester. Asterisk is so fun to hack around with although so far we&#8217;ve just been doing really simple stuff. For the midterm, Li and I teamed up and decided to create an answering bot which you [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a shame I never wrote about Redial class since it really turned out to be my favorite this semester. Asterisk is so fun to hack around with although so far we&#8217;ve just been doing really simple stuff.</p>
<p>For the midterm, <a href="http://itp.nyu.edu/blogs/ll1282/">Li</a> and I teamed up and decided to create <a href="http://itp.nyu.edu/blogs/ll1282/spring-2009-midterm-redial/">an answering bot which you can trash-talk to when you really cannot sleep at night</a> and don&#8217;t wanna bother your friends. Some apparent challenges are real-time level detection, smart (or vague) response behavior (to make sure it&#8217;s not too robotic), and the uncertainty that the monitor application might lock the access to the audio file that it&#8217;s writing into.</p>
<p><strong>DIAL PLAN AND AGI</strong></p>
<p>We started by wrapping up everything within a single php file keeping everything through AGI, and our extension dial plan looked as simple as:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">exten =&gt; s,1,Answer()<br />
exten =&gt; s,n,SetGlobalVar(lx243_caller=${CALLERID(num)})<br />
exten =&gt; s,n,SetGlobalVar(lx243_timestamp=${STRFTIME(${EPOCH},GMT-5,%C%y%m%d%H%M%S)})<br />
exten =&gt; s,n,System(rm /home/lx243/tmp/${CALLERID(num)}/*.*)<br />
exten =&gt; s,n,System(rmdir /home/lx243/tmp/${CALLERID(num)}/)<br />
exten =&gt; s,n,System(mkdir /home/lx243/tmp/${CALLERID(num)})<br />
exten =&gt; s,n,System(chmod 777 /home/lx243/tmp/${CALLERID(num)})<br />
exten =&gt; s,n,Monitor(wav,/home/lx243/tmp/${CALLERID(num)}/monitor)<br />
exten =&gt; s,n,AGI(/home/lx243/asterisk_agi/li.php);<br />
<br />
exten =&gt; h,1,System(mv /home/lx243/tmp/${CALLERID(num)}/monitor-in.wav /home/lx243/asterisk_sounds/moniter-in-${lx243_caller}-${lx243_timestamp}.wav)<br />
exten =&gt; h,n,System(mv /home/lx243/tmp/${CALLERID(num)}/monitor-out.wav /home/lx243/asterisk_sounds/moniter-out-${lx243_caller}-${lx243_timestamp}.wav)</div></td></tr></tbody></table></div>
<p>The dial plan itself didn&#8217;t do much except for initializing some of the global variables, clearing up some of the tmp folders, starting the monitor recording and eventually move the recorded file to another place.</p>
<p>We decided to use Monitor instead of using continuous Record because we realized we cannot record while there&#8217;s an audio file being played back. So far I haven&#8217;t find a good way to bypass this synchronous behavior in AGI. (Probably need to involve more complicated shell scripts? )</p>
<p>Ideally I would use a time stamp as part of the folder name in combination with the caller id, but I&#8217;m having two issues here.</p>
<ul>
<li>I first tried to start the monitor within the php file using AGI, but with no luck. I did not spend too much time on that but for now it seems still doable by including the asterisk manager script and using the <a href="http://phpagi.sourceforge.net/phpagi2/docs/phpAGI/AGI_AsteriskManager.html#Monitor">Monitor</a> function. Will try next time.</li>
<li>Due to the failure above, I just thought I could initiate the Monitor outside the php script in the dial plan, and pass the path to the monitor recording file to php script for further processing. However this is not that straightforward. AGI() application in dialplan does not take more arguments than the php script file name. I guess it could be a workaround to call it by passing the param in a querystring and use $_GET in php to retrieve that. I cannot remember whether that worked for me or not but anyway I didn&#8217;t go that direction.</li>
</ul>
<p>So, I didn&#8217;t want to implement another protocal between dial plan and php either, so I just defined the arbitary naming convention for the monitor recording to be stored under ~/tmp/[callerid].</p>
<p><strong>CUT THE FILE</strong></p>
<p>The second step turned out to be creating a loop in the php script, to constantly monitor and analyse the recorded audio as an user input every ten seconds to provide reasonble feedback. But we were not that far yet. We did some research to find possible ways to analyse only the short clip of the audio file that we&#8217;re interested (last 10 seconds). Several feasible solutions:</p>
<ul>
<li><a href="http://etree.org/shnutils/shntool/">shntool</a>, pretty easy to use and to embed in the php code, which is what we used for this project. We called shntool to cut the file on demand in each iteration by following command:<br />
<blockquote><p>
shntool split -O always -f [cue file name] -d [output folder] [input file name]
</p></blockquote>
<p>The cue file was generated automatically according to the total elapsed time and last interested time period, in following format:</p>
<blockquote><p>
INDEX 01 00:10<br />
INDEX 02 00:20<br />
&#8230;
</p></blockquote>
<p>Detailed <a href="http://etree.org/shnutils/shntool/support/doc/shntool.txt">documentation</a> of shntool.
</li>
<li><a href="http://sox.sourceforge.net/">sox</a>, we just realized after we finished almost everything that sox can do this even simpler, by using trim effect as following:<br />
<blockquote><p>
sox [source file name] [target file name] trim [SECOND TO START] [SECONDS DURATION]
</p></blockquote>
<p>We haven&#8217;t tried this anyway, just throwing it here for documentation.
</ul>
<p><strong>GET THE STAT</strong></p>
<p>Another exciting feature in sox that we found was to do DFT on the sound data. The command is also simple:</p>
<blockquote><p>
sox [sound file name] -e stat -freq
</p></blockquote>
<p>Using the stat effect without the -freq option will give brief info which is actually good enough for basic level detection. Adding the -freq would print out the DFT data. One more thing is it&#8217;s printing to stderr by default, so if you want it be directed to a log file would need to call:</p>
<blockquote><p>
sox [sound file name] -e stat -freq -v 2> [log file name]
</p></blockquote>
<p>We were not sure about the DFT data we got, and solely looking at the numbers was not helpful enough for us to determine the thresholds for volumes. We would like to know the typical output of murmuring, normal talking and probably yelling, so we built a simple processing sketch to verify these outputs.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2009/03/e59bbee78987-1.png" rel="lightbox[504]"><img src="http://leejayxia.com/blog/wp-content/uploads/2009/03/e59bbee78987-1-300x187.png" alt="e59bbee78987-1" title="asterisk log and processing as console" width="300" height="187" class="alignnone size-medium wp-image-522" /></a></p>
<p>As shown in the screenshot, the processing sketch is polling the stat file created for each short chunk of the audio file. We failed to get a perfect realtime output reading in the processing since each file needs a little bit time to be trimmed and calculated. Also we were getting some weird problem which I cannot describe in English now that the AGI scripts would get halt if it&#8217;s trying to access a just-generated file too hasty. Anyway the shortest latency we got was a 5-second-late visualization of the telephone conversation.</p>
<p><strong>MOODS</strong></p>
<p>The processing sketch proved the stat info from sox was valid, and within acceptable range of delay, so we moved on to define different &#8220;mood&#8221; status for the answering bot. We put down the sound effects that we would like to create and broke them into over ten categories, including 3 different greeting mode, 3 levels of &#8220;interested&#8221; mode, 3 levels of &#8220;idle&#8221; mode and a frustrated mode which hangs up the phone &#8212; we called it a BOT HANGUP.</p>
<p>The actual recording of these sound effects didn&#8217;t take very long and was pretty fun to do. We ended up having 58 different responses according to different contexts. Li recorded almost all the sounds, hopefully he would enjoy talking to himself!</p>
<p><strong>STATE MACHINE</strong></p>
<p>The transfer between moods was implement in a simple state machine, by looking into current mood states and current (and some of the history) context, which contains the duration of the previous recorded audio piece, the average, minimum and maximum amplitude. There&#8217;s whole bunches of more information that are made available through the DFT however we didn&#8217;t have enough knowledge about sounds to push it further. </p>
<p>The basic idea is the harder the caller talks, the more interested the bot is supposed to be. If the caller stops talking, the bot falls into idle mode and would eventually go to frustrated mode and hangup. I guess we did pretty well in some of the transitions, but it did happen that the caller might be stuck in one of these states. Sometimes the splitted audio file just could not be updated and so was the stat file. We haven&#8217;t figured out why.</p>
<p><strong>TESTS</strong></p>
<p>We tried to trash talk to the bot, read poems and random news to &#8220;him&#8221;. He got mad pretty easily, or sometimes went retarded. We tweaked the numbers in the state machine, and we read more news to him. We stopped while he was not getting too excited about poems any more. You know these kind of stuff can take forever.</p>
<p>We asked some friends to call. Our friends on the floor were pretty cool and tolerated its stupidness. Some of the others didn&#8217;t feel comfortable with it and would not like to talk. One of my friend hated it and told me it&#8217;s the dumbest thing ever and I guess this was my fault.</p>
<p><strong>CONCLUSION</strong></p>
<p>I&#8217;m happy with what we did in this week and am excited that we made this framework work. The bot sounds pathetic sometimes, but probably I do want to call him while I cannot sleep. To make him smarter seems to be a pretty clear direction to go, we also got some really interesting ideas from Jorge that we might introduce some vague quotes that will fit any conversation, or let him talk about any sports or whatever suggestive topics that might help the conversation. Also we would like to build a web interface for people to retrieve their recordings the following day. The possibility of application is endless, but I will definitely apply this to one of my previous project, which is a dream sharing community website, to make submission via phone possible. I really love this class so far. Asterisk rocks!</p>
<p>If you would like to talk to the bot, or if you were so bored to read my blog at midnight, call:</p>
<h1>1.212.796.0961 x 193</h1>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/when-you-cannot-sleep/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visualizing Sound: Week 2</title>
		<link>http://leejayxia.com/blog/visualizing-sound-week-2/</link>
		<comments>http://leejayxia.com/blog/visualizing-sound-week-2/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 03:43:34 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Visualizing the Five Senses]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Week2]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=84</guid>
		<description><![CDATA[I played a lot with processing today and almost forgot about the homework. Here comes the visualization for the famous pink song: First I changed the audio source to line-in so that I could play live with whatever I want. And I do love to snap to my laptop and see it react. *snap* *snap* [...]]]></description>
			<content:encoded><![CDATA[<p>I played a lot with processing today and almost forgot about the homework.</p>
<p>Here comes the visualization for the famous pink song:</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-10.png" rel="lightbox[84]"><img class="alignnone size-medium wp-image-86" title="pink visualization 1" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-10-300x225.png" alt="" width="300" height="225" /></a> <a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-9.png" rel="lightbox[84]"><img class="alignnone size-medium wp-image-85" title="pink visualization 2" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-9-300x225.png" alt="" width="300" height="225" /></a></p>
<p>First I changed the audio source to line-in so that I could play live with whatever I want. And I do love to snap to my laptop and see it react. *snap* *snap*</p>
<p>Also it&#8217;s fun to whistle at the program to see what&#8217;s happening.</p>
<p>The primary factor for visualization in this piece is the shape of diamond. I do not really want to mess up with 3D transforming and matrix things&#8230;so to make life easier I came up with following specs:</p>
<p>* Frequency &#8211; mapped to color of the diamond. Firstly the full spectrum was mapped to full Hue scope in a linear manner. That is to map 0 &#8211; 22050Hz to 0-360. However for music and vocal the frequency gathers around below 2000Hz, so I trimmed the sample frequency range to 0 &#8211; 16000Hz. Not much difference in the result though because it&#8217;s not enough. But at least it&#8217;s more colorful than before the change, and actually I don&#8217;t really wish to lose the sampling of higher frequency.</p>
<p>* Amplitude &#8211; mapped to saturation and size of the diamond. A little randomness was also added.</p>
<p>* History &#8211; I would rather create an overall feeling of the piece of the sound than to analyze its features at any timeslot. So I made the previous visualization of the sound fade into the background. I&#8217;m thinking of a better solution though&#8230; maybe after I get comfortable with the 3D stuff.</p>
<p>* Keyboard Controls &#8211; several commands could be made through keyboard shortcuts:</p>
<p>1) l (as in Leopard) &#8211; toggle log/debug mode (which shows a waveform of spectrum)</p>
<p>2) c &#8211; clear screen</p>
<p>3) + &#8211; increase threshold for amplitude, which filters frequency with amplitude above threshold to sample</p>
<p>4) &#8211; - decrease threshold for amplitude</p>
<p>After getting tired of snapping, I used miniAudicle to generate sounds for testing, which looks pretty good from the result&#8217;s aspect.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-11.png" rel="lightbox[84]"><img class="alignnone size-medium wp-image-94" title="Random noise between frequency 200 - 1000" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-11-300x225.png" alt="" width="300" height="225" /></a> <a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-8.png" rel="lightbox[84]"><img class="alignnone size-medium wp-image-88" title="Generating sound with miniAudicle" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/e59bbee78987-8-300x228.png" alt="" width="300" height="228" /></a></p>
<p>Link for applet (using pink.mp3)</p>
<p><a href="http://leejayxia.com/processing/v5s_week2/" target="_blank">http://leejayxia.com/processing/v5s_week2/</a></p>
<p>To play it with microphone you need to download <em>Executable for Mac OSX</em></p>
<p><a href="http://leejayxia.com/processing/v5s_week2/week2.zip" target="_blank">http://leejayxia.com/processing/v5s_week2/week2.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/visualizing-sound-week-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualizing Sound: first attempt</title>
		<link>http://leejayxia.com/blog/visualizing-sound-first-attempt/</link>
		<comments>http://leejayxia.com/blog/visualizing-sound-first-attempt/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 13:53:52 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Visualizing the Five Senses]]></category>
		<category><![CDATA[Fall 2008]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[Week1]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=76</guid>
		<description><![CDATA[This is a late post but late is better than nothing. My very first piece of work ever in processing is an &#8220;equalizer&#8221; for an mp3 file. It&#8217;s pretty much basic (well, lame even under my standard) but featuring the FFT and BeatDetect interface in minim library. I played around with the functions the FFT [...]]]></description>
			<content:encoded><![CDATA[<p>This is a late post but late is better than nothing. My very first piece of work ever in processing is an &#8220;equalizer&#8221; for an mp3 file. It&#8217;s pretty much basic (well, lame even under my standard) but featuring the FFT and BeatDetect interface in <a href="http://code.compartmental.net/tools/minim/" target="_blank">minim</a> library.</p>
<p>I played around with the functions the FFT provides and decided to use both the <strong><em>Forward Transform</em></strong> to create full spectrum of the piece of music, and the <strong><em>Averages</em></strong> to see what it would be different than the full scale. I put them oppose from bottom and the top of the screen so that I could compare the amplitutes of different frequences and the aggregated/average values while groups of frequences are combined.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1.jpg" rel="lightbox[76]"><img class="alignnone size-medium wp-image-77" title="processing_week1" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1-300x299.jpg" alt="" width="300" height="299" /> </a><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1_2.jpg" rel="lightbox[76]"><img class="alignnone size-medium wp-image-78" title="processing_week1_2" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1_2-300x300.jpg" alt="" width="300" height="300" /></a></p>
<p>As can be seen from the screenshot the &#8220;average&#8221; group has fewer bands.  However the shape doesn&#8217;t look right compared to the full spectrum, although the most loud parts of the sound gather around lower frequencies, the average shows the most heavy part in the middle. This is because the average was initiated and calculated as Log-Average in stead of Linear. To use a linear average just change the initializing statement from:</p>
<pre lang="java">fftLog.logAverages(22, 3);</pre>
<p>to:</p>
<pre lang="java">fftLog.linAverages(30);</pre>
<p>It turned out to be what&#8217;s expected. Still not making much sense though.</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1_3.jpg" rel="lightbox[76]"><img class="alignnone size-medium wp-image-79" title="processing_week1_3" src="http://leejayxia.com/blog/wp-content/uploads/2008/09/processing_week1_3-300x297.jpg" alt="" width="300" height="297" /></a></p>
<p>Another important factor I thought was important for music visualization is the beat. So I made splash-like effect to the canvas whenever a beat was detected. This is pretty straight-forward and not doing well with the sample music. The sound energy mode tracks just &#8220;significant spikes in the level&#8221; so it might not be accurate for all samples.</p>
<p>TO-DOs for week2</p>
<p>* Make visualization more comprehensive;</p>
<p>* Add dimension of time;</p>
<p>* Allow interaction for exploration into the music</p>
<p>* Try Frequency Energy mode for beat detecting, which is much for flexible with custom parameters in isRange() functionality;</p>
<p>applet link here: <a href="http://leejayxia.com/processing/v5s_week1/" target="_blank">http://leejayxia.com/processing/v5s_week1/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/visualizing-sound-first-attempt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

