Mono to Stereo conversion

后端 未结 5 1549
日久生厌
日久生厌 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:56

    You need to interleave the data, but if the frame length is anything greater than one, none of the above solutions will work. The below code can account for variable frame lengths.

    void Interleave(BYTE* left, BYTE* right, BYTE* stereo,int numSamples_in, int frameSize)
    {
        int writeIndex = 0;
        for (size_t j = 0; j < numSamples_in; j++)
        {
            for (int k = 0; k < frameSize; k++)
            {
                int index = j * frameSize + k;
    
                stereo[k + writeIndex] = left[index];
                stereo[k + writeIndex + frameSize] = right[index];
            }
            writeIndex += 2 * frameSize;
        }
    }
    

提交回复
热议问题