• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Any C/C++ low level audio guys want to help me with this?

Bulldog13

Golden Member
Details on the question can be found here:

http://stackoverflow.com/questions/...roperties-number-of-channels-bits-per-channel

I am not really sure where to begin. I tried using the binaryreader on the .ogg file and comparing it to the file specification on the stackoverflow thread, but it doesn't really seem to make any sense.

Code:
            var binReader =
                new BinaryReader(File.Open("a.ogg", FileMode.Open));
            try
            {
                // If the file is not empty,
                // read the application settings.
                // First read 4 bytes into a buffer to
                // determine if the file is empty.
                var testArray = new byte[5];
                int fileType = binReader.Read(testArray, 0, 5);

                if (fileType != 0)
                {
                    //    // Reset the position in the stream to zero.
                    binReader.BaseStream.Seek(0, SeekOrigin.Begin);

                    //    aspectRatio = binReader.ReadSingle();
                    //    lookupDir = binReader.ReadString();
                    //    autoSaveTime = binReader.ReadInt32();
                    //    showStatusBar = binReader.ReadBoolean();
                }

                var x = BitConverter.ToUInt32(testArray, 0);

                //var z = BitConverter.ToUInt32(testArray, 4);
            }

                // If the end of the stream is reached before reading
            // the four data values, ignore the error and use the
            // default settings for the remaining values.
            catch (EndOfStreamException)
            {
                Console.WriteLine("{0} caught and ignored. " +
                                  "Using default values.", e.GetType().Name);
            }
            finally
            {
                binReader.Close();
            }

I am a .NET webdeveloper, so alot of this stuff is very foreign to me. All I am trying to do is get some very basic attributes of a .ogg file.
 
Some google guided me to this:
http://www.codeproject.com/KB/audio-video/OggPlayer.aspx

It's for C# but maybe it will be useful to you to examine the sources.

The ogg_decode_one_vorbis_packet function writes PCM (Pulse Code Modulation) data into the given buffer and returns the number of bytes written into that buffer. First it calls the ov_read which returns up to the specified number of bytes of decoded PCM audio in the requested endianness, signedness, and word size. If the audio is multichannel, the channels are interleaved in the output buffer. This function is used to decode a Vorbis file within a loop. Our C# application, which we'll see later, will be doing just that.


Next it calls ov_info which returns the vorbis_info struct for the specified bitstream. This allows us to return the number of channels in the bitstream, and the sampling rate of the bitstream to our C# application. There are basically two errors that can occur: OV_HOLE which indicates there was an interruption in the data, and OV_EBADLINK which indicates that an invalid stream section was supplied, or the requested link is corrupt.


The Ogg Vorbis format allows for multiple logical bitstreams to be combined (with restrictions) into a single physical bitstream. Note that the Vorbisfile API could more or less hide the multiple logical bitstream nature of chaining from an application but, when reading audio back, the application must be aware that multiple bitstream sections do not necessarily use the same number of channels or sampling rate. The Ogg Vorbis documentation provides more information on Ogg logical bitstream framing.
 
Details on the question can be found here:

http://stackoverflow.com/questions/...roperties-number-of-channels-bits-per-channel

I am not really sure where to begin. I tried using the binaryreader on the .ogg file and comparing it to the file specification on the stackoverflow thread, but it doesn't really seem to make any sense.

Code:
            var binReader =
                new BinaryReader(File.Open("a.ogg", FileMode.Open));
            try
            {
                // If the file is not empty,
                // read the application settings.
                // First read 4 bytes into a buffer to
                // determine if the file is empty.
                var testArray = new byte[5];
                int fileType = binReader.Read(testArray, 0, 5);

                if (fileType != 0)
                {
                    //    // Reset the position in the stream to zero.
                    binReader.BaseStream.Seek(0, SeekOrigin.Begin);

                    //    aspectRatio = binReader.ReadSingle();
                    //    lookupDir = binReader.ReadString();
                    //    autoSaveTime = binReader.ReadInt32();
                    //    showStatusBar = binReader.ReadBoolean();
                }

                var x = BitConverter.ToUInt32(testArray, 0);

                //var z = BitConverter.ToUInt32(testArray, 4);
            }

                // If the end of the stream is reached before reading
            // the four data values, ignore the error and use the
            // default settings for the remaining values.
            catch (EndOfStreamException)
            {
                Console.WriteLine("{0} caught and ignored. " +
                                  "Using default values.", e.GetType().Name);
            }
            finally
            {
                binReader.Close();
            }

I am a .NET webdeveloper, so alot of this stuff is very foreign to me. All I am trying to do is get some very basic attributes of a .ogg file.

Short description:

It's reading 5 bytes from the file, and then converting the first 4 bytes into an unsigned integer data format.

Long description:

Files are considered streams in .Net. Basically array of bytes. So when you open a file, you get a stream that you can navigate through, much like a string. The first 4 bytes of the file (or string if you want to think of it) would be in a binary format, and it's taking the first 4 bytes (a 32 bit integer) and copying from that stream/byte array into the actual integer datatype. So the bytes (in hex) might be C0 E8 65 12, that is not a numeric by nature because its in binary form/hex format. You need to convert those hex numbers to their decimal values (0-255) and multiply all those values together to get the real number in a 32 bit integer.

I hope that makes sense.

It's no different than converting a string = "10002343" (8 characters, and 8 bytes in ASCII or 16 bytes in unicode) into a 4 byte integer format.

Binary works a bit different because you do not care about the ASCII/Unicode, which is why a character/string is different than bytes, even though they seem very similar.
 
Back
Top