Ticket #12222: alsas24.2.diff

File alsas24.2.diff, 4.0 KB (added by JYA, 10 years ago)
  • mythtv/libs/libmyth/audio/audiooutputalsa.cpp

    diff --git a/mythtv/libs/libmyth/audio/audiooutputalsa.cpp b/mythtv/libs/libmyth/audio/audiooutputalsa.cpp
    index f8bc384..ff15bbc 100644
    a b AudioOutputALSA::AudioOutputALSA(const AudioSettings &settings) : 
    3434    m_pbufsize(-1),
    3535    m_card(-1),
    3636    m_device(-1),
    37     m_subdevice(-1)
     37    m_subdevice(-1),
     38    m_s24_3bytes(false)
    3839{
    3940    m_mixer.handle = NULL;
    4041    m_mixer.elem = NULL;
    AudioOutputSettings* AudioOutputALSA::GetOutputSettings(bool passthrough) 
    382383            default:         continue;
    383384        }
    384385        if (snd_pcm_hw_params_test_format(pcm_handle, params, afmt) >= 0)
     386        {
    385387            settings->AddSupportedFormat(fmt);
     388            m_s24_3bytes = true;
     389        }
     390        else if (fmt == FORMAT_S24LSB)
     391        {
     392#if HAVE_BIGENDIAN
     393            afmt = SND_PCM_FORMAT_S24_3BE;
     394#else
     395            afmt = SND_PCM_FORMAT_S24_3LE;
     396#endif
     397            if (snd_pcm_hw_params_test_format(pcm_handle, params, afmt) >= 0)
     398            {
     399                settings->AddSupportedFormat(fmt);
     400                m_s24_3bytes = true;
     401                VBAUDIO("S24 3 bytes format supported");
     402            }
     403            else
     404            {
     405                m_s24_3bytes = false;
     406            }
     407        }
    386408    }
    387409
    388410    for (uint channels = CHANNELS_MIN; channels <= CHANNELS_MAX; channels++)
    bool AudioOutputALSA::OpenDevice() 
    470492    {
    471493        case FORMAT_U8:     format = SND_PCM_FORMAT_U8;    break;
    472494        case FORMAT_S16:    format = SND_PCM_FORMAT_S16;   break;
    473         case FORMAT_S24LSB: format = SND_PCM_FORMAT_S24;   break;
     495        case FORMAT_S24LSB:
     496            if (m_s24_3bytes)
     497            {
     498#if HAVE_BIGENDIAN
     499                format = SND_PCM_FORMAT_S24_3BE;
     500#else
     501                format = SND_PCM_FORMAT_S24_3LE;
     502#endif
     503            }
     504            else
     505            {
     506                format = SND_PCM_FORMAT_S24;
     507            }
     508            break;
    474509        case FORMAT_S24:    format = SND_PCM_FORMAT_S32;   break;
    475510        case FORMAT_S32:    format = SND_PCM_FORMAT_S32;   break;
    476511        case FORMAT_FLT:    format = SND_PCM_FORMAT_FLOAT; break;
    static inline void ReorderSmpteToAlsa(void *buf, uint frames, 
    543578    }
    544579}
    545580
     581static inline void ConvertS24To3Bytes(uchar *buf, uint samples)
     582{
     583    int *bufi = (int *)buf;
     584
     585    for (uint i = 0; i < samples; i++)
     586    {
     587        int *tmpi = (int *)buf;
     588
     589        *tmpi = *bufi;
     590        bufi++;
     591        buf += 3;
     592    }
     593}
     594
    546595void AudioOutputALSA::WriteAudio(uchar *aubuf, int size)
    547596{
    548597    uchar *tmpbuf = aubuf;
    549598    uint frames = size / output_bytes_per_frame;
    550599    int err, lw = 0;
     600    bool s243bytes = false;
    551601
    552602    if (pcm_handle == NULL)
    553603    {
    void AudioOutputALSA::WriteAudio(uchar *aubuf, int size) 
    561611        ReorderSmpteToAlsa(aubuf, frames, output_format, channels - 6);
    562612    }
    563613
     614    if (output_format == FORMAT_S24LSB && m_s24_3bytes)
     615    {
     616        // Handle special format where ALSA expects
     617        s243bytes = true;
     618        ConvertS24To3Bytes(aubuf, frames * channels);
     619    }
     620
    564621    LOG(VB_AUDIO | VB_TIMESTAMP, LOG_INFO,
    565622            QString("WriteAudio: Preparing %1 bytes (%2 frames)")
    566623            .arg(size).arg(frames));
    void AudioOutputALSA::WriteAudio(uchar *aubuf, int size) 
    576633                        .arg(lw * output_bytes_per_frame));
    577634
    578635            frames -= lw;
    579             tmpbuf += lw * output_bytes_per_frame; // bytes
     636            tmpbuf +=
     637                lw * (s243bytes ? channels * 3 : output_bytes_per_frame); // bytes
    580638            continue;
    581639        }
    582640
  • mythtv/libs/libmyth/audio/audiooutputalsa.h

    diff --git a/mythtv/libs/libmyth/audio/audiooutputalsa.h b/mythtv/libs/libmyth/audio/audiooutputalsa.h
    index b9ec580..b8536f7 100644
    a b class AudioOutputALSA : public AudioOutputBase 
    5858        long               volrange;
    5959    } m_mixer;
    6060
     61    bool         m_s24_3bytes;
    6162};
    6263#endif