I have a 10 second sound effect wave file. What I would like to do is take that file and repeat it n number of times and then save the longer WAV file to disk. This way I can create a much longer background effect rather than auto-repeat on the media player which is a bit stuttered between repeats. I am trying to do this in C#.
That's reasonably easy to do, given the WAV file format - assuming it's uncompressed audio (most WAV files are - or at least, they were last time I had anything to do with them).
There may well be audio APIs you can use to do this without getting stuck into the binary format, but I suspect they'd take as long to learn as just doing it yourself as you're not doing anything particularly complicated.
If you only need to do this with a small number of files, you might as well do it by hand with Audacity.
If you're using .Net 2.0 or higher then you can use the System.Media.SoundPlayer class and specifically its PlayLooping method to achieve what you want with no stuttering. This is preferable to creating a new wav file - it means less disk space for the file and less memory needed to render the sound. In general you should always use buffered techniques like this for audio playback if the sound will be looped or is longer than a few seconds.
You can do this easily in C# using the NAudio .NET audio library. You would need to use the WaveFileReader
and WaveFileWriter
classes. You can also use it to create a custom WaveStream
that will loop your audio as many times as you want without the need to create a long WAV file.