Mono to Stereo conversion

后端 未结 5 1545
日久生厌
日久生厌 2021-01-02 20:25

I have the following issue here: I get a block of bytes (uint16_t*) representing audio data, and the device generating them is capturing mono sound, so obviously I have mono

5条回答
  •  囚心锁ツ
    2021-01-02 20:38

    If you just want interleaved stereo samples then you could use a function like this:

    void interleave(const uint16_t * in_L,     // mono input buffer (left channel)
                    const uint16_t * in_R,     // mono input buffer (right channel)
                    uint16_t * out,            // stereo output buffer
                    const size_t num_samples)  // number of samples
    {
        for (size_t i = 0; i < num_samples; ++i)
        {
            out[i * 2] = in_L[i];
            out[i * 2 + 1] = in_R[i];
        }
    }
    

    To generate stereo from a single mono buffer then you would just pass the same pointer for in_L and in_R, e.g.

    interleave(mono_buffer, mono_buffer, stereo_buffer, num_samples);
    

提交回复
热议问题