在过去的几天里,我一直在尝试让 Opus 与我的 VOIP 应用程序一起工作,这让我很难受。查看 libjitsi 库,我发现了一些我认为非常适合我的应用程序的方法。但是,我没有从解码中得到正确的数据。
我的代码:
// -----------------------BEGIN Try Opus Encoding
long opusEnc = Opus.encoder_create(SAMPLE_RATE, 1);
byte[] bytebuffin = new byte[CHUNK_SIZE * 2];
byte[] bytebuffout = new byte[CHUNK_SIZE * 2];
Random rand = new Random();
rand.nextBytes(bytebuffin);
System.out.println("Begin Encode");
System.out.print("In ");
for (int i = 0; i < bytebuffin.length; i++) {
System.out.print(bytebuffin[i] + " ");
}
System.out.println();
int res = Opus.encode(opusEnc, bytebuffin, 0, CHUNK_SIZE, bytebuffout, 0, bytebuffout.length);
System.out.println("res " + res);
System.out.print("\nOut ");
for (int i = 0; i < bytebuffout.length; i++) {
System.out.print(bytebuffout[i] + " ");
}
System.out.println("End Encode");
System.out.println("Begin Decode");
byte[] output = new byte[res];
for (int i = 0; i < res; i++) {
output[i] = bytebuffout[i];
}
System.out.print("\nCompressed ");
for (int i = 0; i < output.length; i++) {
System.out.print(output[i] + " ");
}
byte[] deflatedData = new byte[CHUNK_SIZE * 2];
long opusDec = Opus.decoder_create(SAMPLE_RATE, 1);
System.out.println("\nopusDec " + opusDec);
int numSamp = Opus.decoder_get_nb_samples(opusDec, bytebuffout, 0, output.length);
System.out.println("numSamp " + numSamp);
int res2 = -1;
res2 = Opus.decode(opusDec, output, 0, output.length, deflatedData, 0, numSamp, 0);
System.out.println("res2 " + res2);
System.out.print("\nDecoded ");
for (int i = 0; i < deflatedData.length; i++) {
System.out.print(deflatedData[i] + " ");
}
System.out.println("End Decode");
Opus.decoder_destroy(opusDec);
// Opus.encoder_destroy(opusEnc);
// ---------------------END Try Opus Encoding
输出如下所示:
开始编码 -64 52 87 104 -78 -126 -108 -117 78 18 -124 75 -56 -51 -82 89 -88 -107 -86 -88 83 56 127 -31 -115 68 -101 -88 73 - 90 -77 -101 61 30 109 -115 36 57 -113 -116 69 120 -11 -43 58 -47 -13 -71 36 -79 29 -99 103 -59 -15 75 -13 -107 111 -126 -93 -72 -30 -117 -65 13 -16 -24 114 33 31 72 52 116 -84 41 88 61 121 -53 -61 -42 75 127 -78 90 73 91 119 82 -16 -121 -94 -83 -42 -49 7 -18 28 23 -14 -40 -125 -76 -14 -54 44 -127 30 2 -88 77 -97 57 -83 -106 -35 63 -4 -17 -39 111 -123 -23 -27 -124 -53 -32 41 38 -83 3 -63 100 33 -19 -51 -121 100 61 -20 70 101 97 102 122 -111 14 -107 92 29 -42 -110 -99 -70 -36 -82 7 -5 -54 12 80 -62 78 61 -26 -45 46 5 -41 122 -17 7 115 116 -4 -39 69 -128 0 11 -75 -26 28 76 71 17 20 99 -39 70 46 -21 62 34 -106 -119 95 85 -14 79 -80 -81 42 23 -58 -31 102 78 67 -97 53 117 -10 102 -31 102 103 32 125 14 24 -28 -42 -42 85 125-98 12 -120 -25 110 82 81 -106 -95 -88 -128 -9 36 47 83 119 92 -117 19 -92 7 113 41 -20 114 -34 -116 -86 -74 50 46 -71 85 - 14 -80 -77 35 45 -120 52 113 -87 -100 127 -66 121 29 -77 1 10 -15 -60 -75 -75 92 -97 -91 -92 108 -23 -71 53 -114 121 12 - 87 -71 -110 -94 -17 -51 -48 -125 -17 21 84 106 62 -16 -80 19 52 34 20 -123 -83 -74 16 52 87 -88 -29 -84 107 -81 97 18 102 20 47 -69 30 49 121 -92 -77 -62 127 -61 35 -18 1 26 79 -75 -19 68 -122 -27 -67 -42 -112 -51 85 41 52 -43 -57 21 -98 - 38 -78 81 49 16 -115 51 16 -68 113 83 -29 -116 48 -109 34 16 -22 -37 -91 114 38 -121 14 119 -89 77 67 51 -43 68 -115 -15 115 -96 22 -92 -45 107 -122 86 5 -21 -54 99 104 28 123 -36 -41 75 30 117 -80 -63 52 77 -86 -47 32 36 76 51 -78 62 80 96 -83 90 -23 - 50 122 -86 96 122 58 74 -39 31 -85 4 87 29 61 20 -127 91 -122 -106 8 -25 -89 -81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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0结束编码
开始解码 压缩 -24 126 -113 -84 7 -17 54 117 -97 44 -11 35 -80 105 80 -64 -5 -125 47 -97 3 103 117 -15 117 -123 -78 -123 28 -1 - 9 -52 -79 -65 66 -32 43 39 -32 125 -119 -89 -95 -69 1 -32 -75 -75 75 -60 -43 39 -29 115 58 72 opusDec 140641825591296 numSamp 240 res2 240
已解码 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 -1 -1 1 0 0 0 - 1 -1 1 0 -1 -1 1 0 0 0 -1 -1 2 0 -2 -1 1 0 1 0 -3 -1 3 0 -1 -1 -1 -1 2 0 -2 -1 1 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 1 0 0 0 -1 -1 2 0 -1 -1 -1 -1 2 0 - 1 -1 -1 -1 2 0 -1 -1 0 0 2 0 -1 -1 0 0 1 0 -1 -1 0 0 1 0 0 0 0 0 1 0 -1 -1 1 0 -1 -1 1 0 1 0 -4 -1 6 0 -3 -1 -3 -1 8 0 -10 -1 5 0 2 0 -9 -1 10 0 -7 -1 1 0 5 0 -8 -1 8 0 -5 - 1 0 0 6 0 -9 -1 7 0 -1 -1 -5 -1 7 0 -4 -1 -2 -1 4 0 -2 -1 -4 -1 6 0 -2 -1 -5 -1 9 0 -6 -1 -2 -1 8 0 -7 -1 1 0 5 0 -5 -1 0 0 5 0 -6 -1 2 0 8 0 -13 -1 9 0 -3 -1 -9 -1 22 0 6 0 -1 -1 -25 -1 6 0 -9 -1 30 0 82 0 -113 -1 -2 -1 44 0 -88 -1 -109 0 41 0 -109 -1 10 0 -58 -1 -11 -1 93 0 -30 -1 -36 -1 -30 0 88 -1 -65 -2 104 1 -63 -1 -57 -1 35 1 -67 -3 -72 0 108 1 71 -3 -105 2 -86 0 40 -4 -99 3 -128 0 84 -4 -56 1 97 -2101 -1 -82 3 -122 -2 -123 -1 126 1 -53 -1 3 1 -34 -2 26 -2 7 0 83 0 -98 0 45 0 -44 -1 10 -2 105 -1 -26 1 32 0 8 2 35 -1 42 -2 73 5 -6 -3 7 -3 -54 2 -83 -7 58 2 -28 6 -38 -9 122 2 -115 5 46 -7 -22 3 64 1 - 57 -7 16 4 114 -1 126 -1 -107 4 -34 -6 70 -2 122 4 65 -1 -99 -1 -32 1 74 -1 -79 -2 96 0 -96 -3 75 2 99 4 54 -4 -128 1 54 -1 26 -5 107 5 49 1 -97 -2 -72 -1 9 -3 -35 0 -38 0 100 2 10 -2 82 -3 46 2 -4 -5 58 2 - 8 1 79 -6 -43 0 13 1 结束解码79 -6 -43 0 13 1 结束解码79 -6 -43 0 13 1 结束解码
摘要:我似乎从 Opus.encode 获取压缩数据,但是当我尝试 Opus.decode 时,返回的数据似乎根本不正确。我也尝试过将其应用于语音数据,但这是不可理解的。
我是否错误地使用了 Opus 方法?还是我对 libjitsi Opus 的基本理解有缺陷?