5
$\begingroup$

Bug introduced in 11.3 or earlier

CASE:4075745


I have been experimenting with using Audio and associated functions for data acquisition using an external sound card. I came across a bizarre problem with generated sine waves, where jagged teeth would appear in the waveform.

ListLinePlot[
  AudioData[
    AudioGenerator[{"Sin", 1000}, 0.1, SampleRate -> 48000]
  ][[1, ;; 100]]
]

Mathematica graphics

This is a problem in the audio itself and not a display or data extraction error, as verified by looking at the output of the sound card on an oscilloscope. This originally occurred when using AudioGenerator, but the error persisted when passing an array of Sin values to Audio.

The problem appears to be caused by Audio interpreting high-precision (but not exact) values of 1/2 as 0.25.

a = N[{Sin[(25*Pi)/6], 1/2, 0.5, 0.4999999, 0.49999999, Sin[(25.*Pi)/6]}]
(* {0.5, 0.5, 0.5, 0.5, 0.5, 0.5} *)

First[AudioData[Audio[a]]]
(* {0.5, 0.5, 0.5, 0.5, 0.25, 0.25} *)

This error was observed on 11.3 on macOS, but also occurs on Mathematica Online. The issue has been reported to Wolfram support [CASE:4075745].

$\endgroup$
12
  • $\begingroup$ By default Audio uses 32 bit maybe try AudioData[Audio[a, "Real"]]? $\endgroup$
    – chuy
    Commented Jun 6, 2018 at 20:47
  • $\begingroup$ @chuy Thanks for the suggestion, but nope. I tried all available type settings, and the last two are always half the value of the first 4. $\endgroup$
    – Daniel W
    Commented Jun 7, 2018 at 13:59
  • $\begingroup$ I appreciate that you made a minimal example, but could you include the actual code that generated the sinewave with the jagged teeth as well? I can't reproduce it with simply First@AudioData@Audio@Table[Sin[x], {x, 0, 10, 0.1}] // ListLinePlot. $\endgroup$
    – MarcoB
    Commented Jun 7, 2018 at 14:02
  • $\begingroup$ @MarcoB Good suggestion, done. $\endgroup$
    – Daniel W
    Commented Jun 7, 2018 at 14:11
  • 1
    $\begingroup$ As @chuy mentioned, this may be OS and version-dependent. With your code above I get some 0.5, some 0.25. The problem goes away entirely if I use Audio[..., "Real"]. $\endgroup$
    – MarcoB
    Commented Jun 7, 2018 at 18:41

1 Answer 1

2
$\begingroup$

This has been acknowledged by Wolfram Support as a bug and the developers have been informed. The workaround Support suggested is as @chuy had suggested in the comments, specifying the "Real" type for Audio:

ListLinePlot[
  AudioData[
    AudioGenerator[{"Sin", 1000}, 0.1, "Real", SampleRate -> 48000]
  ][[1,1 ;; 100]]
]

Mathematica graphics

a = N[{Sin[(25*Pi)/6], 1/2, 0.5, 0.4999999, 0.49999999, Sin[(25.*Pi)/6]}];
First[AudioData[Audio[a, "Real"]]]

(* {0.5, 0.5, 0.5, 0.5, 0.5, 0.5} *)

This workaround failed for me previously because of a silly typographical error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.