liveBook · Manning

exportFile

As explained in Learn Haskell by Example

exportFile is an HCodecs function that writes audio data to a WAV file.

exportFile writes generated audio data to a WAV file. Before calling it, convert a Signal into SampleData, assemble an Audio record with sample rate and channel count, and keep samples within a safe range. section 10.1.2

A typical export pipeline:

  • Clamp the signal before conversion so its values remain below the audio limits. section 10.1.2
  • Convert samples into an array-backed SampleData value with listArray. section 10.1.2
  • Construct Audio with the sample rate, one channel, and converted sample data. section 10.1.2
  • Call Codec.Wav.exportFile with the destination FilePath and Audio value. section 10.1.2

Export four waveforms

writeWav "4waves.wav" $ concatMap (\w -> tone w 220 5) [Sound.Synth.sin, tri, saw, sqw] generates five-second tones and writes them to 4waves.wav. section 10.1.2

How Learn Haskell by Example covers it

How deep it goes
Explains the call, required Audio construction, sample conversion, and limiting, while deferring array internals.
Examples
Uses sine, triangle, sawtooth, and square waves to create 4waves.wav.
What it assumes
Assumes Signal construction and basic Haskell lists; teaches Audio and SampleData preparation while deferring array details.
What you can do after
Operate/configure HCodecs to export synthesized signals as WAV files.
How it connects
Connects exportFile to HCodecs, WAV files, Audio, SampleData, Signal, sample rates, and channels.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.