GSM 6.10 Audio Recording

  • Thread starter Thread starter David D Webb
  • Start date Start date
D

David D Webb

I am trying to add a feature to my app where the user can attach voice notes
to the saved form. I am working with the OpenNETCF.Media.WaveAudio.Recorder
2.0 class, .NETCF2, and Windows Mobile 5 devices. I have a need for the
smallest possible audio files possible, so I wanted to use the GSM 6.10
format. I cannot figure out how to enable that format with the Recorder
class. I assume I am going to have to edit the source, and looking at it,
modify the SoundFormats enum. Any help appreciated.

-Dave
 
The current recorder class doesn't have any provisions for GSM. We are
working on a complete rewrite of the namespace that will allow real-time
audio streaming using GSM, but we're probably looking at a release toward
the end of the year because it's not a small job to implement or test.
 
Thanks Chris, I am not looking to do anything too elaborate, so do you think
I could modify the SoundFormats structure and the RecordFor method to add
the support for GSM? I found some code that had some possible recformat
settings for GSM, but I don't know if they are any good.

Thanks,
Dave
 
I can't say since I don't know your skill level. It's certainly doable as
long as you really understand how marshaling and native calls work.

-Chris
 
Well, I haven't had any luck getting the settings for GSM 6.1 all correct.
I switched over to trying to use the VoiceRecorder control, but have run
into too many issues with that and it creating bad file names. Any
suggestions?

Thanks,
Dave
 
Well, after banging my head against the wall for days, I finally cracked it.
I ended up breaking the OpenNetCF code for all other uncompressed audio
formats, but I didn't need them. Anyway, if you are interested in using
this GSM6.10 format you'll have to get the OpenNetCF 2.0 source code and
make the following changes. I'll probably miss some details, so if you are
interested in the code, email me.

In WaveFormat2.cs

Add the property:
public Int16 SamplesPerBlock;

Add this line to GetBytes
BitConverter.GetBytes(SamplesPerBlock).CopyTo(data, 18);

In Chunks.cs
Change occurances of "18" to "20"

In Recorder.cs

Set the following properties:
m_recformat.Channels = 1;
m_recformat.SamplesPerSec = 8000;
m_recformat.BitsPerSample = 0;
m_recformat.FormatTag = WAVE_FORMAT_GSM610;
m_recformat.BlockAlign = 65;
m_recformat.AvgBytesPerSec = 1625;
m_recformat.Size = 2;
m_recformat.SamplesPerBlock = 320;

comment out:
//CheckWaveError(NativeMethods.waveInOpen(out m_hWaveIn, WAVE_MAPPER,
m_recformat, IntPtr.Zero, 0, WAVE_FORMAT_QUERY));

And add the WAVE_MAPPED flag here - this one was the ticket:
CheckWaveError(NativeMethods.waveInOpen(out m_hWaveIn, (uint)m_deviceID,
m_recformat, m_recmw.Hwnd, 0, CALLBACK_WINDOW | WAVE_MAPPED));

comment out: (not sure the original purpose of this)
//for ( int i = 0; i < 2; i ++ )

In Audio.cs

Add the SoundFormat:
Mono8bit8kHzGSM = 0x1000

And add the constants:
internal const int WAVE_FORMAT_GSM610 = 0x0031;
internal const int WAVE_MAPPED = 0x0004;

In Player.cs

Change this line to add the WAVE_MAPPED flag:
CheckWaveError(NativeMethods.waveOutOpen(out m_hWaveOut, m_deviceID,
m_format, ((SoundMessageWindow)m_mwArray).Hwnd, 0, CALLBACK_WINDOW |
WAVE_MAPPED));


If you want to record to a memory stream instead of a file stream, you'll
have to comment out:
m_streamRecord.Close();
In Recorder.cs or check what kind of stream it is before closing.

I'm not sure what else this will break - I only tested recording and
playing.

Enjoy,
Dave
 
Back
Top