SyntaxHighlighter

Friday 2 August 2013

Day 40: Sound.

ExportJPEGs bug

Fixed a bug in ExportJPEGs, where the FileSystemWatcher would call the "fbx found" event handler multiple times for the same fbx models in the incoming folder. Realised it's because of the regex replacement I do on every fbx found, this triggers the FileSystemWatcher as I've set the FileSystemWatcher to check for changes in files.

Unfortunately the reason I cannot just simply stop the Watcher from detecting file changes is that I am using a side effect of file changes to detect files. I have a touch method for when we want to load existing models in the monitored directory, that changes the creation time of every file - thereby forcing the files to be noticed by the Watcher.

You need to do this to load existing files on startup because there is no way to get the Watcher to see files that are already there.

So now I've edited my touch method, instead of resetting creation time on every file and having the Watcher detect a file change, it now renames every file in the folder and has the Watcher detecting renames. A complicated bit of regex now renames any filename to start with a full stop. If the files already start with a full stop, it replaces the full stop with a comma. In this way the user can also tell which files have been loaded because they pre existed, as all those files names will start with a comma or a full stop.

VMs and AR

Following on from yesterday when I was determining how to move the AR to a fresh machine so that it can run the demos successfully.

Okay, worked out what the issue was on the Virtual Machine and why it wouldn't load the project files: apparently you need to install XNA Game Studio in order to load .contentproj files. Installed the redistributable framework package and then tried to run ExportJPEGs.exe, and it went rather well.

Got up to the point where it told me it couldn't find a Direct3D device. It seems that VirtualBox's virtual graphics adapter isn't good enough to run our AR programs (which are tagged as HiDef Direct3D apps). I don't see this working in a VM any further than this, so the next step will be testing it on a real machine. Katy Donald and Walter are all fully prepped and installed for Visual Studio XNA development, so I can't use them, which leaves Hoops - which is currently in use by Georgiana. So in that case I think I will use Walter or Donald.. just uninstall everything related to AR off one of them and then continue from there.

In any case, the purpose of this exercise was in order to determine the minimum software installation we require in order to run the AR applications, so it is not entirely essential. I already know that we can definitely get the AR to work by moving about 1GB of source code and models, and installing a bunch of dev packages on the target machine. And now via the testing up to this point (i.e. up to until the Virtual Machine failed me), it seems the AR could work with a bare minimum which includes the following:

  1. 100MB binary files and compiled models etc, all in one folder
  2. .Net 4.5 runtime installer
  3. XNA 4.0 runtime
  4. VC redistributable package
If that is indeed all we need then we're in pretty good shape, it's pretty portable stuff.

Sync errors

Tested ExportJPEGs today, and noted that some models were failing to build for some reason. After further inspection I found that if I uploaded a whole bunch of files at once to the web server, they downloaded somewhat slowly back into the incoming directory. This meant that in some rare situations, the model would be present in the incoming model folder but not the texture. So it would fail to build because the texture can't be found.

To fix it, I added a test to check for the texture, and if its not there wait 60 seconds. If it's still not there, print error message, abandon loading that model and carry on with the program. The GUI tells the user which model is being loaded, it displays a live countdown when a file cannot be found, and displays the path of the texture it's looking for and which model it belongs to as the count occurs so if the user knows what they are doing they can attempt to fix it.

A further improvement could be to add models that could not load to a section on the GUI, and allow the user to click on them, to attempt a reload on them, and to view error messages and such about why they could not load. I will implement this later on as time permits.

To be honest this whole thing wasn't exactly a simple task and required some devastatingly interesting regex usage, for example to extract the name of the texture from inside the model file itself:
String texPath = Regex.Match(File.ReadAllText(e.FullPath), @"[rR]elative[fF]ile[nN]ame: ""(.+)""").Groups[1].Value;
And then I appended that to the model path to get the texture path in full... and other interesting nuances :)

But enough of that, moving on! On to a concept that has long awaited its time to shine. And well, now that time has finally arrived. Yes, I'm talking about..
..
s'what I'm talking about


Sound

Found some very nice sound samples online for various effects, and set about collecting them.

The latest version of XNA can handle mp3, wma, and wav files directly, and has some very useful tools for 3D sound; plus allows full control over playback (looping, pausing, stopping, playing, continuing, etc).

I ran into a roadblock very soon when trying to implement it though, Goblin XNA does not provide any way of telling the user when a marker card has been found! The issue is because I want to only play certain sounds when certain demos (i.e. certain markers) are in the view - and those sounds should stop when those demos are removed from the view. Now the only way to do this is to manually check for every single marker card in the Update() function and see if its visible! And add my own code to implement a buffer time for when a marker card is considered in view and when its considered out of the view - because the camera does lose track of markers for miniscule (and longer) periods of time when the cards are moved or when the marker is shortly obscured by light or something. We don't want stuttering audio starting and stopping at every movement of the card!

Trying to get around this now, but the current code is looking uglier by the second! Am studying the Goblin source code to determine if there are any obscure methods I can use to make this more intuitive.

Aaaaaaaand I'm taking the next week off on holiday (surprise!) for religious observances (Eid and Ramadan) plus general relaxation, so I'll be getting back to this stuff a week on Monday all being well. Planning to get started on my MEng report too after the time off so more stuff to look forward to (cough).

And in other news Toby just confirmed my 3 week extensions for this vacation placement so I get to spend even longer partaking in more furious coding fun! Great news, got to admit this vacation has been super productive, really enjoyed myself and learnt an absolute ton.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.