コード例 #1
0
ファイル: opuscodec.cpp プロジェクト: ThereIsNoYeti/sflphone
void Opus::setOptimalFormat(uint32_t sample_rate, uint8_t channels)
{
    // Use a SR higher or equal to sample_rate.
    // Typical case: 44.1kHz => 48kHz.
    unsigned i = 0;
    while (i < VALID_SAMPLING_RATE_NUM - 1 and VALID_SAMPLING_RATE[i] < sample_rate)
        i++;
    sample_rate = VALID_SAMPLING_RATE[i];

    // Opus supports 1 or 2 channels.
    channels = std::max(std::min(channels, (uint8_t) 2), (uint8_t) 1);

    if (not (!encoder_ || !decoder_ || sample_rate != clockRateCur_ || channels != channelsCur_))
        return;

    clockRateCur_ = sample_rate;
    channelsCur_ = channels;

    int err;
    if (encoder_)
        opus_encoder_destroy(encoder_);
    encoder_ = opus_encoder_create(sample_rate, channels, OPUS_APPLICATION_VOIP, &err);
    if (err)
        throw std::runtime_error("opus: could not create encoder");

    if (decoder_)
        opus_decoder_destroy(decoder_);
    lastDecodedFrameSize_ = 0;
    decoder_ = opus_decoder_create(sample_rate, channels, &err);
    if (err)
        throw std::runtime_error("opus: could not create decoder");
}
コード例 #2
0
ファイル: codec.c プロジェクト: ittner/toxcore
static int init_audio_encoder(CSSession *cs)
{
    int rc = OPUS_OK;
    cs->audio_encoder = opus_encoder_create(cs->audio_encoder_sample_rate,
                                            cs->audio_encoder_channels, OPUS_APPLICATION_AUDIO, &rc);

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc));
        return -1;
    }

    rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_encoder_bitrate));

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        return -1;
    }

    rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        return -1;
    }

    return 0;
}
コード例 #3
0
ファイル: EncodeManager.cpp プロジェクト: Zaboon/cpp_babel
EncodeManager::EncodeManager()
{
  _enc = opus_encoder_create(SAMPLE_RATE, 2, OPUS_APPLICATION_VOIP, &_err);
  _dec = opus_decoder_create(SAMPLE_RATE, 2, &_err);
  opus_encoder_ctl(this->_enc, OPUS_GET_BANDWIDTH(&this->_len));
  this->_len = FRAMES_PER_BUFFER;
}
コード例 #4
0
ファイル: opus.c プロジェクト: Chocolatbuddha/sems
long opus_create(const char* format_parameters, const char** format_parameters_out,
		 amci_codec_fmt_info_t** format_description) {
  opus_state_t* codec_inst;
  int error;

  unsigned int maxbandwidth = _OPUS_RATE;
  int useinbandfec = _OPUS_INBAND_FEC_;
  int stereo = 0;

  if (format_parameters) {
    DBG("OPUS params: >>%s<<.\n", format_parameters);
    decode_format_parameters(format_parameters, &maxbandwidth, &useinbandfec, &stereo);
  } 
    
  codec_inst = (opus_state_t*)malloc(sizeof(opus_state_t));

  if (!codec_inst) 
    return -1;

  DBG("OPUS: creating encoder with maxbandwidth=%u, stereo=%s, useinbandfec=%s\n",
      maxbandwidth, stereo?"true":"false", useinbandfec?"true":"false");

  codec_inst->opus_enc = opus_encoder_create(_OPUS_RATE,1,_OPUS_APPLICATION_,&error);
  if (error) {
    DBG("OPUS: error %d while creating encoder state.\n", error);
    return -1;
  }

  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_FORCE_CHANNELS(stereo ? 2:1));

  unsigned int opus_set_bw = _OPUS_RATE;
  if (maxbandwidth <= 8000) {
    opus_set_bw = OPUS_BANDWIDTH_NARROWBAND;
  } else if (maxbandwidth <= 12000) {
    opus_set_bw = OPUS_BANDWIDTH_MEDIUMBAND;
  } else if (maxbandwidth <= 16000) {
    opus_set_bw = OPUS_BANDWIDTH_WIDEBAND;
  } else if (maxbandwidth <= 24000) {
    opus_set_bw = OPUS_BANDWIDTH_SUPERWIDEBAND;
  } else {
    opus_set_bw = OPUS_BANDWIDTH_FULLBAND;
  }
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_MAX_BANDWIDTH(opus_set_bw));

  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_PACKET_LOSS_PERC(_OPUS_PKT_LOSS_PCT_));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_COMPLEXITY(_OPUS_COMPLEXITY_));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_INBAND_FEC(useinbandfec ? 1:0));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_DTX(_OPUS_DTX_));

  codec_inst->opus_dec = opus_decoder_create(_OPUS_RATE,1,&error);
  if (error) {
    DBG("OPUS: error %d while creating decoder state.\n", error);
    opus_encoder_destroy(codec_inst->opus_enc);
    return -1;
  }

  *format_description = opus_fmt_description;

  return (long)codec_inst;
}
コード例 #5
0
ファイル: tdav_codec_opus.c プロジェクト: AndyUI/doubango
static int tdav_codec_opus_open(tmedia_codec_t* self)
{
    tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
    int opus_err;

    if(!opus) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }

    // Initialize the decoder
    if(!opus->decoder.inst) {
        TSK_DEBUG_INFO("[OPUS] Open decoder: rate=%d, channels=%d", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels);
        if(!(opus->decoder.inst = opus_decoder_create((opus_int32)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, &opus_err)) || opus_err != OPUS_OK) {
            TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, opus_err);
            return -2;
        }
    }
    opus->decoder.last_seq  = 0;

    // Initialize the encoder
    if(!opus->encoder.inst) {
        TSK_DEBUG_INFO("[OPUS] Open encoder: rate=%d, channels=%d", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels);
        if(!(opus->encoder.inst = opus_encoder_create((opus_int32)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, OPUS_APPLICATION_VOIP, &opus_err)) || opus_err != OPUS_OK) {
            TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, opus_err);
            return -2;
        }
    }
