Main Site Documentation

Recording sound to a WAV file


#1

Hi all,

I’m trying to record sound to a WAV file. I’m not using the music module for its limitations (it takes too long to start the recording and AFAIK it only records in ogg vorbis).
So I plugged a microphone directly into an extender module.

Now, I need to sample at 44,100 Hz. So I connected another extender module to socket 10 of a FEZ Spider and I’m generating a 44,100 sine wave with a function generator (for the time being), connecting it to pin 3.

My attempt at the code is below, but I don’t receive any interrupt. Is this all I have to do? Can anyone point me in the right direction?

Thanks
Davide


void ProgramStarted()
{
        ...
        Socket socket = Socket.GetSocket(10, true, extender, null);
        GTI.InterruptInput input = new GTI.InterruptInput(
                    socket, GT.Socket.Pin.Three,
                    GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, 
                     GTI.InterruptMode.RisingAndFallingEdge, extender);
        input.Interrupt += new GTI.InterruptInput.InterruptEventHandler(this._input_Interrupt);
        
        ...
        private void _input_Interrupt(GTI.InterruptInput sender, bool value)
        {
            Dubug.Print("interrupt!");
        }

#2

@ gozzilli -

I think RLP is better and 44K is quite high for sample reading


#3

@ Dat thanks for your response. Could you expand a bit? Sorry, I’m a newbie.
I’ve now read about RLP and ok, I can implement the code in that way. How do I sample at 44.1 kHz though if not with an interrupt? Are you suggesting that there is a way to time it with RLP? Or that 44.1 kHz can’t be achieved? I’m interested in sounds with frequency around 20kHz so 44.1 would be necessary (or anyway something in excess for 40 kHz).

Thanks,
Davide


#4

@ gozzilli -

I mean (and I think) C# can not fast enough to read 44K times per second. I am not sure if G400 can do that or not, but I don’t think EMX or G120 can.

I did something like this project 3 years ago at 8KHz in RLP, so I can say that yes, it can be done by RLP. But not sure how max it can be.


#5

While sampling audio is simple, it requires a very accurate timing. This is typically done on a small chip that is doing nothing but sampling the data and it is done in a native language, like C. Sometimes assembly maybe needed as well.

NETMF is suited for high level tasks. In other words, you can use the small chip to sample the data and buffer it and then perhaps send the data to a NETMF device to store on a media or send on the network?

It is all about using the right tool for the job.


#6

I see. Could the music module be that small chip? I can’t find a way to record in WAV (or other uncompressed format that allows me to sample at 44.1 kHz), does it have this capability? Or can it be extended to do that?


#7

The music module can record OGG. I am not sure if it does WAV but you can always check the datasheet of the codec.

It maybe easier fi you just tell us what you are trying to do.


#8

I’m trying to do exactly that, recoding a WAV file (or any other lossless format that allows me to have ~40 kHz). The end goal is to record insect calls (around 15-20 kHz) and do some analysis and classification on the Gadgeteer.


#9

Very cool project. At that rate you will a dedicated chip just you do the audio sampling


#10

@ Dat @ Gus at the moment I have a 555 timer that produces a 15 kHz square wave. With that I was hoping to send an interrupt to the FEZ Spider to save the sample from the microphone. Even at that frequency the Spider can’t handle it, and doesn’t seem to handle just increasing a counter either.

Could you suggest what the best option would be?

  • Writing the interrupt in C with RLP
  • Having an external chip to do the sampling (what does that mean? – please expand)
  • Upgrading to a more powerful motherboard (I have a Hydra available)

Thanks!


#11

Hi all,

I moved to a Hydra but even with that, I cannot trigger an interrupt more than 200 times a second because at a higher rate the interrupts get stacked and cannot keep up (eventually ending up out of memory). Inside the interrupt I’m only increasing a counter for now!

Is it possible that it’s that slow? If so, what are the alternatives? Would it be difficult to implement the interrupt in C and would that be the right path to take?

Once again please point me in the right direction. I’m desperate to find the correct thing to do before I give up with the Gadgeteer.

Thanks,
Davide


#12

200 interrupts a second sounds low… Perhaps it is the added overhead of Gadgeteer.

I have done some interrupt performance tests on the GHI Panda board, and it was able to handle about 1500+ managed interrupts a second while only increasing a variable.

But, Gadgeteer adds an additional layer of queuing over the Micro Framework.

For applications with performance issues, I would suggest not using the Gadgeteer framework.

As to doing it in C. Go to the Community area of the forum, and then to CodeShare. A simple search for “audio recording” brought up a number of sample programs including this https://www.ghielectronics.com/community/codeshare/entry/310