mirror of
https://github.com/xiph/opus.git
synced 2025-05-18 01:18:30 +00:00
Using macros for sizes in the demo
This commit is contained in:
parent
9f78e58392
commit
77d02dbd2f
2 changed files with 13 additions and 11 deletions
|
@ -49,6 +49,8 @@
|
||||||
#define LPCNET_COMPRESSED_SIZE 8
|
#define LPCNET_COMPRESSED_SIZE 8
|
||||||
/** Number of audio samples in a packet. */
|
/** Number of audio samples in a packet. */
|
||||||
#define LPCNET_PACKET_SAMPLES (4*160)
|
#define LPCNET_PACKET_SAMPLES (4*160)
|
||||||
|
/** Number of audio samples in a feature frame (not for encoding/decoding). */
|
||||||
|
#define LPCNET_FRAME_SIZE (160)
|
||||||
|
|
||||||
typedef struct LPCNetState LPCNetState;
|
typedef struct LPCNetState LPCNetState;
|
||||||
|
|
||||||
|
|
|
@ -73,24 +73,24 @@ int main(int argc, char **argv) {
|
||||||
LPCNetEncState *net;
|
LPCNetEncState *net;
|
||||||
net = lpcnet_encoder_create();
|
net = lpcnet_encoder_create();
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned char buf[8];
|
unsigned char buf[LPCNET_COMPRESSED_SIZE];
|
||||||
short pcm[4*FRAME_SIZE];
|
short pcm[LPCNET_PACKET_SAMPLES];
|
||||||
fread(pcm, sizeof(pcm[0]), 4*FRAME_SIZE, fin);
|
fread(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fin);
|
||||||
if (feof(fin)) break;
|
if (feof(fin)) break;
|
||||||
lpcnet_encode(net, pcm, buf);
|
lpcnet_encode(net, pcm, buf);
|
||||||
fwrite(buf, 1, 8, fout);
|
fwrite(buf, 1, LPCNET_COMPRESSED_SIZE, fout);
|
||||||
}
|
}
|
||||||
lpcnet_encoder_destroy(net);
|
lpcnet_encoder_destroy(net);
|
||||||
} else if (mode == MODE_DECODE) {
|
} else if (mode == MODE_DECODE) {
|
||||||
LPCNetDecState *net;
|
LPCNetDecState *net;
|
||||||
net = lpcnet_decoder_create();
|
net = lpcnet_decoder_create();
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned char buf[8];
|
unsigned char buf[LPCNET_COMPRESSED_SIZE];
|
||||||
short pcm[4*FRAME_SIZE];
|
short pcm[LPCNET_PACKET_SAMPLES];
|
||||||
fread(buf, sizeof(buf[0]), 8, fin);
|
fread(buf, sizeof(buf[0]), LPCNET_COMPRESSED_SIZE, fin);
|
||||||
if (feof(fin)) break;
|
if (feof(fin)) break;
|
||||||
lpcnet_decode(net, buf, pcm);
|
lpcnet_decode(net, buf, pcm);
|
||||||
fwrite(pcm, sizeof(pcm[0]), 4*FRAME_SIZE, fout);
|
fwrite(pcm, sizeof(pcm[0]), LPCNET_PACKET_SAMPLES, fout);
|
||||||
}
|
}
|
||||||
lpcnet_decoder_destroy(net);
|
lpcnet_decoder_destroy(net);
|
||||||
} else if (mode == MODE_FEATURES) {
|
} else if (mode == MODE_FEATURES) {
|
||||||
|
@ -101,13 +101,13 @@ int main(int argc, char **argv) {
|
||||||
while (1) {
|
while (1) {
|
||||||
float in_features[NB_TOTAL_FEATURES];
|
float in_features[NB_TOTAL_FEATURES];
|
||||||
float features[NB_FEATURES];
|
float features[NB_FEATURES];
|
||||||
short pcm[FRAME_SIZE];
|
short pcm[LPCNET_FRAME_SIZE];
|
||||||
fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin);
|
fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin);
|
||||||
if (feof(fin)) break;
|
if (feof(fin)) break;
|
||||||
RNN_COPY(features, in_features, NB_FEATURES);
|
RNN_COPY(features, in_features, NB_FEATURES);
|
||||||
RNN_CLEAR(&features[18], 18);
|
RNN_CLEAR(&features[18], 18);
|
||||||
lpcnet_synthesize(net, features, pcm, FRAME_SIZE);
|
lpcnet_synthesize(net, features, pcm, LPCNET_FRAME_SIZE);
|
||||||
fwrite(pcm, sizeof(pcm[0]), FRAME_SIZE, fout);
|
fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout);
|
||||||
}
|
}
|
||||||
lpcnet_destroy(net);
|
lpcnet_destroy(net);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue