Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Wednesday, November 12, 2008

Sound - Debugging

The biggest drawback for me when working with sound is that I don't know that much what I am doing. What I mean is that I have spent many years, for example, working with graphics, transformations etc. and I know the language, terminology and have encountered many problems. The upshot of this is that when working with graphics I have a context to put things into and looking through the code it "makes sense", as do the problems. With sound everything is new. In this regard OSX is basically as unfamiliar as MFC.

My one good stoke of luck is, as ever, that the code is beautfully written and well commented. From the code I know that WAV files are converted to PCM. These files are then consumed by Cello's own ADPCM converter and appear in the final output file.

Having looked through Apple's sample there is a sample SCAudioCompress command line tool that converts sounds. It also has an optional UI that means it is posible to play around with settings. Hacking this in to a class that was based on the original WAV source was not hard. My approach was to just get it in to see if I was on the right track. Once I had something working there would be an opportunity to refine.

My first test file was a short movie with a phrase from Peter Griffin (from "Family Guy").

Adding the code was not too bad. The existing tool wrote a file and loading a buffer wit the contents of a file is quite straight forward. The results were disappointing - the first sound that Cello published was short and unintelligible. Not understanding much about sound I felt a certain amount of despair - where to start?

To debug it I compared the two builds in the debugger. Running Visual Studio under VMware means that I can look at the two builds side-by-side. I also compared the two log files that are created during publishing. My discovery was that the OSX build outputted roughly a 10th of the sound than the PC build. The bug was that in calculating the duration of sound I was out by a factor of 8 - the difference between 8 bits and 1 byte. After fixing this the sound appeared. The unintelligibility of the first part of the sound was due to he strange form of Peter Griffin's voice. If I had chosen a voice like Brian - my life would have been less fraught.

Tuesday, May 20, 2008

typename in templates - gcc errors

Pressing on I am working through the generator files. These are a set of files that generate the output. The biggest problem I found so far in these is some template definitions that tripped up gcc which requires a typename to be specified in some circumstances where visual c++ was quite happy. The following class - when complied on XCode

template <class T>
class Foo
{
public:
  Foo(const T&);
  std::list<T*>::iterator Bar();
};
Results in error: expected ';' before 'Bar'

Adding typename fixes the problem - so the gcc friendy Bar looks like this:
  typename std::list<T*>::iterator Bar();
As with many compiler errors the error message gave me little insight into the problem. I tracked down the solution looking through the boost libraries for code that returns an iterator.

Sunday, May 18, 2008

Pointers to Methods in C++

Working through the ECMA script (JavaScript) interpreter I had some problems compiling a dispatch table that used function pointers. The function pointers were to non-static object methods. My gut reaction was that this must be wrong and a non-standard MSDN/Visual C++ extension. Having worked with C++ for a long time you sort of assume that you know the beast.

I briefly started converting the methods to static methods that passed in the object this in as the first parameter before I stepped back and looked at the problem properly. Function pointers to class methods are a part of the C++ standard. It required a very light touch to get the code to compile correctly. Here is a stolen code sample illustrating pointers to methods. I have modified it slightly to include a typedef for the method pointer.

class Adder
{
int x;
public:
Adder(int in) : x(in) { }
int addx(int y) { return x + y; }

// declare MethodPointer
typedef int (Adder::*MethodPointer)(int);
};

int main()
{
// pointer to the addx method
Adder::MethodPointer new_function
= &Adder::addx;

// Create an Adder instance
Adder foo = Adder(3);

// Call the method
std::cout << (foo.*new_function)(5)
<< std::endl; // prints "8"
return 0;
}
As ever I stand back staggered by what is out there on the internet. Wikipedia has an excellent section on function pointers here - and amazingly there is/was a site http://www.function-pointer.org/ dedicated to explanations of function pointers.

Saturday, May 10, 2008

Side by Wrinkled Side - VMWare Fusion

I have jut installed VMWare Fusion. This is an almost magical piece of software that means that you can run Windows at the same time as OSX. The s/w has some trickery that means that your XP (and I am sure Vista) Windows can be scarily interleaved with your Mac windows should you want it. The whole mish-mash is a little strange (and behaves a little strangely) but it means that you can run Visual Studio at the same time as XCode - and conveniently do things like copy/paste between them.

Later in the MFC->OSX port when I will be debugging I think that being able to run XCode and Visual Studio 'side by wrinkled side ... like two old kippers in a box' will save a huge amount of time.