reactos/base/applications/sndrec32/audio_waveout.hpp
Joachim Henze 546a6f16a8 [0.4.13][SNDREC32] Fast-Forward to 0.4.15-dev-3294-ge98684e state (CORE-17815 and several PRs)
My main motivation was a fix for the bug
CORE-17815 'Fix incorrect opaque text rendering' (#2760)
which was unhidden by 0.4.12-dev-824-g d57f7becc3 .
That specific and most important fix
was picked from 0.4.15-dev-190-g d839e3d9b4
We left out the additional WIN32SS-hardening in this context in the backport to older
releases for now.

Then I looked further in sndrec32 and compared each file of that module on master
head with both: current 0.4.14RC and also current 0.4.7rls and found the rare
situation that I liked each and every change within since 2017.
Specifically this will also backport (#2754), and various translation PRs, whitespace-cleanup,
and (for older releases than 0.4.14RC) it will also bring some x64-improvements.

So I decided to take everything from current master head except the changes in CMakeLists.txt
because that subset is applicable and a win for all ros releases down to 0.4.7.
2022-01-17 22:32:16 +01:00

147 lines
3.6 KiB
C++

/* PROJECT: ReactOS sndrec32
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/applications/sndrec32/audio_waveout.hpp
* PURPOSE: Windows MM wave out abstraction
* PROGRAMMERS: Marco Pagliaricci (irc: rendar)
*/
#ifndef _AUDIOWAVEOUT__H_
#define _AUDIOWAVEOUT__H_
#include "audio_format.hpp"
#include "audio_producer.hpp"
_AUDIO_NAMESPACE_START_
enum audio_waveout_status
{
WAVEOUT_NOTREADY,
WAVEOUT_READY,
WAVEOUT_PLAYING,
WAVEOUT_FLUSHING,
WAVEOUT_PAUSED,
WAVEOUT_STOP,
WAVEOUT_ERR
};
class audio_waveout
{
friend class audio_buffer;
private:
static DWORD WINAPI playing_procedure(LPVOID);
HANDLE wakeup_playthread;
protected:
WAVEFORMATEX wave_format;
WAVEHDR *wave_headers;
HWAVEOUT waveout_handle;
const audio_format &aud_info;
audio_producer &audio_buf;
/* Audio Playing Thread id */
DWORD playthread_id;
audio_waveout_status status;
float buf_secs;
/* The temporary buffers for the audio data outgoing to the waveout
device and its size, and its total number */
/* base address for entire memory */
BYTE *main_buffer;
/* size in bytes for the entire memory */
unsigned int mb_size;
/* number of little buffers */
unsigned int buffers;
/* Protected Functions */
void init_(void);
void alloc_buffers_mem_(unsigned int, float);
void free_buffers_mem_(void);
void init_headers_(void);
void prep_headers_(void);
void unprep_headers_(void);
public:
/* Ctors */
audio_waveout(const audio_format &aud_fmt,
audio_producer &a_buf) : wave_headers(0),
aud_info(aud_fmt),
audio_buf(a_buf),
status(WAVEOUT_NOTREADY),
main_buffer(0),
mb_size(0),
buffers(_AUDIO_DEFAULT_WAVEOUTBUFFERS)
{
/* Initializing internal wavein data */
init_();
}
/* Dtor */
~audio_waveout(void)
{
}
/* Public Functions */
void open(void);
void play(void);
void pause(void);
void stop(void);
void close(void);
audio_waveout_status current_status(void)
{
return status;
}
BYTE *buf(void)
{
return main_buffer;
}
unsigned int bufsz(void)
{
return mb_size;
}
unsigned int samplevalue_max(void)
{
if (aud_info.bits() == 16)
return (unsigned int)65535;
else if (aud_info.bits() == 8)
return (unsigned int)255;
else
return 0;
}
unsigned tot_samples_buf(void)
{
return aud_info.samples_in_bytes(mb_size);
}
unsigned int nsample(unsigned int nsamp)
{
unsigned int svalue;
if (aud_info.bits() == 16)
svalue = (unsigned int)abs(*((short *)(main_buffer + aud_info.bytes_in_samples(nsamp))));
else if (aud_info.bits() == 8)
svalue = (unsigned int)((ptrdiff_t) *(main_buffer + aud_info.bytes_in_samples(nsamp)));
else
svalue = 0;
return svalue;
}
};
_AUDIO_NAMESPACE_END_
#endif /* _AUDIOWAVEOUT__H_ */