Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-04-30 18:22:03 +0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-05-10 22:44:15 +0400
commit5eeeda96d0fa0ab7d06c7fad8faca133ed95877f (patch)
treee23e36f7a37715c7932bf3e7c208ddf4b91b5bd8
parentb72de4afda937eacf9b5b2b44bc5fe065dd00835 (diff)
Make opus_demo r/w little-endian PCM independent of host byte-order.
-rw-r--r--README4
-rw-r--r--README.draft2
-rw-r--r--src/opus_demo.c24
3 files changed, 23 insertions, 7 deletions
diff --git a/README b/README
index 5387aeac..686eb66a 100644
--- a/README
+++ b/README
@@ -1,5 +1,3 @@
-This is a prototype codec and for now it has limited functionality.
-
To build from a distribution tarball, you only need to do the following:
% ./configure
@@ -43,5 +41,5 @@ options:
-dtx : enable SILK DTX
-loss <perc> : simulate packet loss, in percent (0-100); default: 0
-input and output are 16-bit PCM files (machine endian) or opus bitstreams
+input and output are little endian signed 16-bit PCM files or opus bitstreams
with simple opus_demo propritary framing.
diff --git a/README.draft b/README.draft
index 8128e0b2..6723e8e9 100644
--- a/README.draft
+++ b/README.draft
@@ -45,5 +45,5 @@ options:
-dtx : enable SILK DTX
-loss <perc> : simulate packet loss, in percent (0-100); default: 0
-input and output are 16-bit PCM files (machine endian) or opus bitstreams
+input and output are little endian signed 16-bit PCM files or opus bitstreams
with simple opus_demo propritary framing.
diff --git a/src/opus_demo.c b/src/opus_demo.c
index 06f30e19..8d3958ca 100644
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -216,6 +216,7 @@ int main(int argc, char *argv[])
int frame_size, channels;
opus_int32 bitrate_bps=0;
unsigned char *data[2];
+ unsigned char *fbytes;
opus_int32 sampling_rate;
int use_vbr;
int max_payload_bytes;
@@ -559,6 +560,7 @@ int main(int argc, char *argv[])
in = (short*)malloc(max_frame_size*channels*sizeof(short));
out = (short*)malloc(max_frame_size*channels*sizeof(short));
+ fbytes = (unsigned char*)malloc(max_frame_size*channels*sizeof(short));
data[0] = (unsigned char*)calloc(max_payload_bytes,sizeof(char));
if ( use_inbandfec ) {
data[1] = (unsigned char*)calloc(max_payload_bytes,sizeof(char));
@@ -618,6 +620,7 @@ int main(int argc, char *argv[])
break;
}
} else {
+ int i;
if (mode_list!=NULL)
{
opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(mode_list[curr_mode][1]));
@@ -625,11 +628,17 @@ int main(int argc, char *argv[])
opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(mode_list[curr_mode][3]));
frame_size = mode_list[curr_mode][2];
}
- err = fread(in, sizeof(short)*channels, frame_size, fin);
+ err = fread(fbytes, sizeof(short)*channels, frame_size, fin);
curr_read = err;
+ for(i=0;i<curr_read*channels;i++)
+ {
+ opus_int32 s;
+ s=fbytes[2*i+1]<<8|fbytes[2*i];
+ s=((s&0xFFFF)^0x8000)-0x8000;
+ in[i]=s;
+ }
if (curr_read < frame_size)
{
- int i;
for (i=curr_read*channels;i<frame_size*channels;i++)
in[i] = 0;
stop = 1;
@@ -702,7 +711,15 @@ int main(int argc, char *argv[])
if (output_samples>0)
{
if (output_samples>skip) {
- if (fwrite(out+skip*channels, sizeof(short)*channels, output_samples-skip, fout) != (unsigned)(output_samples-skip)){
+ int i;
+ for(i=0;i<(output_samples-skip)*channels;i++)
+ {
+ short s;
+ s=out[i+(skip*channels)];
+ fbytes[2*i]=s&0xFF;
+ fbytes[2*i+1]=(s>>8)&0xFF;
+ }
+ if (fwrite(fbytes, sizeof(short)*channels, output_samples-skip, fout) != (unsigned)(output_samples-skip)){
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
@@ -777,5 +794,6 @@ int main(int argc, char *argv[])
fclose(fout);
free(in);
free(out);
+ free(fbytes);
return EXIT_SUCCESS;
}