CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2009
    Posts
    61

    Copy PBYTE issue, AUDIO programming

    hi

    I want to copy data from alternate location of first PBYTE to another PBYTE
    EX: From first PBYTE array location 0-2-4-6-7 etc to another Pbyte array please help

    PBYTE pBuffer = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    PBYTE pBufferSec = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    short* pbShortBuffer = reinterpret_cast<short*>( pBuffer );
    memcpy(pBufferSec,pBuffer,sizeof(pBuffer));// here i dont know how to copy alternate memory location from source file to pBufferSec
    short* pbLeftBuffer = reinterpret_cast<short*>( pBufferSec );

    Please give some help

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Copy PBYTE issue, AUDIO programming

    I don't understand exactly what you want to copy. Just some bytes (every second one) or the entire buffer, or what?

    I see you are using sizeof(pBuffer). This is not possible. sizeof applied for a pointer (pBuffer is a pointer) always returns the size of the pointer. On 32-bit machines that is 4 bytes. On 64-bit machines that is 8 bytes. So that should actually be:
    Code:
    memcpy(pBufferSec,pBuffer,DATA_SIZE);
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jun 2009
    Posts
    61

    Re: Copy PBYTE issue, AUDIO programming

    PBYTE pBuffer = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    PBYTE pBufferSec = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);


    pAudioStream->GetFormat(&wfx);
    pAudioData->SetBuffer(DATA_SIZE, pBuffer, 0);
    pAudioData->SetFormat(&wfx);

    Here i want to copy data from alternate location(0-2-4-6-8 etc) of pBuffer to pBuferSec. then i want to setbuffer to new pBuffersec

    My purpose is to extract left channel from stereo audio data

    pAudioStream->GetFormat(&wfx);
    pAudioData->SetBuffer(DATA_SIZE, pBufferSec, 0);
    pAudioData->SetFormat(&wfx);

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Copy PBYTE issue, AUDIO programming

    I don't see how you can copy only the Nth (second in your case) byte from a buffer into another buffer without a loop (for, while, etc.). Look at how memcpy is implemented:
    Code:
            while (count--) {
                    *(char *)dst = *(char *)src;
                    dst = (char *)dst + 1;
                    src = (char *)src + 1;
            }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Jun 2009
    Posts
    61

    Re: Copy PBYTE issue, AUDIO programming

    PBYTE pBuffer = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    PBYTE pBufferSec = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);

    short* pbShortBuffer = reinterpret_cast<short*>( pBuffer );
    short* pbLeftBuffer = reinterpret_cast<short*>( pBufferSec );

    Here i want data at alternate location of pBuffer to pBufferSec

    This is my need

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Copy PBYTE issue, AUDIO programming

    As cilu points out, you have to do this in a loop. For normal 16bit LE PCM, your stream should be of samples each 32 bits where HIWORD is the right channel and LOWORD is the left channel.

  7. #7
    Join Date
    Jun 2009
    Posts
    61

    Re: Copy PBYTE issue, AUDIO programming

    First Sorry 4 my late reply and thanks 4 ur valuable helps.

    Now i shifted pbuffer to 16 bit, but same situation not getting audio as single channel. Here i can hear stereo output
    My code

    PBYTE pBuffer = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    PBYTE pBufferSec = (PBYTE)LocalAlloc(LMEM_FIXED, DATA_SIZE);
    if (pBuffer == NULL)
    {
    pAudioStream->Release();
    pAudioData->Release();
    return E_OUTOFMEMORY;
    }

    pAudioStream->GetFormat(&wfx);
    pAudioData->SetBuffer(DATA_SIZE, pBuffer, 0);
    pAudioData->SetFormat(&wfx);

    hr = pAudioStream->CreateSample(pAudioData, 0, &pSample);
    pAudioStream->Release();
    short* pbShortBuffer = reinterpret_cast<short*>( pBuffer );
    short* pbLeftBuffer = reinterpret_cast<short*>( pBufferSec );
    pbLeftBuffer=pbShortBuffer;
    int count = 0;
    while (count>500) {
    *pbLeftBuffer = *pbShortBuffer >>16;
    count ++;

    }

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Copy PBYTE issue, AUDIO programming

    I don't know anything about these classes (pAudioStream,pAudioData) and so I can't comment, but it really looks like you're missing something here. You're allocating pBufferSec as PBYTE, then casting it to short *. Why not just allocate it as short *? Then you're assigning pbLeftBuffer=pbShortBuffer which doesn't do what I think you're expecting it to do. Then setting count to zero, you'll never even enter your while() loop.

    Also, please use real words and use code tags around your code blocks.

  9. #9
    Join Date
    Jun 2009
    Posts
    61

    Re: Copy PBYTE issue, AUDIO programming

    Hi.. Thans 4 ur reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured