Sound recording works on Windows

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5111 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux 1999-12-25 17:38:46 +00:00
parent f9ee644eac
commit e336790467
2 changed files with 22 additions and 18 deletions

View File

@ -21,7 +21,7 @@
typedef struct _wxSoundInternal wxSoundInternal; typedef struct _wxSoundInternal wxSoundInternal;
typedef struct _wxSoundInfoHeader wxSoundInfoHeader; typedef struct _wxSoundInfoHeader wxSoundInfoHeader;
extern char wxCanvasClassName[]; extern const wxChar *wxCanvasClassName;
wxList *wxSoundHandleList = NULL; wxList *wxSoundHandleList = NULL;
@ -68,6 +68,8 @@ wxSoundStreamWin::wxSoundStreamWin()
m_internal->m_input_enabled = FALSE; m_internal->m_input_enabled = FALSE;
m_internal->m_output_enabled = FALSE; m_internal->m_output_enabled = FALSE;
m_waiting_for = FALSE;
if (!OpenDevice(wxSOUND_OUTPUT)) if (!OpenDevice(wxSOUND_OUTPUT))
return; return;
@ -238,16 +240,14 @@ bool wxSoundStreamWin::OpenDevice(int mode)
void wxSoundStreamWin::CloseDevice() void wxSoundStreamWin::CloseDevice()
{ {
if (m_internal->m_output_enabled) { if (m_internal->m_output_enabled) {
m_internal->m_output_enabled = FALSE;
waveOutReset(m_internal->m_devout);
FreeHeaders(wxSOUND_OUTPUT); FreeHeaders(wxSOUND_OUTPUT);
m_internal->m_output_enabled = FALSE;
waveOutClose(m_internal->m_devout); waveOutClose(m_internal->m_devout);
} }
if (m_internal->m_input_enabled) { if (m_internal->m_input_enabled) {
m_internal->m_input_enabled = FALSE;
waveInReset(m_internal->m_devin);
FreeHeaders(wxSOUND_INPUT); FreeHeaders(wxSOUND_INPUT);
m_internal->m_input_enabled = FALSE;
waveInClose(m_internal->m_devin); waveInClose(m_internal->m_devin);
} }
} }
@ -296,7 +296,6 @@ wxSoundInfoHeader *wxSoundStreamWin::AllocHeader(int mode)
header->dwUser = (DWORD)info; header->dwUser = (DWORD)info;
header->dwFlags = WHDR_DONE; header->dwFlags = WHDR_DONE;
// "Prepare" the header // "Prepare" the header
if (mode == wxSOUND_INPUT) { if (mode == wxSOUND_INPUT) {
MMRESULT result; MMRESULT result;
@ -439,13 +438,17 @@ void wxSoundStreamWin::WaitFor(wxSoundInfoHeader *info)
memset(info->m_data + info->m_position, 0, info->m_size); memset(info->m_data + info->m_position, 0, info->m_size);
AddToQueue(info); AddToQueue(info);
} }
return;
} }
if (m_waiting_for) {
// PROBLEM //
return;
}
m_waiting_for = TRUE;
// Else, we wait for its termination // Else, we wait for its termination
while (info->m_playing || info->m_recording) while (info->m_playing || info->m_recording)
wxYield(); wxYield();
m_waiting_for = FALSE;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -623,13 +626,15 @@ void wxSoundStreamWin::NotifyDoneBuffer(wxUint32 dev_handle, int flag)
info = m_headers_play[m_output_frag_out]; info = m_headers_play[m_output_frag_out];
ClearHeader(info); ClearHeader(info);
m_queue_filled = FALSE; m_queue_filled = FALSE;
if (!m_waiting_for)
OnSoundEvent(wxSOUND_OUTPUT); OnSoundEvent(wxSOUND_OUTPUT);
} else { } else {
if (!m_internal->m_input_enabled) if (!m_internal->m_input_enabled)
return; return;
m_input_frag_in = (m_input_frag_in + 1) % WXSOUND_MAX_QUEUE;
m_headers_rec[m_input_frag_in]->m_recording = FALSE; m_headers_rec[m_input_frag_in]->m_recording = FALSE;
m_input_frag_in = (m_input_frag_in + 1) % WXSOUND_MAX_QUEUE;
if (!m_waiting_for)
OnSoundEvent(wxSOUND_INPUT); OnSoundEvent(wxSOUND_INPUT);
m_queue_filled = FALSE; m_queue_filled = FALSE;
} }
@ -657,7 +662,7 @@ bool wxSoundStreamWin::StartProduction(int evt)
m_queue_filled = FALSE; m_queue_filled = FALSE;
// Send a dummy event to start. // Send a dummy event to start.
if (evt & wxSOUND_OUTPUT) if (evt & wxSOUND_OUTPUT)
OnSoundEvent(evt); OnSoundEvent(wxSOUND_OUTPUT);
if (evt & wxSOUND_INPUT) { if (evt & wxSOUND_INPUT) {
int i; int i;
@ -674,9 +679,6 @@ bool wxSoundStreamWin::StartProduction(int evt)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool wxSoundStreamWin::StopProduction() bool wxSoundStreamWin::StopProduction()
{ {
if (m_internal->m_input_enabled)
waveInStop(m_internal->m_devin);
m_production_started = FALSE; m_production_started = FALSE;
CloseDevice(); CloseDevice();
return TRUE; return TRUE;

View File

@ -33,13 +33,15 @@ class WXDLLEXPORT wxSoundStreamWin : public wxSoundStream {
// Internal but defined as public // Internal but defined as public
void NotifyDoneBuffer(wxUint32 dev_handle, int flag); void NotifyDoneBuffer(wxUint32 dev_handle, int flag);
wxUint32 GetBestSize() const { return 4096; }
protected: protected:
wxSoundInternal *m_internal; wxSoundInternal *m_internal;
wxUint32 m_current_frag_in, m_current_frag_out; wxUint32 m_current_frag_in, m_current_frag_out;
wxUint32 m_input_frag_in, m_output_frag_out; wxUint32 m_input_frag_in, m_output_frag_out;
wxSoundInfoHeader **m_headers_play, **m_headers_rec; wxSoundInfoHeader **m_headers_play, **m_headers_rec;
bool m_production_started, m_queue_filled; bool m_production_started, m_queue_filled, m_waiting_for;
protected: protected:
void CreateSndWindow(); void CreateSndWindow();