Full duplex audio with the Waveform Audio Interface

G

Guest

Hello,

I am developping a VoIP application between Ipaq. I use the Waveform Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on .NET
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than OpenNETCF).

I would like to make my application full duplex,(capture,stream and play the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
A

Alex Feinman [MVP]

(sigh) What error? Why do you think knowing the iPaq model is more important
to know when answering the question than the error code?
 
G

Guest

I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the stream
as a result). Dealing with byte[] is very convenient to stream them in UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and never 2
playing requests at the same time. But recording takes place at the same time
the previous sample is played.

The code is working, but every second time approximately, recording fails (I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero
 
A

Alex Feinman [MVP]

I meant, what is the return value of wi.Start()?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the
stream
as a result). Dealing with byte[] is very convenient to stream them in UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and never
2
playing requests at the same time. But recording takes place at the same
time
the previous sample is played.

The code is working, but every second time approximately, recording fails
(I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero



Lionel Reyero said:
Hello,

I am developping a VoIP application between Ipaq. I use the Waveform
Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on
.NET:
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than
OpenNETCF).

I would like to make my application full duplex,(capture,stream and play
the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
G

Guest

wi.Start() returns the error : Wave.MMSYSERR.ERROR.
If that can help... Thanks Alex.


Alex Feinman said:
I meant, what is the return value of wi.Start()?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the
stream
as a result). Dealing with byte[] is very convenient to stream them in UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and never
2
playing requests at the same time. But recording takes place at the same
time
the previous sample is played.

The code is working, but every second time approximately, recording fails
(I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero



Lionel Reyero said:
Hello,

I am developping a VoIP application between Ipaq. I use the Waveform
Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on
.NET:
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than
OpenNETCF).

I would like to make my application full duplex,(capture,stream and play
the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
A

Alex Feinman [MVP]

Looking at the MSDN code the only way you can get MMSYSERR_ERROR from
wi.Start is if you did not call wi.Initialize or have already started
recording on this object. You can easily detect which one is it by stepping
into the code

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
wi.Start() returns the error : Wave.MMSYSERR.ERROR.
If that can help... Thanks Alex.


Alex Feinman said:
I meant, what is the return value of wi.Start()?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the
stream
as a result). Dealing with byte[] is very convenient to stream them in
UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and
never
2
playing requests at the same time. But recording takes place at the
same
time
the previous sample is played.

The code is working, but every second time approximately, recording
fails
(I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref
audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero



:

Hello,

I am developping a VoIP application between Ipaq. I use the Waveform
Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on
.NET:
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than
OpenNETCF).

I would like to make my application full duplex,(capture,stream and
play
the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
G

Guest

Hi,

Now I call the "preload()" function before to start recording, it is working.
The sound quality is awful... when recording sound by 100ms slices, there
are terrible gaps, it is impossible to understand anything...
...I think I'll make real changes to the example to have it suitable for voIP.
Thanks,

Lionel

Alex Feinman said:
Looking at the MSDN code the only way you can get MMSYSERR_ERROR from
wi.Start is if you did not call wi.Initialize or have already started
recording on this object. You can easily detect which one is it by stepping
into the code

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
wi.Start() returns the error : Wave.MMSYSERR.ERROR.
If that can help... Thanks Alex.


Alex Feinman said:
I meant, what is the return value of wi.Start()?

--
Alex Feinman
---
Visit http://www.opennetcf.org
I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the
stream
as a result). Dealing with byte[] is very convenient to stream them in
UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and
never
2
playing requests at the same time. But recording takes place at the
same
time
the previous sample is played.

The code is working, but every second time approximately, recording
fails
(I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref
audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero



:

Hello,

I am developping a VoIP application between Ipaq. I use the Waveform
Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on
.NET:
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than
OpenNETCF).

