From: Larry on
I have a question about Lame-enc DLL:
http://www.fi.muni.cz/~qruzicka/Smid/man.htm

When it comes to beInitStream() it says:

BE_ERR beInitStream(

// Pointer at the struct containing encoder settings.
PBE_CONFIG pbeConfig,

// Pointer at double word where number of samples to send to each
beEncodeChunk() is returned.
PDWORD dwSamples,

// Pointer at double word where minimum size in bytes of output buffer is
returned.
PDWORD dwBufferSize,

// Pointer at integer where Stream handle is returned.
PHBE_STREAM phbeStream
)

So, I should do something like this:

BE_CONFIG beConfig; // then I populate beConfig.(...)
HBE_STREAM hbeStream = 0;
DWORD dwSamples = 0;
DWORD dwMP3Buffer = 0;

beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);

Now, I wonder if I can take no notice of the "dwSamples" value returned,
that's because I am doing real-time endless encoding and I though I would
encode like this:

// 88200 Bytes = 44100 x 2 (Stereo) , 1 second of WAVE audio

so I am like in a: while( dwRead = getWaveChunk(pWavBuffer) > 0 ) where
"dwRead" will be always 88200!

Can it actually be done? for instance:

PBYTE pMP3Buffer = new BYTE[dwMP3Buffer];
DWORD dwRead = 0;
DWORD dwWrite = 0;

while( dwRead = getWaveChunk(pWavBuffer) > 0 )
{
beEncodeChunk( hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite );
// pWAVBuffer contains the WAVE chunk
// pMP3Buffer contains the MP3 encodec chunk
}

where:

beEncodeChunk(

//Handle of the stream.
HBE_STREAM hbeStream,

//Number of samples to be encoded for this call. This should be identical
to what is returned by beInitStream()!
DWORD nSamples,

//Pointer at the 16-bit signed samples to be encoded. These should be in
stereo when encoding a stereo MP3
PSHORT pSamples,

//Where to write the encoded data. This buffer should be at least of the
minimum size returned by beInitStream().
PBYTE pOutput,

//Where to return number of bytes of encoded data written. The amount of
data written might vary from chunk to chunk.
PDWORD pdwOutput
)

So can I force the lame to encode 88200 Bytes at a time?

thanks





From: Larry on
"Larry" <dontmewithme(a)got.it> ha scritto nel messaggio
news:4b400ffc$0$1139$4fafbaef(a)reader1.news.tin.it...
>I have a question about Lame-enc DLL:
>http://www.fi.muni.cz/~qruzicka/Smid/man.htm
>

I am going to do real time encoding while capturing audio with the waveForm
API I was wondering wheter I myself could supply the dwSamples value to the
function:

beInitStream(&bec, &dwSamples, &dwBufferSize, &hbe);

that's beacuse I would like to encode 88200 Bytes of wav at a time! (88200
is 44100 x 2, so, 1 second of audio stereo!)

when I try to read the values return by the beInitStream() function I get:

dwSamples: 2304
dwBufferSize: 8640 (mp3 buffer size)

By the way, what is dwsamples??

thanks

From: Larry on
"Larry" <dontmewithme(a)got.it> ha scritto nel messaggio
news:4b400ffc$0$1139$4fafbaef(a)reader1.news.tin.it...

> When it comes to beInitStream() it says:
>
> BE_ERR beInitStream(
>
> // Pointer at the struct containing encoder settings.
> PBE_CONFIG pbeConfig,
>
> // Pointer at double word where number of samples to send to each
> beEncodeChunk() is returned.
> PDWORD dwSamples,
>
> // Pointer at double word where minimum size in bytes of output buffer is
> returned.
> PDWORD dwBufferSize,
>
> // Pointer at integer where Stream handle is returned.
> PHBE_STREAM phbeStream
> )
>
> So, I should do something like this:
>
> BE_CONFIG beConfig; // then I populate beConfig.(...)
> HBE_STREAM hbeStream = 0;
> DWORD dwSamples = 0;
> DWORD dwMP3Buffer = 0;
>
> beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);
// Define WAVEFORMATEX Structure:

