Esempio n. 1
0
/***********************************************************************
 * hb_work_decdca_init
 ***********************************************************************
 * Allocate the work object, initialize libdca
 **********************************************************************/
static int decdcaInit( hb_work_object_t * w, hb_job_t * job )
{
    hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
    hb_audio_t * audio = w->audio;
    w->private_data = pv;

    pv->job   = job;

    pv->list      = hb_list_init();
    pv->state     = dca_init( 0 );

    /* Decide what format we want out of libdca
    work.c has already done some of this deduction for us in do_job() */

    pv->flags_out = HB_AMIXDOWN_GET_DCA_FORMAT(audio->config.out.mixdown);
    if ( audio->config.out.codec == HB_ACODEC_LAME )
        pv->flags_out |= DCA_ADJUST_LEVEL;

    /* pass the number of channels used into the private work data */
    /* will only be actually used if we're not doing AC3 passthru */
    pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown);

    pv->level     = 32768.0;

    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    dca_state_t *state;

    (void)argc;
    (void)argv;

    state = dca_init(0);
    if (!state) {
        return 1;
    }

    dca_free(state);
    return 0;
}
Esempio n. 3
0
bool TaudioCodecLibDTS::init(const CMediaType &mt)
{
    dll = new Tdll(dllname, config);
    dll->loadFunction(dca_init, "dca_init");
    dll->loadFunction(dca_free, "dca_free");
    dll->loadFunction(dca_syncinfo, "dca_syncinfo");
    dll->loadFunction(dca_frame, "dca_frame");
    dll->loadFunction(dca_dynrng, "dca_dynrng");
    dll->loadFunction(dca_blocks_num, "dca_blocks_num");
    dll->loadFunction(dca_block, "dca_block");
    dll->loadFunction(dca_samples, "dca_samples");
    if (dll->ok) {
        state = dca_init(Tconfig::cpu_flags);
        fmt.sf = TsampleFormat::SF_FLOAT32;
        inited = true;
        return true;
    } else {
        return false;
    }
}
Esempio n. 4
0
static gboolean
gst_dtsdec_start (GstAudioDecoder * dec)
{
  GstDtsDec *dts = GST_DTSDEC (dec);
  GstDtsDecClass *klass;

  GST_DEBUG_OBJECT (dec, "start");

  klass = GST_DTSDEC_CLASS (G_OBJECT_GET_CLASS (dts));
  dts->state = dca_init (klass->dts_cpuflags);
  dts->samples = dca_samples (dts->state);
  dts->bit_rate = -1;
  dts->sample_rate = -1;
  dts->stream_channels = DCA_CHANNEL;
  dts->using_channels = DCA_CHANNEL;
  dts->level = 1;
  dts->bias = 0;
  dts->flag_update = TRUE;

  /* call upon legacy upstream byte support (e.g. seeking) */
  gst_audio_decoder_set_estimate_rate (dec, TRUE);

  return TRUE;
}
Esempio n. 5
0
static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b,
                         hb_work_info_t *info )
{
    int i, flags, rate, bitrate, frame_length;
    dca_state_t * state = dca_init( 0 );

    memset( info, 0, sizeof(*info) );

    /* since DCA frames don't line up with MPEG ES frames scan the
     * entire frame for an DCA sync pattern.  */
    for ( i = 0; i < b->size - 7; ++i )
    {
        if( dca_syncinfo( state, &b->data[i], &flags, &rate, &bitrate,
                          &frame_length ) )
        {
            break;
        }
    }
    if ( i >= b->size - 7 )
    {
        /* didn't find DCA sync */
        return 0;
    }

    info->name = "DCA";
    info->rate = rate;
    info->rate_base = 1;
    info->bitrate = bitrate;
    info->flags = flags;

    if ( ( flags & DCA_CHANNEL_MASK) == DCA_DOLBY )
    {
        info->flags |= AUDIO_F_DOLBY;
    }

    switch( flags & DCA_CHANNEL_MASK )
    {
        /* mono sources */
        case DCA_MONO:
            info->channel_layout = HB_INPUT_CH_LAYOUT_MONO;
            break;
        /* stereo input */
        case DCA_CHANNEL:
        case DCA_STEREO:
        case DCA_STEREO_SUMDIFF:
        case DCA_STEREO_TOTAL:
            info->channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
            break;
        /* 3F/2R input */
        case DCA_3F2R:
            info->channel_layout = HB_INPUT_CH_LAYOUT_3F2R;
            break;
        /* 3F/1R input */
        case DCA_3F1R:
            info->channel_layout = HB_INPUT_CH_LAYOUT_3F1R;
            break;
        /* other inputs */
        case DCA_3F:
            info->channel_layout = HB_INPUT_CH_LAYOUT_3F;
            break;
        case DCA_2F1R:
            info->channel_layout = HB_INPUT_CH_LAYOUT_2F1R;
            break;
        case DCA_2F2R:
            info->channel_layout = HB_INPUT_CH_LAYOUT_2F2R;
            break;
        case DCA_4F2R:
            info->channel_layout = HB_INPUT_CH_LAYOUT_4F2R;
            break;
        /* unknown */
        default:
            info->channel_layout = HB_INPUT_CH_LAYOUT_STEREO;
    }

    if (flags & DCA_LFE)
    {
        info->channel_layout |= HB_INPUT_CH_LAYOUT_HAS_LFE;
    }

    return 1;
}
Esempio n. 6
0
File: dca.c Progetto: etix/vlc
static int Open( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t *)p_this;
    decoder_sys_t *p_sys;

    if( p_dec->fmt_in.i_codec != VLC_CODEC_DTS
     || p_dec->fmt_in.audio.i_rate == 0
     || p_dec->fmt_in.audio.i_physical_channels == 0
     || p_dec->fmt_in.audio.i_original_channels == 0
     || p_dec->fmt_in.audio.i_bytes_per_frame == 0
     || p_dec->fmt_in.audio.i_frame_length == 0 )
        return VLC_EGENERIC;

    /* Allocate the memory needed to store the module's structure */
    p_sys = p_dec->p_sys = malloc( sizeof(decoder_sys_t) );
    if( p_sys == NULL )
        return VLC_ENOMEM;

    p_sys->b_dynrng = var_InheritBool( p_this, "dts-dynrng" );
    p_sys->b_dontwarn = 0;

    /* We'll do our own downmixing, thanks. */
    p_sys->i_nb_channels = aout_FormatNbChannels( &p_dec->fmt_in.audio );
    if( channels_vlc2dca( &p_dec->fmt_in.audio, &p_sys->i_flags )
        != VLC_SUCCESS )
    {
        msg_Warn( p_this, "unknown sample format!" );
        free( p_sys );
        return VLC_EGENERIC;
    }
    //p_sys->i_flags |= DCA_ADJUST_LEVEL;

    /* Initialize libdca */
    p_sys->p_libdca = dca_init( 0 );
    if( p_sys->p_libdca == NULL )
    {
        msg_Err( p_this, "unable to initialize libdca" );
        free( p_sys );
        return VLC_EGENERIC;
    }

    /* libdca channel order
     * libdca currently only decodes 5.1, even if you have a DTS-ES source. */
    static const uint32_t pi_channels_in[] = {
        AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
        AOUT_CHAN_REARCENTER, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
        AOUT_CHAN_LFE, 0
    };

    aout_CheckChannelReorder( pi_channels_in, NULL,
                              p_dec->fmt_in.audio.i_physical_channels,
                              p_sys->pi_chan_table );

    p_dec->fmt_out.i_cat = AUDIO_ES;
    p_dec->fmt_out.audio = p_dec->fmt_in.audio;
    p_dec->fmt_out.audio.i_format = VLC_CODEC_FL32;
    p_dec->fmt_out.i_codec = p_dec->fmt_out.audio.i_format;

    aout_FormatPrepare( &p_dec->fmt_out.audio );

    if( decoder_UpdateAudioFormat( p_dec ) )
    {
        es_format_Init( &p_dec->fmt_out, UNKNOWN_ES, 0 );
        Close( p_this );
        return VLC_EGENERIC;
    }

    p_dec->pf_decode = Decode;
    p_dec->pf_flush  = NULL;
    return VLC_SUCCESS;
}
Esempio n. 7
0
/*****************************************************************************
 * Open:
 *****************************************************************************/
