5

So I think I understand getFloatFrequencyData pretty well. If getFloatFrequencyData returns an array of 1024 values, each value represents the volume of a frequency bin/range. In the case of 1024 values at a sample rate of 44.1, each value would represent the volume of a frequency range of about 20 hertz.

Now what about getFloatTimeDomainData? Let's say I have 2048 values, what does each value represent?

Not the same as understanding getByteTimeDomainData and getByteFrequencyData in web audio. Or at least, this question's answer doesn't answer mine.

Community
  • 1
  • 1
Maxime Dupré
  • 5,319
  • 7
  • 38
  • 72

2 Answers2

6

The Float32Array obtained using getFloatTimeDomainData will contain an array of sample values, each value defining the amplitude at the sampled location, usually in the domain of [-1, 1]. Sample locations are uniquely distributed, the obtained data is essentially the equivalent of raw PCM.

For a sine wave, it would yield gradually changing continuous values among the following approximation curve:

0 ... 0.7 ... 1.0 ... 0.7 ... 0 ... -0.7 ... -1.0 ... -0.7 ... 0 ...

Think of it as a series of subsequent values that together define the shape of the audio wave; if you were to visualize the obtained values on, say, a canvas, using the sample values as y coordinates (amplitude) and a subsequently increasing value for x coordinates (time), you would get an oscilloscope, such as:

sine wave

Note how this sine waveform correlates with the example values above. Here are some example operations you can do on this data to get a better understanding:

  • If you were to multiply each value by 2, you would amplify the volume by 100% (double volume)

  • If you were to replace every value with 0, you would get silence

  • If you were to skip every second value, you would get a 100% pitched up audio (double playback speed)

John Weisz
  • 30,137
  • 13
  • 89
  • 132
3

getFloatTimeDomainData returns a sample of the PCM data from the audio stream - i.e. the raw audio data.

cwilso
  • 13,610
  • 1
  • 30
  • 35
  • 3
    Precisely, what does each value represent? A frequency data value represents the volume of a frequency range. A time domain data represents x of y? – Maxime Dupré Oct 29 '16 at 20:29