This project has moved. For the latest updates, please go here.

noisy input

Feb 4, 2014 at 3:44 AM
this is a video i uploaded to youtube

http://www.youtube.com/watch?v=92UC_drDwB4&feature=youtu.be

why is my input signal so noisy?

I am doing

44100 sampling rate
32768 samples at a time

I have a filter in that i drop any Frequencies with a Magnitude less then 300000
this is so I can cut out noise

I am displaying 500 samples at a time

here in my code :
 void Voice()
        {

            int deviceNumber = 0;
            waveIn = new WaveIn();
            waveIn.BufferMilliseconds = 250;
            waveIn.DeviceNumber = deviceNumber;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.WaveFormat = new WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
            waveIn.StartRecording();
        }

void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
           
            PointPairList list = new PointPairList();
            PointPairList list2 = new PointPairList();
            byte[] buffer = e.Buffer;
            int bytesRecorded = e.BytesRecorded;
            points = new RollingPointPairList(32768/2);
            buffer1 = new double[(32768/2)];
    int tempint = 0;
            for (int index = 0; index < 32768; index += 2)
            {

                buffer1[tempint] = ((buffer[index + 1] << 8) |
                                      buffer[index + 0]);
                
                if (buffer1[tempint] > 32767)
                    buffer1[tempint] = buffer1[tempint] - 65536;

                tempint++;

            }
ect...
Feb 5, 2014 at 12:32 AM
http://www.youtube.com/watch?v=KXMjYtAES_A
ok look that this youtube
sorry the video misses up at times, but you can see all the needed information
I changed the setting to my Mic...
and it looks a lot different ...
but I do not know what is the best setting for the mic

I am reading stereo audio data or mono?
Feb 5, 2014 at 3:14 PM
oh i just check my mic setting and it is
2 channel, 16bit, 48000HZ(DVD Quality)

does anyone know why my input is still so much noisy ?
Feb 5, 2014 at 3:16 PM
oh i just check my mic setting and it is
2 channel, 16bit, 48000HZ(DVD Quality)

does anyone know why my input is still so much noisy ?
Feb 5, 2014 at 3:16 PM
oh i just check my mic setting and it is
2 channel, 16bit, 48000HZ(DVD Quality)

does anyone know why my input is still so much noisy ?
Coordinator
Feb 5, 2014 at 3:18 PM
well you could just have a noisy mix/preamp. Have you tried recording something in a different program, such as Audacity?
Feb 5, 2014 at 3:35 PM
ok on my computer I have a program called sound recorder. I just used it to record myself on the phone and I do hear some noise in background. It sounds like white noise... but at my job the heater is on... so it might be that ... also I cant hear the noise if i play it on my speakers, but I can hear it if I play it with my headphones
Feb 7, 2014 at 2:53 PM
Edited Feb 7, 2014 at 2:58 PM
You are using the onboard audio chip on the motherboard correct? The quality won't be that great, you will get noise from the PCI bus. You may want to invest in a dedicated sound card, but something decent such as the Auzentech range. http://www.auzentech.com/
EDIT.....it appears their website expired. That's odd. Perhaps you can find an Auzen Prelude or similar at a good price.
Feb 7, 2014 at 3:34 PM
I think you are right about this

but there is also something I think that might be the problem
 for (int index = 0; index < 2048; index += 2)
            {

                buffer1[tempint] = ((buffer[index + 1] << 8) |
                                      buffer[index + 0]);

                if (buffer1[tempint] > 2047)
                    buffer1[tempint] = buffer1[tempint] - 4096;
                
                tempint++; 

            }
ok this code takes the input samples and tell if they are negative or positive
now the microphone is returning 2116 sampling but I am only using 2048 samples
so should that mean I should use

if (buffer1[tempint] > 2047)
buffer1[tempint] = buffer1[tempint] - 4232;
?
Feb 7, 2014 at 3:51 PM
Using the << 8 shift and the OR mask doesn't look right. You are better off adding the two channels then divide by 2.

I think you are approaching it the wrong way. Instead of processing the data as it comes in, send the data to an aggregator, then read the contents of the aggregator when needed.
Feb 7, 2014 at 4:08 PM
K24A3

so you are saying ( buffer[index + 1] + buffer[index + 0]) / 2 ?
and then do a convert.toDouble ?
why / by 2?
and what about the negative numbers
sorry I am new to this, can you go in to a little more detail ?
Feb 8, 2014 at 3:25 AM
Edited Feb 9, 2014 at 6:54 AM
Is the input stream mono or stereo?

If you must use waveIn_DataAvailable instead of simply using an Aggregator as a SampleProvider, simply add the buffer bytes to an Aggregator


Then every 100ms or so, call aggregator.Read() to send the data to the graph. Or use the EventHandler in aggregator and tell the aggregator to raise the event every 100ms
Feb 8, 2014 at 1:07 PM
Edited Feb 8, 2014 at 1:10 PM
K24A3,

the input is stereo
I did what you said, not the Aggregator stuff, but this :
 waveIn.BufferMilliseconds = 12;

ect ....

 void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
PointPairList list = new PointPairList();
            PointPairList list2 = new PointPairList();
            byte[] buffer = e.Buffer;
            int bytesRecorded = e.BytesRecorded;
            points = new RollingPointPairList(1024);        
            buffer1 = new double[1024];             
            int tempint = 0;
for (int index = 0; index < 2048; index += 2)
            {

                 buffer1[tempint] = Convert.ToDouble((buffer[index + 1] + buffer[index + 0]) / 2D); 
                
                tempint++; 

            }
and this is how it looks now:
http://www.youtube.com/watch?v=b6wKFRY1mxw&feature=youtu.be

it is still Noisy and I this have to do
.Magnitude less then 30000

IDK why it is not working...
Feb 9, 2014 at 7:19 AM
Hold on, sorry I got confused earlier, I thought the buffer was an int buffer. That explains why you were shifting << 8.


Anyway, assuming the WaveIn data is PCM, try this:

for(int n = 0; n < buffer.Length; n+=2)
{
intBuffer[n/2] = BitConverter.ToInt16(buffer, n);
}

That should give you a paired stereo array. Divide each int by 32768.0d to get a double sample. I dont know how that graph process the data but you may want to drop the Right channel and test it with just the Left channel, or mix them using (doubleL + doubleR) * 0.5d;

If the buffer contains IEEE data, use BitConverter.ToSingle() using a float array instead, cast to double
Feb 9, 2014 at 1:15 PM
How would I know if the buffer contains IEEE data? Why to I have to convert it from byte to int ? I will lost data right ? Can't I just go byte to double ?
Feb 9, 2014 at 9:33 PM
Check the Encoding value of the WaveIn WaveFormat.

If the audio was 8 bit then you could read each byte, but it is most likely 16bit which means each byte is half a sample which needs to be combined into an int.
Feb 12, 2014 at 5:11 PM
K24A3
sorry I do not know how to check the encoded value of wavein WaveFormat...
what do you mean by that ?
I know that there are 44100 bytes coming in at one time.
ebuffer has:
[0] 0
[1] 0
[2] 0
[3] 0
[4] 225
[5] 255
[6] 0
[7] 0
[8] 0
[9] 0
[10] 0
[11] 0
[12] 0
[13] 0
[14] 255
[15] 255
[16] 0
etc...

I do not know what that means
Feb 12, 2014 at 9:57 PM
That doesn't look like audio data to me.

I suggest you try the sample aggregator instead of using DataAvailable.