public void InitDecoder(bool useJitterBuffer, int stepSize, int frameSize) { this.frameSize = frameSize; decodedBits = new SpeexBits(); decoderState = speex_decoder_init_new(0); fixed(SpeexBits *bitsDecode = &decodedBits) { speex_bits_init(bitsDecode); } if (useJitterBuffer) { jitterBuffer = jitter_buffer_init(stepSize); validJitterBits = false; } }
public int InitEncoder(int maxFrameSize, int samplesPerFrame, int samplingRate) { this.maxFrameSize = maxFrameSize; encodedBits = new SpeexBits(); encoderState = speex_encoder_init_new(0); // Don't set VAD in the codec, because we're setting it in // the preprocessor instead fixed(int *fSize = &frameSize) { speex_encoder_ctl(encoderState, (int)SpeexCtlCode.SPEEX_GET_FRAME_SIZE, fSize); } fixed(SpeexBits *bitsAdd = &encodedBits) { speex_bits_init(bitsAdd); } preprocessState = speex_preprocess_state_init(samplesPerFrame, samplingRate); return(frameSize); }
public static extern int speex_bits_remaining(ref SpeexBits bits);
public static extern void speex_bits_destroy(ref SpeexBits bits);
public static extern uint speex_bits_peek(ref SpeexBits bits);
public static extern void speex_bits_insert_terminator(ref SpeexBits bits);
public extern static int Speex_bits_unpack_signed(ref SpeexBits bits, int nbBits);
/** Frees all resources associated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/ void speex_bits_destroy(SpeexBits *bits);
/** Append bytes to the bit-stream * * @param bits Bit-stream to operate on * @param bytes pointer to the bytes what will be appended * @param len Number of bytes of append */ void speex_bits_read_whole_bytes(SpeexBits *bits, char *bytes, int len);
public static extern void speex_bits_rewind(ref SpeexBits bits);
public static extern void speex_bits_read_from(ref SpeexBits bits, byte[] bytes, int len);
public static extern void speex_bits_read_whole_bytes(ref SpeexBits bits, IntPtr bytes, int len);
public static extern int speex_bits_peek(ref SpeexBits bits);
public static extern void speex_bits_pack(ref SpeexBits bits, int data, int nbBits);
public static extern int speex_bits_nbytes(ref SpeexBits bits);
public static extern void speex_bits_set_bit_buffer(ref SpeexBits bits, IntPtr buff, int buf_size);
IntPtr reserved2; /**< Reserved for future use */ /** Initializes and allocates resources for a SpeexBits struct */ void speex_bits_init(SpeexBits bits);
/** Uses an existing decoder state to decode one frame of speech from * bit-stream bits. The output speech is saved written to out. * * @param state Decoder state * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) * @param out Where to write the decoded frame * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) */ int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out);
/** Rewind the bit-stream to the beginning (ready for read) without erasing the content */ void speex_bits_rewind(SpeexBits *bits);
public extern static IntPtr Speex_bits_init_buffer(ref SpeexBits bits, byte[] ouput, int len);
public static extern uint speex_bits_unpack_unsigned(ref SpeexBits bits, int nbBits);
public static extern void speex_bits_init(ref SpeexBits bits);
public extern static void Speex_bits_reset(ref SpeexBits bits);
public static extern int speex_bits_write(ref SpeexBits bits, byte[] bytes, int max_len);
public extern static void Speex_bits_set_bit_buffer(ref SpeexBits bits, byte[] buff, int buffSize);
public static extern int speex_bits_write_whole_bytes(ref SpeexBits bits, IntPtr bytes, int max_len);
public extern static void Speex_bits_read_from(ref SpeexBits bits, byte[] bytes, int len);
public static extern int speex_decode(IntPtr state, ref SpeexBits bits, IntPtr outFloat);
public static extern uint speex_bits_peek_unsigned(ref SpeexBits bits, int nbBits);
public static extern int speex_decode_int(IntPtr state, ref SpeexBits bits, byte[] outShort);
public static extern void speex_bits_advance(ref SpeexBits bits, int n);
public static extern int speex_encode(IntPtr state, IntPtr inFloat, ref SpeexBits bits);
public static extern int speex_encode_int(IntPtr state, IntPtr inShort, ref SpeexBits bits);
public static extern void speex_bits_init_buffer(ref SpeexBits bits, byte[] buff, int buf_size);
public static extern void speex_encode_stereo(float[] data, int frame_size, ref SpeexBits bits);
/** Sets the bits in a SpeexBits struct to use data from an existing buffer (for decoding without copying data) */ void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size);
public static extern void speex_encode_stereo_int(Int16[] data, int frame_size, ref SpeexBits bits);
/** Resets bits to initial value (just after initialization, erasing content)*/ void speex_bits_reset(SpeexBits *bits);
public static extern int speex_std_stereo_request_handler(ref SpeexBits bits, IntPtr state, IntPtr data);
/** Initializes the bit-stream from the data in an area of memory */ void speex_bits_read_from(SpeexBits *bits, char *bytes, int len);
/** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits);
/** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits);
/** Callback handler for intensity stereo info */ int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data);
/** Uses an existing decoder state to decode one frame of speech from * bit-stream bits. The output speech is saved written to out. * * @param state Decoder state * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost) * @param out Where to write the decoded frame * @return return status (0 for no error, -1 for end of stream, -2 corrupt stream) */ int speex_decode(void *state, SpeexBits *bits, float *out);
public extern static void Speex_bits_init(ref SpeexBits bits);
public extern static int Speex_bits_write(ref SpeexBits bits, byte[] ouput, int len);
public static extern void speex_bits_read_whole_bytes(ref SpeexBits bits, byte[] bytes, int len);
public extern static int Speex_bits_peek(ref SpeexBits bits);
public static extern int speex_bits_write_whole_bytes(ref SpeexBits bits, byte[] bytes, int max_len);
public extern static int Speex_bits_rewind(ref SpeexBits bits);
public extern static void Speex_bits_destroy(ref SpeexBits bits);
public extern static int Speex_bits_nbytes(ref SpeexBits bits);
public extern static int Speex_decode_int(IntPtr state, ref SpeexBits bits, short[] output);