#if TDAV_UNDER_MOBILE /* iOS, Android and WP8 */
    opus_encoder_ctl(opus->encoder.inst, OPUS_SET_COMPLEXITY(3));
#endif
    opus_encoder_ctl(opus->encoder.inst, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));

    return 0;
}
コード例 #6
0
ファイル: opus_sm.c プロジェクト: jzombi/opus_sm
OpusSM* sm_init(int samplerate, int channels)
{
	OpusSM* sm = (OpusSM*)malloc(sizeof(OpusSM));
	sm->error = SM_OK;
	if (samplerate != SM_SUPPORTED_SAMPLERATE) {
		sm->error = SM_ERR_UNSUPPORTED_SAMPLERATE;
		sm->opus_enc = NULL;
		return sm;
	}
	/* application can be: (see opus_encoder_init() in src/opus_encoder.c)
	     OPUS_APPLICATION_VOIP
	     OPUS_APPLICATION_AUDIO
	     OPUS_APPLICATION_RESTRICTED_LOWDELAY */
	int error;
	sm->opus_enc = opus_encoder_create(samplerate, channels, OPUS_APPLICATION_VOIP, &error);
	if (error != 0) {
		sm->error = SM_ERR_OPUS_ENC_CREATE_FAILED;
		return sm;
	}

	sm->celt_enc = (CELTEncoder*)((char*)sm->opus_enc + sm->opus_enc->celt_enc_offset);
	celt_encoder_ctl(sm->celt_enc, CELT_GET_MODE(&sm->celt_mode));
	sm->lsb_depth = IMIN(16, sm->opus_enc->lsb_depth);
	sm->delay_compensation = 0;
	if (sm->opus_enc->application != OPUS_APPLICATION_RESTRICTED_LOWDELAY) sm->delay_compensation = sm->opus_enc->delay_compensation;
	return sm;
}
コード例 #7
0
ファイル: opus.c プロジェクト: FihlaTV/BareSip-Android
static int alloc(struct aucodec_st **stp, struct aucodec *ac,
		 struct aucodec_prm *encp, struct aucodec_prm *decp,
		 const char *fmtp)
{
	struct aucodec_st *st;
	const uint32_t srate = aucodec_srate(ac);
	const uint8_t ch = aucodec_ch(ac);
	uint32_t ptime = DEFAULT_PTIME;
	int use_inbandfec;
	int use_dtx;
	int err = 0;
	int opuserr;

	(void)decp;
	(void)fmtp;

	st = mem_zalloc(sizeof(*st), destructor);
	if (!st)
		return ENOMEM;

	if (encp && encp->ptime)
		ptime = encp->ptime;

	st->ac         = mem_ref(ac);
	st->frame_size = srate * ptime / 1000;
	st->fsize      = 2 * st->frame_size * ch;

	/* Encoder */
	st->enc = opus_encoder_create(srate, ch, opus.app, &opuserr);
	if (!st->enc) {
		err = ENOMEM;
		goto out;
	}

	use_inbandfec = 1;
	use_dtx = 1;

	opus_encoder_ctl(st->enc, OPUS_SET_BITRATE(opus.bitrate));
	opus_encoder_ctl(st->enc, OPUS_SET_BANDWIDTH(opus.bandwidth));
	opus_encoder_ctl(st->enc, OPUS_SET_VBR(opus.vbr));
	opus_encoder_ctl(st->enc, OPUS_SET_COMPLEXITY(opus.complex));
	opus_encoder_ctl(st->enc, OPUS_SET_INBAND_FEC(use_inbandfec));
	opus_encoder_ctl(st->enc, OPUS_SET_DTX(use_dtx));

	/* Decoder */
	st->dec = opus_decoder_create(srate, ch, &opuserr);
	if (!st->dec) {
		err = ENOMEM;
		goto out;
	}

 out:
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
コード例 #8
0
    virtual bool Construct()
    {
      int error;
      if ((m_encoder = opus_encoder_create(m_sampleRate, m_channels, OPUS_APPLICATION_VOIP, &error)) != NULL)
        return true;

      PTRACE(1, MY_CODEC_LOG, "Encoder create error " << error << ' ' << opus_strerror(error));
      return false;
    }
コード例 #9
0
JNIEXPORT jlong JNICALL Java_org_echocat_jopus_OpusEncoderJNI_create
    (JNIEnv *env, jclass thisClass, jint samplingRateInHz, jint numberOfChannels, jint application) {

    int error;
    long result = (long) opus_encoder_create((int) samplingRateInHz, (int) numberOfChannels, application, &error);
    Java_org_echocat_jogg_OggJNISupport_checkResponse(env, error);

    return result;
}
コード例 #10
0
ファイル: CJOpus.c プロジェクト: gblosser42/Discord-Dice
EMSCRIPTEN_KEEPALIVE
Encoder* create_encoder_and_decoder(opus_int32 sample_rate, int channels, int application) {
    Encoder* enc = malloc(sizeof(Encoder));

    enc->encoder = opus_encoder_create( sample_rate, channels, application, &enc->encoder_error );
    enc->decoder = opus_decoder_create( sample_rate, channels, &enc->decoder_error );

    return enc;
}
コード例 #11
0
ファイル: media.c プロジェクト: anandanwar4/ProjectTox-Core
int init_audio_encoder(CodecState *cs, uint32_t audio_channels)
{
    int err = OPUS_OK;
    cs->audio_encoder = opus_encoder_create(cs->audio_sample_rate, audio_channels, OPUS_APPLICATION_AUDIO, &err);
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate));
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));


    return err == OPUS_OK ? 0 : -1;
}
コード例 #12
0
nsresult
OpusTrackEncoder::Init(int aChannels, int aSamplingRate)
{
  // This monitor is used to wake up other methods that are waiting for encoder
  // to be completely initialized.
  ReentrantMonitorAutoEnter mon(mReentrantMonitor);

  NS_ENSURE_TRUE((aChannels <= MAX_SUPPORTED_AUDIO_CHANNELS) && (aChannels > 0),
                 NS_ERROR_FAILURE);

  // This version of encoder API only support 1 or 2 channels,
  // So set the mChannels less or equal 2 and
  // let InterleaveTrackData downmix pcm data.
  mChannels = aChannels > MAX_CHANNELS ? MAX_CHANNELS : aChannels;

  // Reject non-audio sample rates.
  NS_ENSURE_TRUE(aSamplingRate >= 8000, NS_ERROR_INVALID_ARG);
  NS_ENSURE_TRUE(aSamplingRate <= 192000, NS_ERROR_INVALID_ARG);

  // According to www.opus-codec.org, creating an opus encoder requires the
  // sampling rate of source signal be one of 8000, 12000, 16000, 24000, or
  // 48000. If this constraint is not satisfied, we resample the input to 48kHz.
  nsTArray<int> supportedSamplingRates;
  supportedSamplingRates.AppendElements(kOpusSupportedInputSamplingRates,
                         ArrayLength(kOpusSupportedInputSamplingRates));
  if (!supportedSamplingRates.Contains(aSamplingRate)) {
    int error;
    mResampler = speex_resampler_init(mChannels,
                                      aSamplingRate,
                                      kOpusSamplingRate,
                                      SPEEX_RESAMPLER_QUALITY_DEFAULT,
                                      &error);

    if (error != RESAMPLER_ERR_SUCCESS) {
      return NS_ERROR_FAILURE;
    }
  }
  mSamplingRate = aSamplingRate;
  NS_ENSURE_TRUE(mSamplingRate > 0, NS_ERROR_FAILURE);

  int error = 0;
  mEncoder = opus_encoder_create(GetOutputSampleRate(), mChannels,
                                 OPUS_APPLICATION_AUDIO, &error);


  mInitialized = (error == OPUS_OK);

  if (mAudioBitrate) {
    opus_encoder_ctl(mEncoder, OPUS_SET_BITRATE(static_cast<int>(mAudioBitrate)));
  }

  mReentrantMonitor.NotifyAll();

  return error == OPUS_OK ? NS_OK : NS_ERROR_FAILURE;
}
コード例 #13
0
ファイル: OpusEncoder.cpp プロジェクト: BearWare/TeamTalk5
bool OpusEncode::Open(int sample_rate, int channels, int app)
{
    if(m_encoder)
        return false;

    int err = 0;
    m_encoder = opus_encoder_create(sample_rate, channels, app, &err);
    assert(err == 0);

    return m_encoder != NULL;
}
コード例 #14
0
ファイル: AudioCodec.cpp プロジェクト: CedLaPute/cpp_babel
AudioCodec::AudioCodec() {
  this->FrameSize = 24000;
  this->num_channels = 2;
  this->enc = opus_encoder_create(this->FrameSize, this->num_channels,
                                  OPUS_APPLICATION_VOIP, &this->error);
  this->dec =
      opus_decoder_create(this->FrameSize, this->num_channels, &this->error);
  opus_int32 size;
  opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&size));
  this->data_size = size;
}
コード例 #15
0
ファイル: encode_opus.c プロジェクト: jpanikulam/visar
//function sets up the encoder/decoder structs and buffers, returns required samples/frame
int setup_codecs(){
  //create the encoder and decoder state structs
  int error = 0;
  if(!(enc_state = opus_encoder_create(SAMPLE_RATE,1,APP_MODE,&error)))
    printf("Error Creating Encoder: %d\n",error);
  if(!(dec_state = opus_decoder_create(SAMPLE_RATE,1,&error)))
    printf("Error Creating Decoder: %d\n",error);
  
  opus_encoder_ctl(enc_state, OPUS_SET_COMPLEXITY(QUALITY));
  
  return FRAME_SIZE;  //return the frame size (
}
JNIEXPORT jlong JNICALL
Java_org_jitsi_impl_neomedia_codec_audio_opus_Opus_encoder_1create
    (JNIEnv *env, jclass clazz, jint Fs, jint channels)
{
    int error;
    OpusEncoder *encoder
        = opus_encoder_create(Fs, channels, OPUS_APPLICATION_VOIP, &error);

    if (OPUS_OK != error)
        encoder = 0;
    return (jlong) (intptr_t) encoder;
}
コード例 #17
0
ファイル: encoder.cpp プロジェクト: h2so5/Coil
Encoder::Encoder(QObject *parent) :
    QObject(parent),
    encoder_(NULL),
    position_(0),
    framesize_(2880)
{
    int error = 0;
    encoder_ = opus_encoder_create(Consts::Audio::sampling_rate, 2, OPUS_APPLICATION_AUDIO, &error);
    if (error != 0) {
        qWarning() << "opus_encoder_create() falied:" << error;
    }
}
コード例 #18
0
ファイル: opus_encode.cpp プロジェクト: DragonZX/Butt
int opus_enc_init(opus_enc *opus)
{
    int err;

	err = 0;
	opus->header = (OpusHeader *)calloc(1, sizeof(OpusHeader));
	opus->header_data = (unsigned char *)calloc (1, 1024);	
	opus->tags = (unsigned char *)calloc (1, 1024);
	opus->buffer = (unsigned char *)calloc (1, 4 * 4096);
    srand(time(NULL));
    ogg_stream_init(&opus->os, rand());
	opus->header->gain = 0;
	opus->header->channels = opus->channel;
	
	if ((opus->bitrate < 8000) || (opus->bitrate > 320000)) {
		opus->bitrate = DEFAULT_OPUS_BITRATE;
	}

	opus->header->input_sample_rate = 48000;
	opus->encoder = opus_encoder_create (opus->header->input_sample_rate, opus->channel, OPUS_APPLICATION_AUDIO, &err);
	opus_encoder_ctl (opus->encoder, OPUS_SET_BITRATE(opus->bitrate));
	if (opus->encoder == NULL) {
		printf("Opus Encoder creation error: %s\n", opus_strerror (err));
		return 1;
	}
	opus->last_bitrate = opus->bitrate;
	opus_encoder_ctl (opus->encoder, OPUS_GET_LOOKAHEAD (&opus->header->preskip));
	opus->header_size = opus_header_to_packet (opus->header, opus->header_data, 100);

	opus->tags_size = 
	8 + 4 + strlen (opus_get_version_string ()) + 4 + 4 + strlen ("ENCODER=") + strlen (VERSION);
	
	memcpy (opus->tags, "OpusTags", 8);
	
	opus->tags[8] = strlen (opus_get_version_string ());
	
	memcpy (opus->tags + 12, opus_get_version_string (), strlen (opus_get_version_string ()));

	opus->tags[12 + strlen (opus_get_version_string ())] = 1;

	opus->tags[12 + strlen (opus_get_version_string ()) + 4] = strlen ("ENCODER=") + strlen (VERSION);
	
	memcpy (opus->tags + 12 + strlen (opus_get_version_string ()) + 4 + 4, "ENCODER=", strlen ("ENCODER="));
	
	memcpy (opus->tags + 12 + strlen (opus_get_version_string ()) + 4 + 4 + strlen ("ENCODER="),
			VERSION,
			strlen (VERSION));	

	//printf("Opus Encoder Created\n");

    return 0;
}
コード例 #19
0
ファイル: audio.c プロジェクト: GrayHatter/toxcore
OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
{
    int status = OPUS_OK;
    OpusEncoder *rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_VOIP, &status);

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status));
        return NULL;
    }

    status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Enable in-band forward error correction in codec */
    status = opus_encoder_ctl(rc, OPUS_SET_INBAND_FEC(1));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Make codec resistant to up to 10% packet loss
     * NOTE This could also be adjusted on the fly, rather than hard-coded,
     *      with feedback from the receiving client.
     */
    status = opus_encoder_ctl(rc, OPUS_SET_PACKET_LOSS_PERC(10));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Set algorithm to the highest complexity, maximizing compression */
    status = opus_encoder_ctl(rc, OPUS_SET_COMPLEXITY(10));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    return rc;

FAILURE:
    opus_encoder_destroy(rc);
    return NULL;
}
コード例 #20
0
int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, int32_t channels) {
  OpusEncInst* state;
  state = (OpusEncInst*) calloc(1, sizeof(OpusEncInst));
  if (state) {
    int error;
    state->encoder = opus_encoder_create(48000, channels, OPUS_APPLICATION_VOIP,
                                         &error);
    if (error == OPUS_OK || state->encoder != NULL ) {
      *inst = state;
      return 0;
    }
    free(state);
  }
  return -1;
}
コード例 #21
0
bool FVoiceEncoderOpus::Init(int32 InSampleRate, int32 InNumChannels)
{
	UE_LOG(LogVoiceEncode, Display, TEXT("EncoderVersion: %s"), ANSI_TO_TCHAR(opus_get_version_string()));

	SampleRate = InSampleRate;
	NumChannels = InNumChannels;

	// 20ms frame sizes are a good choice for most applications (1000ms / 20ms = 50)
	FrameSize = SampleRate / NUM_OPUS_FRAMES_PER_SEC;
	//MaxFrameSize = FrameSize * MAX_OPUS_FRAMES;

	int32 EncError = 0;

#if USE_UE4_MEM_ALLOC
	int32 EncSize = opus_encoder_get_size(NumChannels);
	Encoder = (OpusEncoder*)FMemory::Malloc(EncSize);
	EncError = opus_encoder_init(Encoder, SampleRate, NumChannels, OPUS_APPLICATION_VOIP);
#else
	Encoder = opus_encoder_create(SampleRate, NumChannels, OPUS_APPLICATION_VOIP, &EncError);
#endif

	if (EncError != OPUS_OK)
	{
		UE_LOG(LogVoiceEncode, Warning, TEXT("Failed to init Opus Encoder: %s"), ANSI_TO_TCHAR(opus_strerror(EncError)));
		Destroy();
	}

	// Turn on variable bit rate encoding
	int32 UseVbr = 1;
	opus_encoder_ctl(Encoder, OPUS_SET_VBR(UseVbr));

	// Turn off constrained VBR
	int32 UseCVbr = 0;
	opus_encoder_ctl(Encoder, OPUS_SET_VBR_CONSTRAINT(UseCVbr));

	// Complexity (1-10)
	int32 Complexity = 1;
	opus_encoder_ctl(Encoder, OPUS_SET_COMPLEXITY(Complexity));

	// Forward error correction
	int32 InbandFEC = 0;
	opus_encoder_ctl(Encoder, OPUS_SET_INBAND_FEC(InbandFEC));

#if DEBUG_OPUS
	DebugEncoderInfo(Encoder);
#endif // DEBUG_OPUS
	return EncError == OPUS_OK;
}
コード例 #22
0
ファイル: opus_interface.c プロジェクト: Gurtej/op
WebRtc_Word16 WebRtcOpus_CreateEnc(OPUS_encinst_t** inst, WebRtc_Word16 samplFreq) {

  *inst=(OPUS_encinst_t*)malloc(sizeof(OPUS_Enc_Inst_t));
  if (*inst==NULL) {
    return(-1);
  }
  
  int err;
  
  ((OPUS_Enc_Inst_t*)*inst)->enc = opus_encoder_create(16000, 1, OPUS_APPLICATION_VOIP, &err);
  if(err != OPUS_OK || ((OPUS_Enc_Inst_t*)*inst)->enc==NULL) {
    return(-1);
  }

  return(0);
}
コード例 #23
0
ファイル: msopus.c プロジェクト: william30101/linphonemedia
static void ms_opus_enc_preprocess(MSFilter *f) {
	int error;

	OpusEncData *d = (OpusEncData *)f->data;
	/* create the encoder */
	d->state = opus_encoder_create(d->samplerate, d->channels, d->application, &error);
	if (error != OPUS_OK) {
		ms_error("Opus encoder creation failed: %s", opus_strerror(error));
		return;
	}

	/* set complexity to 0 for single processor arm devices */
#if defined(__arm__) || defined(_M_ARM)
	if (ms_factory_get_cpu_count(f->factory)==1){
		opus_encoder_ctl(d->state, OPUS_SET_COMPLEXITY(0));
	}else{
		opus_encoder_ctl(d->state, OPUS_SET_COMPLEXITY(5));
	}
#endif
	error = opus_encoder_ctl(d->state, OPUS_SET_PACKET_LOSS_PERC(10));
	if (error != OPUS_OK) {
		ms_error("Could not set default loss percentage to opus encoder: %s", opus_strerror(error));
	}

	/* set the encoder parameters: VBR, IN_BAND_FEC, DTX and bitrate settings */
	ms_opus_enc_set_vbr(f);
	ms_opus_enc_set_inbandfec(f);
	ms_opus_enc_set_dtx(f);
	/* if decoder prefers mono signal, force encoder to output mono signal */
	if (d->stereo == 0) {
		error = opus_encoder_ctl(d->state, OPUS_SET_FORCE_CHANNELS(1));
		if (error != OPUS_OK) {
			ms_error("could not force mono channel to opus encoder: %s", opus_strerror(error));
		}
		if (d->channels == 2) ms_message("Opus encoder configured to encode mono despite it is feed with stereo.");
	}else if (d->channels == 2){
		ms_message("Opus encoder configured to encode stereo.");
	}

	ms_filter_lock(f);
	// set bitrate wasn't call, compute it with the default network bitrate (36000)
	if (d->bitrate==-1) {
		compute_max_bitrate(d, 0);
	}
	apply_max_bitrate(d);
	ms_filter_unlock(f);
}
コード例 #24
0
ファイル: AV_codec.c プロジェクト: okiyama/ProjectTox-Core
int init_send_audio(codec_state *cs)
{
    cs->support_send_audio = 0;

    const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
    int i = 0;
    const ALchar *device_names[20];

    if (pDeviceList) {
        printf("\nAvailable Capture Devices are:\n");

        while (*pDeviceList) {
            device_names[i] = pDeviceList;
            printf("%d) %s\n", i, device_names[i]);
            pDeviceList += strlen(pDeviceList) + 1;
            ++i;
        }
    }

    printf("enter capture device number: \n");
    char dev[2];
    fgets(dev, sizeof(dev), stdin);
    cs->audio_capture_device = alcCaptureOpenDevice(device_names[dev[0] - 48], AUDIO_SAMPLE_RATE, AL_FORMAT_MONO16,
                               AUDIO_FRAME_SIZE * 4);

    if (alcGetError(cs->audio_capture_device) != AL_NO_ERROR) {
        printf("could not start capture device! %d\n", alcGetError(cs->audio_capture_device));
        return 0;
    }

    int err = OPUS_OK;
    cs->audio_bitrate = AUDIO_BITRATE;
    cs->audio_encoder = opus_encoder_create(AUDIO_SAMPLE_RATE, 1, OPUS_APPLICATION_VOIP, &err);
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate));
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));

    opus_encoder_init(cs->audio_encoder, AUDIO_SAMPLE_RATE, 1, OPUS_APPLICATION_VOIP);

    int nfo;
    err = opus_encoder_ctl(cs->audio_encoder, OPUS_GET_LOOKAHEAD(&nfo));
    /* printf("Encoder lookahead delay : %d\n", nfo); */
    printf("init audio encoder successful\n");

    return 1;
}
コード例 #25
0
ファイル: sender.c プロジェクト: KJYoo1989/Ubercaster
static void audio_encoder_init(uint32_t samplerate, int complexity,
                                                            uint32_t bitrate)
{
    assert(opus_enc == NULL);

    int err = 0;
    /* 1 channel (mono), OPUS audio profile */
    opus_enc = opus_encoder_create(samplerate, 1, OPUS_APPLICATION_AUDIO, &err);
    if (!opus_enc) {
        fprintf(stderr, "ERROR: opus_encoder_create() has failed - %d\n", err);
        exit(EXIT_FAILURE);
    }

    opus_encoder_ctl(opus_enc, OPUS_SET_COMPLEXITY(complexity));
    opus_encoder_ctl(opus_enc, OPUS_SET_BITRATE(bitrate));
    opus_encoder_ctl(opus_enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
    opus_encoder_ctl(opus_enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND));
}
コード例 #26
0
ファイル: opus_interface.c プロジェクト: biddyweb/webrtc-core
int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, int32_t channels) {
  OpusEncInst* state;
  state = (OpusEncInst*) calloc(1, sizeof(OpusEncInst));
  if (state) {
    int error;
    // Default to VoIP application for mono, and AUDIO for stereo.
    int application = (channels == 1) ?
        OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO;

    state->encoder = opus_encoder_create(48000, channels, application, &error);
    if (error == OPUS_OK || state->encoder != NULL ) {
      *inst = state;
      return 0;
    }
    free(state);
  }
  return -1;
}
コード例 #27
0
ファイル: transcode.c プロジェクト: indrwthaachen/pulseaudio
OpusEncoder *tc_opus_create_encoder(int sample_rate, int channels, int bitrate)
{
   int err;

   OpusEncoder *encoder = opus_encoder_create(sample_rate, channels, OPUS_APPLICATION_AUDIO, &err);
   if (err<0){
      pa_log_error("failed to create an encoder: %s", opus_strerror(err));
      return NULL;
   }

   err = opus_encoder_ctl(encoder, OPUS_SET_BITRATE(bitrate));
   if (err<0)
   {
      pa_log_error("failed to set bitrate: %s", opus_strerror(err));
      return NULL;
   }

   return encoder;
}
コード例 #28
0
JNIEXPORT jlong JNICALL Java_aopus_OpusLibrary_encoderCreate
  (JNIEnv *env, jobject obj, jint clockRate, jint channels, jint packetTime)
{
    Encoder *encoder = malloc(sizeof* encoder);
    
    encoder->frameSizePerChannel = (clockRate * packetTime) / 1000;
    encoder->maxBufferSize = 4000;
    encoder->buffer = malloc(encoder->maxBufferSize);

    // initialize encoder
    int error;
    encoder->enc = opus_encoder_create(clockRate, channels, OPUS_APPLICATION_VOIP, &error);
    if (error != OPUS_OK)
    {
        __android_log_print(ANDROID_LOG_ERROR, "fm.libopus", "Could not initialize encoder. %d", error);
        return 0;
    }
    return encoder;
}
コード例 #29
0
ファイル: audio.cpp プロジェクト: rlankenau/firestr
            opus_encoder::opus_encoder()
            {
                int err;

                _opus = opus_encoder_create(SAMPLE_RATE,CHANNELS, OPUS_APPLICATION_VOIP, &err); 

                if(err != OPUS_OK) 
                { 
                    LOG << "opus encoder create error: "; 
                    log_opus_error(err);
                }

                opus_encoder_ctl(_opus, OPUS_SET_BITRATE(OPUS_AUTO));
                opus_encoder_ctl(_opus, OPUS_SET_VBR(1));
                opus_encoder_ctl(_opus, OPUS_SET_FORCE_CHANNELS(1)); //force mono
                opus_encoder_ctl(_opus, OPUS_SET_PACKET_LOSS_PERC(2));

                ENSURE(_opus);
            }
