Conversation
akashtc
commented
Feb 5, 2026
- Implemented WAV file support for encoding in oac_demo.
- Added a test WAV file to the tests directory.
- Updated the
- README
- to reflect the new functionality.
- Successfully built and tested the changes.
Keep QEXT just for 96 kHz input/output Signed-off-by: Jean-Marc Valin <jeanmarcv@google.com>
Remove ENABLE_RES24 option, keep QEXT just for 96 kHz support Signed-off-by: Jean-Marc Valin <jeanmarcv@google.com>
We now use 32-bit precision, but MIPS code matches older 16-bit implementation.
These will break every time we change the bitstream
Now always using ec_tell_frac() to check the number of remaining bits instead of attempting our own accounting, which is more complicated and could (in extremely rare cases) fail.
Also update condition for coding the trim symbol
Also update condition for coding the pitch symbols
Backport from Opus commit a3f0ec02 (gitlab MR 190)
| #include "oac.h" | ||
| #include "oac_multistream.h" | ||
| #include "oac_private.h" | ||
| #include "oac_types.h" |
There was a problem hiding this comment.
Why do you need to change the order?
| int size; | ||
| int sample_size = 2; | ||
| if (format == FORMAT_S24_LE) | ||
| sample_size = 3; |
There was a problem hiding this comment.
As per coding style, have the statement on the same line as the if as in the original code
src/oac_demo.c
Outdated
| fseek(fin, 0, SEEK_SET); | ||
| mode_switch_time = size/sample_size/channels/nb_modes_in_list; | ||
| fprintf(stderr, "Switching mode every %d samples\n", mode_switch_time); | ||
| const char *ext = strrchr(inFile, '.'); |
There was a problem hiding this comment.
declaration after statement. We're still in C90
src/oac_demo.c
Outdated
| channels); | ||
| fprintf(stderr, "Using parameters from command line.\n"); | ||
| } | ||
| } else if (mode_list) { |
There was a problem hiding this comment.
Don't understand why that needs to be in an else for the wav code. mode_list is a totally independent thing.
| fprintf(stderr, "Switching mode every %d samples\n", mode_switch_time); | ||
| const char *ext = strrchr(inFile, '.'); | ||
| if (!decode_only && ext && strcmp(ext, ".wav") == 0) { | ||
| char header[44]; |
src/oac_demo.c
Outdated
| goto failure; | ||
| } | ||
|
|
||
| oac_int32 wav_format_samplerate = *(oac_int32 *)(header + 24); |
There was a problem hiding this comment.
This kind of casting is not legal in C and it would break on a big endian machine. Use char_to_int() instead.
src/oac_demo.c
Outdated
| } | ||
|
|
||
| oac_int32 wav_format_samplerate = *(oac_int32 *)(header + 24); | ||
| short wav_format_channels = *(short *)(header + 22); |
There was a problem hiding this comment.
See above, but you'll need your own 16-bit conversion code.
src/oac_demo.c
Outdated
| wav_format_samplerate, wav_format_channels, sampling_rate, | ||
| channels); | ||
| fprintf(stderr, "Using parameters from command line.\n"); | ||
| } |
There was a problem hiding this comment.
You'll also want to check and/or auto-detect the PCM format (16-bit, 24-bit, float).
README
Outdated
| -loss <perc> : simulate packet loss, in percent (0-100); default: 0 | ||
|
|
||
| input and output are little-endian signed 16-bit PCM files or OAC | ||
| input and output are little-endian signed 16-bit PCM files, WAV files (for decoding), or OAC |
There was a problem hiding this comment.
Shouldn't it say "for encoding" since wav input is for encode?
|
One feature of wav files is they can be made of multiple chunks, which would break your current code. I don't think we should necessarily handle multiple chunks, but it would be good to not silently do something crazy when that happens. For example, we could just detect that and saw we don't support it, or encode just the first chunk, or something else that sane. Right now the next chunks may just end up interpreted as noise. |
| fprintf (stderr, "Could not open input file %s\n", argv[argc - 2]); | ||
| goto failure; | ||
| } | ||
| const char *ext; |
There was a problem hiding this comment.
Still a declaration after statement.
| unsigned char data_size_bytes[4]; | ||
| oac_int32 riff_chunk_size; | ||
| oac_int32 data_chunk_size; | ||
| short bits_per_sample; |
There was a problem hiding this comment.
Best to use the oac_int16 type (or just "int" here would work) because short doesn't have a fixed length.
|
|
||
| // Helper function for little-endian 16-bit | ||
| static short char_to_short(unsigned char ch[2]) { | ||
| return (short)(((unsigned short)ch[1] << 8) | (unsigned short)ch[0]); |
There was a problem hiding this comment.
please use oac_int16 instead of "short" here.
| case 24: | ||
| format = FORMAT_S24_LE; | ||
| break; | ||
| case 32: // Assuming float for 32-bit |
There was a problem hiding this comment.
Please don't use // comments (C90 again)
| fseek(fin, 0, SEEK_SET); | ||
| mode_switch_time = size/sample_size/channels/nb_modes_in_list; | ||
| fprintf(stderr, "Switching mode every %d samples\n", mode_switch_time); | ||
| int size; |
There was a problem hiding this comment.
Please don't reindent the code.
|
So this patch only handles encode, correct? |
Yes |
|
You might want to rebase your PR. You can do it on top of main or on top of oac-next. |