Android: Sine Wave Generation

前端 未结 3 1269
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 10:39

I\'m trying to use AudioTrack to generate sine, square, and sawtooth waves. However, the audio this is creating doesn\'t sound like a pure sine wave, but like it has some kind o

3条回答
  •  情书的邮戳
    2021-02-08 11:19

    None of these anwers fixes the problem. The buffer length should be a multiple of the sample rate, or at least the length of one rotation. Let's break it in ton of variables to show we understand things:

    int sampleRate = 44100;
    int bitsPerChannel = 16;
    int bytesPerChannel = bitsPerChannel / 8;
    int channelCount = 1;
    int bytesPerSample = channelCount * bytesPerChannel;
    int bytesPerRotation = sampleRate * bytesPerSample * (1d / (double) frequency);
    

    Then you can multiply this bytesPerRotation by anything, it won't change a fact: there won't be glitch in the sound.

提交回复
热议问题