| 1 |
/* |
| 2 |
* aptX encoder utility |
| 3 |
* Copyright (C) 2018-2020 Pali Rohár <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#ifdef _WIN32 |
| 24 |
#include <fcntl.h> |
| 25 |
#include <io.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <openaptx.h>cxx . . $ `<file>/openaptx.h`/ |
| 29 |
|
| 30 |
static unsigned char input_buffercxx . . $ input_buffer.[512*3*2*4]; |
| 31 |
static unsigned char output_buffercxx . . $ output_buffer.[512*6]; |
| 32 |
|
| 33 |
int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 34 |
{ |
| 35 |
int i; |
| 36 |
int hd; |
| 37 |
int ret; |
| 38 |
size_tcxx . . $ size_t# length; |
| 39 |
size_tcxx . . $ size_t# processed; |
| 40 |
size_tcxx . . $ size_t# written; |
| 41 |
struct aptx_contextcxx . . $ aptx_context# *ctx; |
| 42 |
|
| 43 |
#ifdef _WIN32 |
| 44 |
_setmode(_fileno(stdin), _O_BINARY); |
| 45 |
_setmode(_fileno(stdout), _O_BINARY); |
| 46 |
#endif |
| 47 |
|
| 48 |
hd = 0; |
| 49 |
|
| 50 |
for (i = 1; i < argc; ++i) { |
| 51 |
if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], "-h") == 0 || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], "--help") == 0) { |
| 52 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "aptX encoder utility %d.%d.%d (using libopenaptx %d.%d.%d)\n", OPENAPTX_MAJORcxx . . $ `openaptx.h:23:9`!, OPENAPTX_MINORcxx . . $ `openaptx.h:24:9`!, OPENAPTX_PATCHcxx . . $ `openaptx.h:25:9`!, aptx_majorcxx . . $ aptx_major., aptx_minorcxx . . $ aptx_minor., aptx_patchcxx . . $ aptx_patch.); |
| 53 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 54 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "This utility encodes a raw 24 bit signed stereo\n"); |
| 55 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "samples from stdin to aptX or aptX HD on stdout\n"); |
| 56 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 57 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage:\n"); |
| 58 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s [options]\n", argv[0]); |
| 59 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 60 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Options:\n"); |
| 61 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -h, --help Display this help\n"); |
| 62 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " --hd Encode to aptX HD\n"); |
| 63 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 64 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Examples:\n"); |
| •65 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 66 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s < sample.s24le > sample.aptx\n", argv[0]); |
| •67 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 68 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s --hd < sample.s24le > sample.aptxhd\n", argv[0]); |
| •69 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 70 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " sox sample.wav -t raw -r 44.1k -L -e s -b 24 -c 2 - | %s > sample.aptx\n", argv[0]); |
| 71 |
return 1; |
| 72 |
} else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], "--hd") == 0) { |
| 73 |
hd = 1; |
| 74 |
} else { |
| 75 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Invalid option %s\n", argv[0], argv[i]); |
| 76 |
return 1; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
ctx = aptx_initcxx . . $ aptx_init(212766b5e5b264ef).(hd); |
| 81 |
if (!ctx) { |
| 82 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Cannot initialize aptX encoder\n", argv[0]); |
| 83 |
return 1; |
| 84 |
} |
| 85 |
|
| 86 |
ret = 0; |
| 87 |
|
| 88 |
while (!feofcxx . . $ feof(89bc1efcdac0ca22).(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) { |
| 89 |
length = freadcxx . . $ fread(738fc8ac1d711e58).(input_buffercxx . . $ input_buffer., 1, sizeof(input_buffercxx . . $ input_buffer.), stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!); |
| 90 |
if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) { |
| 91 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: aptX encoding failed to read input data\n", argv[0]); |
| 92 |
ret = 1; |
| 93 |
} |
| 94 |
if (length == 0) |
| 95 |
break; |
| 96 |
processed = aptx_encodecxx . . $ aptx_encode(3bf53fcd271104d2).(ctx, input_buffercxx . . $ input_buffer., length, output_buffercxx . . $ output_buffer., sizeof(output_buffercxx . . $ output_buffer.), &written); |
| 97 |
if (processed != length) { |
| 98 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: aptX encoding stopped in the middle of the sample, dropped %lu byte%s\n", argv[0], (unsigned long)(length-processed), (length-processed != 1) ? "s" : ""); |
| 99 |
ret = 1; |
| 100 |
} |
| 101 |
if (fwritecxx . . $ fwrite(ab0609fa07c47d6e).(output_buffercxx . . $ output_buffer., 1, written, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) != written) { |
| 102 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: aptX encoding failed to write encoded data\n", argv[0]); |
| 103 |
ret = 1; |
| 104 |
break; |
| 105 |
} |
| 106 |
if (processed != length) |
| 107 |
break; |
| 108 |
} |
| 109 |
|
| 110 |
if (aptx_encode_finishcxx . . $ aptx_encode_finish(5cf2aa7c390a9ed4).(ctx, output_buffercxx . . $ output_buffer., sizeof(output_buffercxx . . $ output_buffer.), &written)) { |
| 111 |
if (fwritecxx . . $ fwrite(ab0609fa07c47d6e).(output_buffercxx . . $ output_buffer., 1, written, stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) != written) { |
| 112 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: aptX encoding failed to write encoded data\n", argv[0]); |
| 113 |
ret = 1; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
aptx_finishcxx . . $ aptx_finish(b3e9d6ffbe9cc111).(ctx); |
| 118 |
return ret; |
| 119 |
} |