| 37 | } |
| 38 | |
| 39 | bool aenc_Compress(char *input_filename, char *output_filename, const int *input_levels, const int *input_samples, |
| 40 | const int *input_rate, const int *input_channels, const float *input_factor, |
| 41 | const float *input_volscale) { |
| 42 | FILE *in, *out; |
| 43 | int32_t result; |
| 44 | |
| 45 | int levels = 0, samples_per_subband = 0; |
| 46 | unsigned sample_rate = 0, channels = 0; |
| 47 | float factor = 0, volume_scale = 0; |
| 48 | int levels_set = 0, samples_per_subband_set = 0, sample_rate_set = 0, channels_set = 0, factor_set = 0, |
| 49 | volume_scale_set = 0; |
| 50 | |
| 51 | in = fopen(input_filename, "rb"); |
| 52 | if (!in) { |
| 53 | mprintf(0, "AENC: Unable to open %s for input.\n", input_filename); |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | if (input_levels) { |
| 58 | levels = *input_levels; // Levels (default 7 or for 2k total) |
| 59 | levels_set = 1; |
| 60 | if (levels < 0 || levels > 16) { |
| 61 | mprintf(0, "AENC: Warning: levels outside of the range 0 to 16\n"); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (input_samples) { |
| 66 | samples_per_subband = *input_samples; // Samples per subband (default 16 or for 2k total) |
| 67 | samples_per_subband_set = 1; |
| 68 | if (samples_per_subband < 1 || samples_per_subband > 1024) { |
| 69 | mprintf(0, "AENC: Warning: samples per subband not in the range 1 to 1024\n"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (input_rate) { |
| 74 | sample_rate = *input_rate; // Sample rate (default 22K) |
| 75 | sample_rate_set = 1; |
| 76 | if (sample_rate != 11025 && sample_rate != 22050 && sample_rate != 44100) { |
| 77 | mprintf(0, "AENC: Warning: sample rate not 11025, 22050, or 44100\n"); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (input_channels) { |
| 82 | channels = *input_channels; |
| 83 | channels_set = 1; |
| 84 | if (channels != 1 && channels != 2) { |
| 85 | mprintf(0, "AENC: Warning: /C channels not 1 or 2\n"); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if (input_factor) { |
| 90 | factor = *input_factor; // Factor of compression (default 4 for 22K, 8 for 44K) |
| 91 | factor_set = 1; |
| 92 | |
| 93 | if (factor != 0.0f && factor < 1.0f) |
| 94 | factor = 1.0f / factor; |
| 95 | |
| 96 | if (factor <= 0.0f) { |
no test coverage detected