mirror of
https://github.com/xiph/opus.git
synced 2025-05-29 22:57:41 +00:00
Adding API for PLC
Packet loss concealment based on LPCNet (work in progress)
This commit is contained in:
parent
b2b2e226c3
commit
969bd7662f
7 changed files with 206 additions and 11 deletions
|
@ -38,23 +38,30 @@
|
|||
#define MODE_DECODE 1
|
||||
#define MODE_FEATURES 2
|
||||
#define MODE_SYNTHESIS 3
|
||||
#define MODE_PLC 4
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int mode;
|
||||
int plc_percent=0;
|
||||
FILE *fin, *fout;
|
||||
if (argc != 4)
|
||||
if (argc != 4 && !(argc == 5 && strcmp(argv[1], "-plc") == 0))
|
||||
{
|
||||
fprintf(stderr, "usage: lpcnet_demo -encode <input.pcm> <compressed.lpcnet>\n");
|
||||
fprintf(stderr, " lpcnet_demo -decode <compressed.lpcnet> <output.pcm>\n");
|
||||
fprintf(stderr, " lpcnet_demo -features <input.pcm> <features.f32>\n");
|
||||
fprintf(stderr, " lpcnet_demo -synthesis <features.f32> <output.pcm>\n");
|
||||
fprintf(stderr, " lpcnet_demo -plc <percent> <input.pcm> <output.pcm>\n");
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[1], "-encode") == 0) mode=MODE_ENCODE;
|
||||
else if (strcmp(argv[1], "-decode") == 0) mode=MODE_DECODE;
|
||||
else if (strcmp(argv[1], "-features") == 0) mode=MODE_FEATURES;
|
||||
else if (strcmp(argv[1], "-synthesis") == 0) mode=MODE_SYNTHESIS;
|
||||
else {
|
||||
else if (strcmp(argv[1], "-plc") == 0) {
|
||||
mode=MODE_PLC;
|
||||
plc_percent = atoi(argv[2]);
|
||||
argv++;
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
fin = fopen(argv[2], "rb");
|
||||
|
@ -123,6 +130,23 @@ int main(int argc, char **argv) {
|
|||
fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout);
|
||||
}
|
||||
lpcnet_destroy(net);
|
||||
} else if (mode == MODE_PLC) {
|
||||
int count=0;
|
||||
int loss=0;
|
||||
LPCNetPLCState *net;
|
||||
net = lpcnet_plc_create();
|
||||
while (1) {
|
||||
short pcm[FRAME_SIZE];
|
||||
size_t ret;
|
||||
ret = fread(pcm, sizeof(pcm[0]), FRAME_SIZE, fin);
|
||||
if (feof(fin) || ret != FRAME_SIZE) break;
|
||||
if (count % 2 == 0) loss = rand() < RAND_MAX*(float)plc_percent/100.f;
|
||||
if (loss) lpcnet_plc_conceal(net, pcm);
|
||||
else lpcnet_plc_update(net, pcm);
|
||||
fwrite(pcm, sizeof(pcm[0]), FRAME_SIZE, fout);
|
||||
count++;
|
||||
}
|
||||
lpcnet_plc_destroy(net);
|
||||
} else {
|
||||
fprintf(stderr, "unknown action\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue