Playing audio on G-120

Hi,

I am trying to find an example of playing audio on g-120 with 4.2 sdk.
the following example code does not compile:

[http://www.ghielectronics.com/docs/10/analog-outputs ]

using Microsoft.SPOT.Hardware;
 
namespace change_this_to_your_namespace
{
   public class Program
   {
      public static void Main()
      {
         //Setup Analog on our first analog output channel
         AnalogOutput output = new AnalogOutput((Cpu.AnalogOutputChannel)Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0);
         output.Scale = 3.3; //Set scale to maximum voltage offset
         output.Write(0.5); //Write half of the maximum
      }
   }
}

I actually can’t find the AnalogOutput type in this SDK.
I think it was in the Microsoft.SPOT namespace, but its not there anymore…

Thanks,

Yoav

@ YoavG -
it is in Microsoft.SPOT.Hardware and you should add Microsoft.SPOT.Hardware in References

I have added it in References,
It seems that my version of .NET micro framework does not include the AnalogOut type…
I don’t see it on MSDN as well…

I am using .NET micro framework 4.2.

I was using an example code for FEZ I downloaded, in it the type was AnalogOut instead of AnalogOutput. I did not notice it till now.

Now does anyone have an example for playing a WAV file?

in the code I had GUS used :


static AnalogOut aout = new AnalogOut(AnalogOut.Pin.Aout0);

public static void PlayFile(string str)
        {
            FileStream file = new FileStream("\\SD\\" + str + ".wav", FileMode.Open, FileAccess.Read);
            int length = file.Read(buffer, 0, buffer.Length);
 
            WAVE wav = new WAVE(buffer);
 
            aout.Set(buffer, wav.GetDataIndex(), wav.GetDataSize(), wav.GetSampleRate());
 
            file.Close();
        }

https://www.ghielectronics.com/community/codeshare/entry/511

I have AnalogOutput instead of AnalogOut, it does not have a Set() method…

How do I play a WAV file?

Thanks,

Yoav

There is a method in Util class:

https://www.ghielectronics.com/community/forum/topic?id=4955&page=2#msg113621

1 Like

Thanks Architect, that’s what I was looking for.

You are welcome!

BTW, is there a way I could have gotten to this solution without the forum?
Am I missing a documentation resource?

It is in the API reference.

I got WAV playing on my cobra 2 board.
Recorded some speech on the PC and used a free converter to convert to WAV, 8bit, 8khz, mono.
Seems that the audio is played faster than it should.
I had to configure the Data rate parameter to around 6KHz to get it to play correctly.

I also opened the converted file on a hex editor to varify the WAV header. Seems fine.

Can this be a timing problem with GHI libs on the G120?
Can GHI team help to verify this?

Thanks,
S.B.D

What is the sample rate?

Hi Gus,

The WAV file is 8KHz, 8bit, Mono.

When I configured the Data Rate parameter to 8khz it made me sound like a chipmunk.
It started to sound correct when I lowered the Data rate to around 6KHz.

How can I attach the file?

Thanks,
S.B.D

We will investigate