static int Open( vlc_object_t *p_this, filter_sys_t *p_sys,
                 audio_format_t input, audio_format_t output )
{
    p_sys->b_dynrng = var_InheritBool( p_this, "dts-dynrng" );
    p_sys->b_dontwarn = 0;

    /* We'll do our own downmixing, thanks. */
    p_sys->i_nb_channels = aout_FormatNbChannels( &output );
    switch ( (output.i_physical_channels & AOUT_CHAN_PHYSMASK)
              & ~AOUT_CHAN_LFE )
    {
    case AOUT_CHAN_CENTER:
        if ( (output.i_original_channels & AOUT_CHAN_CENTER)
              || (output.i_original_channels
                   & (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
        {
            p_sys->i_flags = DCA_MONO;
        }
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT:
        if ( output.i_original_channels & AOUT_CHAN_DOLBYSTEREO )
        {
            p_sys->i_flags = DCA_DOLBY;
        }
        else if ( input.i_original_channels == AOUT_CHAN_CENTER )
        {
            p_sys->i_flags = DCA_MONO;
        }
        else if ( input.i_original_channels & AOUT_CHAN_DUALMONO )
        {
            p_sys->i_flags = DCA_CHANNEL;
        }
        else
        {
            p_sys->i_flags = DCA_STEREO;
        }
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER:
        p_sys->i_flags = DCA_3F;
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARCENTER:
        p_sys->i_flags = DCA_2F1R;
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
          | AOUT_CHAN_REARCENTER:
        p_sys->i_flags = DCA_3F1R;
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
        p_sys->i_flags = DCA_2F2R;
        break;

    case AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT:
        p_sys->i_flags = DCA_3F2R;
        break;

    default:
        msg_Warn( p_this, "unknown sample format!" );
        free( p_sys );
        return -1;
    }
    if ( output.i_physical_channels & AOUT_CHAN_LFE )
    {
        p_sys->i_flags |= DCA_LFE;
    }
    //p_sys->i_flags |= DCA_ADJUST_LEVEL;

    /* Initialize libdca */
    p_sys->p_libdca = dca_init( 0 );
    if( p_sys->p_libdca == NULL )
    {
        msg_Err( p_this, "unable to initialize libdca" );
        return VLC_EGENERIC;
    }

    aout_CheckChannelReorder( pi_channels_in, NULL,
                              output.i_physical_channels & AOUT_CHAN_PHYSMASK,
                              p_sys->i_nb_channels,
                              p_sys->pi_chan_table );

    return VLC_SUCCESS;
}
Esempio n. 8
0
/***********************************************************************
 * hb_work_decdca_init
 ***********************************************************************
 * Allocate the work object, initialize libdca
 **********************************************************************/
static int decdcaInit( hb_work_object_t * w, hb_job_t * job )
{
    hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
    hb_audio_t * audio = w->audio;
    w->private_data = pv;

    pv->job   = job;

    pv->list      = hb_list_init();
    pv->state     = dca_init( 0 );
    pv->level     = 1.0;

    /* Decide what format we want out of libdca;
     * work.c has already done some of this deduction for us in do_job().
     * Dolby Surround and Pro Logic II are a bit tricky. */
    int layout = (audio->config.in.channel_layout & ~AV_CH_LOW_FREQUENCY);
    switch (audio->config.out.mixdown)
    {
        case HB_AMIXDOWN_6CH:
            pv->flags_out = (DCA_3F2R|DCA_LFE);
            break;

        case HB_AMIXDOWN_DOLBYPLII:
        {
            if (layout == AV_CH_LAYOUT_5POINT0)
            {
                // Dolby Pro Logic II output is supported
                pv->flags_out = (DCA_3F2R|DCA_OUT_DPLII);
            }
            else if (layout == AV_CH_LAYOUT_4POINT0)
            {
                // Dolby Surround output and DCA_3F1R downmix are supported
                pv->flags_out = (DCA_3F1R|DCA_OUT_DPLI);
            }
            else if (layout == AV_CH_LAYOUT_STEREO ||
                     layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
            {
                // Dolby Surround output not supported OR
                // Dolby Surround input just gets passed through as is
                pv->flags_out = DCA_STEREO;
            }
            else
            {
                // Dolby Surround output is supported, but DCA_3F1R downmix isn't
                pv->flags_out = DCA_DOLBY;
            }
        } break;

        case HB_AMIXDOWN_DOLBY:
        {
            if (layout == AV_CH_LAYOUT_5POINT0 || layout == AV_CH_LAYOUT_4POINT0)
            {
                // Dolby Surround output and DCA_3F1R downmix are supported
                pv->flags_out = (DCA_3F1R|DCA_OUT_DPLI);
            }
            else if (layout == AV_CH_LAYOUT_STEREO ||
                     layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
            {
                // Dolby Surround output not supported OR
                // Dolby Surround input just gets passed through as is
                pv->flags_out = DCA_STEREO;
            }
            else
            {
                // Dolby Surround output is supported, but DCA_3F1R downmix isn't
                pv->flags_out = DCA_DOLBY;
            }
        } break;

        case HB_AMIXDOWN_MONO:
            pv->flags_out = DCA_MONO;
            break;

        default:
            pv->flags_out = DCA_STEREO;
            break;
    }

    /* pass the number of channels used into the private work data */
    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );

    return 0;
}
Esempio n. 9
0
static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b,
                         hb_work_info_t *info )
{
    int i, flags, rate, bitrate, frame_length;
    dca_state_t * state = dca_init( 0 );

    memset( info, 0, sizeof(*info) );

    /* since DCA frames don't line up with MPEG ES frames scan the
     * entire frame for an DCA sync pattern.  */
    for ( i = 0; i < b->size - 7; ++i )
    {
        if( dca_syncinfo( state, &b->data[i], &flags, &rate, &bitrate,
                          &frame_length ) )
        {
            break;
        }
    }
    if ( i >= b->size - 7 )
    {
        /* didn't find DCA sync */
        dca_free( state );
        return 0;
    }

    info->name = "DCA";
    info->rate = rate;
    info->rate_base = 1;
    info->bitrate = bitrate;
    info->flags = flags;
    info->samples_per_frame = frame_length;

    switch( flags & DCA_CHANNEL_MASK )
    {
        /* mono sources */
        case DCA_MONO:
            info->channel_layout = AV_CH_LAYOUT_MONO;
            break;
        /* stereo input */
        case DCA_CHANNEL:
        case DCA_STEREO:
        case DCA_STEREO_SUMDIFF:
        case DCA_STEREO_TOTAL:
            info->channel_layout = AV_CH_LAYOUT_STEREO;
            break;
        /* Dolby Pro Logic (a.k.a. Dolby Surround), 4.0 channels (matrix-encoded) */
        case DCA_DOLBY:
            info->channel_layout = AV_CH_LAYOUT_STEREO_DOWNMIX;
            break;
        /* 3F/2R input */
        case DCA_3F2R:
            info->channel_layout = AV_CH_LAYOUT_5POINT0;
            break;
        /* 3F/1R input */
        case DCA_3F1R:
            info->channel_layout = AV_CH_LAYOUT_4POINT0;
            break;
        /* other inputs */
        case DCA_3F:
            info->channel_layout = AV_CH_LAYOUT_SURROUND;
            break;
        case DCA_2F1R:
            info->channel_layout = AV_CH_LAYOUT_2_1;
            break;
        case DCA_2F2R:
            info->channel_layout = AV_CH_LAYOUT_2_2;
            break;
        case DCA_4F2R:
            info->channel_layout = AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER;
            break;
        /* unknown */
        default:
            info->channel_layout = AV_CH_LAYOUT_STEREO;
    }

    if (flags & DCA_LFE)
    {
        info->channel_layout |= AV_CH_LOW_FREQUENCY;
    }

    info->channel_map = &hb_qt_chan_map;

    dca_free( state );
    return 1;
}