示例#1
0
ECA_AUDIO_FORMAT::ECA_AUDIO_FORMAT(void)
{ 
  set_channels(0);
  set_samples_per_second(-1);
  set_sample_format(sfmt_none);
  toggle_interleaved_channels(true);
}
示例#2
0
/**
 * Parse audio variable
 * @return < 0 if unknown
 */
static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
                           const char *name, int size)
{
    MvContext *mv = avctx->priv_data;
    AVIOContext *pb = avctx->pb;
    if (!strcmp(name, "__DIR_COUNT")) {
        st->nb_frames = var_read_int(pb, size);
    } else if (!strcmp(name, "AUDIO_FORMAT")) {
        mv->aformat = var_read_int(pb, size);
    } else if (!strcmp(name, "COMPRESSION")) {
        mv->acompression = var_read_int(pb, size);
    } else if (!strcmp(name, "DEFAULT_VOL")) {
        var_read_metadata(avctx, name, size);
    } else if (!strcmp(name, "NUM_CHANNELS")) {
        return set_channels(avctx, st, var_read_int(pb, size));
    } else if (!strcmp(name, "SAMPLE_RATE")) {
        st->codecpar->sample_rate = var_read_int(pb, size);
        avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate);
    } else if (!strcmp(name, "SAMPLE_WIDTH")) {
        st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8;
    } else
        return AVERROR_INVALIDDATA;

    return 0;
}
示例#3
0
static int
open_audio_port (AudioContext return_ac, AudioContext desc)
{
  ALconfig config = ALnewconfig();
  long params[2];

  adjust_audio_volume (& desc->device);
  return_ac->ac_left_speaker_gain = desc->ac_left_speaker_gain;
  return_ac->ac_right_speaker_gain = desc->ac_right_speaker_gain;
  params[0] = AL_OUTPUT_RATE;
  params[1] = desc->ac_output_rate;
  ALsetparams (desc->ac_device, params, 2);
  return_ac->ac_output_rate = desc->ac_output_rate;
  if (set_channels (config, desc->ac_nchan)==-1)
    return -1;
  return_ac->ac_nchan = desc->ac_nchan;
  if (set_output_format (config, desc->ac_format)==-1)
    return -1;
  return_ac->ac_format = desc->ac_format;
  ALsetqueuesize (config, (long) CHUNKSIZE);
  return_ac->ac_port = ALopenport("XEmacs audio output", "w", config);
  ALfreeconfig (config);
  if (return_ac->ac_port==0)
    {
      report_file_error ("Opening audio output port", Qnil);
      return -1;
    }
  return 0;
}
示例#4
0
void image_channels_param_t::set_channel_list( const std::vector<std::string>& channels)
{
	if( !channel_list_.empty())
	{
		std::string ch0, ch1, ch2, ch3;
		get_channel_names( ch0, ch1, ch2, ch3);
		channel_list_ = channels;
		set_channels( ch0, ch1, ch2, ch3);
	}
	else
	{
		channel_list_ = channels;
		value().assign( tuple4i_t( 0, 1, 2, 3));
	}

	tuple4i_t ch( get_value<tuple4i_t>( *this));
	
	if( red_combo_)
	{
		update_popup( red_combo_   , boost::get<0>( ch));
		update_popup( green_combo_ , boost::get<1>( ch));
		update_popup( blue_combo_  , boost::get<2>( ch));
		update_popup( alpha_combo_ , boost::get<3>( ch));
	}
}
示例#5
0
文件: af_pan.c 项目: ThreeGe/mpv
// Initialization and runtime control
static int control(struct af_instance* af, int cmd, void* arg)
{
    af_pan_t* s = af->priv;

    switch(cmd) {
    case AF_CONTROL_REINIT:
        // Sanity check
        if(!arg) return AF_ERROR;

        af->data->rate   = ((struct mp_audio*)arg)->rate;
        mp_audio_set_format(af->data, AF_FORMAT_FLOAT);
        set_channels(af->data, s->nch ? s->nch: ((struct mp_audio*)arg)->nch);

        if((af->data->format != ((struct mp_audio*)arg)->format) ||
                (af->data->bps != ((struct mp_audio*)arg)->bps)) {
            mp_audio_set_format((struct mp_audio*)arg, af->data->format);
            return AF_FALSE;
        }
        return AF_OK;
    case AF_CONTROL_SET_PAN_LEVEL: {
        int    i;
        int    ch = ((af_control_ext_t*)arg)->ch;
        float* level = ((af_control_ext_t*)arg)->arg;
        if (ch >= AF_NCH)
            return AF_FALSE;
        for(i=0; i<AF_NCH; i++)
            s->level[ch][i] = level[i];
        return AF_OK;
    }
    case AF_CONTROL_SET_PAN_NOUT:
        // Reinit must be called after this function has been called

        // Sanity check
        if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH) {
            MP_ERR(af, "The number of output channels must be"
                   " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]);
            return AF_ERROR;
        }
        s->nch=((int*)arg)[0];
        return AF_OK;
    case AF_CONTROL_SET_PAN_BALANCE: {
        float val = *(float*)arg;
        if (s->nch)
            return AF_ERROR;
        if (af->data->nch >= 2) {
            s->level[0][0] = MPMIN(1.f, 1.f - val);
            s->level[0][1] = MPMAX(0.f, val);
            s->level[1][0] = MPMAX(0.f, -val);
            s->level[1][1] = MPMIN(1.f, 1.f + val);
        }
        return AF_OK;
    }
    case AF_CONTROL_GET_PAN_BALANCE:
        if (s->nch)
            return AF_ERROR;
        *(float*)arg = s->level[0][1] - s->level[1][0];
        return AF_OK;
    }
    return AF_UNKNOWN;
}
示例#6
0
/**
 * Sets audio format to that of 'f'.
 */