I would like to make my application full duplex,(capture,stream and
play
the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
G

Guest

Lionel,

I am looking to create a simular application to what you are working on. In
your previous post, you stated that the recording / playback was unusable and
that you would need to make some real changes to get it to work.

Were you successfull at making the sould quality acceptable? Or have you
stopped utilizing this example as a starting point?

Thanks in advance.

Aaron


Lionel Reyero said:
Hi,

Now I call the "preload()" function before to start recording, it is working.
The sound quality is awful... when recording sound by 100ms slices, there
are terrible gaps, it is impossible to understand anything...
..I think I'll make real changes to the example to have it suitable for voIP.
Thanks,

Lionel

Alex Feinman said:
Looking at the MSDN code the only way you can get MMSYSERR_ERROR from
wi.Start is if you did not call wi.Initialize or have already started
recording on this object. You can easily detect which one is it by stepping
into the code

--
Alex Feinman
---
Visit http://www.opennetcf.org
Lionel Reyero said:
wi.Start() returns the error : Wave.MMSYSERR.ERROR.
If that can help... Thanks Alex.


:

I meant, what is the return value of wi.Start()?

--
Alex Feinman
---
Visit http://www.opennetcf.org
I use a slightly modified version of the sample of the Waveform Audio
Interface of MSDN. I added method SaveBuffer(), and PlayBuffer() to the
WaveIn and WaveOut. I have done very few changes in the sample code
(MemoryStream instead of FileStream, and I return the bytes[] of the
stream
as a result). Dealing with byte[] is very convenient to stream them in
UDP
packets.

Here is the code :

It record 100ms of sound, and play it. And loop 100 times.
I force the thread to sleep if the recording (or the playback) is not
finished.
So, there should never be 2 recording requests at the same time, and
never
2
playing requests at the same time. But recording takes place at the
same
time
the previous sample is played.

The code is working, but every second time approximately, recording
fails
(I
have the message "FAILURE: Failed to start recording" in the console).

If you can help, that would be great!


WaveIn wi = new WaveIn();
WaveOut wo = new WaveOut();
audioBuf = new byte[256*1024];

int bidul = 0;

if (Wave.MMSYSERR.NOERROR != wi.Preload(1000, 256*1024))
{
writeLineToConsole("FAILURE: Failed to preload buffers");
}


try
{
for (int i = 0; i < 100 ; i++)
{

if (!firstTime)
{
int sleepTime = 5;
int watchDog = 0;
int maxLoops = 100 / 5;
while(!wi.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}

if (Wave.MMSYSERR.NOERROR != wi.Start())
{
writeLineToConsole("FAILURE: Failed to start recording");
}

Thread.Sleep(100);

wi.Stop();





if (Wave.MMSYSERR.NOERROR != wi.SaveBuffer(ref audioBuf, ref
audioSize))
{
writeLineToConsole("FAILURE: Failed to save file");
}

writeLineToConsole("recorded " + audioSize + " bytes of audio");


if (firstTime)
{
firstTime = false;
}
else
{

int sleepTime = 5;
int watchDog = 0;
int maxLoops = (int)(wo.Milliseconds() / sleepTime);
while(!wo.Done())
{
Thread.Sleep(sleepTime);
Application.DoEvents();
watchDog++;

if (watchDog > maxLoops)
{
writeLineToConsole("FAILURE: Failed to detecte end of sound");
return;
}
}
}


if (Wave.MMSYSERR.NOERROR != wo.PlayBuffer(ref audioBuf, ref audioSize,
ref bidul, 0xffff, 0xffff))
{
writeLineToConsole("FAILURE: Failed to play sound test.wav");
}
}

Lionel Reyero



:

Hello,

I am developping a VoIP application between Ipaq. I use the Waveform
Audio
Interface to capture and play audio.

(See the MSDN example, it is the best on audio capture and playback on
.NET:
http://msdn.microsoft.com/mobility/default.aspx?pull=/library/en-us/dnnetcomp/html/waveinout.asp
You can download the sample code, it is much easier to modify than
OpenNETCF).

I would like to make my application full duplex,(capture,stream and
play
the
sound simultaneously on the 2 ipaqs)).
Problem:
I get an error when I try to record sound while playing sound.

Does the problem come from my ipaq ? (I use Ipaq rx3715). Or is it a
limitation of the Waveform Audio Interface ?

Thank you,

Lionel Reyero
 
J

John Long

Half duplex would work for my app.
What are you doing for communications between the two Ipaq's ?
I guess basic sockets TCP/IP or are you using UDP?

I'm new to the network programming so please forgive the basic questions.

Any hints as a way to start developing would be helpful.



Thanks
John Long
KW7A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top