-
March 11th, 2010, 11:31 PM
#1
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
-
March 12th, 2010, 02:33 AM
#2
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);
-
March 12th, 2010, 03:35 AM
#3
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);
-
March 12th, 2010, 03:48 AM
#4
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;
}
-
March 12th, 2010, 04:14 AM
#5
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
-
March 12th, 2010, 08:44 AM
#6
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.
-
March 15th, 2010, 03:31 AM
#7
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 ++;
}
-
March 15th, 2010, 07:33 AM
#8
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.
-
March 15th, 2010, 08:11 AM
#9
Re: Copy PBYTE issue, AUDIO programming
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|