void ECA_AUDIO_FORMAT::set_audio_format(const ECA_AUDIO_FORMAT& f)
{
  set_channels(f.channels());
  set_sample_format(f.sample_format());
  set_samples_per_second(f.samples_per_second());
  toggle_interleaved_channels(f.interleaved_channels());
}
示例#7
0
controller::controller(std::string pyton_config_file_)
// can not init init list form r vals, hence lmbd hack
    :	buffers       {	[]{	std::vector<std::unique_ptr<buffer>> b;
    b.push_back(util::make_unique<log_buffer>("status"));
    return b;
}()
                }
,	view              { io_service, *buffers[0]           }
#ifdef USING_PYTHON
,	python_controller { std::move(pyton_config_file_)  }
#endif //USING_PYTHON
{
    auto username=util::try_get_user_name();
    if(username) {
        default_username=*username;
        default_nick=std::move(*username);
    }
    auto fullname=util::try_get_full_name();
    if(fullname) default_fullname=std::move(*fullname);

    view.connect_on_text_input(
        std::bind(&controller::handle_text_input, this, ph::_1));

    view.connect_on_ctrl_char(
        std::bind(&controller::handle_ctrl_char, this, ph::_1));

#ifdef USING_PYTHON
    python_controller.connect_on_connect(
    [this](const std::string& server) {
        start_connection(server);
    });
    python_controller.connect_on_change_default_nick(
        util::make_assign_on_call(default_nick));
    python_controller.connect_on_change_default_username(
        util::make_assign_on_call(default_username));
    python_controller.connect_on_change_default_fullname(
        util::make_assign_on_call(default_fullname));
    python_controller.connect_on_python_error(
    [this](const std::string s) {
        if(show_errors) {
            auto& status_buf=get_status_buffer();
            std::ostringstream oss;
            oss << "PYTHON ERROR: " << s;
            status_buf.push_back_msg(oss.str());
        }
    }
    );
    python_controller.connect_on_python_output(
    [this](const std::string s) {
        auto& status_buf=get_status_buffer();
        std::ostringstream oss;
        oss << "PYTHON: " << s;
        status_buf.push_back_msg(oss.str());
    }
    );
    python_controller.reload_conf();
#endif //USING_PYTHON

    set_channels();
}
void EFFECT_RESONATOR::init(SAMPLE_BUFFER* insample) {
  i.init(insample);

  set_channels(insample->number_of_channels());

  saout0.resize(insample->number_of_channels());
  saout1.resize(insample->number_of_channels());
}
void EFFECT_COMB_FILTER::init(SAMPLE_BUFFER* insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  buffer.resize(insample->number_of_channels());
}
示例#10
0
static gboolean gst_devsound_src_setcaps(GstBaseSrc *bsrc, GstCaps *caps)
    {
    GstDevsoundSrc *devsoundsrc;
    GstStructure *structure;
    const gchar *mimetype;
    int rate;
    int channel;

    devsoundsrc = GST_DEVSOUND_SRC (bsrc);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps ENTER ",NULL);
    structure = gst_caps_get_structure(caps, 0);
    mimetype = gst_structure_get_name(structure);

    gst_structure_get_int(structure, "rate", &rate);
    gst_structure_get_int(structure, "channels", &channel);

    devsoundsrc->rate = gst_devsound_src_get_rate(rate);
    devsoundsrc->channels = channel;

    set_channels(devsoundsrc->handle, devsoundsrc->channels);

    set_rate(devsoundsrc->handle, devsoundsrc->rate);

    if (!strncmp(mimetype, "audio/x-raw-int", 15))
        {
        devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
        }
    else if (!strncmp(mimetype, "audio/amr", 9))
        {
        devsoundsrc->fourcc = 0x524d4120; //KMMFFourCCCodeAMR
        }
    else if (!strncmp(mimetype, "audio/x-mulaw", 13)||
             !strncmp(mimetype,"audio/x-alaw", 12))
        {
        devsoundsrc->fourcc = 0x31313747; //KMccFourCCIdG711
        }
    else if (!strncmp(mimetype, "audio/ilbc", 10))
        {
        devsoundsrc->fourcc = 0x43424c49; //KMccFourCCIdILBC
        }
    else if (!strncmp(mimetype, "audio/g729", 10))
        {
        devsoundsrc->fourcc = 0x39323747; //KMccFourCCIdG729
        }
    else
        {
        devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
        }

    set_fourcc(devsoundsrc->handle, devsoundsrc->fourcc);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Signal DevSound from STOP",NULL);
    pthread_mutex_lock(&(create_mutex1));
    pthread_cond_signal(&(create_condition1));
    pthread_mutex_unlock(&(create_mutex1));
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Signal DevSound from STOP ",NULL);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps EXIT ",NULL);
    return TRUE;
    }
