Hello all, I'm not convinced this is the correct forum for SoundPlayer questions, but I did a search and most were cropping up here so here goes:
I'm using a SoundPlayer object to play a .wav stream continuously. I precompute the data for a user-defined frequency into a MemoryStream, instantiate the SoundPlayer while passing the MemoryStream object as an argument to the constructor and then play continuously via the "SoundPlayer.PlayLooping()" method. I'm using the PlayLooping() method because the amount of time that the sound while be emitted is determined by the user and is therefore non-deterministic. Everything is working very nicely except for a bit of a clicking/popping sound at the end every time the SoundPlayer loops back to the beginning. Is there a way to get rid of this noise? Thanks!
-L |
| LKeene Wednesday, October 07, 2009 8:46 PM |
Doubtful. Do make sure the final sample is identical to the first sample. You'll have to stretch the time to make that happen so it is an integer multiple of the period of the waveform. I reckon you'll still have a brief pause while the stream rewinds, that would be audible. Ask more questions about this at a multi-media or audio development newsgroup or forum.
Hans Passant.- Marked As Answer byAland LiMSFT, Moderator2 hours 36 minutes ago
-
|
| nobugz Wednesday, October 07, 2009 9:26 PM |
Doubtful. Do make sure the final sample is identical to the first sample. You'll have to stretch the time to make that happen so it is an integer multiple of the period of the waveform. I reckon you'll still have a brief pause while the stream rewinds, that would be audible. Ask more questions about this at a multi-media or audio development newsgroup or forum.
Hans Passant.- Marked As Answer byAland LiMSFT, Moderator2 hours 36 minutes ago
-
|
| nobugz Wednesday, October 07, 2009 9:26 PM |
Yes, shortly after posting I realized that my sampling was stopping in an arbitrary point in the waveform and then restarting. This would introduce the periodic high frequency click that I'm hearing. I also opened a 5 second 1 Khz .wav file I found online and looped it using the SoundPlayer class and I couldn't hear any discontinuity, so it looks like this is the main problem.
One question, though...should the final sample be identical to the first, or should it be identical to a sample that would immediately precede the first?
-L |
| LKeene Wednesday, October 07, 2009 9:52 PM |
Technically, you should be one sample short so an infinitely fast rewind makes it smooth. Discontinuities causes pops, missing or duplicate samples makes the frequency spectrum dirty.
Hans Passant. |
| nobugz Wednesday, October 07, 2009 10:34 PM |
Sorry,
by "one sample short" you mean the first and last sample should be the same value (i.e. we are assuming the looping approximates an infinite speed relative to the acoustic freuquency)?
-L
|
| LKeene Wednesday, October 07, 2009 10:49 PM |
Assuming you've got N samples for one period of the waveform, your last sample should be the N-1 sample. Hans Passant. |
| nobugz Wednesday, October 07, 2009 11:46 PM |
Let's assume I have a sine wave that I've sampled 5 times (0, 90, 180, 270, 360). I supply the SoundPlayer with a MemoryStream object loaded with a header and the data...but you're saying the data should only contain the samples for 0, 90, 180, 270 degrees? If the rewind speed is very fast, then the next alternation of the sine wave will occur very close to the N-1 sample, that is very close to the sample at 270 degrees and the wave recycles too quickly. Isn't that going to sound pretty distorted? When the player loops, does it allow the same amount of time to elapse before starting the loop as elapses between samples?
Sorry for all the questions, and thanks in advance!
-L |
| LKeene Thursday, October 08, 2009 12:18 AM |
The last sample at N-1 ends at N. I'd suggest you try this. Hans Passant. |
| nobugz Thursday, October 08, 2009 12:21 AM |