WAVEFORMATEX wf;
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.wBitsPerSample = 16;
wf.nChannels = 2
wf.nSamplesPerSec = 44100
wf.nBlockAlign = (wf.nChannels * wf.wBitsPerSample) / 8;
wf.nAvgBytesPerSec = (wf.nSamplesPerSec * wf.nBlockAlign);

//

This mean "nAvgBytesPerSec" will be (DWORD) 176400 Bytes (per second)

My application does real time capturing from a given source and notify me
thru a CALLBACK_EVENT when the (LPBYTE) buffer[176400] is filled and return
the buffer:

while(1)
{
// CALLBACK EVENT
WaitForSingleObject(hevent, INFINITE);

// sizeof(buffer) = 176400

// encode buffer
}

The code above is the barebones of my capturing & encoding programm! On the
other hand, I have found out that the Lame-enc DLL returns me some values
telling me how many samples it is willing to encode when I first init it!

PBYTE pMP3Buffer =NULL;
PSHORT pWAVBuffer =NULL;

beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);

// Allocate MP3 buffer
pMP3Buffer = new BYTE[dwMP3Buffer]; // (dword) 8640

// Allocate WAV buffer
pWAVBuffer = new SHORT[dwSamples]; // (dword) 2304

whereas 2304 is too little for me! Also, 176400 / 2304 = 76,56 as I don't
really get it!

I have found some code on the internet to show how to use the DLL to encode
a WAVE file. What the code basically does it the following:


// Convert All PCM samples
while ( (dwRead = fread(pWAVBuffer,sizeof(SHORT),dwSamples,pFileIn)) > 0 )
{
// Encode samples
beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);

// Save chunk
fwrite(pMP3Buffer,1,dwWrite,pFileOut);
}

It basically reads "dwSamples" in "pWAVBuffer" and sends it to the
encoder...

I am really stuck at this. I wish I could push as many samples as I want!
(176400)

thanks

From: Bob Masta on
On Sun, 3 Jan 2010 23:52:48 +0100, "Larry"
<dontmewithme(a)got.it> wrote:

>"Larry" <dontmewithme(a)got.it> ha scritto nel messaggio
>news:4b400ffc$0$1139$4fafbaef(a)reader1.news.tin.it...
>
>> When it comes to beInitStream() it says:
>>
>> BE_ERR beInitStream(
>>
>> // Pointer at the struct containing encoder settings.
>> PBE_CONFIG pbeConfig,
>>
>> // Pointer at double word where number of samples to send to each
>> beEncodeChunk() is returned.
>> PDWORD dwSamples,
>>
>> // Pointer at double word where minimum size in bytes of output buffer is
>> returned.
>> PDWORD dwBufferSize,
>>
>> // Pointer at integer where Stream handle is returned.
>> PHBE_STREAM phbeStream
>> )
>>
>> So, I should do something like this:
>>
>> BE_CONFIG beConfig; // then I populate beConfig.(...)
>> HBE_STREAM hbeStream = 0;
>> DWORD dwSamples = 0;
>> DWORD dwMP3Buffer = 0;
>>
>> beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);
>// Define WAVEFORMATEX Structure:
>
>WAVEFORMATEX wf;
>wf.wFormatTag = WAVE_FORMAT_PCM;
>wf.wBitsPerSample = 16;
>wf.nChannels = 2
>wf.nSamplesPerSec = 44100
>wf.nBlockAlign = (wf.nChannels * wf.wBitsPerSample) / 8;
>wf.nAvgBytesPerSec = (wf.nSamplesPerSec * wf.nBlockAlign);
>
>//
>
>This mean "nAvgBytesPerSec" will be (DWORD) 176400 Bytes (per second)
>
>My application does real time capturing from a given source and notify me
>thru a CALLBACK_EVENT when the (LPBYTE) buffer[176400] is filled and return
>the buffer:
>
>while(1)
>{
> // CALLBACK EVENT
> WaitForSingleObject(hevent, INFINITE);
>
> // sizeof(buffer) = 176400
>
> // encode buffer
>}
>
>The code above is the barebones of my capturing & encoding programm! On the
>other hand, I have found out that the Lame-enc DLL returns me some values
>telling me how many samples it is willing to encode when I first init it!
>
>PBYTE pMP3Buffer =NULL;
>PSHORT pWAVBuffer =NULL;
>
>beInitStream(&beConfig, &dwSamples, &dwMP3Buffer, &hbeStream);
>
>// Allocate MP3 buffer
>pMP3Buffer = new BYTE[dwMP3Buffer]; // (dword) 8640
>
>// Allocate WAV buffer
>pWAVBuffer = new SHORT[dwSamples]; // (dword) 2304
>
>whereas 2304 is too little for me! Also, 176400 / 2304 = 76,56 as I don't
>really get it!
>
>I have found some code on the internet to show how to use the DLL to encode
>a WAVE file. What the code basically does it the following:
>
>
>// Convert All PCM samples
>while ( (dwRead = fread(pWAVBuffer,sizeof(SHORT),dwSamples,pFileIn)) > 0 )
>{
> // Encode samples
> beEncodeChunk(hbeStream, dwRead, pWAVBuffer, pMP3Buffer, &dwWrite);
>
> // Save chunk
> fwrite(pMP3Buffer,1,dwWrite,pFileOut);
>}
>
>It basically reads "dwSamples" in "pWAVBuffer" and sends it to the
>encoder...
>
>I am really stuck at this. I wish I could push as many samples as I want!
>(176400)