示例#11
0
static int
sscape_audio_ioctl(int dev, u_int cmd, ioctl_arg arg, int local)
{
    sscape_info    *devc = (sscape_info *) audio_devs[dev]->devc;

    switch (cmd) {
    case SOUND_PCM_WRITE_RATE:
	if (local)
	    return set_speed(devc, (int) arg);
	return *(int *) arg = set_speed(devc, (*(int *) arg));

    case SOUND_PCM_READ_RATE:
	if (local)
	    return 8000;
	return *(int *) arg = 8000;

    case SNDCTL_DSP_STEREO:
	if (local)
	    return set_channels(devc, (int) arg + 1) - 1;
	return *(int *) arg = set_channels(devc, (*(int *) arg) + 1) - 1;

    case SOUND_PCM_WRITE_CHANNELS:
	if (local)
	    return set_channels(devc, (int) arg);
	return *(int *) arg = set_channels(devc, (*(int *) arg));

    case SOUND_PCM_READ_CHANNELS:
	if (local)
	    return 1;
	return *(int *) arg = 1;

    case SNDCTL_DSP_SAMPLESIZE:
	if (local)
	    return set_format(devc, (int) arg);
	return *(int *) arg = set_format(devc, (*(int *) arg));

    case SOUND_PCM_READ_BITS:
	if (local)
	    return 8;
	return *(int *) arg = 8;

    default:;
    }
    return -(EINVAL);
}
void EFFECT_RESONANT_BANDPASS::init(SAMPLE_BUFFER* insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  outhist1.resize(insample->number_of_channels());
  outhist2.resize(insample->number_of_channels());
}
void EFFECT_INVERSE_COMB_FILTER::init(SAMPLE_BUFFER* insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  buffer.resize(insample->number_of_channels());
  laskuri.resize(insample->number_of_channels(), parameter_t(0.0));
}
void EFFECT_ALLPASS_FILTER::init(SAMPLE_BUFFER* insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  inbuf.resize(insample->number_of_channels());
  //  outbuf.resize(insample->number_of_channels());
}
void EFFECT_BW_FILTER::init(SAMPLE_BUFFER *insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  sin.resize(insample->number_of_channels(), std::vector<SAMPLE_SPECS::sample_t> (2));
  sout.resize(insample->number_of_channels(), std::vector<SAMPLE_SPECS::sample_t> (2));
}
示例#16
0
文件: mint.c 项目: Deslon/Supernova
static int reset_parameters(out123_handle *ao)
{
	int ret;
	ret = ioctl(ao->fn,AIOCRESET,NULL);
	if(ret >= 0) ret = set_format(ai);
	if(ret >= 0) ret = set_channels(ai);
	if(ret >= 0) ret = set_rate(ai);
	return ret;
}
示例#17
0
void controller::handle_connection_connect(
    std::shared_ptr<irc::connection> connection,
    std::string nick,
    std::string username,
    std::string fullname) {
    assert(connection && "can not craete sesion with invalid connection");
    sessions.push_back(
        util::make_unique<irc::session>(
            std::move(connection), std::move(nick),
            std::move(username), std::move(fullname))
    );
    auto& session=sessions.back();
    auto sess_win=util::make_unique<session_buffer>(*session);

    buffers.push_back(std::move(sess_win));
    set_channels();
    //if auto change
    set_channel(*buffers.back());

    //this will create a new buffer view
    session->connect_on_join_channel(
        std::bind(
            &controller::handle_session_join_channel,
            this,
            ph::_1
        )
    );

    // ne need to register all users so we can hook
    // any priv_msgs
    session->connect_on_new_user(
    [&](irc::user& u) {
        u.connect_on_direct_message(
        [](irc::user& u, const std::string&) {
            //TODO implement privmsg here
        }
        );

        /* Currently this functionality is in session buffer
        u.connect_on_notice(
        	[&](irc::user& u, const std::string& msg) {
        		auto& status_buf=get_status_buffer();
        		std::ostringstream oss;
        		oss << "NOTICE: " << u.get_nick() << ": " << msg;
        		status_buf.push_back_msg(oss.str());
        	}
        );
        */
    }

    );

#ifdef USING_PYTHON
    python_controller.accept_new_session(*session);
#endif //USING_PYTHON
}
void EFFECT_LOWPASS_SIMPLE::init(SAMPLE_BUFFER *insample)
{
  i.init(insample);

  set_channels(insample->number_of_channels());

  outhist.resize(insample->number_of_channels());
  tempin.resize(insample->number_of_channels());
  temphist.resize(insample->number_of_channels());
}
示例#19
0
ECA_AUDIO_FORMAT::ECA_AUDIO_FORMAT(int channels, 
				   long int srate,
				   ECA_AUDIO_FORMAT::Sample_format format, 
				   bool ileaved)
{
  set_channels(channels);
  set_samples_per_second(srate);
  set_sample_format(format);
  toggle_interleaved_channels(ileaved);
}
示例#20
0
void audio_chunk::set_data(const audio_sample * src,t_size samples,unsigned nch,unsigned srate,unsigned channel_config)
{
	t_size size = samples * nch;
	set_data_size(size);
	if (src)
		pfc::memcpy_t(get_data(),src,size);
	else
		pfc::memset_t(get_data(),(audio_sample)0,size);
	set_sample_count(samples);
	set_channels(nch,channel_config);
	set_srate(srate);
}
示例#21
0
void EFFECT_BASE::init(SAMPLE_BUFFER* sbuf)
{
  ECA_LOG_MSG(ECA_LOGGER::user_objects,
	      "Init w/ samplerate " +
	      kvu_numtostr(samples_per_second()) + " for object " +
	      name() + ".");

  set_channels(sbuf->number_of_channels());

  DBC_CHECK(channels() > 0);
  DBC_CHECK(samples_per_second() > 0);
}
示例#22
0
void controller::handle_session_join_channel(irc::channel& chan) {
    chan.connect_on_channel_part(
    [&](irc::channel& chand) {
        auto it=std::find_if(begin(buffers), end(buffers),
        [&](const std::unique_ptr<buffer>& b) {
            assert(b);
            has_channel hc { *b };
            return &hc.get_channel() == &chan;
        }
                            );
        if(it!=end(buffers)) {
            buffers.erase(it);
            set_channels();
            set_channel(get_status_buffer());
        }
    }
    );

    buffers.push_back(util::make_unique<channel_buffer>(chan));
    set_channels();
    set_channel(*buffers.back());
}
int check_audio_ioctls(int fd_audio)
{
	int err = 0;

	err += set_bits(fd_audio);
	err += set_channels(fd_audio);
	err += set_speed(fd_audio);
#ifndef CONFIG_MX21ADS
	err += set_adder(fd_audio);
	err += set_balance(fd_audio);
#endif
	return err;
}
示例#24
0
/*
 * Fast and time critical loop for:
 * - controlling the quadrocopter
 * - fetching rc signals
 * - filtering and processing sensor data necessary for flight
 */
