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

> I am really stuck at that :-(

Great! I seem to have sorted it out like this:

int k = 0;
while(1)
{
if(stop_thread_flag)
break;
// CALLBACK EVENT
WaitForSingleObject(hevent, INFINITE);

if(buff[k].dwFlags & WHDR_DONE && !stop_thread_flag)
{
// Save WAVE
hFile2.write(buff[k].lpData, buff[k].dwBytesRecorded);
dwWAVBufferCounter += buff[k].dwBytesRecorded;

// Encode samples
//
// (LPSTR) buff[k].lpData is (system_buf_len) bytes long (8 BIT)
// (PSHORT)buff[k].lpData is (system_buf_len)/2 (16 BIT)
//
result = beEncodeChunk(hbeStream, dwSamples, (PSHORT)buff[k].lpData,
pMP3Buffer, &dwWrite);

// Save MP3
hFile.write((LPSTR)pMP3Buffer, dwWrite);
dwMP3BufferCounter += dwWrite;

waveInAddBuffer(hwi, &buff[k], sizeof(WAVEHDR));
}

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

From: ScottMcP [MVP] on
On Jan 8, 5:56 pm, "Larry" <dontmewit...(a)got.it> wrote:
> I'm sorry, that is not working either...do you think I should cast? what I
> dont get is the following
>
> // dwSamples = 2304;
> dwRead = fread(pWAVBuffer, sizeof(SHORT), dwSamples, pFileIn));
>
> basically that is reading sizeof(SHORT)*dwSamples (4608). Yet, dwRead is
> 2304...

That's what it should do. fread returns the number of "items" read,
where the 2nd parameter is the size of an "item".


>
> I record the same time a WAVE and MP3 file, this is the main code for my
> project:
>
> while(1)
>  {
>   if(stop_thread_flag)
>    break;
>   // CALLBACK EVENT
>   WaitForSingleObject(hevent, INFINITE);
>
>   if(buff[k].dwFlags & WHDR_DONE && !stop_thread_flag)
>   {
>    // Save WAVE
>    hFile2.write(buff[k].lpData, buff[k].dwBytesRecorded);
>    dwWAVBufferCounter  += buff[k].dwBytesRecorded;
>
>    // Encode chunk by chunk (dwLoop = 0)
>    while(dwLoop <= 3)
>    {
>     // copy part of the buffer...PSHORT pWAVChunk = new SHORT[dwSamples]
>     memcpy(pWAVChunk, buff[k].lpData + dwChunkSeek*sizeof(SHORT), 2304);
>
>     // Encode samples
>     result = beEncodeChunk(hbeStream, 2304, pWAVChunk, pMP3Buffer,
> &dwWrite);
>
>     //printf("%d -> %d \n", hashChunk[dwLoop], dwWrite);
>     // Save MP3
>     hFile.write((LPSTR)pMP3Buffer, dwWrite);
>     dwChunkSeek         += 2304;
>     dwMP3BufferCounter  += dwWrite;
>     ++dwLoop;
>    }

This loop runs 4 times. But your earlier post says 3 is what you
intend. Be careful!


>    dwLoop      = 0;
>    dwChunkSeek = 0;
>    waveInAddBuffer(hwi, &buff[k], sizeof(WAVEHDR));
>   }
>   if(k == num_buffers -1)
>    k = 0;
>   else
>    k++;
>
>  }
>
> I am really stuck at that :-(

Don't know which "that" you mean, and you didn't say what's wrong.
From: Larry on

"Larry" <dontmewithme(a)got.it> ha scritto nel messaggio
news:4b47eb1d$0$1127$4fafbaef(a)reader3.news.tin.it...
> "Larry" <dontmewithme(a)got.it> ha scritto nel messaggio
> news:4b47b816$0$1141$4fafbaef(a)reader1.news.tin.it...

> Great! I seem to have sorted it out like this:

basically I get the audio thru the WAVFORM API to a 2304*2 bytes long buffer
(LPSTR),

so that when I do (PSHORT)buffer to the DLL it'll look like 2304 samples (16
BIT)

having said that, I am getting mono audio...

the whole code is avaible here:

http://theartofweb.net/cpp/mp3Recorder_05.txt

the programm is supposed to grab the audi from a device and save it realtime
in both WAVE and MP3 files