Record and playback with Opus Codec in Android
Asked Answered
A

2

7

I'm working on a project that need to record and playback with Opus Codec, I search a lot but I can't find any demo/example using that solution. I find a demo having encoder but can't find the decoder. I only find the source code of this codec using C, can you help me?

Anselma answered 20/11, 2014 at 14:33 Comment(2)
Did you find anything? I'm looking for the same...Adiell
If you just need to record, this app claims to do it: play.google.com/store/apps/…Meimeibers
H
1

Hello that demo is a good place to start, he was realy close to solving it. However each package must be sent separetly from the encoder to the decoder. Instead of saving all to a file and then read them back without any regard of package start.
I modified the code to also write the number of encoded bytes and when I decode, I read first the number of bytes in each packet and then the payload.

Here is the modified code in OpusEncoder.java

public void write( short[] buffer ) throws IOException
    {
        byte[] encodedBuffer = new byte[buffer.length];
        int lenEncodedBytes = this.nativeEncodeBytes( buffer , encodedBuffer);
        Log.i(TAG,"encoded "+lenEncodedBytes+" bytes");
        if (lenEncodedBytes > 0)
        {
            this.out.write(lenEncodedBytes);
            this.out.write( encodedBuffer, 0, lenEncodedBytes );
        }
        else
        {
            Log.e( TAG, "Error during Encoding. Error Code: " +  lenEncodedBytes);

            throw new IOException( "Error during Encoding. Error Code: " +  lenEncodedBytes );
        }
    }


Here is the modified code in OpusDecoder.java

        byte[] encodedBuffer;
        int bytesEncoded=this.in.read();
        int bytesDecoded=0;

        Log.d( TAG, bytesEncoded + " bytes read from input stream" );
        if ( bytesEncoded >= 0 )
        {
            encodedBuffer=new byte[bytesEncoded];
            int bytesRead = this.in.read( encodedBuffer );
            bytesDecoded = nativeDecodeBytes( encodedBuffer , buffer);
            Log.d( TAG, bytesEncoded + " bytes decoded" );
        }
Heeling answered 13/10, 2015 at 13:46 Comment(2)
by "package" do you mean "packet"? i tried your patch but still didn't get the record and playback to work. lots of just pops and clicksEpisiotomy
still playing around with this, it appears to record ok, but the playback doesn't work. opus is reporting only decoding 3 bytes at a time.Episiotomy
C
0

Try this GitHub demo. I compiled it but, it doesn't play the recorded sound.

Casanova answered 21/11, 2014 at 12:4 Comment(1)
Hi, I tried it, but it not worked.and the release note in that git mentioned "What does not work: Recording and playing using the opus codec"Anselma

© 2022 - 2024 — McMap. All rights reserved.