@@ -55,20 +55,32 @@ public int Read(byte[] buffer, int offset, int count)
5555 {
5656 lock ( syncRoot )
5757 {
58- while ( remoteSound . BufferedBytes >= bytesPerFrame && localSound . BufferedBytes >= bytesPerFrame )
59- {
60- // read source of echo
61- remoteSound . Read ( remoteFrame , 0 , bytesPerFrame ) ;
62- // read local sound + echo
63- localSound . Read ( localFrame , 0 , bytesPerFrame ) ;
64-
65- filter . Filter ( localFrame , remoteFrame , outputFrame ) ;
66- filtered . AddSamples ( outputFrame , 0 , outputFrame . Length ) ;
67- }
58+ FilterEcho ( ) ;
6859 return filtered . Read ( buffer , offset , count ) ;
6960 }
7061 }
7162
63+ void FilterEcho ( )
64+ {
65+ while ( remoteSound . BufferedBytes >= bytesPerFrame && localSound . BufferedBytes >= bytesPerFrame )
66+ {
67+ // read source of echo
68+ remoteSound . Read ( remoteFrame , 0 , bytesPerFrame ) ;
69+ // read local sound + echo
70+ localSound . Read ( localFrame , 0 , bytesPerFrame ) ;
71+
72+ filter . Filter ( localFrame , remoteFrame , outputFrame ) ;
73+ filtered . AddSamples ( outputFrame , 0 , outputFrame . Length ) ;
74+ }
75+
76+ // read the remaining remote sound and play it
77+ while ( remoteSound . BufferedBytes > 0 )
78+ {
79+ remoteSound . Read ( remoteFrame , 0 , bytesPerFrame ) ;
80+ filtered . AddSamples ( remoteFrame , 0 , remoteFrame . Length ) ;
81+ }
82+ }
83+
7284 public void Dispose ( )
7385 {
7486 filter . Dispose ( ) ;
0 commit comments