Example #1
0
static int config_output(AVFilterLink *outlink)
{
    AVFilterContext *ctx = outlink->src;
    Bs2bContext    *bs2b = ctx->priv;
    AVFilterLink *inlink = ctx->inputs[0];

    int srate = inlink->sample_rate;

    switch (inlink->format) {
    case AV_SAMPLE_FMT_U8:
        bs2b->filter = bs2b_cross_feed_u8;
        break;
    case AV_SAMPLE_FMT_S16:
        bs2b->filter = (void*)bs2b_cross_feed_s16;
        break;
    case AV_SAMPLE_FMT_S32:
        bs2b->filter = (void*)bs2b_cross_feed_s32;
        break;
    case AV_SAMPLE_FMT_FLT:
        bs2b->filter = (void*)bs2b_cross_feed_f;
        break;
    case AV_SAMPLE_FMT_DBL:
        bs2b->filter = (void*)bs2b_cross_feed_d;
        break;
    default:
        return AVERROR_BUG;
    }

    if ((srate < BS2B_MINSRATE) || (srate > BS2B_MAXSRATE))
        return AVERROR(ENOSYS);

    bs2b_set_srate(bs2b->bs2bp, srate);

    return 0;
}
Example #2
0
static void bs2b_start (gint * channels, gint * rate)
{
    if (bs2b == NULL)
        return;

    bs2b_channels = * channels;

    if (* channels != 2)
        return;

    bs2b_set_srate (bs2b, * rate);
}
Example #3
0
/*
    InitContext

    Initialize Context variables
*/
static ALvoid InitContext(ALCcontext *pContext)
{
    int level;

    //Initialise listener
    pContext->Listener.Gain = 1.0f;
    pContext->Listener.MetersPerUnit = 1.0f;
    pContext->Listener.Position[0] = 0.0f;
    pContext->Listener.Position[1] = 0.0f;
    pContext->Listener.Position[2] = 0.0f;
    pContext->Listener.Velocity[0] = 0.0f;
    pContext->Listener.Velocity[1] = 0.0f;
    pContext->Listener.Velocity[2] = 0.0f;
    pContext->Listener.Forward[0] = 0.0f;
    pContext->Listener.Forward[1] = 0.0f;
    pContext->Listener.Forward[2] = -1.0f;
    pContext->Listener.Up[0] = 0.0f;
    pContext->Listener.Up[1] = 1.0f;
    pContext->Listener.Up[2] = 0.0f;

    //Validate pContext
    pContext->LastError = AL_NO_ERROR;
    pContext->InUse = AL_FALSE;

    //Set output format
    pContext->Frequency = pContext->Device->Frequency;

    //Set globals
    pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
    pContext->DopplerFactor = 1.0f;
    pContext->DopplerVelocity = 1.0f;
    pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;

    pContext->lNumStereoSources = 1;
    pContext->lNumMonoSources = pContext->Device->MaxNoOfSources - pContext->lNumStereoSources;

    pContext->ExtensionList = "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_LOKI_quadriphonic";

    level = GetConfigValueInt(NULL, "cf_level", 0);
    if(level > 0 && level <= 6)
    {
        pContext->bs2b = calloc(1, sizeof(*pContext->bs2b));
        bs2b_set_srate(pContext->bs2b, pContext->Frequency);
        bs2b_set_level(pContext->bs2b, level);
    }
}
Example #4
0
/*
    alcCreateContext

    Create and attach a Context to a particular Device.
*/
ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
{
    ALuint attrIdx, reqStereoSources;
    ALCcontext *ALContext;
    void *temp;
    ALuint i;

    SuspendContext(NULL);

    if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
    {
        alcSetError(ALC_INVALID_DEVICE);
        ProcessContext(NULL);
        return NULL;
    }

    // Reset Context Last Error code
    g_eLastContextError = ALC_NO_ERROR;

    // If a context is already running on the device, stop playback so the
    // device attributes can be updated
    if(device->NumContexts > 0)
    {
        ProcessContext(NULL);
        ALCdevice_StopPlayback(device);
        SuspendContext(NULL);
    }

    // Check for attributes
    if(attrList)
    {
        ALCint level = device->Bs2bLevel;
        ALCuint freq = device->Frequency;
        ALCint numMono = device->lNumMonoSources;
        ALCint numStereo = device->lNumStereoSources;
        ALCuint numSends = device->NumAuxSends;

        attrIdx = 0;
        while(attrList[attrIdx])
        {
            if(attrList[attrIdx] == ALC_FREQUENCY)
            {
                freq = attrList[attrIdx + 1];
                if(freq == 0)
                    freq = device->Frequency;
            }

            if(attrList[attrIdx] == ALC_STEREO_SOURCES)
            {
                reqStereoSources = attrList[attrIdx + 1];
                if(reqStereoSources > device->MaxNoOfSources)
                    reqStereoSources = device->MaxNoOfSources;

                numStereo = reqStereoSources;
                numMono = device->MaxNoOfSources - numStereo;
            }

            if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
            {
                numSends = attrList[attrIdx + 1];
                if(numSends > MAX_SENDS)
                    numSends = MAX_SENDS;
            }

            attrIdx += 2;
        }

        device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", level);
        device->Frequency = GetConfigValueInt(NULL, "frequency", freq);
        device->lNumMonoSources = numMono;
        device->lNumStereoSources = numStereo;
        device->NumAuxSends = GetConfigValueInt(NULL, "sends", numSends);
    }

    if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
    {
        alcSetError(ALC_INVALID_DEVICE);
        aluHandleDisconnect(device);
        ProcessContext(NULL);
        return NULL;
    }

    for(i = 0;i < device->NumContexts;i++)
    {
        ALCcontext *context = device->Contexts[i];
        ALeffectslot *slot;
        ALsource *source;

        SuspendContext(context);
        for(slot = context->AuxiliaryEffectSlot;slot != NULL;slot = slot->next)
        {
            if(!slot->EffectState)
                continue;

            if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
            {
                alcSetError(ALC_INVALID_DEVICE);
                aluHandleDisconnect(device);
                ProcessContext(context);
                ProcessContext(NULL);
                ALCdevice_StopPlayback(device);
                return NULL;
            }
            ALEffect_Update(slot->EffectState, context, &slot->effect);
        }

        for(source = context->Source;source != NULL;source = source->next)
        {
            ALuint s = device->NumAuxSends;
            while(s < MAX_SENDS)
            {
                if(source->Send[s].Slot)
                    source->Send[s].Slot->refcount--;
                source->Send[s].Slot = NULL;
                source->Send[s].WetFilter.type = 0;
                source->Send[s].WetFilter.filter = 0;
                s++;
            }
        }
        ProcessContext(context);
    }

    if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
    {
        if(!device->Bs2b)
        {
            device->Bs2b = calloc(1, sizeof(*device->Bs2b));
            bs2b_clear(device->Bs2b);
        }
        bs2b_set_srate(device->Bs2b, device->Frequency);
        bs2b_set_level(device->Bs2b, device->Bs2bLevel);
    }
    else
    {
        free(device->Bs2b);
        device->Bs2b = NULL;
    }

    temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
    if(!temp)
    {
        alcSetError(ALC_OUT_OF_MEMORY);
        ProcessContext(NULL);
        return NULL;
    }
    device->Contexts = temp;

    ALContext = calloc(1, sizeof(ALCcontext));
    if(!ALContext)
    {
        alcSetError(ALC_OUT_OF_MEMORY);
        ProcessContext(NULL);
        return NULL;
    }

    device->Contexts[device->NumContexts++] = ALContext;
    ALContext->Device = device;

    InitContext(ALContext);

    ALContext->next = g_pContextList;
    g_pContextList = ALContext;
    g_ulContextCount++;

    ProcessContext(NULL);

    return ALContext;
}
Example #5
0
static gboolean gst_crossfeed_setup (GstAudioFilter * filter,
  GstRingBufferSpec * format)
{
  GstCrossfeed *crossfeed = GST_CROSSFEED (filter);

  crossfeed->func = NULL;

  if (format->type == GST_BUFTYPE_LINEAR) {
    if (format->width == 8) {
      if (format->sign)
        crossfeed->func = &bs2b_cross_feed_s8;
      else
        crossfeed->func = &bs2b_cross_feed_u8;
    }
    else if (format->width == 16) {
      if (format->bigend && format->sign)
        crossfeed->func = &bs2b_cross_feed_s16be;
      else if(format->bigend)
        crossfeed->func = &bs2b_cross_feed_u16be;
      else if (format->sign)
        crossfeed->func = &bs2b_cross_feed_s16le;
      else
        crossfeed->func = &bs2b_cross_feed_u16le;
    }
    else if (format->width == 24) {
      if (format->bigend && format->sign)
        crossfeed->func = &bs2b_cross_feed_s24be;
      else if(format->bigend)
        crossfeed->func = &bs2b_cross_feed_u24be;
      else if (format->sign)
        crossfeed->func = &bs2b_cross_feed_s24le;
      else
        crossfeed->func = &bs2b_cross_feed_u24le;
    }
    else if (format->width == 32) {
      if (format->bigend && format->sign)
        crossfeed->func = &bs2b_cross_feed_s32be;
      else if(format->bigend)
        crossfeed->func = &bs2b_cross_feed_u32be;
      else if (format->sign)
        crossfeed->func = &bs2b_cross_feed_s32le;
      else
        crossfeed->func = &bs2b_cross_feed_u32le;
    }
  }
  else if (format->type == GST_BUFTYPE_FLOAT) {
    if (format->width == 32) {
      if (format->bigend)
        crossfeed->func = &bs2b_cross_feed_fbe;
      else
        crossfeed->func = &bs2b_cross_feed_fle;
    }
    else if (format->width == 64) {
      if (format->bigend)
        crossfeed->func = &bs2b_cross_feed_dbe;
      else
        crossfeed->func = &bs2b_cross_feed_dle;
    }
  }

  if (crossfeed->func == NULL)
    return FALSE;

  GST_CROSSFEED_LOCK (crossfeed);
  gst_crossfeed_update_passthrough (crossfeed);
  GST_CROSSFEED_UNLOCK (crossfeed);

  crossfeed->divider = format->width / 4;

  /* set_rate calls clear, so no need to reset the filter here */
  GST_CROSSFEED_BS2B_LOCK (crossfeed);
  bs2b_set_srate (crossfeed->bs2bdp, format->rate);
  GST_CROSSFEED_BS2B_UNLOCK (crossfeed);

  return TRUE;
}