1

I am using the EXTAudioFileReadTest app provided in the Core Audio SDK documentation and I'm trying to get all of the floating point values from the mData buffer so that I can draw a waveform with them.

Currently, I'm printing out the floating point values for single channel and this is what I'm getting in the console:

2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] 0.127136
2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] -0.057033
2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] -0.146455
2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] 0.090759
2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] 0.240837
2010-09-10 19:22:43.360 ExtAudioFileReadTest[71828:a0f] -0.072719
2010-09-10 19:22:43.361 ExtAudioFileReadTest[71828:a0f] -0.258782
2010-09-10 19:22:43.361 ExtAudioFileReadTest[71828:a0f] -0.063972
2010-09-10 19:22:43.361 ExtAudioFileReadTest[71828:a0f] 0.088692
2010-09-10 19:22:43.361 ExtAudioFileReadTest[71828:a0f] 0.153571
2010-09-10 19:22:43.361 ExtAudioFileReadTest[71828:a0f] 0.080644
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] -0.087060
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] 0.196455
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] 0.167777
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] -0.192430
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] -0.209936
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] 0.012049
2010-09-10 19:22:43.383 ExtAudioFileReadTest[71828:a0f] 0.110493
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] 0.150715
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] 0.016413
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] -0.056843
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] 0.206117
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] 0.020673
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] -0.561129
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] -0.184265
2010-09-10 19:22:43.384 ExtAudioFileReadTest[71828:a0f] 0.620910
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] 0.309018
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] -0.371634
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] -0.238362
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] 0.125136
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] 0.139757
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] -0.023419
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] -0.142903
2010-09-10 19:22:43.385 ExtAudioFileReadTest[71828:a0f] 0.041068
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] 0.252621
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] -0.002240
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] -0.261686
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] -0.105053
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] 0.072798
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] 0.141572
2010-09-10 19:22:43.386 ExtAudioFileReadTest[71828:a0f] 0.110190

I guess i'm confused.. .as I was expecting to find some type of voltage sample and not a number between -1 and 1. What do these values actually mean? What would be a good formula for converting these values to some upper/lower limit that would be between 0 and 1?

Thanks in advance. I've been searching all over the place and can't find this information anywhere... especially not in the documentation.

Corey
  • 41
  • 3
  • Hi Corey, you R one step forward to me respect wath i would to achieve in my project: can you share de code that output ExtAudioFileReadTest float value? thanks – sundsx Apr 04 '13 at 11:45

2 Answers2

2

this is normal.

the common floating point representation of audio samples modulate from [-1...1]; where the values -1 and 1 represent one sample at 0 dBFS.

a continuous stream of floating point values '0.0' represents a silent signal.

a signal with no DC offset will have equal weight in the positive and negative domains.

if you'd like to convert these values to [0...1], use the formula:

result = (0.5 * inputSample) + 0.5;

but you may have to use a more sophisticated algorithm if the signal extends beyond [-1...1].

in most cases, you should keep it at [-1...1] if you want to store it in floating point.

justin
  • 104,054
  • 14
  • 179
  • 226
  • 1
    Depending on how the audio was converted to float, the sample range may not be [-1, 1]. Specifically, on OS X floating point audio is typically (although not always) in the range [-1, 1). For example, using Apple's AudioConverter, for 16 bit audio the minimum sample -32768 is converted to -1 but the maximum sample 32767 is converted to (32767/32768) ≈ 0.999969 – sbooth Sep 13 '10 at 06:07
  • @Justin - I hope you its not too old to ask on this thread but what should be done with the -1 .. 1 float values? What do they represent? Is it better to convert them all to 0 .. 1 range in order to draw a waveform? I have 2 channels of audio and averaged channel 1 and 2 so I can then use them to draw a waveform, however I am not sure what you mean by "where the values -1 and 1 represent one sample at 0 dBFS." I have the first 20 frames averaged below 0, negative values. – user773578 Jul 22 '12 at 07:20
  • @user773578 well, these probably deserve their own questions. related discussion: http://stackoverflow.com/questions/4849076/efficient-method-to-draw-a-line-with-millions-of-points/4849784#4849784 short answers: 1) amplitude of the pcm sample 2) not necessarily. multiple transformations are required in my implementation, to convert a signal to a waveform onscreen (see link) 3) if you are feeding the hardware samples, 0dBFS is the maximum output sample value it will represent. beyond that, you clip the output (greatly simplified in introductory terms). – justin Jul 22 '12 at 17:00
  • that just makes me more confused as I dont know the complete story – user773578 Jul 22 '12 at 19:12
  • @user773578 ok. the subject doesn't really fit into comment fields. if searching does not help, feel free to create new questions. – justin Jul 23 '12 at 03:00
0

I think i've figured this out. I just graphed those points above in excel and it seems to look like a waveform. I didn't realize it was giving the negative voltages as well... but it makes sense.

Corey
  • 41
  • 3