这篇教程C++ vorbis_block_init函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中vorbis_block_init函数的典型用法代码示例。如果您正苦于以下问题:C++ vorbis_block_init函数的具体用法?C++ vorbis_block_init怎么用?C++ vorbis_block_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了vorbis_block_init函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: UpdateInputstatic int UpdateInput(vorbis* p){ vorbis_block_clear(&p->Block); vorbis_dsp_clear(&p->DSP); if (p->Codec.In.Format.Type == PACKET_AUDIO) { vorbis_info* Info = (vorbis_info*)p->Codec.In.Format.Extra; if (Info) { vorbis_synthesis_init(&p->DSP,Info); vorbis_block_init(&p->DSP,&p->Block); p->Codec.In.Format.ByteRate = Info->bitrate_nominal >> 3; p->Codec.In.Format.Format.Audio.SampleRate = Info->rate; p->Codec.In.Format.Format.Audio.Channels = Info->channels; } PacketFormatPCM(&p->Codec.Out.Format,&p->Codec.In.Format,OGG_F_BITS+1); p->Codec.Out.Format.Format.Audio.Flags = PCM_PLANES; }
开发者ID:BigHNF,项目名称:tcpmp-revive,代码行数:21,
示例2: encoder_create_vbrencoder_instance encoder_create_vbr(int ch, int bitrate, float quality) { encoder_instance state = malloc(sizeof(struct encoder_state)); state->data = NULL; state->data_len = 0; vorbis_info_init(&state->vi); if (vorbis_encode_init_vbr(&state->vi, ch, bitrate, quality) != 0) { free(state); return NULL; } vorbis_comment_init(&state->vc); vorbis_comment_add_tag(&state->vc, "ENCODER", "libvorbis.js"); vorbis_analysis_init(&state->vd, &state->vi); vorbis_block_init(&state->vd, &state->vb); srand(time(NULL)); ogg_stream_init(&state->os, rand()); return state;}
开发者ID:paul-wade,项目名称:libvorbis.js,代码行数:23,
示例3: vorbis_encoder_reinitstatic boolvorbis_encoder_reinit(struct vorbis_encoder *encoder, GError **error){ vorbis_info_init(&encoder->vi); if (encoder->quality >= -1.0) { /* a quality was configured (VBR) */ if (0 != vorbis_encode_init_vbr(&encoder->vi, encoder->audio_format.channels, encoder->audio_format.sample_rate, encoder->quality * 0.1)) { g_set_error(error, vorbis_encoder_quark(), 0, "error initializing vorbis vbr"); vorbis_info_clear(&encoder->vi); return false; } } else { /* a bit rate was configured */ if (0 != vorbis_encode_init(&encoder->vi, encoder->audio_format.channels, encoder->audio_format.sample_rate, -1.0, encoder->bitrate * 1000, -1.0)) { g_set_error(error, vorbis_encoder_quark(), 0, "error initializing vorbis encoder"); vorbis_info_clear(&encoder->vi); return false; } } vorbis_analysis_init(&encoder->vd, &encoder->vi); vorbis_block_init(&encoder->vd, &encoder->vb); ogg_stream_init(&encoder->os, g_random_int()); return true;}
开发者ID:andrewrk,项目名称:mpd,代码行数:37,
示例4: xmms_ices_encoder_create/* Create an ogg stream and vorbis encoder, with the configuration * specified in the encoder_state. */static gbooleanxmms_ices_encoder_create (encoder_state *s, vorbis_comment *vc){ ogg_packet header[3]; if (s->encoder_inited) { XMMS_DBG ("OOPS: xmms_ices_encoder_create called " "with s->encoder_inited == TRUE !"); } XMMS_DBG ("Creating encoder in ABR mode: min/avg/max bitrate %d/%d/%d", s->min_br, s->nom_br, s->max_br); /* Create the Vorbis encoder. */ vorbis_info_init (&s->vi); if (vorbis_encode_init (&s->vi, s->channels, s->rate, s->max_br, s->nom_br, s->min_br) < 0) return FALSE; vorbis_analysis_init (&s->vd, &s->vi); vorbis_block_init (&s->vd, &s->vb); /* Initialize the ogg stream and input the vorbis header * packets. */ ogg_stream_init (&s->os, s->serial++); vorbis_analysis_headerout (&s->vd, vc, &header[0], &header[1], &header[2]); ogg_stream_packetin (&s->os, &header[0]); ogg_stream_packetin (&s->os, &header[1]); ogg_stream_packetin (&s->os, &header[2]); s->in_header = TRUE; s->flushing = FALSE; s->samples_in_current_page = 0; s->previous_granulepos = 0; s->encoder_inited = TRUE; return TRUE;}
开发者ID:eggpi,项目名称:xmms2-guilherme,代码行数:40,
示例5: vorbis_info_init StreamEncoder::StreamEncoder() { //Initialize the info vorbis_info_init(&mVorbisInfo); if (ErrorCheck(vorbis_encode_init(&mVorbisInfo, 2, 44100, 100, 80, 60)) == true) { //Error Write("vorbis_encode_init error"); return; } if (ErrorCheck(vorbis_analysis_init(&mVorbisDspState, &mVorbisInfo)) == true) { //Error Write("vorbis_analysis_init error"); return; } vorbis_comment_init(&mVorbisComment); //vorbis_comment_add(&mVorbisComment, "Comments"); int vahCode = vorbis_analysis_headerout(&mVorbisDspState, &mVorbisComment, &mOggPacketIdentification, &mOggPacketComment, &mOggPacketCodes); if (ErrorCheck(vahCode) == true) { //Error Write("vorbis_analysis_init error"); return; } if (ErrorCheck(vorbis_block_init(&mVorbisDspState, &mVorbisBlock)) == true) { //Error Write("vorbis_block_init error"); return; } }
开发者ID:zippo227,项目名称:ogg_enc_buffer,代码行数:36,
示例6: vorbis_analysis_initvoid EncoderVorbis::initStream() { // set up analysis state and auxiliary encoding storage vorbis_analysis_init(&m_vdsp, &m_vinfo); vorbis_block_init(&m_vdsp, &m_vblock); // set up packet-to-stream encoder; attach a random serial number srand(time(0)); ogg_stream_init(&m_oggs, getSerial()); // add comment vorbis_comment_init(&m_vcomment); vorbis_comment_add_tag(&m_vcomment, "ENCODER", "mixxx/libvorbis"); if (m_metaDataArtist != NULL) { vorbis_comment_add_tag(&m_vcomment, "ARTIST", m_metaDataArtist); } if (m_metaDataTitle != NULL) { vorbis_comment_add_tag(&m_vcomment, "TITLE", m_metaDataTitle); } if (m_metaDataAlbum != NULL) { vorbis_comment_add_tag(&m_vcomment, "ALBUM", m_metaDataAlbum); } // set up the vorbis headers ogg_packet headerInit; ogg_packet headerComment; ogg_packet headerCode; vorbis_analysis_headerout(&m_vdsp, &m_vcomment, &headerInit, &headerComment, &headerCode); ogg_stream_packetin(&m_oggs, &headerInit); ogg_stream_packetin(&m_oggs, &headerComment); ogg_stream_packetin(&m_oggs, &headerCode); // The encoder is now inialized. The encode method will start streaming by // sending the header first. m_header_write = true; m_bStreamInitialized = true;}
开发者ID:dk0104,项目名称:mixxx,代码行数:36,
示例7: vorbis_handle_type_packetstatic GstFlowReturnvorbis_handle_type_packet (GstVorbisDec * vd){ gint res; g_assert (vd->initialized == FALSE);#ifdef USE_TREMOLO if (G_UNLIKELY ((res = vorbis_dsp_init (&vd->vd, &vd->vi)))) goto synthesis_init_error;#else if (G_UNLIKELY ((res = vorbis_synthesis_init (&vd->vd, &vd->vi)))) goto synthesis_init_error; if (G_UNLIKELY ((res = vorbis_block_init (&vd->vd, &vd->vb)))) goto block_init_error;#endif vd->initialized = TRUE; return GST_FLOW_OK; /* ERRORS */synthesis_init_error: { GST_ELEMENT_ERROR (GST_ELEMENT (vd), STREAM, DECODE, (NULL), ("couldn't initialize synthesis (%d)", res)); return GST_FLOW_ERROR; }block_init_error: { GST_ELEMENT_ERROR (GST_ELEMENT (vd), STREAM, DECODE, (NULL), ("couldn't initialize block (%d)", res)); return GST_FLOW_ERROR; }}
开发者ID:Lachann,项目名称:gst-plugins-base,代码行数:36,
示例8: eprintf// Just create the Quicktime objects since this routine is also called// for reopening.int FileVorbis::open_file(int rd, int wr){ int result = 0; this->rd = rd; this->wr = wr;//printf("FileVorbis::open_file 1/n"); if(rd) {//printf("FileVorbis::open_file 1/n"); if(!(fd = fopen(asset->path, "rb"))) { eprintf("Error while opening /"%s/" for reading. /n%m/n", asset->path); result = 1; } else {//printf("FileVorbis::open_file 2 %p %p/n", fd, vf); if(ov_open(fd, &vf, NULL, 0) < 0) { eprintf("Invalid bitstream in %s/n", asset->path); result = 1; } else {//printf("FileVorbis::open_file 1/n"); vorbis_info *vi = ov_info(&vf, -1); asset->channels = vi->channels; if(!asset->sample_rate) asset->sample_rate = vi->rate;//printf("FileVorbis::open_file 1/n"); asset->audio_length = ov_pcm_total(&vf,-1);//printf("FileVorbis::open_file 1/n"); asset->audio_data = 1;// printf("FileVorbis::open_file 1 %d %d %d/n", // asset->channels, // asset->sample_rate, // asset->audio_length); } } } if(wr) { if(!(fd = fopen(asset->path, "wb"))) { eprintf("Error while opening /"%s/" for writing. /n%m/n", asset->path); result = 1; } else { vorbis_info_init(&vi); if(!asset->vorbis_vbr) result = vorbis_encode_init(&vi, asset->channels, asset->sample_rate, asset->vorbis_max_bitrate, asset->vorbis_bitrate, asset->vorbis_min_bitrate); else { result = vorbis_encode_setup_managed(&vi, asset->channels, asset->sample_rate, asset->vorbis_max_bitrate, asset->vorbis_bitrate, asset->vorbis_min_bitrate); result |= vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_AVG, NULL); result |= vorbis_encode_setup_init(&vi); } if(!result) { vorbis_analysis_init(&vd, &vi); vorbis_block_init(&vd, &vb); vorbis_comment_init(&vc); srand(time(NULL)); ogg_stream_init(&os, rand()); ogg_packet header; ogg_packet header_comm; ogg_packet header_code; vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code); ogg_stream_packetin(&os, &header); ogg_stream_packetin(&os, &header_comm); ogg_stream_packetin(&os, &header_code); while(1) { int result = ogg_stream_flush(&os, &og); if(result == 0) break;//.........这里部分代码省略.........
开发者ID:beequ7et,项目名称:cinelerra-cv,代码行数:101,
示例9: lame_decode_ogg_initfile//.........这里部分代码省略......... header is an easy way to identify a Vorbis bitstream and it's useful to see that functionality seperated out. */ vorbis_info_init(&vi); vorbis_comment_init(&vc); if(ogg_stream_pagein(&os,&og)<0){ /* error; stream version mismatch perhaps */ ERRORF( gfc, "Error reading first page of Ogg bitstream data./n" ); return -1; } if(ogg_stream_packetout(&os,&op)!=1){ /* no page? must not be vorbis */ ERRORF( gfc, "Error reading initial header packet./n" ); return -1; } if(vorbis_synthesis_headerin(&vi,&vc,&op)<0){ /* error case; not a vorbis header */ ERRORF( gfc, "This Ogg bitstream does not contain Vorbis " "audio data./n"); return -1; } /* At this point, we're sure we're Vorbis. We've set up the logical (Ogg) bitstream decoder. Get the comment and codebook headers and set up the Vorbis decoder */ /* The next two packets in order are the comment and codebook headers. They're likely large and may span multiple pages. Thus we reead and submit data until we get our two pacakets, watching that no pages are missing. If a page is missing, error out; losing a header page is the only place where missing data is fatal. */ i=0; while(i<2){ while(i<2){ int result=ogg_sync_pageout(&oy,&og); if(result==0)break; /* Need more data */ /* Don't complain about missing or corrupt data yet. We'll catch it at the packet output phase */ if(result==1){ ogg_stream_pagein(&os,&og); /* we can ignore any errors here as they'll also become apparent at packetout */ while(i<2){ result=ogg_stream_packetout(&os,&op); if(result==0)break; if(result==-1){ /* Uh oh; data at some point was corrupted or missing! We can't tolerate that in a header. Die. */ ERRORF( gfc, "Corrupt secondary header. Exiting./n" ); return -1; } vorbis_synthesis_headerin(&vi,&vc,&op); i++; } } } /* no harm in not checking before adding more */ buffer=ogg_sync_buffer(&oy,4096); bytes=fread(buffer,1,4096,fd); if(bytes==0 && i<2){ ERRORF( gfc, "End of file before finding all Vorbis headers!/n" ); return -1; } ogg_sync_wrote(&oy,bytes); } /* Throw the comments plus a few lines about the bitstream we're decoding */ { /* char **ptr=vc.user_comments; while(*ptr){ MSGF( gfc, "%s/n", *ptr ); ++ptr; } MSGF( gfc, "/nBitstream is %d channel, %ldHz/n", vi.channels, vi.rate ); MSGF( gfc, "Encoded by: %s/n/n", vc.vendor ); */ } /* OK, got and parsed all three headers. Initialize the Vorbis packet->PCM decoder. */ vorbis_synthesis_init(&vd,&vi); /* central decode state */ vorbis_block_init(&vd,&vb); /* local state for most of the decode so multiple block decodes can proceed in parallel. We could init multiple vorbis_block structures for vd here */ mp3data->stereo = vi.channels; mp3data->samplerate = vi.rate; mp3data->bitrate = 0; //ov_bitrate_instant(&vf); mp3data->nsamp=MAX_U_32_NUM; return 0;}
开发者ID:aahud,项目名称:harvey,代码行数:101,
示例10: init//.........这里部分代码省略......... mp_msg(MSGT_DECAUDIO,MSGL_V,"ad_vorbis, extradata seems is %d bytes long/n", sh->wf->cbSize); extradata = (char*) (sh->wf+1); if(*extradata != 2) { mp_msg (MSGT_DEMUX, MSGL_WARN, "ad_vorbis: Vorbis track does not contain valid headers./n"); ERROR(); } offset = 1; for (i=0; i < 2; i++) { length = 0; while ((extradata[offset] == (unsigned char) 0xFF) && length < sh->wf->cbSize) { length += 255; offset++; } if(offset >= (sh->wf->cbSize - 1)) { mp_msg (MSGT_DEMUX, MSGL_WARN, "ad_vorbis: Vorbis track does not contain valid headers./n"); ERROR(); } length += extradata[offset]; offset++; mp_msg (MSGT_DEMUX, MSGL_V, "ad_vorbis, offset: %u, length: %u/n", offset, length); hsizes[i] = length; } headers[0] = &extradata[offset]; headers[1] = &extradata[offset + hsizes[0]]; headers[2] = &extradata[offset + hsizes[0] + hsizes[1]]; hsizes[2] = sh->wf->cbSize - offset - hsizes[0] - hsizes[1]; mp_msg (MSGT_DEMUX, MSGL_V, "ad_vorbis, header sizes: %d %d %d/n", hsizes[0], hsizes[1], hsizes[2]); for(i=0; i<3; i++) { op.bytes = hsizes[i]; op.packet = headers[i]; op.b_o_s = (i == 0); if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) { mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: header n. %d broken! len=%ld/n", i, op.bytes); ERROR(); } if(i == 2) { float rg_gain=0.f, rg_peak=0.f; char **ptr=vc.user_comments; while(*ptr){ mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s/n",*ptr); /* replaygain */ read_vorbis_comment( *ptr, "replaygain_album_gain=", "%f", &rg_gain ); read_vorbis_comment( *ptr, "rg_audiophile=", "%f", &rg_gain ); if( !rg_gain ) { read_vorbis_comment( *ptr, "replaygain_track_gain=", "%f", &rg_gain ); read_vorbis_comment( *ptr, "rg_radio=", "%f", &rg_gain ); } read_vorbis_comment( *ptr, "replaygain_album_peak=", "%f", &rg_peak ); if( !rg_peak ) { read_vorbis_comment( *ptr, "replaygain_track_peak=", "%f", &rg_peak ); read_vorbis_comment( *ptr, "rg_peak=", "%f", &rg_peak ); } ++ptr; } /* replaygain: scale */ if(!rg_gain) ov->rg_scale = 1.f; /* just in case pow() isn't standard-conformant */ else ov->rg_scale = pow(10.f, rg_gain/20); /* replaygain: anticlip */ if(ov->rg_scale * rg_peak > 1.f) ov->rg_scale = 1.f / rg_peak; /* replaygain: security */ if(ov->rg_scale > 15.) ov->rg_scale = 15.;#ifdef CONFIG_TREMOR ov->rg_scale_int = (int)(ov->rg_scale*64.f);#endif mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel%s, %dHz, %dbit/s %cBR/n",(int)ov->vi.channels,ov->vi.channels>1?"s":"",(int)ov->vi.rate,(int)ov->vi.bitrate_nominal, (ov->vi.bitrate_lower!=ov->vi.bitrate_nominal)||(ov->vi.bitrate_upper!=ov->vi.bitrate_nominal)?'V':'C'); if(rg_gain || rg_peak) mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Gain = %+.2f dB, Peak = %.4f, Scale = %.2f/n", rg_gain, rg_peak, ov->rg_scale); mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s/n",vc.vendor); } } vorbis_comment_clear(&vc);// printf("lower=%d upper=%d /n",(int)ov->vi.bitrate_lower,(int)ov->vi.bitrate_upper); // Setup the decoder sh->channels=ov->vi.channels; sh->samplerate=ov->vi.rate; sh->samplesize=2; // assume 128kbit if bitrate not specified in the header sh->i_bps=((ov->vi.bitrate_nominal>0) ? ov->vi.bitrate_nominal : 128000)/8; sh->context = ov; /// Finish the decoder init vorbis_synthesis_init(&ov->vd,&ov->vi); vorbis_block_init(&ov->vd,&ov->vb); mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!/n"); return 1;}
开发者ID:0p1pp1,项目名称:mplayer,代码行数:101,
示例11: vorbis_info_initRefPtr<MediaDataDecoder::InitPromise>VorbisDataDecoder::Init(){ vorbis_info_init(&mVorbisInfo); vorbis_comment_init(&mVorbisComment); PodZero(&mVorbisDsp); PodZero(&mVorbisBlock); AutoTArray<unsigned char*,4> headers; AutoTArray<size_t,4> headerLens; if (!XiphExtradataToHeaders(headers, headerLens, mInfo.mCodecSpecificConfig->Elements(), mInfo.mCodecSpecificConfig->Length())) { return InitPromise::CreateAndReject( MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, RESULT_DETAIL("Could not get vorbis header.")), __func__); } for (size_t i = 0; i < headers.Length(); i++) { if (NS_FAILED(DecodeHeader(headers[i], headerLens[i]))) { return InitPromise::CreateAndReject( MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, RESULT_DETAIL("Could not decode vorbis header.")), __func__); } } MOZ_ASSERT(mPacketCount == 3); int r = vorbis_synthesis_init(&mVorbisDsp, &mVorbisInfo); if (r) { return InitPromise::CreateAndReject( MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, RESULT_DETAIL("Systhesis init fail.")), __func__); } r = vorbis_block_init(&mVorbisDsp, &mVorbisBlock); if (r) { return InitPromise::CreateAndReject( MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, RESULT_DETAIL("Block init fail.")), __func__); } if (mInfo.mRate != (uint32_t)mVorbisDsp.vi->rate) { LOG(LogLevel::Warning, ("Invalid Vorbis header: container and codec rate do not match!")); } if (mInfo.mChannels != (uint32_t)mVorbisDsp.vi->channels) { LOG(LogLevel::Warning, ("Invalid Vorbis header: container and codec channels do not match!")); } AudioConfig::ChannelLayout layout(mVorbisDsp.vi->channels); if (!layout.IsValid()) { return InitPromise::CreateAndReject( MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, RESULT_DETAIL("Invalid audio layout.")), __func__); } return InitPromise::CreateAndResolve(TrackInfo::kAudioTrack, __func__);}
开发者ID:luke-chang,项目名称:gecko-1,代码行数:64,
示例12: main//.........这里部分代码省略......... /* The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec */ if(ogg_sync_pageout(&oy,&og)>0){ queue_page(&og); /* demux into the appropriate stream */ }else{ int ret=buffer_data(infile,&oy); /* someone needs more data */ if(ret==0){ fprintf(stderr,"End of file while searching for codec headers./n"); exit(1); } } } /* and now we have it all. initialize decoders */ if(theora_p){ theora_decode_init(&td,&ti); printf("Ogg logical stream %x is Theora %dx%d %.02f fps video/n", (unsigned int)to.serialno,ti.width,ti.height, (double)ti.fps_numerator/ti.fps_denominator); if(ti.width!=ti.frame_width || ti.height!=ti.frame_height) printf(" Frame content is %dx%d with offset (%d,%d)./n", ti.frame_width, ti.frame_height, ti.offset_x, ti.offset_y); report_colorspace(&ti); dump_comments(&tc); }else{ /* tear down the partial theora setup */ theora_info_clear(&ti); theora_comment_clear(&tc); } if(vorbis_p){ vorbis_synthesis_init(&vd,&vi); vorbis_block_init(&vd,&vb); fprintf(stderr,"Ogg logical stream %x is Vorbis %d channel %d Hz audio./n", (unsigned int)vo.serialno,vi.channels,(int)vi.rate); }else{ /* tear down the partial vorbis setup */ vorbis_info_clear(&vi); vorbis_comment_clear(&vc); } /* open audio */ if(vorbis_p)open_audio(); /* open video */ if(theora_p)open_video(); /* install signal handler as SDL clobbered the default */ signal (SIGINT, sigint_handler); /* on to the main decode loop. We assume in this example that audio and video start roughly together, and don't begin playback until we have a start frame for both. This is not necessarily a valid assumption in Ogg A/V streams! It will always be true of the example_encoder (and most streams) though. */ stateflag=0; /* playback has not begun */ while(!got_sigint){ /* we want a video and audio frame ready to go at all times. If we have to buffer incoming, buffer the compressed data (ie, let ogg do the buffering) */ while(vorbis_p && !audiobuf_ready){ int ret; float **pcm;
开发者ID:petterreinholdtsen,项目名称:cinelerra-hv,代码行数:67,
示例13: ogg_vorbis_open//.........这里部分代码省略......... int result; char **ptr; char *buffer; struct vorbis_desc *tmp = (struct vorbis_desc *)s->_private; tmp->writing = 0; ogg_sync_init(&tmp->oy); buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE); bytes = fread(buffer, 1, BLOCK_SIZE, s->f); ogg_sync_wrote(&tmp->oy, bytes); result = ogg_sync_pageout(&tmp->oy, &tmp->og); if (result != 1) { if(bytes < BLOCK_SIZE) { ast_log(LOG_ERROR, "Run out of data.../n"); } else { ast_log(LOG_ERROR, "Input does not appear to be an Ogg bitstream./n"); } ogg_sync_clear(&tmp->oy); return -1; } ogg_stream_init(&tmp->os, ogg_page_serialno(&tmp->og)); vorbis_info_init(&tmp->vi); vorbis_comment_init(&tmp->vc); if (ogg_stream_pagein(&tmp->os, &tmp->og) < 0) { ast_log(LOG_ERROR, "Error reading first page of Ogg bitstream data./n");error: ogg_stream_clear(&tmp->os); vorbis_comment_clear(&tmp->vc); vorbis_info_clear(&tmp->vi); ogg_sync_clear(&tmp->oy); return -1; } if (ogg_stream_packetout(&tmp->os, &tmp->op) != 1) { ast_log(LOG_ERROR, "Error reading initial header packet./n"); goto error; } if (vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op) < 0) { ast_log(LOG_ERROR, "This Ogg bitstream does not contain Vorbis audio data./n"); goto error; } for (i = 0; i < 2 ; ) { while (i < 2) { result = ogg_sync_pageout(&tmp->oy, &tmp->og); if (result == 0) break; if (result == 1) { ogg_stream_pagein(&tmp->os, &tmp->og); while(i < 2) { result = ogg_stream_packetout(&tmp->os,&tmp->op); if(result == 0) break; if(result < 0) { ast_log(LOG_ERROR, "Corrupt secondary header. Exiting./n"); goto error; } vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op); i++; } } } buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE); bytes = fread(buffer, 1, BLOCK_SIZE, s->f); if (bytes == 0 && i < 2) { ast_log(LOG_ERROR, "End of file before finding all Vorbis headers!/n"); goto error; } ogg_sync_wrote(&tmp->oy, bytes); } for (ptr = tmp->vc.user_comments; *ptr; ptr++) ast_log(LOG_DEBUG, "OGG/Vorbis comment: %s/n", *ptr); ast_log(LOG_DEBUG, "OGG/Vorbis bitstream is %d channel, %ldHz/n", tmp->vi.channels, tmp->vi.rate); ast_log(LOG_DEBUG, "OGG/Vorbis file encoded by: %s/n", tmp->vc.vendor); if (tmp->vi.channels != 1) { ast_log(LOG_ERROR, "Only monophonic OGG/Vorbis files are currently supported!/n"); goto error; } if (tmp->vi.rate != DEFAULT_SAMPLE_RATE) { ast_log(LOG_ERROR, "Only 8000Hz OGG/Vorbis files are currently supported!/n"); vorbis_block_clear(&tmp->vb); vorbis_dsp_clear(&tmp->vd); goto error; } vorbis_synthesis_init(&tmp->vd, &tmp->vi); vorbis_block_init(&tmp->vd, &tmp->vb); return 0;}
开发者ID:sipwise,项目名称:asterisk,代码行数:101,
示例14: oggvorbis_decode_initstatic int oggvorbis_decode_init(AVCodecContext *avccontext) { OggVorbisDecContext *context = avccontext->priv_data ; uint8_t *p= avccontext->extradata; int i, hsizes[3]; unsigned char *headers[3], *extradata = avccontext->extradata; vorbis_info_init(&context->vi) ; vorbis_comment_init(&context->vc) ; if(! avccontext->extradata_size || ! p) { av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent/n"); return -1; } if(p[0] == 0 && p[1] == 30) { for(i = 0; i < 3; i++){ hsizes[i] = bytestream_get_be16((const uint8_t **)&p); headers[i] = p; p += hsizes[i]; } } else if(*p == 2) { unsigned int offset = 1; p++; for(i=0; i<2; i++) { hsizes[i] = 0; while((*p == 0xFF) && (offset < avccontext->extradata_size)) { hsizes[i] += 0xFF; offset++; p++; } if(offset >= avccontext->extradata_size - 1) { av_log(avccontext, AV_LOG_ERROR, "vorbis header sizes damaged/n"); return -1; } hsizes[i] += *p; offset++; p++; } hsizes[2] = avccontext->extradata_size - hsizes[0]-hsizes[1]-offset;#if 0 av_log(avccontext, AV_LOG_DEBUG, "vorbis header sizes: %d, %d, %d, / extradata_len is %d /n", hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size);#endif headers[0] = extradata + offset; headers[1] = extradata + offset + hsizes[0]; headers[2] = extradata + offset + hsizes[0] + hsizes[1]; } else { av_log(avccontext, AV_LOG_ERROR, "vorbis initial header len is wrong: %d/n", *p); return -1; } for(i=0; i<3; i++){ context->op.b_o_s= i==0; context->op.bytes = hsizes[i]; context->op.packet = headers[i]; if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged/n", i+1); return -1; } } avccontext->channels = context->vi.channels; avccontext->sample_rate = context->vi.rate; avccontext->sample_fmt = AV_SAMPLE_FMT_S16; avccontext->time_base= (AVRational){1, avccontext->sample_rate}; vorbis_synthesis_init(&context->vd, &context->vi); vorbis_block_init(&context->vd, &context->vb); return 0 ;}
开发者ID:0xFFeng,项目名称:ffmpeg,代码行数:74,
示例15: Startbool Start(void *ctx, int iInChannels, int iInRate, int iInBits, const char* title, const char* artist, const char* albumartist, const char* album, const char* year, const char* track, const char* genre, const char* comment, int iTrackLength){ ogg_context *context = (ogg_context *)ctx; if (!context || !context->callbacks.write) return false; // we accept only 2 ch 16bit atm if (iInChannels != 2 || iInBits != 16) return false; if (preset == -1) vorbis_encode_init(&context->vorbisInfo, iInChannels, iInRate, -1, bitrate*1000, -1); else vorbis_encode_init_vbr(&context->vorbisInfo, iInChannels, iInRate, float(preset)/10.0f); /* add a comment */ vorbis_comment comm; vorbis_comment_init(&comm); vorbis_comment_add_tag(&comm, (char*)"comment", (char*)comment); vorbis_comment_add_tag(&comm, (char*)"artist", (char*)artist); vorbis_comment_add_tag(&comm, (char*)"title", (char*)title); vorbis_comment_add_tag(&comm, (char*)"album", (char*)album); vorbis_comment_add_tag(&comm, (char*)"albumartist", (char*)albumartist); vorbis_comment_add_tag(&comm, (char*)"genre", (char*)genre); vorbis_comment_add_tag(&comm, (char*)"tracknumber", (char*)track); vorbis_comment_add_tag(&comm, (char*)"date", (char*)year); /* set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init(&context->vorbisDspState, &context->vorbisInfo); vorbis_block_init(&context->vorbisDspState, &context->vorbisBlock); /* set up our packet->stream encoder */ /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ srand((unsigned int)time(NULL)); ogg_stream_init(&context->oggStreamState, rand()); /* write out the metadata */ ogg_packet header; ogg_packet header_comm; ogg_packet header_code; ogg_page page; vorbis_analysis_headerout(&context->vorbisDspState, &comm, &header, &header_comm, &header_code); ogg_stream_packetin(&context->oggStreamState, &header); ogg_stream_packetin(&context->oggStreamState, &header_comm); ogg_stream_packetin(&context->oggStreamState, &header_code); while (1) { /* This ensures the actual * audio data will start on a new page, as per spec */ int result = ogg_stream_flush(&context->oggStreamState, &page); if (result == 0) break; context->callbacks.write(context->callbacks.opaque, page.header, page.header_len); context->callbacks.write(context->callbacks.opaque, page.body, page.body_len); } vorbis_comment_clear(&comm); context->inited = true; return true;}
开发者ID:jmarshallnz,项目名称:audioencoder.vorbis,代码行数:71,
示例16: WXUNUSEDint ExportOGG::Export(AudacityProject *project, int numChannels, const wxString &fName, bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec, const Tags *metadata, int WXUNUSED(subformat)){ double rate = project->GetRate(); const TrackList *tracks = project->GetTracks(); double quality = (gPrefs->Read(wxT("/FileFormats/OggExportQuality"), 50)/(float)100.0); wxLogNull logNo; // temporarily disable wxWidgets error messages int updateResult = eProgressSuccess; int eos = 0; FileIO outFile(fName, FileIO::Output); if (!outFile.IsOpened()) { wxMessageBox(_("Unable to open target file for writing")); return false; } // All the Ogg and Vorbis encoding data ogg_stream_state stream; ogg_page page; ogg_packet packet; vorbis_info info; vorbis_comment comment; vorbis_dsp_state dsp; vorbis_block block; // Encoding setup vorbis_info_init(&info); vorbis_encode_init_vbr(&info, numChannels, int(rate + 0.5), quality); // Retrieve tags if (!FillComment(project, &comment, metadata)) { return false; } // Set up analysis state and auxiliary encoding storage vorbis_analysis_init(&dsp, &info); vorbis_block_init(&dsp, &block); // Set up packet->stream encoder. According to encoder example, // a random serial number makes it more likely that you can make // chained streams with concatenation. srand(time(NULL)); ogg_stream_init(&stream, rand()); // First we need to write the required headers: // 1. The Ogg bitstream header, which contains codec setup params // 2. The Vorbis comment header // 3. The bitstream codebook. // // After we create those our responsibility is complete, libvorbis will // take care of any other ogg bistream constraints (again, according // to the example encoder source) ogg_packet bitstream_header; ogg_packet comment_header; ogg_packet codebook_header; vorbis_analysis_headerout(&dsp, &comment, &bitstream_header, &comment_header, &codebook_header); // Place these headers into the stream ogg_stream_packetin(&stream, &bitstream_header); ogg_stream_packetin(&stream, &comment_header); ogg_stream_packetin(&stream, &codebook_header); // Flushing these headers now guarentees that audio data will // start on a NEW page, which apparently makes streaming easier while (ogg_stream_flush(&stream, &page)) { outFile.Write(page.header, page.header_len); outFile.Write(page.body, page.body_len); } const WaveTrackConstArray waveTracks = tracks->GetWaveTrackConstArray(selectionOnly, false); { auto mixer = CreateMixer(waveTracks, tracks->GetTimeTrack(), t0, t1, numChannels, SAMPLES_PER_RUN, false, rate, floatSample, true, mixerSpec); ProgressDialog progress(wxFileName(fName).GetName(), selectionOnly ? _("Exporting the selected audio as Ogg Vorbis") : _("Exporting the entire project as Ogg Vorbis")); while (updateResult == eProgressSuccess && !eos) { float **vorbis_buffer = vorbis_analysis_buffer(&dsp, SAMPLES_PER_RUN); sampleCount samplesThisRun = mixer->Process(SAMPLES_PER_RUN); if (samplesThisRun == 0) {//.........这里部分代码省略.........
开发者ID:AthiVarathan,项目名称:audacity,代码行数:101,
示例17: vorbis_read_header//.........这里部分代码省略......... } ; } ; /* ** At this point, we're sure we're Vorbis. We've set up the logical (Ogg) ** bitstream decoder. Get the comment and codebook headers and set up the ** Vorbis decoder. ** ** The next two packets in order are the comment and codebook headers. ** They're likely large and may span multiple pages. Thus we reead ** and submit data until we get our two pacakets, watching that no ** pages are missing. If a page is missing, error out ; losing a ** header page is the only place where missing data is fatal. */ i = 0 ; /* Count of number of packets read */ while (i < 2) { int result = ogg_sync_pageout (&odata->osync, &odata->opage) ; if (result == 0) { /* Need more data */ buffer = ogg_sync_buffer (&odata->osync, 4096) ; bytes = psf_fread (buffer, 1, 4096, psf) ; if (bytes == 0 && i < 2) { psf_log_printf (psf, "End of file before finding all Vorbis headers!/n") ; return SFE_MALFORMED_FILE ; } ; nn = ogg_sync_wrote (&odata->osync, bytes) ; } else if (result == 1) { /* ** Don't complain about missing or corrupt data yet. We'll ** catch it at the packet output phase. ** ** We can ignore any errors here as they'll also become apparent ** at packetout. */ nn = ogg_stream_pagein (&odata->ostream, &odata->opage) ; while (i < 2) { result = ogg_stream_packetout (&odata->ostream, &odata->opacket) ; if (result == 0) break ; if (result < 0) { /* Uh oh ; data at some point was corrupted or missing! ** We can't tolerate that in a header. Die. */ psf_log_printf (psf, "Corrupt secondary header. Exiting./n") ; return SFE_MALFORMED_FILE ; } ; vorbis_synthesis_headerin (&vdata->vinfo, &vdata->vcomment, &odata->opacket) ; i++ ; } ; } ; } ; if (log_data) { int printed_metadata_msg = 0 ; int k ; psf_log_printf (psf, "Bitstream is %d channel, %D Hz/n", vdata->vinfo.channels, vdata->vinfo.rate) ; psf_log_printf (psf, "Encoded by : %s/n", vdata->vcomment.vendor) ; /* Throw the comments plus a few lines about the bitstream we're decoding. */ for (k = 0 ; k < ARRAY_LEN (vorbis_metatypes) ; k++) { char *dd ; dd = vorbis_comment_query (&vdata->vcomment, vorbis_metatypes [k].name, 0) ; if (dd == NULL) continue ; if (printed_metadata_msg == 0) { psf_log_printf (psf, "Metadata :/n") ; printed_metadata_msg = 1 ; } ; psf_store_string (psf, vorbis_metatypes [k].id, dd) ; psf_log_printf (psf, " %-10s : %s/n", vorbis_metatypes [k].name, dd) ; } ; psf_log_printf (psf, "End/n") ; } ; psf->sf.samplerate = vdata->vinfo.rate ; psf->sf.channels = vdata->vinfo.channels ; psf->sf.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; /* OK, got and parsed all three headers. Initialize the Vorbis ** packet->PCM decoder. ** Central decode state. */ vorbis_synthesis_init (&vdata->vdsp, &vdata->vinfo) ; /* Local state for most of the decode so multiple block decodes can ** proceed in parallel. We could init multiple vorbis_block structures ** for vd here. */ vorbis_block_init (&vdata->vdsp, &vdata->vblock) ; vdata->loc = 0 ; return 0 ;} /* vorbis_read_header */
开发者ID:stohrendorf,项目名称:libsndfile,代码行数:101,
示例18: vorbis_write_headerstatic intvorbis_write_header (SF_PRIVATE *psf, int UNUSED (calc_length)){ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ; VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ; int k, ret ; vorbis_info_init (&vdata->vinfo) ; /* The style of encoding should be selectable here, VBR quality mode. */ ret = vorbis_encode_init_vbr (&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, vdata->quality) ;#if 0 ret = vorbis_encode_init (&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, -1, 128000, -1) ; /* average bitrate mode */ ret = ( vorbis_encode_setup_managed (&vdata->vinfo, psf->sf.channels, psf->sf.samplerate, -1, 128000, -1) || vorbis_encode_ctl (&vdata->vinfo, OV_ECTL_RATEMANAGE_AVG, NULL) || vorbis_encode_setup_init (&vdata->vinfo) ) ;#endif if (ret) return SFE_BAD_OPEN_FORMAT ; vdata->loc = 0 ; /* add a comment */ vorbis_comment_init (&vdata->vcomment) ; vorbis_comment_add_tag (&vdata->vcomment, "ENCODER", "libsndfile") ; for (k = 0 ; k < SF_MAX_STRINGS ; k++) { const char * name ; if (psf->strings.data [k].type == 0) break ; switch (psf->strings.data [k].type) { case SF_STR_TITLE : name = "TITLE" ; break ; case SF_STR_COPYRIGHT : name = "COPYRIGHT" ; break ; case SF_STR_SOFTWARE : name = "SOFTWARE" ; break ; case SF_STR_ARTIST : name = "ARTIST" ; break ; case SF_STR_COMMENT : name = "COMMENT" ; break ; case SF_STR_DATE : name = "DATE" ; break ; case SF_STR_ALBUM : name = "ALBUM" ; break ; case SF_STR_LICENSE : name = "LICENSE" ; break ; case SF_STR_TRACKNUMBER : name = "Tracknumber" ; break ; case SF_STR_GENRE : name = "Genre" ; break ; default : continue ; } ; vorbis_comment_add_tag (&vdata->vcomment, name, psf->strings.storage + psf->strings.data [k].offset) ; } ; /* set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init (&vdata->vdsp, &vdata->vinfo) ; vorbis_block_init (&vdata->vdsp, &vdata->vblock) ; /* ** Set up our packet->stream encoder. ** Pick a random serial number ; that way we can more likely build ** chained streams just by concatenation. */ ogg_stream_init (&odata->ostream, psf_rand_int32 ()) ; /* Vorbis streams begin with three headers ; the initial header (with most of the codec setup parameters) which is mandated by the Ogg bitstream spec. The second header holds any comment fields. The third header holds the bitstream codebook. We merely need to make the headers, then pass them to libvorbis one at a time ; libvorbis handles the additional Ogg bitstream constraints */ { ogg_packet header ; ogg_packet header_comm ; ogg_packet header_code ; int result ; vorbis_analysis_headerout (&vdata->vdsp, &vdata->vcomment, &header, &header_comm, &header_code) ; ogg_stream_packetin (&odata->ostream, &header) ; /* automatically placed in its own page */ ogg_stream_packetin (&odata->ostream, &header_comm) ; ogg_stream_packetin (&odata->ostream, &header_code) ;//.........这里部分代码省略.........
开发者ID:stohrendorf,项目名称:libsndfile,代码行数:101,
示例19: oe_encodeint oe_encode ( oe_enc_opt* opt ){ ogg_stream_state os; ogg_page og; ogg_packet op; vorbis_dsp_state vd; vorbis_block vb; vorbis_info vi; long samplesdone = 0; int eos; long bytes_written = 0; long packetsdone = 0; int ret = 0; vorbis_info_init ( &vi ); if ( opt->quality >= 0.0f ) { if ( vorbis_encode_init_vbr ( &vi, opt->channels, opt->rate, opt->quality ) ) { vorbis_info_clear ( &vi ); return 1; } } else { if ( vorbis_encode_init ( &vi, opt->channels, opt->rate, opt->max_bitrate > 0 ? opt->max_bitrate * 1000 : -1, opt->bitrate * 1000, opt->min_bitrate > 0 ? opt->min_bitrate * 1000 : -1 ) ) { vorbis_info_clear ( &vi ); return 1; } } vorbis_analysis_init ( &vd, &vi ); vorbis_block_init ( &vd, &vb ); ogg_stream_init ( &os, opt->serialno ); ogg_packet header_main; ogg_packet header_comments; ogg_packet header_codebooks; int result; vorbis_analysis_headerout ( &vd,opt->comments, &header_main, &header_comments, &header_codebooks ); ogg_stream_packetin ( &os, &header_main ); ogg_stream_packetin ( &os, &header_comments ); ogg_stream_packetin ( &os, &header_codebooks ); while ( ( result = ogg_stream_flush ( &os, &og ) ) ) { if ( !result ) break; ret = oe_write_page ( &og, opt->out ); if ( ret != og.header_len + og.body_len ) { ret = 1; goto cleanup; } else bytes_written += ret; } eos = 0; while ( !eos ) { float** buffer = vorbis_analysis_buffer ( &vd, READSIZE ); long samples_read = opt->read_samples ( opt->readdata, buffer, READSIZE ); if ( samples_read == 0 ) vorbis_analysis_wrote ( &vd, 0 ); else { samplesdone += samples_read; vorbis_analysis_wrote ( &vd, samples_read ); } while ( vorbis_analysis_blockout ( &vd, &vb ) == 1 ) { vorbis_analysis ( &vb, NULL ); vorbis_bitrate_addblock ( &vb ); while ( vorbis_bitrate_flushpacket ( &vd, &op ) ) { ogg_stream_packetin ( &os,&op ); packetsdone++;//.........这里部分代码省略.........
开发者ID:Fliper12,项目名称:darkbasicpro,代码行数:101,
示例20: OGV_LoadAudio/* return: audio wants more packets*/static qboolean OGV_LoadAudio(cinematic_t *cin){ qboolean anyDataTransferred = qtrue; float **pcm; int frames, frameNeeded; int i, j; short *ptr; ogg_packet op; vorbis_block vb; memset(&op, 0, sizeof(op)); memset(&vb, 0, sizeof(vb)); vorbis_block_init(&g_ogm->vd, &vb); while (anyDataTransferred && g_ogm->currentTime + MAX_AUDIO_PRELOAD > (int)(g_ogm->vd.granulepos * 1000 / g_ogm->vi.rate)) { anyDataTransferred = qfalse; if ((frames = vorbis_synthesis_pcmout(&g_ogm->vd, &pcm)) > 0) { // vorbis -> raw ptr = (short *)g_ogm->audioBuffer; frameNeeded = (SIZEOF_RAWBUFF) / (OGG_SAMPLEWIDTH * g_ogm->vi.channels); if (frames < frameNeeded) { frameNeeded = frames; } for (i = 0; i < frameNeeded; i++) { for (j = 0; j < g_ogm->vi.channels; j++) { *(ptr++) = (short)((pcm[j][i] >= -1.0f && pcm[j][i] <= 1.0f) ? pcm[j][i] * 32767.f : 32767 * ((pcm[j][i] > 0.0f) - (pcm[j][i] < 0.0f))); } } // tell libvorbis how many samples we actually consumed (we ate them all!) vorbis_synthesis_read(&g_ogm->vd, frameNeeded); if (!(cin->flags & CIN_silent)) { S_RawSamples(0, frameNeeded, g_ogm->vi.rate, OGG_SAMPLEWIDTH, g_ogm->vi.channels, g_ogm->audioBuffer, 1.0f, 1.0f); } anyDataTransferred = qtrue; } if (!anyDataTransferred) { // op -> vorbis if (ogg_stream_packetout(&g_ogm->os_audio, &op)) { if (vorbis_synthesis(&vb, &op) == 0) { vorbis_synthesis_blockin(&g_ogm->vd, &vb); } anyDataTransferred = qtrue; } } } vorbis_block_clear(&vb); return (qboolean)(g_ogm->currentTime + MIN_AUDIO_PRELOAD > (int)(g_ogm->vd.granulepos * 1000 / g_ogm->vi.rate));}
开发者ID:dstaesse,项目名称:etlegacy,代码行数:71,
示例21: encode_vorbis_file//.........这里部分代码省略......... /********** Encode setup ************/ /* choose an encoding mode */ /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */ vorbis_info_init(&vi); // always encode to mono // SL-52913 & SL-53779 determined this quality level to be our 'good // enough' general-purpose quality level with a nice low bitrate. // Equivalent to oggenc -q0.5 F32 quality = 0.05f;// quality = (bitrate==128000 ? 0.4f : 0.1);// if (vorbis_encode_init(&vi, /* num_channels */ 1 ,sample_rate, -1, bitrate, -1)) if (vorbis_encode_init_vbr(&vi, /* num_channels */ 1 ,sample_rate, quality))// if (vorbis_encode_setup_managed(&vi,1,sample_rate,-1,bitrate,-1) ||// vorbis_encode_ctl(&vi,OV_ECTL_RATEMANAGE_AVG,NULL) ||// vorbis_encode_setup_init(&vi)) { llwarns << "unable to initialize vorbis codec at quality " << quality << llendl; // llwarns << "unable to initialize vorbis codec at bitrate " << bitrate << llendl; return(LLVORBISENC_DEST_OPEN_ERR); } /* add a comment */ vorbis_comment_init(&vc);// vorbis_comment_add(&vc,"Linden"); /* set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init(&vd,&vi); vorbis_block_init(&vd,&vb); /* set up our packet->stream encoder */ /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ ogg_stream_init(&os, ll_rand()); /* Vorbis streams begin with three headers; the initial header (with most of the codec setup parameters) which is mandated by the Ogg bitstream spec. The second header holds any comment fields. The third header holds the bitstream codebook. We merely need to make the headers, then pass them to libvorbis one at a time; libvorbis handles the additional Ogg bitstream constraints */ { ogg_packet header; ogg_packet header_comm; ogg_packet header_code; vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code); ogg_stream_packetin(&os,&header); /* automatically placed in its own page */ ogg_stream_packetin(&os,&header_comm); ogg_stream_packetin(&os,&header_code); /* We don't have to write out here, but doing so makes streaming * much easier, so we do, flushing ALL pages. This ensures the actual * audio data will start on a new page */ while(!eos){ int result=ogg_stream_flush(&os,&og); if(result==0)break; outfile.write(og.header, og.header_len);
开发者ID:1234-,项目名称:SingularityViewer,代码行数:67,
示例22: main//.........这里部分代码省略......... } i++; } } } /* no harm in not checking before adding more */ buffer=ogg_sync_buffer(&oy,4096); //bytes=fread(buffer,1,4096,stdin); bytes=fread(buffer,1,4096,instream); if(bytes==0 && i<2){ fprintf(stderr,"End of file before finding all Vorbis headers!/n"); exit(1); } ogg_sync_wrote(&oy,bytes); } /* Throw the comments plus a few lines about the bitstream we're decoding */ { char **ptr=vc.user_comments; while(*ptr){ fprintf(stderr,"%s/n",*ptr); ++ptr; } fprintf(stderr,"/nBitstream is %d channel, %ldHz/n",vi.channels,vi.rate); fprintf(stderr,"Encoded by: %s/n/n",vc.vendor); } convsize=4096/vi.channels; /* OK, got and parsed all three headers. Initialize the Vorbis packet->PCM decoder. */ if(vorbis_synthesis_init(&vd,&vi)==0){ /* central decode state */ vorbis_block_init(&vd,&vb); /* local state for most of the decode so multiple block decodes can proceed in parallel. We could init multiple vorbis_block structures for vd here */ /* The rest is just a straight decode loop until end of stream */ while(!eos){ while(!eos){ int result=ogg_sync_pageout(&oy,&og); if(result==0)break; /* need more data */ if(result<0){ /* missing or corrupt data at this page position */ fprintf(stderr,"Corrupt or missing data in bitstream; " "continuing.../n"); }else{ ogg_stream_pagein(&os,&og); /* can safely ignore errors at this point */ while(1){ result=ogg_stream_packetout(&os,&op); if(result==0)break; /* need more data */ if(result<0){ /* missing or corrupt data at this page position */ /* no reason to complain; already complained above */ }else{ /* we have a packet. Decode it */ float **pcm; int samples; if(vorbis_synthesis(&vb,&op)==0) /* test for success! */ vorbis_synthesis_blockin(&vd,&vb); /* **pcm is a multichannel float vector. In stereo, for
开发者ID:KolorKode,项目名称:Stg,代码行数:67,
示例23: main//.........这里部分代码省略......... --------------------------------------------------------------------- Encoding using an average bitrate mode (ABR). example: 44kHz stereo coupled, average 128kbps VBR ret = vorbis_encode_init(&vi,2,44100,-1,128000,-1); --------------------------------------------------------------------- Encode using a quality mode, but select that quality mode by asking for an approximate bitrate. This is not ABR, it is true VBR, but selected using the bitrate interface, and then turning bitrate management off: ret = ( vorbis_encode_setup_managed(&vi,2,44100,-1,128000,-1) || vorbis_encode_ctl(&vi,OV_ECTL_RATEMANAGE2_SET,NULL) || vorbis_encode_setup_init(&vi)); *********************************************************************/ ret=vorbis_encode_init_vbr(&vi,2,44100,0.1); /* do not continue if setup failed; this can happen if we ask for a mode that libVorbis does not support (eg, too low a bitrate, etc, will return 'OV_EIMPL') */ if(ret)exit(1); /* add a comment */ vorbis_comment_init(&vc); vorbis_comment_add_tag(&vc,"ENCODER","encoder_example.c"); /* set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init(&vd,&vi); vorbis_block_init(&vd,&vb); /* set up our packet->stream encoder */ /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ srand(time(NULL)); ogg_stream_init(&os,rand()); /* Vorbis streams begin with three headers; the initial header (with most of the codec setup parameters) which is mandated by the Ogg bitstream spec. The second header holds any comment fields. The third header holds the bitstream codebook. We merely need to make the headers, then pass them to libvorbis one at a time; libvorbis handles the additional Ogg bitstream constraints */ { ogg_packet header; ogg_packet header_comm; ogg_packet header_code; vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code); ogg_stream_packetin(&os,&header); /* automatically placed in its own page */ ogg_stream_packetin(&os,&header_comm); ogg_stream_packetin(&os,&header_code); /* This ensures the actual * audio data will start on a new page, as per spec */ while(!eos){ int result=ogg_stream_flush(&os,&og); if(result==0)break; fwrite(og.header,1,og.header_len,stdout);
开发者ID:John-He-928,项目名称:krkrz,代码行数:67,
示例24: ProcessHeaders/***************************************************************************** * ProcessHeaders: process Vorbis headers. *****************************************************************************/static int ProcessHeaders( decoder_t *p_dec ){ decoder_sys_t *p_sys = p_dec->p_sys; ogg_packet oggpacket; unsigned pi_size[XIPH_MAX_HEADER_COUNT]; void *pp_data[XIPH_MAX_HEADER_COUNT]; unsigned i_count; if( xiph_SplitHeaders( pi_size, pp_data, &i_count, p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) ) return VLC_EGENERIC; if( i_count < 3 ) return VLC_EGENERIC; oggpacket.granulepos = -1; oggpacket.e_o_s = 0; oggpacket.packetno = 0; /* Take care of the initial Vorbis header */ oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */ oggpacket.bytes = pi_size[0]; oggpacket.packet = pp_data[0]; if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 ) { msg_Err( p_dec, "this bitstream does not contain Vorbis audio data"); return VLC_EGENERIC; } /* Setup the format */ p_dec->fmt_out.audio.i_rate = p_sys->vi.rate; p_dec->fmt_out.audio.i_channels = p_sys->vi.channels; if( p_dec->fmt_out.audio.i_channels >= ARRAY_SIZE(pi_channels_maps) ) { msg_Err( p_dec, "invalid number of channels (1-%zu): %i", ARRAY_SIZE(pi_channels_maps), p_dec->fmt_out.audio.i_channels ); return VLC_EGENERIC; } p_dec->fmt_out.audio.i_physical_channels = p_dec->fmt_out.audio.i_original_channels = pi_channels_maps[p_sys->vi.channels]; p_dec->fmt_out.i_bitrate = __MAX( 0, (int32_t) p_sys->vi.bitrate_nominal ); date_Init( &p_sys->end_date, p_sys->vi.rate, 1 ); msg_Dbg( p_dec, "channels:%d samplerate:%ld bitrate:%ud", p_sys->vi.channels, p_sys->vi.rate, p_dec->fmt_out.i_bitrate ); /* The next packet in order is the comments header */ oggpacket.b_o_s = 0; oggpacket.bytes = pi_size[1]; oggpacket.packet = pp_data[1]; if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 ) { msg_Err( p_dec, "2nd Vorbis header is corrupted" ); return VLC_EGENERIC; } ParseVorbisComments( p_dec ); /* The next packet in order is the codebooks header * We need to watch out that this packet is not missing as a * missing or corrupted header is fatal. */ oggpacket.b_o_s = 0; oggpacket.bytes = pi_size[2]; oggpacket.packet = pp_data[2]; if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 ) { msg_Err( p_dec, "3rd Vorbis header is corrupted" ); return VLC_EGENERIC; } if( !p_sys->b_packetizer ) { /* Initialize the Vorbis packet->PCM decoder */ vorbis_synthesis_init( &p_sys->vd, &p_sys->vi ); vorbis_block_init( &p_sys->vd, &p_sys->vb ); } else { p_dec->fmt_out.i_extra = p_dec->fmt_in.i_extra; p_dec->fmt_out.p_extra = xrealloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra ); memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra ); } ConfigureChannelOrder(p_sys->pi_chan_table, p_sys->vi.channels, p_dec->fmt_out.audio.i_physical_channels, true); return VLC_SUCCESS;}
开发者ID:J861449197,项目名称:vlc,代码行数:96,
示例25: vorbis_openstatic gint vorbis_open(void){ ogg_packet header; ogg_packet header_comm; ogg_packet header_code; vorbis_init(NULL); vorbis_info_init(&vi); vorbis_comment_init(&vc); if (tuple) { gchar tmpstr[32]; gint scrint; add_string_from_tuple (& vc, "title", tuple, FIELD_TITLE); add_string_from_tuple (& vc, "artist", tuple, FIELD_ARTIST); add_string_from_tuple (& vc, "album", tuple, FIELD_ALBUM); add_string_from_tuple (& vc, "genre", tuple, FIELD_GENRE); add_string_from_tuple (& vc, "date", tuple, FIELD_DATE); add_string_from_tuple (& vc, "comment", tuple, FIELD_COMMENT); if ((scrint = tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL))) { g_snprintf(tmpstr, sizeof(tmpstr), "%d", scrint); vorbis_comment_add_tag(&vc, "tracknumber", tmpstr); } if ((scrint = tuple_get_int(tuple, FIELD_YEAR, NULL))) { g_snprintf(tmpstr, sizeof(tmpstr), "%d", scrint); vorbis_comment_add_tag(&vc, "year", tmpstr); } } if (vorbis_encode_init_vbr (& vi, input.channels, input.frequency, v_base_quality)) { vorbis_info_clear(&vi); return 0; } vorbis_analysis_init(&vd, &vi); vorbis_block_init(&vd, &vb); srand(time(NULL)); ogg_stream_init(&os, rand()); vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code); ogg_stream_packetin(&os, &header); ogg_stream_packetin(&os, &header_comm); ogg_stream_packetin(&os, &header_code); while (ogg_stream_flush (& os, & og)) { write_output(og.header, og.header_len); write_output(og.body, og.body_len); } return 1;}
开发者ID:ivan-dives,项目名称:audacious-plugins,代码行数:63,
示例26: ERR_FAIL_COND//.........这里部分代码省略......... fprintf(stderr, "Error parsing Theora stream headers; " "corrupt stream?/n"); clear(); return; } theora_p++; } /* look for more vorbis header packets */ while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(&vo, &op))) { if (ret < 0) { fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?/n"); clear(); return; } ret = vorbis_synthesis_headerin(&vi, &vc, &op); if (ret) { fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?/n"); clear(); return; } vorbis_p++; if (vorbis_p == 3) break; } /* The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec */ if (ogg_sync_pageout(&oy, &og) > 0) { queue_page(&og); /* demux into the appropriate stream */ } else { int ret = buffer_data(); /* someone needs more data */ if (ret == 0) { fprintf(stderr, "End of file while searching for codec headers./n"); clear(); return; } } } /* and now we have it all. initialize decoders */ if (theora_p) { td = th_decode_alloc(&ti, ts); printf("Ogg logical stream %lx is Theora %dx%d %.02f fps", to.serialno, ti.pic_width, ti.pic_height, (double)ti.fps_numerator / ti.fps_denominator); px_fmt = ti.pixel_fmt; switch (ti.pixel_fmt) { case TH_PF_420: printf(" 4:2:0 video/n"); break; case TH_PF_422: printf(" 4:2:2 video/n"); break; case TH_PF_444: printf(" 4:4:4 video/n"); break; case TH_PF_RSVD: default: printf(" video/n (UNKNOWN Chroma sampling!)/n"); break; } if (ti.pic_width != ti.frame_width || ti.pic_height != ti.frame_height) printf(" Frame content is %dx%d with offset (%d,%d)./n", ti.frame_width, ti.frame_height, ti.pic_x, ti.pic_y); th_decode_ctl(td, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max, sizeof(pp_level_max)); pp_level = 0; th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, sizeof(pp_level)); pp_inc = 0; int w; int h; w = (ti.pic_x + ti.frame_width + 1 & ~1) - (ti.pic_x & ~1); h = (ti.pic_y + ti.frame_height + 1 & ~1) - (ti.pic_y & ~1); size.x = w; size.y = h; texture->create(w, h, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE); } else { /* tear down the partial theora setup */ th_info_clear(&ti); th_comment_clear(&tc); } th_setup_free(ts); if (vorbis_p) { vorbis_synthesis_init(&vd, &vi); vorbis_block_init(&vd, &vb); fprintf(stderr, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio./n", vo.serialno, vi.channels, vi.rate); //_setup(vi.channels, vi.rate); } else { /* tear down the partial vorbis setup */ vorbis_info_clear(&vi); vorbis_comment_clear(&vc); } playing = false; buffering = true; time = 0; audio_frames_wrote = 0;};
开发者ID:Bonfi96,项目名称:godot,代码行数:101,
示例27: OpenEncoder/***************************************************************************** * OpenEncoder: probe the encoder and return score *****************************************************************************/static int OpenEncoder( vlc_object_t *p_this ){ encoder_t *p_enc = (encoder_t *)p_this; encoder_sys_t *p_sys; int i_quality, i_min_bitrate, i_max_bitrate; ogg_packet header[3]; if( p_enc->fmt_out.i_codec != VLC_CODEC_VORBIS && !p_enc->b_force ) { return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL ) return VLC_ENOMEM; p_enc->p_sys = p_sys; p_enc->pf_encode_audio = Encode; p_enc->fmt_in.i_codec = VLC_CODEC_FL32; p_enc->fmt_out.i_codec = VLC_CODEC_VORBIS; config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg ); i_quality = var_GetInteger( p_enc, ENC_CFG_PREFIX "quality" ); if( i_quality > 10 ) i_quality = 10; if( i_quality < 0 ) i_quality = 0; if( var_GetBool( p_enc, ENC_CFG_PREFIX "cbr" ) ) i_quality = 0; i_max_bitrate = var_GetInteger( p_enc, ENC_CFG_PREFIX "max-bitrate" ); i_min_bitrate = var_GetInteger( p_enc, ENC_CFG_PREFIX "min-bitrate" ); /* Initialize vorbis encoder */ vorbis_info_init( &p_sys->vi ); if( i_quality > 0 ) { /* VBR mode */ if( vorbis_encode_setup_vbr( &p_sys->vi, p_enc->fmt_in.audio.i_channels, p_enc->fmt_in.audio.i_rate, i_quality * 0.1 ) ) { vorbis_info_clear( &p_sys->vi ); free( p_enc->p_sys ); msg_Err( p_enc, "VBR mode initialisation failed" ); return VLC_EGENERIC; } /* Do we have optional hard quality restrictions? */ if( i_max_bitrate > 0 || i_min_bitrate > 0 ) { struct ovectl_ratemanage_arg ai; vorbis_encode_ctl( &p_sys->vi, OV_ECTL_RATEMANAGE_GET, &ai ); ai.bitrate_hard_min = i_min_bitrate; ai.bitrate_hard_max = i_max_bitrate; ai.management_active = 1; vorbis_encode_ctl( &p_sys->vi, OV_ECTL_RATEMANAGE_SET, &ai ); } else { /* Turn off management entirely */ vorbis_encode_ctl( &p_sys->vi, OV_ECTL_RATEMANAGE_SET, NULL ); } } else { if( vorbis_encode_setup_managed( &p_sys->vi, p_enc->fmt_in.audio.i_channels, p_enc->fmt_in.audio.i_rate, i_min_bitrate > 0 ? i_min_bitrate * 1000: -1, p_enc->fmt_out.i_bitrate, i_max_bitrate > 0 ? i_max_bitrate * 1000: -1 ) ) { vorbis_info_clear( &p_sys->vi ); msg_Err( p_enc, "CBR mode initialisation failed" ); free( p_enc->p_sys ); return VLC_EGENERIC; } } vorbis_encode_setup_init( &p_sys->vi ); /* Add a comment */ vorbis_comment_init( &p_sys->vc); vorbis_comment_add_tag( &p_sys->vc, "ENCODER", "VLC media player"); /* Set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init( &p_sys->vd, &p_sys->vi ); vorbis_block_init( &p_sys->vd, &p_sys->vb ); /* Create and store headers */ vorbis_analysis_headerout( &p_sys->vd, &p_sys->vc, &header[0], &header[1], &header[2]); for( int i = 0; i < 3; i++ ) {//.........这里部分代码省略.........
开发者ID:J861449197,项目名称:vlc,代码行数:101,
示例28: OggInit//.........这里部分代码省略......... ogg_stream_pagein(&data->vstream, &data->page); }#endif stream_start = 1; break; } ogg_stream_init(&test, ogg_page_serialno(&data->page)); ogg_stream_pagein(&test, &data->page); // initial codec headers while (ogg_stream_packetout(&test, &packet) == 1) {#ifdef USE_THEORA if (theora_decode_header(&data->tinfo, &data->tcomment, &packet) >= 0) { memcpy(&data->vstream, &test, sizeof(test)); ++num_theora; } else#endif if (!vorbis_synthesis_headerin(&data->vinfo, &data->vcomment, &packet)) { memcpy(&data->astream, &test, sizeof(test)); ++num_vorbis; } else { ogg_stream_clear(&test); } } } data->audio = num_vorbis;#ifdef USE_THEORA data->video = num_theora;#endif // remainint codec headers while ((num_vorbis && num_vorbis < 3)#ifdef USE_THEORA || (num_theora && num_theora < 3) ) { // are we in the theora page ? while (num_theora && num_theora < 3 && (ret = ogg_stream_packetout(&data->vstream, &packet))) { if (ret < 0) { return -1; } if (theora_decode_header(&data->tinfo, &data->tcomment, &packet)) { return -1; } ++num_theora; }#else ) {#endif // are we in the vorbis page ? while (num_vorbis && num_vorbis < 3 && (ret = ogg_stream_packetout(&data->astream, &packet))) { if (ret < 0) { return -1; } if (vorbis_synthesis_headerin(&data->vinfo, &data->vcomment, &packet)) { return -1; } ++num_vorbis; } if (OggGetNextPage(&data->page, &data->sync, f)) { break; } if (num_vorbis) { ogg_stream_pagein(&data->astream, &data->page); }#ifdef USE_THEORA if (num_theora) { ogg_stream_pagein(&data->vstream, &data->page); }#endif } if (num_vorbis) { vorbis_synthesis_init(&data->vdsp, &data->vinfo); vorbis_block_init(&data->vdsp, &data->vblock); } else { vorbis_info_clear(&data->vinfo); vorbis_comment_clear(&data->vcomment); }#ifdef USE_THEORA if (num_theora) { theora_decode_init(&data->tstate, &data->tinfo); data->tstate.internal_encode = NULL; // needed for a bug in libtheora (fixed in next release) } else { theora_info_clear(&data->tinfo); theora_comment_clear(&data->tcomment); } return !(num_vorbis || num_theora);#else return !num_vorbis;#endif}
开发者ID:OneSleepyDev,项目名称:boswars_osd,代码行数:101,
示例29: lame_encode_ogg_initint lame_encode_ogg_init(lame_global_flags *gfp){ lame_internal_flags *gfc=gfp->internal_flags; char comment[MAX_COMMENT_LENGTH+1]; /********** Encode setup ************/ /* choose an encoding mode */ /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */ if (gfp->compression_ratio < 5.01) { memcpy(&vi2,&info_E,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_E /n" ); } else if (gfp->compression_ratio < 6) { memcpy(&vi2,&info_D,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_D /n" ); } else if (gfp->compression_ratio < 8) { memcpy(&vi2,&info_C,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_C /n" ); } else if (gfp->compression_ratio < 10) { memcpy(&vi2,&info_B,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_B /n" ); } else if (gfp->compression_ratio < 12) { memcpy(&vi2,&info_A,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_A /n" ); } else { memcpy(&vi2,&info_A,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_A /n" ); } vi2.channels = gfc->channels_out; vi2.rate = gfp->out_samplerate; /* add a comment */ vorbis_comment_init(&vc2); vorbis_comment_add(&vc2,"Track encoded using L.A.M.E. libvorbis interface."); /* Add ID3-style comments to the output using (for the time being) the "private data members" in the "id3tag_spec" data structure. This was from a patch by Ralph Giles <[email C++ vorbis_comment_add_tag函数代码示例 C++ vorbis_bitrate_flushpacket函数代码示例
|