// --------------------------------------------------------------------------
// SetSoundFormat(const wxSoundFormatBase& format) is one of the most
// important function of the wxSoundStream class. It prepares the stream to
// receive or send the data in a strict format. Normally, the sound stream
// should be ready to accept any format it is asked to manage but in certain
// cases, it really cannot: in that case it returns false. To have more
// details in the functionnalities of SetSoundFormat see
// wxSoundRouterStream::SetSoundFormat()
// --------------------------------------------------------------------------
bool wxSoundStream::SetSoundFormat(const wxSoundFormatBase& format)
{
    // delete the previous prepared format
    if (m_sndformat)
        delete m_sndformat;

    // create a new one by cloning the format passed in parameter
    m_sndformat = format.Clone();
    return true;
}
Beispiel #2
0
// --------------------------------------------------------------------------
// SetSoundFormat(): this function specifies which format we want and which
// format is available
// --------------------------------------------------------------------------
bool wxSoundStreamESD::SetSoundFormat(const wxSoundFormatBase& format)
{
#ifndef HAVE_ESD_H
    m_snderror = wxSOUND_INVDEV;
    return false;
#else
    wxSoundFormatPcm *pcm_format;

    if (format.GetType() != wxSOUND_PCM) {
        m_snderror = wxSOUND_INVFRMT;
        return false;
    }

    if (!m_esd_ok) {
        m_snderror = wxSOUND_INVDEV;
        return false;
    }

    if (m_sndformat)
        delete m_sndformat;

    m_sndformat = format.Clone();
    if (!m_sndformat) {
        m_snderror = wxSOUND_MEMERROR;
        return false;
    }
    pcm_format = (wxSoundFormatPcm *)m_sndformat;

    // Detect the best format
    DetectBest(pcm_format);

    m_snderror = wxSOUND_NOERROR;
    if (*pcm_format != format) {
        m_snderror = wxSOUND_NOEXACT;
        return false;
    }
    return true;
#endif // defined HAVE_ESD_H
}
Beispiel #3
0
bool wxSoundStreamOSS::SetSoundFormat(const wxSoundFormatBase& format)
{
    int tmp;
    wxSoundFormatPcm *pcm_format;

    if (format.GetType() != wxSOUND_PCM) {
        m_snderror = wxSOUND_INVFRMT;
        return false;
    }

    if (!m_oss_ok) {
        m_snderror = wxSOUND_INVDEV;
        return false;
    }

    if (m_sndformat)
        delete m_sndformat;

    m_sndformat = format.Clone();
    if (!m_sndformat) {
        m_snderror = wxSOUND_MEMERROR;
        return false;
    }
    pcm_format = (wxSoundFormatPcm *)m_sndformat;

    // We temporary open the OSS device
    if (m_oss_stop) {
        m_fd = open(m_devname.mb_str(), O_WRONLY);
        if (m_fd == -1) {
            m_snderror = wxSOUND_INVDEV;
            return false;
        }
    }

    // Set the sample rate field.
    tmp = pcm_format->GetSampleRate();
    ioctl(m_fd, SNDCTL_DSP_SPEED, &tmp);

    pcm_format->SetSampleRate(tmp);

    // Detect the best format
    DetectBest(pcm_format);
    // Try to apply it
    SetupFormat(pcm_format);

    tmp = pcm_format->GetChannels();
    ioctl(m_fd, SNDCTL_DSP_CHANNELS, &tmp);
    pcm_format->SetChannels(tmp);

    // Close the OSS device
    if (m_oss_stop)
        close(m_fd);

    m_snderror = wxSOUND_NOERROR;
    if (*pcm_format != format) {
        m_snderror = wxSOUND_NOEXACT;
        return false;
    }

    return true;
}