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

too many samples?

May 12, 2014 at 12:26 PM
I've got a very simple script that opens up a mic in 8khz mono and plays it back live using the default wave out device. The live playback starts off with a 100ms delay which gradually increases until the bufferedwaveprovider hits its limit at 5 seconds and starts chopping off the sound. I've done some digging and it seems that the mic is returning around 8.7khz instead of 8khz - it's about 9% out. The same goes if it's stereo or 11khz or 44khz it is always returning around 9% more samples than i've asked it to. Any ideas on whats going on here? Other mics are working fine. Is there a way to tell naudio to drop extra bytes? I'm thinking of writing some code to work out how many bytes should have arrived based on the waveformat and the time since recording but i'm hoping there is something better i can do about it... Thanks!
Coordinator
May 12, 2014 at 8:19 PM
are you making sure you only use BytesRecorded from the record buffer? It may not be full
May 13, 2014 at 12:36 AM
Yeah i'm using BytesRecorded
May 13, 2014 at 1:43 AM
Edited May 13, 2014 at 2:18 AM
This is a code snippet and a debug log of bytes recorded against time. In about 24 seconds there is about 5 seconds of drift (stereo 8khz). I've tried updating the drivers - no change. My code works fine with every other mic i've got, it's just this one that is doing this... :(
WaveOutProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
double s = (DateTime.Now - d).TotalSeconds;
l += e.BytesRecorded;
Debug.WriteLine(l + " bytes in " + s + " seconds, should be " + RecordingFormat.AverageBytesPerSecond * s);

