-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jin Jae-yeon
committed
May 8, 2017
1 parent
2b7074a
commit fed5003
Showing
6 changed files
with
328 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "DaramCam.h" | ||
|
||
DCWaveAudioGenerator::DCWaveAudioGenerator () | ||
: stream ( nullptr ), capturer ( nullptr ) | ||
{ | ||
} | ||
|
||
|
||
DWORD WINAPI WAVAG_Progress ( LPVOID vg ) | ||
{ | ||
DCWaveAudioGenerator * audioGen = ( DCWaveAudioGenerator* ) vg; | ||
|
||
audioGen->capturer->Begin (); | ||
|
||
HRESULT hr; | ||
|
||
unsigned total = 0; | ||
while ( audioGen->threadRunning ) | ||
{ | ||
unsigned bufferLength; | ||
void * data = audioGen->capturer->GetAudioData ( &bufferLength ); | ||
if ( data == nullptr ) | ||
continue; | ||
audioGen->stream->Write ( data, bufferLength, nullptr ); | ||
total += bufferLength; | ||
} | ||
|
||
audioGen->capturer->End (); | ||
|
||
ULARGE_INTEGER temp; | ||
|
||
LARGE_INTEGER riffSeeker = { 0, }; | ||
riffSeeker.QuadPart = 4; | ||
hr = audioGen->stream->Seek ( riffSeeker, STREAM_SEEK_SET, &temp ); | ||
int totalFileSize = total + 44; | ||
hr = audioGen->stream->Write ( &totalFileSize, 4, nullptr ); | ||
|
||
LARGE_INTEGER dataSeeker = { 0, }; | ||
dataSeeker.QuadPart = 40; | ||
hr = audioGen->stream->Seek ( dataSeeker, STREAM_SEEK_SET, &temp ); | ||
hr = audioGen->stream->Write ( &total, 4, nullptr ); | ||
|
||
LARGE_INTEGER endPointSeeker = { 0, }; | ||
endPointSeeker.QuadPart = 0; | ||
hr = audioGen->stream->Seek ( endPointSeeker, STREAM_SEEK_END, nullptr ); | ||
|
||
hr = audioGen->stream->Commit ( STGC_DEFAULT ); | ||
|
||
return 0; | ||
} | ||
|
||
void DCWaveAudioGenerator::Begin ( IStream * _stream, DCAudioCapturer * _capturer ) | ||
{ | ||
stream = _stream; | ||
capturer = _capturer; | ||
|
||
stream->Write ( "RIFF", 4, nullptr ); | ||
LARGE_INTEGER riffSeeker = { 0, }; | ||
riffSeeker.QuadPart = 4; | ||
stream->Seek ( riffSeeker, STREAM_SEEK_CUR, nullptr ); | ||
stream->Write ( "WAVE", 4, nullptr ); | ||
|
||
int fmtSize = 16; | ||
short audioType = WAVE_FORMAT_PCM; | ||
short audioChannels = capturer->GetChannels (); | ||
int sampleRate = capturer->GetSamplerate (); | ||
short blockAlign = capturer->GetBitsPerSample () / 8; | ||
short bitsPerSample = capturer->GetBitsPerSample (); | ||
int byteRate = audioChannels * bitsPerSample * sampleRate / 8; | ||
|
||
stream->Write ( "fmt ", 4, nullptr ); | ||
stream->Write ( &fmtSize, 4, nullptr ); | ||
stream->Write ( &audioType, 2, nullptr ); | ||
stream->Write ( &audioChannels, 2, nullptr ); | ||
stream->Write ( &sampleRate, 4, nullptr ); | ||
stream->Write ( &byteRate, 4, nullptr ); | ||
stream->Write ( &blockAlign, 2, nullptr ); | ||
stream->Write ( &bitsPerSample, 2, nullptr ); | ||
|
||
stream->Write ( "data", 4, nullptr ); | ||
LARGE_INTEGER dataSeeker = { 0, }; | ||
riffSeeker.QuadPart = 4; | ||
stream->Seek ( dataSeeker, STREAM_SEEK_CUR, nullptr ); | ||
|
||
threadRunning = true; | ||
threadHandle = CreateThread ( nullptr, 0, WAVAG_Progress, this, 0, 0 ); | ||
} | ||
|
||
void DCWaveAudioGenerator::End () | ||
{ | ||
threadRunning = false; | ||
WaitForSingleObject ( threadHandle, INFINITE ); | ||
} |
Oops, something went wrong.