I don't know anything about Lame, but with wave
operations it is normal to have multiple buffers,
typically 3 or more. That way you can have one
filling, one waiting to be filled, and one being
processed.

It's not clear why you want *exactly* 176400 bytes
in your buffer, but if this is indeed a
requirement for some reason, you could use enough
smaller buffers to exceed 176400 total bytes, then
treat it like a circular buffer when using 176400
bytes at a time. This might require some pointer
manipulations and breaking the transfer into 2
chunks. Why not just use some multiple of 2304
bytes?

Best regards,


Bob Masta

DAQARTA v5.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
Frequency Counter, FREE Signal Generator
Pitch Track, Pitch-to-MIDI
DaqMusic - FREE MUSIC, Forever!
(Some assembly required)
Science (and fun!) with your sound card!
From: Larry on
"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
news:4b41ea41.952592(a)news.eternal-september.org...

> It's not clear why you want *exactly* 176400 bytes
> in your buffer, but if this is indeed a
> requirement for some reason, you could use enough
> smaller buffers to exceed 176400 total bytes, then
> treat it like a circular buffer when using 176400
> bytes at a time. This might require some pointer
> manipulations and breaking the transfer into 2
> chunks. Why not just use some multiple of 2304
> bytes?

Hi,

for some reason the Lame-enc DLL will only accept 2304 Samples (Stereo:
2x1152) at a time. I cannot set the wave encoder buffer to 2304 bytes, even
if I push 77 buffers:

2304 x 77 = 177408 (>176400)

This because the sound will be choppy (suck) I tried that over and over...

All I can do is set up a buffer of 176400 Bytes OR I can always push 30
buffers of 5880 each! (I love this last one, I do get perfect sound!) Also
5880 is really a small chuck.

So, when I get signalized the buffer is filled (5880 bytes) I will have to
encode the WAVE buffer to MP3 by calling the beEncodeChunk() function, say 3
times in order to pass it a part of the buffer say:

2304 bytes, 2304 bytes and 1272 bytes = 5880 bytes!

Now, how can I do this? I should substr the buffer...

this is the event loop:

while(1)
{
// CALLBACK EVENT
WaitForSingleObject(hevent, INFINITE);

if(buff[k].dwFlags & WHDR_DONE)
{
//buff[k].lpData is 5880 Bytes long...

while(...)
{
//encode();
}
waveInAddBuffer(hwi, &buff[k], sizeof(WAVEHDR));
}

if(k == num_buffers -1)
k=0;
else
k++;
}


thanks