/// <summary> /// Creates a multichannel Opus encoder using the "new API". This constructor allows you to use predefined Vorbis channel mappings, or specify your own. /// </summary> /// <param name="Fs">The samples rate of the input</param> /// <param name="channels">The total number of channels to encode (1 - 255)</param> /// <param name="mapping_family">The mapping family to use. 0 = mono/stereo, 1 = use Vorbis mappings, 255 = use raw channel mapping</param> /// <param name="streams">The number of streams to encode</param> /// <param name="coupled_streams">The number of coupled streams</param> /// <param name="mapping">A raw mapping of input/output channels</param> /// <param name="application">The application to use for the encoders</param> public static OpusMSEncoder CreateSurround( int Fs, int channels, int mapping_family, out int streams, out int coupled_streams, byte[] mapping, OpusApplication application ) { int ret; OpusMSEncoder st; if ((channels > 255) || (channels < 1) || application == OpusApplication.OPUS_APPLICATION_UNIMPLEMENTED) { throw new ArgumentException("Invalid channel count or application"); } BoxedValueInt nb_streams = new BoxedValueInt(); BoxedValueInt nb_coupled_streams = new BoxedValueInt(); GetStreamCount(channels, mapping_family, nb_streams, nb_coupled_streams); st = new OpusMSEncoder(nb_streams.Val, nb_coupled_streams.Val); ret = st.opus_multistream_surround_encoder_init(Fs, channels, mapping_family, out streams, out coupled_streams, mapping, application); if (ret != OpusError.OPUS_OK) { if (ret == OpusError.OPUS_BAD_ARG) { throw new ArgumentException("Bad argument passed to CreateSurround"); } throw new OpusException("Could not create multistream encoder", ret); } return(st); }
/// <summary> /// Creates a new multichannel Opus encoder using the "old API". /// </summary> /// <param name="Fs">The sample rate of the input signal</param> /// <param name="channels">The number of channels to encode (1 - 255)</param> /// <param name="streams">The number of streams to encode</param> /// <param name="coupled_streams">The number of coupled streams</param> /// <param name="mapping">A raw mapping between input and output channels</param> /// <param name="application">The application to use for the encoder</param> public static OpusMSEncoder Create( int Fs, int channels, int streams, int coupled_streams, byte[] mapping, OpusApplication application ) { int ret; if ((channels > 255) || (channels < 1) || (coupled_streams > streams) || (streams < 1) || (coupled_streams < 0) || (streams > 255 - coupled_streams)) { throw new ArgumentException("Invalid channel / stream configuration"); } OpusMSEncoder st = new OpusMSEncoder(streams, coupled_streams); ret = st.opus_multistream_encoder_init(Fs, channels, streams, coupled_streams, mapping, application, 0); if (ret != OpusError.OPUS_OK) { if (ret == OpusError.OPUS_BAD_ARG) { throw new ArgumentException("OPUS_BAD_ARG when creating MS encoder"); } throw new OpusException("Could not create MS encoder", ret); } return(st); }