void M4XFrame::calc_attitude_hold() {
  // additional filter or rc variables
  static float targ_yaw = 0.f; // yaw target from rc

  // Wait if there is no new data (save ressources)
  while(!m_pHalBoard->m_pInert->wait_for_sample(MAIN_T_MS) );

  // Handle all defined problems (time-outs, broken gyrometer, GPS signal ..)
  m_pExeption->handle();

  // Variables to store remote control commands plus "rcalt" for the desired altitude in cm
  float rcpit, rcrol, rcyaw, _iThrOut;
  set_channels(m_pReceiver, rcpit, rcrol, rcyaw, _iThrOut);

  // Update sensor information
  m_pHalBoard->update_attitude();
  Vector3f vAtti = m_pHalBoard->get_atti_cor_deg(); // returns the fused sensor value (gyrometer and accelerometer)
  Vector3f vGyro = m_pHalBoard->get_gyro_cor_deg(); // returns the sensor value from the gyrometer

  // Throttle raised, turn on stabilisation.
  if(_iThrOut > RC_THR_ACRO) {
    // Stabilise PIDS
    float pit_stab_output = constrain_float(m_pHalBoard->m_rgPIDS[PID_PIT_STAB].get_pid(rcpit - vAtti.x, 1), -250, 250);
    float rol_stab_output = constrain_float(m_pHalBoard->m_rgPIDS[PID_ROL_STAB].get_pid(rcrol - vAtti.y, 1), -250, 250);
    float yaw_stab_output = constrain_float(m_pHalBoard->m_rgPIDS[PID_YAW_STAB].get_pid(wrap180_f(targ_yaw - vAtti.z), 1), -360, 360);

    // is pilot asking for yaw change - if so feed directly to rate pid (overwriting yaw stab output)
    if(fabs(rcyaw ) > 5.f) {
      yaw_stab_output = rcyaw;
      targ_yaw = vAtti.z; // remember this yaw for when pilot stops
    }

    // rate PIDS
    _iPitOut = static_cast<int_fast16_t>(constrain_float(m_pHalBoard->m_rgPIDS[PID_PIT_RATE].get_pid(pit_stab_output - vGyro.x, 1), -500, 500) );
    _iRolOut = static_cast<int_fast16_t>(constrain_float(m_pHalBoard->m_rgPIDS[PID_ROL_RATE].get_pid(rol_stab_output - vGyro.y, 1), -500, 500) );
    _iYawOut = static_cast<int_fast16_t>(constrain_float(m_pHalBoard->m_rgPIDS[PID_YAW_RATE].get_pid(yaw_stab_output - vGyro.z, 1), -500, 500) );
    _iThrOut -= RC_THR_OFF; // Remote control output ==>  to motor input range
    m_pMotors->armed(true);
  }
  else {
    clear();

    // reset yaw target so we maintain this on take-off
    targ_yaw = vAtti.z;

    // reset PID integrals whilst on the ground
    for(uint_fast8_t i = 0; i < NR_OF_PIDS; i++) {
      m_pHalBoard->m_rgPIDS[i].reset_I();
    }
  }
}
示例#25
0
bool audio_chunk::set_data(const audio_sample * src,unsigned samples,unsigned nch,unsigned srate)
{
	bool rv = false;
	unsigned size = samples * nch;
	audio_sample * out = check_data_size(size);
	if (out)
	{
		if (src)
			mem_ops<audio_sample>::copy(out,src,size);
		else
			mem_ops<audio_sample>::set(out,0,size);
		set_sample_count(samples);
		set_channels(nch);
		set_srate(srate);
		rv = true;
	}
	else reset();
	return rv;
}
示例#26
0
文件: af_pan.c 项目: ArcherSeven/mpv
// Filter data through filter
static struct mp_audio* play(struct af_instance* af, struct mp_audio* data)
{
  struct mp_audio*    c    = data;		// Current working data
  struct mp_audio*	l    = af->data;	// Local data
  af_pan_t*  	s    = af->setup; 	// Setup for this instance
  float*   	in   = c->audio;	// Input audio data
  float*   	out  = NULL;		// Output audio data
  float*	end  = in+c->len/4; 	// End of loop
  int		nchi = c->nch;		// Number of input channels
  int		ncho = l->nch;		// Number of output channels
  register int  j,k;