6400 bytes in 0 seconds, should be 0
12800 bytes in 0.1899942 seconds, should be 6079.8144
19200 bytes in 0.3699188 seconds, should be 11837.4016
25600 bytes in 0.5507787 seconds, should be 17624.9184
32000 bytes in 0.7398712 seconds, should be 23675.8784
38400 bytes in 0.9205609 seconds, should be 29457.9488
44800 bytes in 1.1098386 seconds, should be 35514.8352
51200 bytes in 1.2898699 seconds, should be 41275.8368
57600 bytes in 1.4698369 seconds, should be 47034.7808
64000 bytes in 1.6598577 seconds, should be 53115.4464
70400 bytes in 1.8396003 seconds, should be 58867.2096
76800 bytes in 2.0209052 seconds, should be 64668.9664
83200 bytes in 2.2095396 seconds, should be 70705.2672
89600 bytes in 2.3901385 seconds, should be 76484.432
96000 bytes in 2.5798551 seconds, should be 82555.3632
102400 bytes in 2.7596933 seconds, should be 88310.1856
108800 bytes in 2.9402036 seconds, should be 94086.5152
115200 bytes in 3.1311376 seconds, should be 100196.4032
121600 bytes in 3.3097883 seconds, should be 105913.2256
128000 bytes in 3.490824 seconds, should be 111706.368
134400 bytes in 3.6878024 seconds, should be 118009.6768
140800 bytes in 3.8694716 seconds, should be 123823.0912
147200 bytes in 4.0512218 seconds, should be 129639.0976
153600 bytes in 4.2397046 seconds, should be 135670.5472
160000 bytes in 4.4195177 seconds, should be 141424.5664
166400 bytes in 4.6099075 seconds, should be 147517.04
172800 bytes in 4.7897568 seconds, should be 153272.2176
179200 bytes in 4.9694643 seconds, should be 159022.8576
185600 bytes in 5.165522 seconds, should be 165296.704
192000 bytes in 5.3504647 seconds, should be 171214.8704
198400 bytes in 5.5298852 seconds, should be 176956.3264
204800 bytes in 5.7198466 seconds, should be 183035.0912
211200 bytes in 5.8997902 seconds, should be 188793.2864
217600 bytes in 6.095821 seconds, should be 195066.272
224000 bytes in 6.2696751 seconds, should be 200629.6032
230400 bytes in 6.449901 seconds, should be 206396.832
236800 bytes in 6.6398729 seconds, should be 212475.9328
243200 bytes in 6.8196846 seconds, should be 218229.9072
249600 bytes in 6.9998903 seconds, should be 223996.4896
256000 bytes in 7.1897871 seconds, should be 230073.1872
262400 bytes in 7.3700361 seconds, should be 235841.1552
268800 bytes in 7.5606351 seconds, should be 241940.3232
275200 bytes in 7.7398071 seconds, should be 247673.8272
281600 bytes in 7.9198517 seconds, should be 253435.2544
288000 bytes in 8.1093336 seconds, should be 259498.6752
294400 bytes in 8.2904094 seconds, should be 265293.1008
300800 bytes in 8.4694794 seconds, should be 271023.3408
307200 bytes in 8.6598484 seconds, should be 277115.1488
313600 bytes in 8.8397238 seconds, should be 282871.1616
320000 bytes in 9.0208821 seconds, should be 288668.2272
326400 bytes in 9.2102379 seconds, should be 294727.6128
332800 bytes in 9.3897564 seconds, should be 300472.2048
339200 bytes in 9.5798372 seconds, should be 306554.7904
345600 bytes in 9.760284 seconds, should be 312329.088
352000 bytes in 9.9392159 seconds, should be 318054.9088
358400 bytes in 10.1298321 seconds, should be 324154.6272
364800 bytes in 10.3092271 seconds, should be 329895.2672
371200 bytes in 10.4902509 seconds, should be 335688.0288
377600 bytes in 10.6803177 seconds, should be 341770.1664
384000 bytes in 10.8598256 seconds, should be 347514.4192
390400 bytes in 11.0503002 seconds, should be 353609.6064
396800 bytes in 11.2301473 seconds, should be 359364.7136
403200 bytes in 11.4099873 seconds, should be 365119.5936
409600 bytes in 11.5998191 seconds, should be 371194.2112
416000 bytes in 11.779818 seconds, should be 376954.176
422400 bytes in 11.9608183 seconds, should be 382746.1856
428800 bytes in 12.1497941 seconds, should be 388793.4112
435200 bytes in 12.3293626 seconds, should be 394539.6032
441600 bytes in 12.5191871 seconds, should be 400613.9872
448000 bytes in 12.699736 seconds, should be 406391.552
454400 bytes in 12.8798323 seconds, should be 412154.6336
460800 bytes in 13.0695828 seconds, should be 418226.6496
467200 bytes in 13.249805 seconds, should be 423993.76
473600 bytes in 13.4307711 seconds, should be 429784.6752
480000 bytes in 13.6203873 seconds, should be 435852.3936
486400 bytes in 13.800538 seconds, should be 441617.216
492800 bytes in 13.9956524 seconds, should be 447860.8768
499200 bytes in 14.1796563 seconds, should be 453749.0016
505600 bytes in 14.3598805 seconds, should be 459516.176
512000 bytes in 14.5494961 seconds, should be 465583.8752
518400 bytes in 14.7292077 seconds, should be 471334.6464
524800 bytes in 14.9102068 seconds, should be 477126.6176
531200 bytes in 15.0991844 seconds, should be 483173.9008
537600 bytes in 15.279711 seconds, should be 488950.752
544000 bytes in 15.4704074 seconds, should be 495053.0368
550400 bytes in 15.6498545 seconds, should be 500795.344
556800 bytes in 15.8299593 seconds, should be 506558.6976
563200 bytes in 16.0200381 seconds, should be 512641.2192
569600 bytes in 16.199943 seconds, should be 518398.176
576000 bytes in 16.3798931 seconds, should be 524156.5792
582400 bytes in 16.5694744 seconds, should be 530223.1808
588800 bytes in 16.7497735 seconds, should be 535992.752
595200 bytes in 16.9405927 seconds, should be 542098.9664
601600 bytes in 17.1276657 seconds, should be 548085.3024
608000 bytes in 17.2997713 seconds, should be 553592.6816
614400 bytes in 17.4896675 seconds, should be 559669.36
620800 bytes in 17.6697454 seconds, should be 565431.8528
627200 bytes in 17.8569968 seconds, should be 571423.8976
633600 bytes in 18.040488 seconds, should be 577295.616
640000 bytes in 18.2196551 seconds, should be 583028.9632
646400 bytes in 18.4101213 seconds, should be 589123.8816
652800 bytes in 18.5896585 seconds, should be 594869.072
659200 bytes in 18.7718426 seconds, should be 600698.9632
665600 bytes in 18.9593882 seconds, should be 606700.4224
672000 bytes in 19.1396891 seconds, should be 612470.0512
678400 bytes in 19.319336 seconds, should be 618218.752
684800 bytes in 19.5096263 seconds, should be 624308.0416
691200 bytes in 19.6895821 seconds, should be 630066.6272
697600 bytes in 19.8795076 seconds, should be 636144.2432
704000 bytes in 20.0596346 seconds, should be 641908.3072
710400 bytes in 20.2396446 seconds, should be 647668.6272
716800 bytes in 20.4296666 seconds, should be 653749.3312
723200 bytes in 20.6096784 seconds, should be 659509.7088
729600 bytes in 20.7896846 seconds, should be 665269.9072
736000 bytes in 20.9876601 seconds, should be 671605.1232
742400 bytes in 21.1696856 seconds, should be 677429.9392
748800 bytes in 21.3506874 seconds, should be 683221.9968
755200 bytes in 21.5397015 seconds, should be 689270.448
761600 bytes in 21.7196796 seconds, should be 695029.7472
768000 bytes in 21.9126226 seconds, should be 701203.9232
774400 bytes in 22.0996039 seconds, should be 707187.3248
780800 bytes in 22.2692751 seconds, should be 712616.8032
787200 bytes in 22.4599574 seconds, should be 718718.6368
793600 bytes in 22.6397117 seconds, should be 724470.7744
800000 bytes in 22.8207054 seconds, should be 730262.5728
806400 bytes in 23.0190936 seconds, should be 736610.9952
812800 bytes in 23.1908857 seconds, should be 742108.3424
Coordinator
May 13, 2014 at 8:07 AM
it could be a soundcard driver issue. Are you using WaveIn? It's likely that your mic is actually capturing audio at 44.1kHz and the driver is resampling it. Try capturing at 44.1kHz or 48kHz and seeing if that drifts
May 14, 2014 at 9:15 AM
Edited May 14, 2014 at 9:17 AM
yeah i've tried that, all rates have the exact same level of drift, stereo/mono makes no difference either. Is it possible that the mic is actually returning some weird custom samplerate? Any way to find out what rates the device driver claims to support?
Coordinator
May 23, 2014 at 2:39 PM
try with WasapiCapture and see if that improves things