开发者

Pointer to first byte of a vector<float>

The pointer to the audio buffer of the XAUDIO_BUFFER s开发者_如何学JAVAtructure in XAudio2 is defined as BYTE *pAudioData. When I was using 16-bit Integer PCM, this is what my program looked like:

void buildWaveBuffer(std::vector<unsigned char> &vec)
{
    std::string lineString;
    int lineInt;
    unsigned char lowByte, highByte;
    std::ifstream myfile("sineInt16");

    if (myfile.is_open())
    {
        while(myfile.good())
        {
            std::getline(myfile,lineString,',');
            lineInt = atoi(lineString.c_str());
            highByte = (lineInt >> 8) & 0x00FF;
            lowByte = lineInt & 0x00FF;
            vec.push_back(lowByte);
            vec.push_back(highByte);
        }
        myfile.close();
    }
}

"sineInt16" being a .csv file. Since the vector is organized sequentially in the memory, I would simply do pAudioData = &vec[0] and it would work. What if I want to change the format of my .csv to float? How do I give a pointer to the first byte in the vector? Should I use another container like a simple array of chars?


How do I give a pointer to the first byte in the vector?

The exact same way, but I'm not sure it will do what you expect. Read the comments to your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