Project - Self-calculator


This project makes FEZ play audio with nothing but a PC speaker. This is not meant to play music but it is ideal if your product/project will need to voice out some commands or alerts. Maybe dial a number or playback a message … You can probably think of a million ways to use this.

The project plays two random number between 0 and 99 and randomly their addition, subtraction or multiplication. All audio files are saved on an SD card. They are PCM 8000KHz, 8 bit mono.

The files are read from the SD card and then parsed using a WAVE parser. The audio data is then sent to the analog output of FEZ.

The output is connected to an audio jack of a PC speaker. Basically, you just need ground and audio signal. See this:

The audio files included are NOT licensed fro commercial use. I found these somewhere while googleing.

Hey Gus,

I’ve been trying to get your wav player sample running. [em] (If I’m somehow using the wrong references, forgive me, or point me at them.)[/em] But here’s what I’m seeing:

The progam.cs code seems to be out of date with respect to references, or maybe their current names changed? Anything with GHIElectronics.NETMF was broken.

AnalogOut class didn’t seem to exist so I changed your definition to this:

   static AnalogOutput aout = new AnalogOutput((Cpu.AnalogOutputChannel)


That seemed to compile. So far so good? I still show one error on the actual sending of data to the port using:

aout.Set(buffer, wav.GetDataIndex(), wav.GetDataSize(), wav.GetSampleRate());

There is no .Set() method anymore, but there is a .Write and a .WriteRaw.

Basically, can you see how things in the example may have changed? I’m not that clear on how to find GHI references. I was kind of hoping Nuget would deal with that.

I think the example was made long time ago when analog out was part of the GHI libs before Microsoft added it to the core. With the latest software, you will need to use analog out in the Microsoft libs.

That said, the example uses the WAV playback which is GHI exclusive still. Look into Util class in our libs.


I found the PlayPCMAudio function in the GHI.OSHW.Hardware.Utils and revised your sample code which now builds successfully.

The program fails to deploy because “An unhandled exception of type ‘System.NotSupportedException’ occurred in GHI.OSHW.Hardware.dll”

I am trying to run this on a Fez Spider. Without much experience, I’m assuming that hardware.dll is incompatible with the chip or something?

Do I have any options with the Spider to get the same play functionality or is there a separate Hardware.Utils for it?


Thanks Andre,

Hmm… Using the Spider and GHI.Premium.System, I was able to get the PlayPCMAudio() method to build.

I set the PlayFile() in a GT.timer loop that repeats every second. But where is the output? Sounds funny to say, but when you can’t find it, its not clear what the problem is.

aout =AnalogOutput((Cpu.AnalogOutputChannel)Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0);

I didn’t see much in the docs about the Analog Out on the Spider. Only a vague hint that it might be GPIO_0. Well my scope says that isn’t it. Which header is it mapped to?

  1. I tried the same project on a Cerberus.(using the OSHW.Hardware) It starts off giving this in the output window:
    Failed allocation for 343 blocks, 4116 bytes

and ends up failing on an exception, after trying to load the .wav using the FileStream command.
System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll

Alternative method for finding ANALOG_OUTPUT: The Developers’ Guide for Spider found in its catalog entry ( ), under the Resources tab says that Socket 9 is ANALOG_OUTPUT_0. Under “Support” tab on web’s main page, consult .NET Gadgeteer ( ), Socket Types. The only socket type with AOUT is “O”, which is socket 9 on Spider. Read the Pin number from the chart.

Just pointing this out because the Socket page is a good source of info for Pins. Most of the module Letter types map to the first Letter of the primary usage for that type (R, B, G --> LCD Red Blue Green, I -> I2C protocol devices, etc.)

For Cerberus the Developers’ Guide shows socket 3 and 4 as ANALOG_OUTPUT_0 and ANALOG_OUPUT_1. But as andre.m pointed out the Cerb family is OSHW and doesn’t support the PlayPCMAudio. If you’re unfamiliar with the difference between OSHW and premium take a look at

Excellent. Thanks Andre and Jeff.

I stared at the Spider schematic a good while and just missed it in there. The socket diagram is much better. Andre’s configuration made a big difference as well.

If I get this demo cleaned up on the Spider, I will try to post it to Codeshare.

8kHz is a very low sampling rate. I was hoping for 22kHz/8bit to get reasonable audio quality. Is that achievable, or is it a hardware limitation on PCM rate or ram buffer size or something?

It’s not clear to me what the difference is there…

I used a Gadgeteer template in VS to create the Spider and Cerberus projects, and the graphical connection feature. The hardware is the Fez Spider and Fez Cerberus.

Is that what you mean?

I’m exploring a proof of concept here. I need a few features to work well, before I can consider developing on the platform. It will be up against things like the RasPI, Netduino, and Arduino. If I can have a hardware base that can be used by more than one OS, it will improve the chances of using it at all.

I was tempted to use the music module, and maybe I still will. But if it’s not necessary, then it will just add space and cost. So I want to know its limitations. How much audio can I load into RAM. What is the max sampling rate? Can it to ADPCM? Play more than one sound simultaneously.Things like this.

Holy cow! I had no idea you could do this w/o a music module. I just bought a cheap WTV020SD module off eBay that I was going to try and use for this very purpose. “Joe” is getting a voice!

As I understand it, “Joe” is built on Cerberus, where you would need the music module…?

@ Familyghost - [quote]It’s not clear to me what the difference is there…[/quote]

If you’re talking about andre.m’s question [quote]btw is it a gadgeteer project you have?[/quote] give you’re using the Gadgeteer Designer, you have a Gadgeteer project.

In brief Gadgeteer provides open source drivers for all the modules ( and is an event based programming framework where the drivers are initialized in an automatically generated start-up program. Drivers are based on Gadgeteer Socket types and their pins (

Pure NETMF programs, in general require you provide drivers for the module (easiest to modify Gadgeteer drivers) and the framework is based on a traditional [em]you start in the Main program[/em] and write code linearly or make it event driven based on your needs.

Right. Then I have a Gadgeteer project here.

Some Notes:
I need to play sounds and do other things. Like animate an LCD, run some SPI devices. So I modified the sound player to play a sound on button press. I also added the code and hardware to take-a-camera-picture->display it on the LCD from the getting started example. The PlaySound() sound method plays first, then the camera.TakePicture(). SPI is being sent in a 16ms GT timer loop continuously.

It reveals two issues:

  1. The SPI signals cut out while the audio is playing. (regardless of whether it is taking a picture)
  2. While its taking a picture, the audio plays at maybe 1/10 speed.

So PlayPCMAudio is blocking a GT timer event? Or slowing down while the camera/display refresh? Can anything be done to prevent either issue?

Have I overlooked something? Why do you say that? It looks to me that all you need is an “O” socket which the Cerberus has.

I am probably wrong, but the tight memory might make it a little difficult to play reasonable sound files…but of course the sample rate is low so a few human sounds might be pulled off. Cerberus might even be faster than the Spider - isnt that right?

Hmm… I originally thought the demo video was on a Panda-II (96KB RAM) but upon closer inspection I’m not really sure what that is…

Looks like it could be a Domino (also USBizi based – I think it’s a 144 vs 100 - a 144 has the same memory) - I’ll check when I get home.

I just ordered an AMP M35 module which seems to be a perfect compliment to this little experiment. I’ll hopefully get “Joe” talking during DevLink next week if not sooner.