Re: audio device on ubuntu

Carl Karsten <[email protected]> Sun, 30 Aug 2009 11:42:21 -0500
Newsgroups gmane.comp.video.kino.devel
Message-ID <[email protected]>
On Sat, Aug 29, 2009 at 11:29 PM, Dan Dennedy<[email protected]> wrote:
> On Sat, Aug 29, 2009 at 5:45 PM, Carl Karsten<[email protected]> wrote:
>> It seams to be playing at 1x.
>
> That message is not based on what speed you are playing at; it is
> based on what speed it was at when you recorded. It could be that the
> message only appears for a couple of frames and you have some other
> audio output problem. Do you think you are getting the message for
> each frame while playing.

yes.  played 30 frames, got 30 lines of # no audio

>
>> It is dv from dvgrab/dvswitch, should be
>> fine.

Actually, some new dvswitch  code was written back in March that
creates a dv stream from alsa (black video.)  There is a chance that
it isn't quite right.

you mind reviewing some code:

dvsource-alsa calls dv_buffer_set_audio in dif_audio.c

http://svn.debian.org/wsvn/dvswitch/trunk/src/dvsource-alsa.c
http://svn.debian.org/wsvn/dvswitch/trunk/src/dif_audio.c

void dv_buffer_set_audio(uint8_t * buffer,
                         enum dv_sample_rate sample_rate_code,
                         unsigned frame_count, const int16_t * samples)
{
    const struct dv_system * system = dv_buffer_system(buffer);

    assert(sample_rate_code >= 0 && sample_rate_code < dv_sample_rate_count);
    assert(frame_count >= system->audio_frame_counts[sample_rate_code].min &&
           frame_count <= system->audio_frame_counts[sample_rate_code].max);

    bool use_12bit = sample_rate_code == dv_sample_rate_32k;
    unsigned sample_count = frame_count * 2; // stereo

    // Each audio block has a 3-byte block id, a 5-byte AAUX
    // pack, and 72 bytes of samples.  Audio block 3 in each
    // sequence has an AS (audio source) pack, audio block 4
    // has an ASC (audio source control) pack, and the other
    // packs seem to be optional.
    static const uint8_t aaux_blank_pack[DIF_PACK_SIZE] = {
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF
    };
    uint8_t aaux_as_pack[DIF_PACK_SIZE] = {
        // pack id; 0x50 for AAUX source
        0x50,
        // bits 0-5: number of audio frames in video frame minus minimum value
        // bit 6: flag "should be 1"
        // bit 7: flag for unlocked audio sampling
        (frame_count - system->audio_frame_counts[sample_rate_code].min)
        | (1 << 6) | (1 << 7),
        // bits 0-3: audio mode
        // bit 4: flag for independent channels
        // bit 5: flag for "lumped" stereo (?)
        // bits 6-7: number of audio channels per block minus 1
        use_12bit << 6,
        // bits 0-4: system type; 0x0 for DV
        // bit 5: frame rate; 0 for 29.97 fps, 1 for 25 fps
        // bit 6: flag for multi-language audio
        // bit 7: ?
        dv_buffer_system_code(buffer) << 5,
        // bits 0-2: quantisation; 0 for 16-bit LPCM, 1 for 12-bit
        // bits 3-5: sample rate code
        // bit 6: time constant of emphasis; must be 1
        // bit 7: flag for no emphasis
        use_12bit | (sample_rate_code << 3) | (1 << 6) | (1 << 7)
    };
    static const uint8_t aaux_asc_pack[DIF_PACK_SIZE] = {
        // pack id; 0x51 for AAUX source control
        0x51,
        // bits 0-1: emphasis flag and ?
        // bits 2-3: compression level; 0 for once
        // bits 4-5: input type; 1 for digital
        // bits 6-7: copy generation management system; 0 for unrestricted
        (1 << 4),
        // bits 0-2: ?
        // bits 3-5: recording mode; 1 for original (XXX should indicate dub)
        // bit 6: recording end flag, inverted
        // bit 7: recording start flag, inverted
        (1 << 3) | (1 << 6) | (1 << 7),
        // bits 0-6: speed; 0x20 seems to be normal
        // bit 7: direction: 1 for forward
        0x20 | (1 << 7),
        // bits 0-6: genre; 0x7F seems to be unknown
        // bit 7: reserved
        0x7F
    };

    for (unsigned seq = 0; seq != system->seq_count; ++seq)
    {
        if (use_12bit && seq == system->seq_count / 2)
            samples = NULL; // silence extra 2 channels

        for (unsigned block_n = 0; block_n != 9; ++block_n)
        {
            uint8_t * out = (buffer + seq * DIF_SEQUENCE_SIZE +
                             (6 + 16 * block_n) * DIF_BLOCK_SIZE +
                             DIF_BLOCK_ID_SIZE);
            const uint8_t * pack;

            if (block_n == ((seq & 1) ? 0 : 3))
                pack = aaux_as_pack;
            else if (block_n == ((seq & 1) ? 1 : 4))
                pack = aaux_asc_pack;
            else
                pack = aaux_blank_pack;
            memcpy(out, pack, DIF_PACK_SIZE);
            out += DIF_PACK_SIZE;

            if (samples == NULL)
            {
                memset(out, 0, DIF_BLOCK_SIZE - DIF_BLOCK_ID_SIZE -
DIF_PACK_SIZE);
            }
            else if (use_12bit)
            {
                for (unsigned i = 0; i != 24; ++i)
                {
                    unsigned pos = (system->audio_shuffle[seq][block_n] +
                                    i * system->seq_count * 9);
                    unsigned code1 =
                        (pos < sample_count) ? encode_12bit(samples[pos]) : 0;
                    pos = (system->audio_shuffle[
                               seq + system->seq_count / 2][block_n] +
                           i * system->seq_count * 9);
                    unsigned code2 =
                        (pos < sample_count) ? encode_12bit(samples[pos]) : 0;

                    *out++ = code1 >> 4;
                    *out++ = code2 >> 4;
                    *out++ = (code1 << 4) | (code2 & 0xf);
                }
            }
            else // 16-bit
            {
                for (unsigned i = 0; i != 36; ++i)
                {
                    unsigned pos = (system->audio_shuffle[seq][block_n] +
                                    i * system->seq_count * 9);
                    int16_t sample = (pos < sample_count) ? samples[pos] : 0;

                    *out++ = sample >> 8;
                    *out++ = sample & 0xff;
                }
            }
        }
    }
}




>  Mplayer plays it ok.  If I disable audio, then no error.
>
> mplayer might be using qdv.dll
>
>>
>> On Aug 29, 2009 6:53 PM, "Dan Dennedy" <[email protected]> wrote:
>>
>> On Sat, Aug 29, 2009 at 3:49 PM, Carl Karsten<[email protected]> wrote:
>>> kino doesn't play aud...
>>
>> That is a libdv message that means it was unable to either parse the
>> audio header sections of the DV data or that the video is not running
>> at normal, 1x forward speed.
>>
>> --
>> +-DRD-+
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Kino-dev mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/kino-dev
>>
>>
>
>
>
> --
> +-DRD-+
>
>



-- 
Carl K

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july