Beispiel #1
0
bool wxSoundFormatG72X::operator !=(const wxSoundFormatBase& frmt2) const
{
    wxSoundFormatG72X *g72x = (wxSoundFormatG72X *)&frmt2;
    
    if (frmt2.GetType() != wxSOUND_G72X)
        return true;
    
    return (g72x->m_srate != m_srate || g72x->m_g72x_type != m_g72x_type);
}
// --------------------------------------------------------------------------
// 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 #3
0
bool wxSoundFormatPcm::operator!=(const wxSoundFormatBase& format) const
{
  wxSoundFormatPcm *format2 = (wxSoundFormatPcm *)&format;

  if (format.GetType() != wxSOUND_PCM)
    return true;

  return ( (m_srate != format2->m_srate) ||
           (m_bps != format2->m_bps) ||
           (m_nchan != format2->m_nchan) ||
           (m_order != format2->m_order) ||
           (m_signed != format2->m_signed) );
}
Beispiel #4
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 #5
0
bool wxSoundStreamG72X::SetSoundFormat(const wxSoundFormatBase& format)
{
    if (format.GetType() != wxSOUND_G72X) {
        m_snderror = wxSOUND_INVFRMT;
        return false;
    }
    
    wxSoundFormatPcm pcm;
    wxSoundFormatG72X *g72x;
    
    wxSoundStreamCodec::SetSoundFormat(format);
    
    g72x = (wxSoundFormatG72X *)m_sndformat;
    
    // Set PCM as the output format of the codec
    pcm.SetSampleRate(g72x->GetSampleRate());
    pcm.SetBPS(16);
    pcm.SetChannels(1); // Only mono supported
    pcm.Signed(true);
    pcm.SetOrder(wxBYTE_ORDER);

    // Look for the correct codec to use and set its bit width
    switch (g72x->GetG72XType()) {
        case wxSOUND_G721:
            m_n_bits  = 4;
            m_coder   = g721_encoder;
            m_decoder = g721_decoder;
            break;
        case wxSOUND_G723_24:
            m_n_bits  = 3;
            m_coder   = g723_24_encoder;
            m_decoder = g723_24_decoder;
            break;
        case wxSOUND_G723_40:
            m_n_bits  = 5;
            m_coder   = g723_40_encoder;
            m_decoder = g723_40_decoder;
            break;
    }

    // Let the router finish the work
    m_router->SetSoundFormat(pcm);
    
    return true;
}
Beispiel #6
0
// --------------------------------------------------------------------------
// SetSoundFormat(const wxSoundFormatBase& format) first tries to setup the
// sound driver using the specified format. If this fails, it uses personnal
// codec converters: for the moment there is a PCM converter (PCM to PCM:
// with optional resampling, ...), an ULAW converter (ULAW to PCM), a G72X
// converter (G72X to PCM). If nothing works, it returns false.
// --------------------------------------------------------------------------
bool wxSoundRouterStream::SetSoundFormat(const wxSoundFormatBase& format)
{
    if (m_router)
        delete m_router;
    
    // First, we try to setup the sound device
    if (m_sndio->SetSoundFormat(format)) {
        // We are lucky, it is working.
        wxSoundStream::SetSoundFormat(m_sndio->GetSoundFormat());
        return true;
    }
    
    switch(format.GetType()) {
        case wxSOUND_NOFORMAT:
            return false;
        case wxSOUND_PCM:
            m_router = new wxSoundStreamPcm(*m_sndio);
            m_router->SetSoundFormat(format);
            break;
        case wxSOUND_ULAW:
            m_router = new wxSoundStreamUlaw(*m_sndio);
            m_router->SetSoundFormat(format);
            break;
        case wxSOUND_G72X:
            m_router = new wxSoundStreamG72X(*m_sndio);
            m_router->SetSoundFormat(format);
            break;
        case wxSOUND_MSADPCM:
            m_router = new  wxSoundStreamMSAdpcm(*m_sndio);
            m_router->SetSoundFormat(format);
            break;
        default:
            return false;
        
    }
    wxSoundStream::SetSoundFormat(m_router->GetSoundFormat());
    return true;
}
Beispiel #7
0
bool wxSoundStreamPcm::SetSoundFormat(const wxSoundFormatBase& format)
{
    wxSoundFormatBase *new_format;
    wxSoundFormatPcm *pcm_format, *pcm_format2;
    
    if (m_sndio->SetSoundFormat(format)) {
        m_function_out = NULL;
        m_function_in = NULL;
        return true;
    }
    if (format.GetType() != wxSOUND_PCM) {
        m_snderror = wxSOUND_INVFRMT;
        return false;
    }
    if (m_sndformat)
        delete m_sndformat;
    
    new_format = m_sndio->GetSoundFormat().Clone();
    pcm_format = (wxSoundFormatPcm *)&format;
    pcm_format2 = (wxSoundFormatPcm *)new_format;

#if 0
    // ----------------------------------------------------
    // Test whether we need to resample
    if (pcm_format->GetSampleRate() != pcm_format2->GetSampleRate()) {
        wxUint32 src_rate, dst_rate;

        src_rate = pcm_format->GetSampleRate();
        dst_rate = pcm_format2->GetSampleRate();
        m_needResampling = true;
        if (src_rate < dst_rate)
            m_expandSamples = true;
        else
            m_expandSamples = false;
        m_pitch = (src_rate << FLOATBITS) / dst_rate;
    }
#endif
    // ----------------------------------------------------
    // Select table to use:
    //     * 8 bits -> 8 bits
    //     * 16 bits -> 8 bits
    //     * 8 bits -> 16 bits
    //     * 16 bits -> 16 bits

    int table_no, table_no2;
    int i_sign, i_swap;
    
    switch (pcm_format->GetBPS()) {
        case 8:
            table_no = 0;
            break;
        case 16:
            table_no = 1;
            break;
        default:
            // TODO: Add something here: error, log, ...
            return false;
    }
    switch (pcm_format2->GetBPS()) {
        case 8:
            table_no2 = 0;
            break;
        case 16:
            table_no2 = 1;
            break;
        default:
            // TODO: Add something here: error, log, ...
            return false;
    }
    
    if (pcm_format2->Signed() != pcm_format->Signed())
        i_sign = 1;
    else
        i_sign = 0;

#define MY_ORDER wxBYTE_ORDER
#if wxBYTE_ORDER == wxLITTLE_ENDIAN
#define OTHER_ORDER wxBIG_ENDIAN
#else
#define OTHER_ORDER wxLITTLE_ENDIAN
#endif

    // --------------------------------------------------------
    // Find the good converter !

    if (pcm_format->GetOrder() == OTHER_ORDER) {
        if (pcm_format->GetOrder() == pcm_format2->GetOrder())
            i_swap = 2;
        else
            i_swap = 1;
    } else {
        if (pcm_format->GetOrder() == pcm_format2->GetOrder())
            i_swap = 0;
        else
            i_swap = 1;
    }

    m_function_out = s_converters[table_no*2+table_no2][i_swap][i_sign];
    m_function_in  = s_converters[table_no2*2+table_no][i_swap][i_sign];
    m_multiplier_out = s_converters_multip[table_no*2+table_no2];
    m_multiplier_in  = s_converters_multip[table_no2*2+table_no2];

    if (m_prebuffer)
        delete[] m_prebuffer;

    // We try to minimize the need for dynamic memory allocation by preallocating a buffer. But
    // to be sure it will be efficient we minimize the best size.
    if (m_multiplier_in < m_multiplier_out) {
        m_prebuffer_size = (wxUint32)(m_sndio->GetBestSize() *
                                      m_multiplier_out);
        m_best_size = (wxUint32)(m_sndio->GetBestSize() *
                                 m_multiplier_in);
    } else {
        m_prebuffer_size = (wxUint32)(m_sndio->GetBestSize() *
                                      m_multiplier_in);
        m_best_size = (wxUint32)(m_sndio->GetBestSize() *
                                 m_multiplier_out);
    }
    
    m_prebuffer = new char[m_prebuffer_size];
    
    bool SetSoundFormatReturn;

    SetSoundFormatReturn = m_sndio->SetSoundFormat(*new_format);
    wxASSERT( SetSoundFormatReturn );
    wxUnusedVar( SetSoundFormatReturn );
    
    m_sndformat = new_format;
    return true;
}
bool wxSoundFormatBase::operator!=(const wxSoundFormatBase& frmt2) const
{
    return (GetType() != frmt2.GetType());
}
Beispiel #9
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;
}