  if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
    return NULL;

  out = l->audio;
  // Execute panning
  // FIXME: Too slow
  while(in < end){
    for(j=0;j<ncho;j++){
      register float  x   = 0.0;
      register float* tin = in;
      for(k=0;k<nchi;k++)
	x += tin[k] * s->level[j][k];
      out[j] = x;
    }
    out+= ncho;
    in+= nchi;
  }

  // Set output data
  c->audio = l->audio;
  c->len   = c->len / c->nch * l->nch;
  set_channels(c, l->nch);

  return c;
}
示例#27
0
文件: sgi.c 项目: 5py/libmpg123
static int open_sgi(audio_output_t *ao)
{
	int dev = AL_DEFAULT_OUTPUT;
	ALconfig config = alNewConfig();
	ALport port = NULL;
	
	/* Test for correct completion */
	if (config == 0) {
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Set port parameters */
	if(ao->channels == 2)
		alSetChannels(config, AL_STEREO);
	else
		alSetChannels(config, AL_MONO);
	
	alSetWidth(config, AL_SAMPLE_16);
	alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP);
	alSetQueueSize(config, 131069);
	
	/* Setup output device to specified module. If there is no module
	specified in ao structure, use the default four output */
	if ((ao->device) != NULL) {
		char *dev_name;
		
		dev_name=malloc((strlen(ao->device) + strlen(analog_output_res_name) + 1) *
		  sizeof(char));
		
		strcpy(dev_name,ao->device);
		strcat(dev_name,analog_output_res_name);
		
		/* Find the asked device resource */
		dev=alGetResourceByName(AL_SYSTEM,dev_name,AL_DEVICE_TYPE);
		
		/* Free allocated space */
		free(dev_name);
		
		if (!dev) {
			error2("Invalid audio resource: %s (%s)",dev_name, alGetErrorString(oserror()));
			return -1;
		}
	}
	
	/* Set the device */
	if (alSetDevice(config,dev) < 0)
	{
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Open the audio port */
	port = alOpenPort("mpg123-VSC", "w", config);
	if(port == NULL) {
		error1("Unable to open audio channel: %s", alGetErrorString(oserror()));
		return -1;
	}
	
	ao->userptr = (void*)port;
	
	
	set_format(ao, config);
	set_channels(ao, config);
	set_rate(ao, config);
	
	
	alFreeConfig(config);
	
	return 1;
}
示例#28
0
int main(int argc, char *argv[])
{
	int c, i;
	char *fn, *fn2 = NULL;
	int cmd_decode = 0;
	int cmd_chg_channels = 0;
	int cmd_info = 0, cmd_play = 0;
	int cf_set_chans = 0;

	while ((c = getopt(argc, argv, "pdiMSqhrmsnvo:")) != -1) {
		switch (c) {
		case 'h':
			usage(0);
			break;
		case 'd':
			cmd_decode = 1;
			break;
		case 'i':
			cmd_info = 1;
			break;
		case 'p':
			cmd_play = 1;
			break;
		case 'M':
			cmd_chg_channels = 1;
			cf_set_chans = 1;
			break;
		case 'S':
			cmd_chg_channels = 1;
			cf_set_chans = 2;
			break;
		case 'q':
			cf_quiet = 1;
			break;
		case 'm':
			cf_force_chans = 1;
			break;
		case 's':
			cf_force_chans = 2;
			break;
		case 'r':
			cf_raw = 1;
			break;
		case 'n':
			cf_no_output = 1;
			break;
		case 'o':
			fn2 = optarg;
			break;
		case 'v':
			printf("%s\n", version);
			exit(0);
		default:
			fprintf(stderr, "bad arg: -%c\n", c);
			usage(1);
		}
	}
	i = cmd_chg_channels + cmd_info + cmd_decode + cmd_play;
	if (i < 1 || i > 1) {
		fprintf(stderr, "only one command at a time please\n");
		usage(1);
	}

	/* play file */
	if (cmd_play) {
#ifdef HAVE_AO
		ao_initialize();
		for (i = optind; i < argc; i++)
			play_file(argv[i]);
		close_audio();
		ao_shutdown();
		return 0;
#else
		fprintf(stderr, "For audio output, please compile with libao.\n");
		return 1;
#endif
	}

	/* show info */
	if (cmd_info) {
		for (i = optind; i < argc; i++)
			show_info(argv[i]);
		return 0;
	}
	
	/* channel changing */
	if (cmd_chg_channels) {
		for (i = optind; i < argc; i++)
			set_channels(argv[i], cf_set_chans);
		return 0;
	}
	
	/* regular converting */
	if (optind == argc)
		usage(1);
	if (fn2) {
		if (optind + 1 != argc)
			usage(1);
		fn = argv[optind];
		decode_file(fn, fn2);
	} else {
		while (optind < argc) {
			fn = argv[optind++];
			fn2 = makefn(fn, cf_raw ? ".raw" : ".wav");
			decode_file(fn, fn2);
			free(fn2);
		}
	}
	return 0;
}
示例#29
0
static int mv_read_header(AVFormatContext *avctx)
{
    MvContext *mv = avctx->priv_data;
    AVIOContext *pb = avctx->pb;
    AVStream *ast = NULL, *vst = NULL; //initialization to suppress warning
    int version, i;
    int ret;

    avio_skip(pb, 4);

    version = avio_rb16(pb);
    if (version == 2) {
        uint64_t timestamp;
        int v;
        avio_skip(pb, 22);

        /* allocate audio track first to prevent unnecessary seeking
         * (audio packet always precede video packet for a given frame) */
        ast = avformat_new_stream(avctx, NULL);
        if (!ast)
            return AVERROR(ENOMEM);

        vst = avformat_new_stream(avctx, NULL);
        if (!vst)
            return AVERROR(ENOMEM);
        avpriv_set_pts_info(vst, 64, 1, 15);
        vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        vst->avg_frame_rate    = av_inv_q(vst->time_base);
        vst->nb_frames         = avio_rb32(pb);
        v = avio_rb32(pb);
        switch (v) {
        case 1:
            vst->codecpar->codec_id = AV_CODEC_ID_MVC1;
            break;
        case 2:
            vst->codecpar->format = AV_PIX_FMT_ARGB;
            vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
            break;
        default:
            avpriv_request_sample(avctx, "Video compression %i", v);
            break;
        }
        vst->codecpar->codec_tag = 0;
        vst->codecpar->width     = avio_rb32(pb);
        vst->codecpar->height    = avio_rb32(pb);
        avio_skip(pb, 12);

        ast->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
        ast->nb_frames          = vst->nb_frames;
        ast->codecpar->sample_rate = avio_rb32(pb);
        if (ast->codecpar->sample_rate <= 0) {
            av_log(avctx, AV_LOG_ERROR, "Invalid sample rate %d\n", ast->codecpar->sample_rate);
            return AVERROR_INVALIDDATA;
        }
        avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate);
        if (set_channels(avctx, ast, avio_rb32(pb)) < 0)
            return AVERROR_INVALIDDATA;

        v = avio_rb32(pb);
        if (v == AUDIO_FORMAT_SIGNED) {
            ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
        } else {
            avpriv_request_sample(avctx, "Audio compression (format %i)", v);
        }

        avio_skip(pb, 12);
        var_read_metadata(avctx, "title", 0x80);
        var_read_metadata(avctx, "comment", 0x100);
        avio_skip(pb, 0x80);

        timestamp = 0;
        for (i = 0; i < vst->nb_frames; i++) {
            uint32_t pos   = avio_rb32(pb);
            uint32_t asize = avio_rb32(pb);
            uint32_t vsize = avio_rb32(pb);
            avio_skip(pb, 8);
            av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
            av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
            timestamp += asize / (ast->codecpar->channels * 2);
        }
    } else if (!version && avio_rb16(pb) == 3) {
        avio_skip(pb, 4);

        if ((ret = read_table(avctx, NULL, parse_global_var)) < 0)
            return ret;

        if (mv->nb_audio_tracks > 1) {
            avpriv_request_sample(avctx, "Multiple audio streams support");
            return AVERROR_PATCHWELCOME;
        } else if (mv->nb_audio_tracks) {
            ast = avformat_new_stream(avctx, NULL);
            if (!ast)
                return AVERROR(ENOMEM);
            ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
            if ((read_table(avctx, ast, parse_audio_var)) < 0)
                return ret;
            if (mv->acompression == 100 &&
                mv->aformat == AUDIO_FORMAT_SIGNED &&
                ast->codecpar->bits_per_coded_sample == 16) {
                ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
            } else {
                avpriv_request_sample(avctx,
                                      "Audio compression %i (format %i, sr %i)",
                                      mv->acompression, mv->aformat,
                                      ast->codecpar->bits_per_coded_sample);
                ast->codecpar->codec_id = AV_CODEC_ID_NONE;
            }
            if (ast->codecpar->channels <= 0) {
                av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n");
                return AVERROR_INVALIDDATA;
            }
        }

        if (mv->nb_video_tracks > 1) {
            avpriv_request_sample(avctx, "Multiple video streams support");
            return AVERROR_PATCHWELCOME;
        } else if (mv->nb_video_tracks) {
            vst = avformat_new_stream(avctx, NULL);
            if (!vst)
                return AVERROR(ENOMEM);
            vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
            if ((ret = read_table(avctx, vst, parse_video_var))<0)
                return ret;
        }

        if (mv->nb_audio_tracks)
            read_index(pb, ast);

        if (mv->nb_video_tracks)
            read_index(pb, vst);
    } else {
        avpriv_request_sample(avctx, "Version %i", version);
        return AVERROR_PATCHWELCOME;
    }

    return 0;
}
示例#30
0
void ADVANCED_COMPRESSOR::init(SAMPLE_BUFFER* insample) {
  iter.init(insample);

  set_channels(insample->number_of_channels());
  set_samples_per_second(samples_per_second());
}