bool wxSoundStreamOSS::StartProduction(int evt) { wxSoundFormatBase *old_frmt; if (!m_oss_stop) StopProduction(); old_frmt = m_sndformat->Clone(); if (!old_frmt) { m_snderror = wxSOUND_MEMERROR; return false; } if (evt == wxSOUND_OUTPUT) m_fd = open(m_devname.mb_str(), O_WRONLY); else if (evt == wxSOUND_INPUT) m_fd = open(m_devname.mb_str(), O_RDONLY); if (m_fd == -1) { m_snderror = wxSOUND_INVDEV; return false; } SetSoundFormat(*old_frmt); delete old_frmt; int trig; if (evt == wxSOUND_OUTPUT) { #ifdef __WXGTK__ m_tag = gdk_input_add(m_fd, GDK_INPUT_WRITE, _wxSound_OSS_CBack, (gpointer)this); #endif trig = PCM_ENABLE_OUTPUT; } else { #ifdef __WXGTK__ m_tag = gdk_input_add(m_fd, GDK_INPUT_READ, _wxSound_OSS_CBack, (gpointer)this); #endif trig = PCM_ENABLE_INPUT; } ioctl(m_fd, SNDCTL_DSP_SETTRIGGER, &trig); m_oss_stop = false; m_q_filled = false; return true; }
bool wxSoundWave::HandleOutputG721(wxDataInputStream& WXUNUSED(data), wxUint32 len, wxUint16 WXUNUSED(channels), wxUint32 sample_fq, wxUint32 WXUNUSED(byte_p_sec), wxUint16 WXUNUSED(byte_p_spl), wxUint16 WXUNUSED(bits_p_spl)) { wxSoundFormatG72X sndformat; sndformat.SetSampleRate(sample_fq); sndformat.SetG72XType(wxSOUND_G721); if (!SetSoundFormat(sndformat)) return false; m_input->SeekI(len, wxFromCurrent); return true; }
bool wxSoundWave::HandleOutputPCM(wxDataInputStream& WXUNUSED(data), wxUint32 len, wxUint16 channels, wxUint32 sample_fq, wxUint32 WXUNUSED(byte_p_sec), wxUint16 WXUNUSED(byte_p_spl), wxUint16 bits_p_spl) { wxSoundFormatPcm sndformat; sndformat.SetSampleRate(sample_fq); sndformat.SetBPS(bits_p_spl); sndformat.SetChannels(channels); sndformat.Signed(true); sndformat.SetOrder(wxLITTLE_ENDIAN); if (!SetSoundFormat(sndformat)) return false; m_input->SeekI(len, wxFromCurrent); return true; }
wxSoundStreamESD::wxSoundStreamESD(const wxString& hostname) { #ifndef HAVE_ESD_H m_snderror = wxSOUND_INVDEV; return; #else wxSoundFormatPcm pcm_default; // First, we make some basic test: is there ESD on this computer ? m_esd_ok = false; if (hostname.IsNull()) m_fd_output = esd_play_stream(ESD_PLAY | ESD_STREAM, 22050, hostname.mb_str(), MY_ESD_NAME); else m_fd_output = esd_play_stream(ESD_PLAY | ESD_STREAM, 22050, NULL, MY_ESD_NAME); if (m_fd_output == -1) { // Answer: no. We return with an error. m_snderror = wxSOUND_INVDEV; return; } // Close this unuseful stream. esd_close(m_fd_output); m_hostname = hostname; // Set the default audio format SetSoundFormat(pcm_default); // Initialize some variable m_snderror = wxSOUND_NOERROR; m_esd_stop = true; m_q_filled = true; m_esd_ok = true; m_fd_output= -1; m_fd_input = -1; #endif // defined HAVE_ESD_H }
bool wxSoundWave::HandleOutputMSADPCM(wxDataInputStream& data, wxUint32 len, wxUint16 channels, wxUint32 sample_fq, wxUint32 WXUNUSED(byte_p_sec), wxUint16 WXUNUSED(byte_p_spl), wxUint16 WXUNUSED(bits_p_spl)) { wxSoundFormatMSAdpcm sndformat; wxInt16 *coefs[2]; wxUint16 coefs_len, i; wxUint16 block_size; sndformat.SetSampleRate(sample_fq); sndformat.SetChannels(channels); block_size = data.Read16(); coefs_len = data.Read16(); coefs[0] = new wxInt16[coefs_len]; coefs[1] = new wxInt16[coefs_len]; for (i=0;i<coefs_len;i++) { coefs[0][i] = data.Read16(); coefs[1][i] = data.Read16(); } sndformat.SetCoefs(coefs, 2, coefs_len); sndformat.SetBlockSize(block_size); delete[] coefs[0]; delete[] coefs[1]; if (!SetSoundFormat(sndformat)) return false; len -= coefs_len*4 + 4; m_input->SeekI(len, wxFromCurrent); return true; }
bool wxSoundWave::PrepareToRecord(wxUint32 time) { #define WRITE_SIGNATURE(s,sig) \ signature = sig; \ signature = wxUINT32_SWAP_ON_BE(signature); \ FAIL_WITH(s->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM); wxUint32 signature; wxMemoryOutputStream fmt_data; if (!m_output) { m_snderror = wxSOUND_INVSTRM; return false; } wxDataOutputStream data(*m_output); wxDataOutputStream fmt_d_data(fmt_data); data.BigEndianOrdered(false); fmt_d_data.BigEndianOrdered(false); WRITE_SIGNATURE(m_output, RIFF_SIGNATURE); FAIL_WITH(m_output->LastWrite() != 4, wxSOUND_INVSTRM); WRITE_SIGNATURE((&fmt_data), WAVE_SIGNATURE); { wxSoundFormatBase *frmt; WRITE_SIGNATURE((&fmt_data), FMT_SIGNATURE); switch (m_sndformat->GetType()) { case wxSOUND_PCM: frmt = HandleInputPCM(fmt_d_data); break; case wxSOUND_G72X: frmt = HandleInputG72X(fmt_d_data); break; default: m_snderror = wxSOUND_NOCODEC; return false; } FAIL_WITH(!frmt, wxSOUND_NOCODEC); if (!SetSoundFormat(*frmt)) { delete frmt; return false; } delete frmt; } data << (wxUint32)(fmt_data.GetSize() + m_sndformat->GetBytesFromTime(time)); // We, finally, copy the header block to the output stream { char *out_buf; out_buf = new char[fmt_data.GetSize()]; fmt_data.CopyTo(out_buf, fmt_data.GetSize()); m_output->Write(out_buf, fmt_data.GetSize()); delete[] out_buf; } WRITE_SIGNATURE(m_output, DATA_SIGNATURE); data.Write32(m_sndformat->GetBytesFromTime(time)); return true; }