Exemple #1
0
        public SpeexHeader speex_packet_to_header(byte[] packet, int size)
        {
            int i;
            SpeexHeader le_header;
            const char* h = "Speex   ";
            for (i = 0; i < 8; i++)
                if (packet[i] != h[i])
                {
                    speex.notify("This doesn't look like a Speex file");
                    return null;
                }

            /*FIXME: Do we allow larger headers?*/
            if (size < (int)Marshal.SizeOf(SpeexHeader))
            {
                speex.notify("Speex header too small");
                return null;
            }

            le_header = new SpeexHeader();

            speex.SPEEX_COPY(le_header, (SpeexHeader)packet, 1);

            /*Make sure everything is converted correctly from little-endian*/
            ENDIAN_SWITCH(le_header.speex_version_id);
            ENDIAN_SWITCH(le_header.header_size);
            ENDIAN_SWITCH(le_header.rate);
            ENDIAN_SWITCH(le_header.mode);
            ENDIAN_SWITCH(le_header.mode_bitstream_version);
            ENDIAN_SWITCH(le_header.nb_channels);
            ENDIAN_SWITCH(le_header.bitrate);
            ENDIAN_SWITCH(le_header.frame_size);
            ENDIAN_SWITCH(le_header.vbr);
            ENDIAN_SWITCH(le_header.frames_per_packet);
            ENDIAN_SWITCH(le_header.extra_headers);

            if (le_header.mode >= SPEEX_NB_MODES || le_header.mode < 0)
            {
                speex.notify("Invalid mode specified in Speex header");
                //speex_free (le_header);
                return null;
            }

            if (le_header.nb_channels > 2)
                le_header.nb_channels = 2;
            if (le_header.nb_channels < 1)
                le_header.nb_channels = 1;

            return le_header;

        }
Exemple #2
0
 public SpeexHeader(SpeexHeader header)
 {
 }
Exemple #3
0
        public byte[] speex_header_to_packet(SpeexHeader header, out int size)
        {
            SpeexHeader le_header = new SpeexHeader(header);

            speex.SPEEX_COPY(le_header, header, 1);

            /*Make sure everything is now little-endian*/
            ENDIAN_SWITCH(le_header.speex_version_id);
            ENDIAN_SWITCH(le_header.header_size);
            ENDIAN_SWITCH(le_header.rate);
            ENDIAN_SWITCH(le_header.mode);
            ENDIAN_SWITCH(le_header.mode_bitstream_version);
            ENDIAN_SWITCH(le_header.nb_channels);
            ENDIAN_SWITCH(le_header.bitrate);
            ENDIAN_SWITCH(le_header.frame_size);
            ENDIAN_SWITCH(le_header.vbr);
            ENDIAN_SWITCH(le_header.frames_per_packet);
            ENDIAN_SWITCH(le_header.extra_headers);

            size = Marshal.SizeOf(SpeexHeader);
            return (byte[])le_header;
        }