コード例 #30
0
ファイル: msopus.c プロジェクト: biddyweb/azfone-ios
static void ms_opus_enc_preprocess(MSFilter *f) {
	int error;

	OpusEncData *d = (OpusEncData *)f->data;
	/* create the encoder */
	d->state = opus_encoder_create(d->samplerate, d->channels, d->application, &error);
	if (error != OPUS_OK) {
		ms_error("Opus encoder creation failed: %s", opus_strerror(error));
		return;
	}

	/* set complexity to 0 for arm devices */
#ifdef __arm__
	opus_encoder_ctl(d->state, OPUS_SET_COMPLEXITY(0));
#endif
	error = opus_encoder_ctl(d->state, OPUS_SET_PACKET_LOSS_PERC(10));
	if (error != OPUS_OK) {
		ms_error("Could not set default loss percentage to opus encoder: %s", opus_strerror(error));
	}

	/* set the encoder parameters: VBR, IN_BAND_FEC, DTX and bitrate settings */
	ms_opus_enc_set_vbr(f);
	ms_opus_enc_set_inbandfec(f);
	ms_opus_enc_set_dtx(f);
	/* if decoder prefers mono signal, force encoder to output mono signal */
	if (d->stereo == 0) {
		error = opus_encoder_ctl(d->state, OPUS_SET_FORCE_CHANNELS(1));
		if (error != OPUS_OK) {
			ms_error("could not force mono channel to opus encoder: %s", opus_strerror(error));
		}
	}

	ms_filter_lock(f);
	if (d->ptime==-1) { // set ptime wasn't call, set default:20ms
		d->ptime = 20;
	}
	if (d->bitrate==-1) { // set bitrate wasn't call, compute it with the default network bitrate (36000)
		compute_max_bitrate(d, 0);
	}
	apply_max_bitrate(d);
	ms_filter_unlock(f);
}