sfplay~ -> sfrecord~: output != input...

Geoff Martin's icon

Hi,

My longstanding, nearly religious faith in MSP is being shaken as a result of things not-sounding-as-clean-as-they-should.

So, I ran a little test to see if I'm going crazy.

I made a 24-bit, 44.1 kHz, 2-channel .wav sound file using MATLAB. It contains various signals including an impulse and sine tones at various levels (ranging from 0 dB FS down to -100 dB FS) and various frequencies (ranging from about 100 Hz to about 10 kHz - I say "about" because I chose frequencies that would be on the centre of an FFT bin for later analysis, instead of pretty-looking numbers...). The audio file is TPDF dithered, but that doesn't matter for the remainder of my story. The two channels in the file are identical (both signal and dither), and that does matter for the remainder of my story...

Step 1 was to use Max/MSP and check that my sfplay~ and sfrecord~ objects are behaving. So, I made a simple patcher where I connected the outputs of an "sfplay~ 2" to the inputs of an "sfrecord~2" and set the latter to "samptype int24". Pressed "play" and "record" and waited until the file was finished playing...

Then I bring the recorded sound file back into MATLAB for analysis. Of course, step one is to find out whether output == input (i.e. the recorded file matches the played file). Turns out that the answer is "no"

And, before you ask, the answers are
- yes, I time-aligned them
- the sampling rate of MSP was 44.1 kHz
- the sampling rate of the Core Audio was 44.1 kHz
- the problem is not in MATLAB
- Max/MSP versions is 6.1.6
- MacBook Pro 17" 2.4 GHz, Core i7 running 10.9.2

For example, below is a plot of the difference in the played and recorded files with the 100 Hz, 0 dB FS sine tone. Note three things:
1. The difference is not zero.
2. The difference is different on the two channels

3. What's up with the spikes?

The second plot is the difference of the same frequency with a level of -20 dB FS.

The third plot is the difference with a -40 dB FS.

Once the signal gets down to about -60 or lower, the difference between the two is about 6 dB. In my opinion, this is significant for a signal level that's not too low.

The question, of course, is "where are things going wrong in the chain?" Is the problem in the sfplay~ object, the sfrecord~ object or the connection between them? My suspicion is to not blame the splay~ object, since I get similar errors when I play the file out of iTunes through soundflower into MSP's sfrecord~object.

Anyone that has any thoughts on why this is happening, where it's happening, or how to fix/avoid it would be appreciated.

Cheers
-geoff

100Hz_0dBFS_IO_difference.png
png
100Hz_-20dBFS_IO_difference.png.png
png
100Hz_-40dBFS_IO_difference.png
png
Geoff Martin's icon

I did a little more digging:

I tried again with MSP 6.1.7 and a slightly modified audio file.

It turns out that the different behaviour on the two audio channels was my fault. I've attached similar plots from the results of a MSP 6.1.7 test on this posting. The behaviour is the same - except that the two channels are now behaving identically.

Cheers
-geoff

100Hz_-40dBFS_IO_difference1.png
png
100Hz_-20dBFS_IO_difference1.png1.png
png
100Hz_0dBFS_IO_difference1.png
png
Geoff Martin's icon

Update #2:

Same test but with a different signal path.

The same original file is played in Amarra 2.6, routed through SoundFlower 2 ch into the adc~ object of MSP. Both the Amarra and the Mac volume levels were set to maximum. So, no sfplay~ object. Of course, this was recorded before SoundFlower started its clocking/glitch misbehaviour.

The basic performance of this signal path is similar - but slightly better. At least the spikes are gone on the 0 dB FS signal. So, now it looks like a simple gain difference through a quantiser.

Cheers
-geoff