Anyone tried adding an audio resource to the a Gadgeteer project?

I have used resources for fonts, strings and images, but when I add audio it fails miserably.

Warning 1 The custom tool ‘ResXFileCodeGenerator’ failed. Exception has been thrown by the target of an invocation. c:\users\njb\documents\visual studio 2012\Projects\SoundResourceTest2\SoundResourceTest2\Resources.resx SoundResourceTest2

After that attempt the whole project file is corrupt, and I have tried several file formats and file-sizes.

Any experiences?

Coincidently, I was trying to add an audio resource to a NETMF 4.2 project today to then stream the bytes to the Gadgeteer Music Module. I added the resource, but then could not use it at all. After 20 minutes of trying I gave up and solved the problem by adding an SD card and retrieving the audio file (having converted it to a .ogg file) from that. This approached work just fine.

I’ll be interested to here if anyone else has been successful.

This should be an issue in codeplex…?

Can I see your code for sd play?

Two methods here. One to mount the SD and load four ogg files into byte arrays, and one to actually play the files.

I used http://media.io/ to convert some wav files I downloaded into ogg files. The wav files didn’t always play correctly, but once I’d converted them to ogg they were fine. Although I don’t think it was necessary I also formatted my SD card to Fat32 (it is a 32GB card) and copied the ogg files onto it using my laptop.

You’ll also need the following includes:


using Microsoft.SPOT.IO;
using System.IO;


        private void ConfigureSD()
        {
            string _root = string.Empty;
            try
            {
                sdCard.MountSDCard();
                Thread.Sleep(500);

                String rootDirectory = sdCard.GetStorageDevice().RootDirectory;
                if (VolumeInfo.GetVolumes()[0].IsFormatted)
                {
                    _root = VolumeInfo.GetVolumes()[0].RootDirectory;
                    string[] files = Directory.GetFiles(_root);

                    // Lists all files on SD Card
                    for (int i = 0; i < files.Length; i++)
                    {
                        Debug.Print(files[i]);
                    }
                }
                else
                {
                    Debug.Print("Cannot use SD-Card");
                }

                // Setup string for each of the ogg files I want to load
                string path = _root + @ "\demofile.txt";
                string wavPath1 = _root + @ "\wickedlaugh1.ogg";
                string wavPath2 = _root + @ "\spooked.ogg";
                string wavPath3 = _root + @ "\ghost01.ogg";
                string wavPath4 = _root + @ "\hauntedhouse.ogg";


                // Load each file into it's byte array and then wait 1sec before loading the next
                wavContents1 = File.ReadAllBytes(wavPath1);
                Thread.Sleep(1000);
                Debug.Print("WAV1 loaded");
                wavContents2 = File.ReadAllBytes(wavPath2);
                Thread.Sleep(1000);
                Debug.Print("WAV2 loaded");
                wavContents3 = File.ReadAllBytes(wavPath3);
                Thread.Sleep(1000);
                Debug.Print("WAV3 loaded");
                wavContents4 = File.ReadAllBytes(wavPath4);
                Thread.Sleep(1000);
                Debug.Print("WAV4 loaded");

                // All ogg files loaded
                Debug.Print("All WAV files loaded");
            }
            catch (Exception ex)
            {

                Debug.Print(ex.Message);
            }
        }


        private void PlayNextSound()
        {
            // If a sound is currently not playing then play the next one
            if (!playingMusic)
            {
                // Move the next next sound
                wav++;
                // Set sound volume
                music.SetVolume(200);
                // Set a flag to say a sound is playing to stop any more calls
                playingMusic = true;

                // Play the current sound
                if (wav == 1)
                {
                    music.Play(wavContents1);
                }
                else if (wav == 2)
                {
                    music.Play(wavContents2);
                }
                else if (wav == 3)
                {
                    music.Play(wavContents3);
                }
                else if (wav == 4)
                {
                    // If this is the last sound then start at the beginning again.
                    music.Play(wavContents4);
                    wav = 0;
                }
            }
        }

1 Like

@ Jason - Thanks a lot, I think thats a way forward to mee, converting to ogg.

Have you tried playing the file directly from the SD-card with the music.Play([path])?

Can I ask you to try with your card, looking to my code in: https://www.ghielectronics.com/community/forum/topic?id=16348

Thanks ;D

I will do. Give me a while and I’ll get back to you.

This might take a while as I am still using V4.2 and don’t have the method to play a file. That would mean upgrading my Spider to V4.3.1 and my c# project.

Keep watching and I’ll see what I can do.

I assume that the audio files are not that big, since you want to store them as resources. I haven’t look into the details off your resource problem but another approach is to convert an audio file to a static c# source code byte array and include it in your source code, or add them to a library that you link with your application.

I spent half an hour trying to uninstall 4.2 and install 4.3 of GHI SDK.

I GAVE UP !!!

If I can find a machine that I am less reliant on I will give it another try, but my hardware is all running 4.2 and when I tried to upgrade my spider it wasn’t happy. Swapped to the loader (by moving the switches) mode to charge the boot loader but then my PC could not see the spider (even in Device Manager the com port was broken).

The software seemed to go on OK, but I couldn’t change the hardware.

If I manage to get GHI SDK 4.3 installed on a machine and update my Spider I’ll check how the Music Module behaves and post back.

I thought is was powered, but now I’m not so sure. A PSU was plugged into the wall, but when I just looked at it, it was switched off :-[

Not sure if that was the case when I tried the upgrade.

I’ll try again when I have more time.