Skip to content
Snippets Groups Projects
Commit c77b9633 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Removing useless files

parent 27169ca9
No related branches found
No related tags found
No related merge requests found
/* Copyright (c) 2010 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
static int decode_length(unsigned char *c, int len)
{
int tmp;
tmp = c[0];
if (len < 1)
return -1;
if (tmp >= 252)
{
if (len >= 2)
return 4*c[1] + (tmp&0x3) + 252;
else
return -1;
} else {
return tmp;
}
}
int count_frames(unsigned char *packet, int len)
{
int sz = packet[0]&0x7;
if (sz == 0)
return 1;
else if (sz == 1 || sz == 4)
return 2;
else if (sz == 2 || sz == 5)
return 3;
else if (sz == 3)
{
/* Many packets, same size */
int count, payload;
int flen = decode_length(packet+1, len-1);
if (flen<=0)
return -1;
payload = len - 2;
if (flen>=252)
payload--;
count = payload/flen;
if (count*flen==payload)
return count;
else
return -1;
} else /* if (sz == 6 || sz == 7) */
{
/* Many packets, different sizes */
int count = 0;
int pos = 1;
int bytes = 1;
int extra = 0;
if (sz==7)
extra = 1;
while (bytes < len)
{
int tmp=extra+1;
int flen = decode_length(packet+pos, len-bytes);
if (flen==-1)
return -1;
if (flen >= 252)
tmp = 2;
pos += tmp;
bytes += tmp+flen;
count++;
}
if (bytes != len)
return -1;
else
return count;
}
}
#define MAX_FRAMES 256
int opus_merge_packets(unsigned char **packets, int *plen, int nb_packets,
unsigned *output, int maxlen)
{
int i;
unsigned char cfg[MAX_FRAMES];
unsigned char flen[MAX_FRAMES];
int nb_frames=0;
for (i=0;i<nb_packets;i++)
{
int tmp = count_frames(packets[i], plen[i]);
if (tmp<=0)
return -1;
nb_frames += tmp;
}
return nb_frames;
}
/* Copyright (c) 2007-2008 CSIRO
Copyright (c) 2007-2009 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "opus.h"
#define MAX_PACKET 1275
int main(int argc, char *argv[])
{
int err;
char *inFile, *outFile;
FILE *fin, *fout;
OpusDecoder *dec;
int len;
int frame_size, channels;
int bytes_per_packet;
unsigned char data[MAX_PACKET];
int rate;
int loss = 0;
int count = 0;
int stop=0;
int vbr=0;
int tot_read=0;
short *in, *out;
int mode=MODE_HYBRID;
double bits=0;
if (argc != 5 && argc != 6)
{
fprintf (stderr, "Usage: test_opus <rate (kHz)> <channels> "
"[<packet loss rate>] "
"<input> <output>\n");
return 1;
}
rate = atoi(argv[1]);
channels = atoi(argv[2]);
if (argc >= 7)
loss = atoi(argv[3]);
inFile = argv[argc-2];
fin = fopen(inFile, "rb");
if (!fin)
{
fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
return 1;
}
outFile = argv[argc-1];
fout = fopen(outFile, "wb+");
if (!fout)
{
fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
return 1;
}
dec = opus_decoder_create(rate, channels);
out = (short*)malloc(960*channels*sizeof(short));
while (!stop)
{
len = ((fgetc(fin)<<8)&0xFF00) | (fgetc(fin)&0xFF);
if (feof(fin) || len>MAX_PACKET)
break;
bits += len*8;
err = fread(data, 1, len, fin);
frame_size = opus_decode(dec, rand()%100<loss ? NULL : data, len, out, 960);
count+=frame_size;
fwrite(out, sizeof(short), frame_size*channels, fout);
}
fprintf (stderr, "average bit-rate: %f kb/s\n", bits*rate/((double)count));
opus_decoder_destroy(dec);
fclose(fin);
fclose(fout);
free(in);
free(out);
return 0;
}
/* Copyright (c) 2007-2008 CSIRO
Copyright (c) 2007-2009 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "opus.h"
#define MAX_PACKET 1024
int main(int argc, char *argv[])
{
int err;
char *inFile, *outFile;
FILE *fin, *fout;
OpusEncoder *enc;
int len;
int frame_size, channels;
int bytes_per_packet;
unsigned char data[MAX_PACKET];
int rate;
int count = 0;
int stop=0;
int vbr=0;
int tot_read=0, tot_written=0;
short *in, *out;
int mode=MODE_HYBRID;
double bits=0;
if (argc != 9 && argc != 8 && argc != 7)
{
fprintf (stderr, "Usage: test_opus <rate (kHz)> <channels> <frame size> "
" <bytes per packet> [<VBR rate (kb/s)>] [<packet loss rate>] "
"<input> <output>\n");
return 1;
}
rate = atoi(argv[1]);
channels = atoi(argv[2]);
frame_size = atoi(argv[3]);
bytes_per_packet = atoi(argv[4]);
if (argc >= 8)
vbr = atoi(argv[5]);
if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET)
{
fprintf (stderr, "bytes per packet must be between 0 and %d\n",
MAX_PACKET);
return 1;
}
inFile = argv[argc-2];
fin = fopen(inFile, "rb");
if (!fin)
{
fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
return 1;
}
outFile = argv[argc-1];
fout = fopen(outFile, "wb+");
if (!fout)
{
fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
return 1;
}
enc = opus_encoder_create(rate, channels);
mode = MODE_HYBRID;
opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(BANDWIDTH_FULLBAND));
opus_encoder_ctl(enc, OPUS_SET_MODE(mode));
in = (short*)malloc(frame_size*channels*sizeof(short));
while (!stop)
{
int write_samples;
err = fread(in, sizeof(short), frame_size*channels, fin);
tot_read += err;
if (err < frame_size*channels)
{
int i;
for (i=err;i<frame_size*channels;i++)
in[i] = 0;
stop = 1;
}
len = opus_encode(enc, in, frame_size, data, bytes_per_packet);
if (len <= 0)
{
fprintf (stderr, "opus_encode() returned %d\n", len);
return 1;
}
bits += len*8;
count++;
fputc((len>>8)&0xFF, fout);
fputc((len)&0xFF, fout);
fwrite(data, 1, len, fout);
}
fprintf (stderr, "average bit-rate: %f kb/s\n", bits*rate/(frame_size*(double)count));
opus_encoder_destroy(enc);
fclose(fin);
fclose(fout);
free(in);
free(out);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment