summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_opus.cc29
1 files changed, 20 insertions, 9 deletions
diff --git a/test/test_opus.cc b/test/test_opus.cc
index 68ea0f4..9e41a42 100644
--- a/test/test_opus.cc
+++ b/test/test_opus.cc
@@ -40,7 +40,7 @@
#define KEY "123456789012345678901234567890123456789012345678901234567890"
#define SSRC 1234567890
-#define FS 8000
+#define FS 48000
#define F1 440
#define AF1 0.3
@@ -127,21 +127,27 @@ int main()
OPUS_APPLICATION_AUDIO, &err);
printf("Opus create err: %d\n", err);
- opus_encoder_ctl(opus, OPUS_SET_BITRATE(64000));// [500;512000]
+ opus_encoder_ctl(opus, OPUS_SET_BITRATE(32000));// [500;512000]
opus_encoder_ctl(opus, OPUS_SET_COMPLEXITY(10)); // [0;10]
- opus_encoder_ctl(opus, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
+ opus_encoder_ctl(opus, OPUS_SET_SIGNAL(OPUS_AUTO));
+ //opus_encoder_ctl(opus, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND));
int cnt = 0;
size_t timestamp = 0;
- for(unsigned int ts = 0; ts < 120; ts++) {
+ size_t idx = 0;
+ for(unsigned int ts = 0; ts < FS / 10; ts++) {
printf("packet #%d\n", ts);
- size_t idx = rand() % (sizeof(ms)/sizeof(size_t));
printf("idx: %d\n", idx);
size_t pcmsize = ms[idx] / (48000.0 / FS); // Number of samples pr channel
short *pcm = new short[100000/*pcmsize * channels*/];
for(int i = 0 ; i < pcmsize; i++) {
sin_x++;
+
+ if((int)sin_x % FS == 0) {
+ idx++;// = rand() % (sizeof(ms)/sizeof(size_t));
+ idx = idx % (sizeof(ms)/sizeof(size_t));
+ }
double amp1 = sin((2*M_PI/(double)FS)*(double)sin_x * AF1) * SHRT_MAX;
double amp2 = sin((2*M_PI/(double)FS)*(double)sin_x * AF2) * SHRT_MAX;
@@ -164,7 +170,8 @@ int main()
printf("Opus error: %s\n", opus_strerror(framesize));
}
- printf("Opus Packet: %d bytes from %d bytes\n", pcmsize, framesize);
+ printf("Opus Packet: %d bytes compressed to %d bytes\n",
+ channels * pcmsize * sizeof(short), framesize);
int ret = lrtp_enqueue_frame(profile, frame, framesize);
while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) {
@@ -209,19 +216,21 @@ int main()
const char *packet = i->data();
unsigned int ts;
- printf("unpack sz: %d - %p\n", packetsize, packet);
+ // printf("unpack sz: %d - %p\n", packetsize, packet);
lrtp_unpack(lrtp, packet, packetsize);
+ int n = 0;
int ret;
while((ret = lrtp_dequeue_frame(lrtp, frame, sizeof(frame), &csrc, &ts))
!= 0) {
size_t pcmsize = 16*1024;//ms[idx] / (48000 / FS);
short *pcm = new short[pcmsize * channels];
- printf("pcmsize %d\n", pcmsize); fflush(stdout);
+ //printf("pcmsize %d\n", pcmsize); fflush(stdout);
int res = opus_decode(opus, (const unsigned char*)frame, ret,
pcm, pcmsize, 0);
- printf("Decompressed %d bytes\n", res);
+ // printf("Decompressed %d bytes\n", res);
+ n += res;
// pcmsize = res * channels * sizeof(short);
audio.play((char *)pcm, res * channels * sizeof(short));
@@ -229,6 +238,8 @@ int main()
delete[] pcm;
}
+ printf("ratio: %d => %d\n", packetsize, n * channels);
+
i++;
}