Dear experts, I am trying to use an example I found here: http://svn.xiph.org/trunk/vorbis/examples/encoder_example.c Could you please tell me what float** buffer is needed for (I don't see it used anywhere). Also, could you please tell me what this code is doing: for(i=0;i<bytes/4;i++){ buffer[0][i]=((readbuffer[i*4+1]<<8)| (0x00ff&(int)readbuffer[i*4]))/32768.f; buffer[1][i]=((readbuffer[i*4+3]<<8)| (0x00ff&(int)readbuffer[i*4+2]))/32768.f; } Again, buffer is not used afterwards. And where does the actual encoding happens? Maybe you could recommend some tutorial to understand how this works? Thank you very much, Dmitriy -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/vorbis-dev/attachments/20110310/aec50933/attachment.htm
ogg.k.ogg.k at googlemail.com
2011-Mar-10 17:15 UTC
[Vorbis-dev] Wav to Ogg Vorbis conversion
> Could you please tell me what float** buffer is needed for (I don't see > it used anywhere).It's needed to pass the samples to libvorbis for encoding. It's used in the libvorbis code. It was returned by vorbis_analysis_buffer for the client code to write samples in, so libvorbis has kept a reference to this buffer internally, and will be using it afterwards.> for(i=0;i<bytes/4;i++){ > > buffer[0][i]=((readbuffer[i*4+1]<<8)| > > (0x00ff&(int)readbuffer[i*4]))/32768.f; > > buffer[1][i]=((readbuffer[i*4+3]<<8)| > > (0x00ff&(int)readbuffer[i*4+2]))/32768.f; > > }This seems to be converting 16 bit stereo integer samples to float samples.> And where does the actual encoding happens?In the libvorbis code, probably _blockout, but it should not matter for you if you're using the libvorbis API.> Maybe you could recommend some tutorial to understand how this works?http://www.bluishcoder.co.nz/2009/06/26/decoding-vorbis-files-with-libvorbis.html
Dear experts,>> for(i=0;i<bytes/4;i++){ >> >> buffer[0][i]=((readbuffer[i*4+1]<<8)| >> >> (0x00ff&(int)readbuffer[i*4]))/32768.f; >> >> buffer[1][i]=((readbuffer[i*4+3]<<8)| >> >> (0x00ff&(int)readbuffer[i*4+2]))/32768.f; >> >> }>This seems to be converting 16 bit stereo integer samples to float samples.Could you please explain to me what each part of the code doing, not just general outcome?>> Maybe you could recommend some tutorial to understand how this works?>http://www.bluishcoder.co.nz/2009/06/26/decoding-vorbis-files-with-libvorbis.htmlThis is decoding tutorial. I wonder if there is any encoding tutorial. Thanks, Dmitriy -----Original Message----- From: ogg.k.ogg.k at googlemail.com [mailto:ogg.k.ogg.k at googlemail.com] Sent: Thursday, March 10, 2011 12:15 PM To: Dmitriy Reznik Cc: vorbis-dev at xiph.org Subject: Re: [Vorbis-dev] Wav to Ogg Vorbis conversion> for(i=0;i<bytes/4;i++){ > > buffer[0][i]=((readbuffer[i*4+1]<<8)| > > (0x00ff&(int)readbuffer[i*4]))/32768.f; > > buffer[1][i]=((readbuffer[i*4+3]<<8)| > > (0x00ff&(int)readbuffer[i*4+2]))/32768.f; > > }This seems to be converting 16 bit stereo integer samples to float samples.> Maybe you could recommend some tutorial to understand how this works?http://www.bluishcoder.co.nz/2009/06/26/decoding-vorbis-files-with-libvorbis.html
Dmitriy Reznik wrote:> I am trying to use an example I found here: > > http://svn.xiph.org/trunk/vorbis/examples/encoder_example.cIf all you want to do is to write data to an Ogg/Vorbis file, you might have a look at libsndfile: http://www.mega-nerd.com/libsndfile/ Writing an Ogg/Vorbis file with libsndfile looks like: SNDFILE *file ; SF_INFO info ; memset (&info, 0, sizeof (info)) ; info.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; info.channels = 2 ; info.samplerate = 44100 ; if ((file = sf_open (filename, SFM_WRITE, &info)) == NULL) handle_error () ; sf_writef_float (file, data, frames) ; sf_close (file) ; Hope this helps. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
Dear Erik, Thank you for your answer. It looks way simpler than what I was trying to do. Could you please answer a few of my questions? 1) Can I add libsndfile to my MFC project, and if yes, how? Because I need to be able to distribute the software in one executable. 2) I have to convert to ogg vorbis not .wav files, but raw wave data stored in multiple BYTE (unsigned char) arrays. Could you please tell me how the code should look then? I want all that data to be converted into one .ogg file. Thank you so much, Dmitriy -----Original Message----- From: vorbis-dev-bounces at xiph.org [mailto:vorbis-dev-bounces at xiph.org] On Behalf Of Erik de Castro Lopo Sent: Thursday, March 10, 2011 5:03 PM To: vorbis-dev at xiph.org Subject: Re: [Vorbis-dev] Wav to Ogg Vorbis conversion Dmitriy Reznik wrote:> I am trying to use an example I found here: > > http://svn.xiph.org/trunk/vorbis/examples/encoder_example.cIf all you want to do is to write data to an Ogg/Vorbis file, you might have a look at libsndfile: http://www.mega-nerd.com/libsndfile/ Writing an Ogg/Vorbis file with libsndfile looks like: SNDFILE *file ; SF_INFO info ; memset (&info, 0, sizeof (info)) ; info.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; info.channels = 2 ; info.samplerate = 44100 ; if ((file = sf_open (filename, SFM_WRITE, &info)) == NULL) handle_error () ; sf_writef_float (file, data, frames) ; sf_close (file) ; Hope this helps. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/ _______________________________________________ Vorbis-dev mailing list Vorbis-dev at xiph.org http://lists.xiph.org/mailman/listinfo/vorbis-dev