0 Comments

 

Here’s a little snippet of NAudio code showing how you can convert a 16 bit PCM mono WAV file to GSM. But this time I thought I’d use F#, to show that it is quite simple to use NAudio from F#. In fact, the F# use keyword really shines here, as it reduces the level of indentation that you’d have with C#.

Here’s the sample. C# developers should have no problem using this. Basically the signal chain is a WaveFileReader –> WaveFormatConversionStream –> WaveFileWriter, which is the typical pattern you would use for all sorts of format conversions in NAudio.

let convertToGsm (input:string) output =
    use reader = new WaveFileReader(input)
    let targetFormat = new Gsm610WaveFormat()
    use converter = new WaveFormatConversionStream(targetFormat, reader)
    WaveFileWriter.CreateWaveFile(output, converter)

convertToGsm "pcm.wav" "gsm.wav"
Want to get up to speed with the the fundamentals principles of digital audio and how to got about writing audio applications with NAudio? Be sure to check out my Pluralsight courses, Digital Audio Fundamentals, and Audio Programming with NAudio.
Vote on HN
comments powered by Disqus