liveBook · Manning

SampleData

As explained in Learn Haskell by Example

SampleData is an HCodecs representation of audio samples backed internally by arrays.

SampleData is HCodecs’ representation of audio samples, backed internally by arrays. It converts a Signal into data that can become part of an Audio value for WAV export. section 10.1.2

A practical conversion follows these steps:

  • Use listArray with bounds from 0 through the final sample index to build SampleData from a list. section 10.1.2
  • Convert each Sample with fromSample, and clamp the signal before conversion so values remain safely within the audio range. section 10.1.2

Converting and exporting a signal

signalToSampleData signal = listArray (0, n) $ map fromSample signal, where n = length signal - 1. The WAV-writing pipeline applies limit first, then stores the result as mono audio.

How Learn Haskell by Example covers it

How deep it goes
Explains array construction, bounds, sample conversion, and clamping, but defers the internal details of arrays.
Examples
Uses signalToSampleData, listArray, limit, Audio construction, and writeWav to demonstrate signal-to-WAV conversion.
What it assumes
Assumes a Signal and Sample representation, while introducing listArray and the need for array dependencies.
What you can do after
Build audio export by converting signals into SampleData and passing them to Codec.Wav.exportFile.
How it connects
Connects SampleData with Signal, Sample, Audio, arrays, HCodecs, and WAV files.

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.