Skip to content

Feature/wav decoding support in oac_demo #10

Draft
akashtc wants to merge 28 commits intooac-nextfrom
feature/wav-decoding
Draft

Feature/wav decoding support in oac_demo #10
akashtc wants to merge 28 commits intooac-nextfrom
feature/wav-decoding

Conversation

@akashtc
Copy link

@akashtc akashtc commented Feb 5, 2026

  1. Implemented WAV file support for encoding in oac_demo.
  2. Added a test WAV file to the tests directory.
  3. Updated the
  4. README
  5. to reflect the new functionality.
  6. Successfully built and tested the changes.

jmvalin and others added 24 commits January 15, 2026 11:10
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)
@akashtc akashtc changed the base branch from main to oac-next February 5, 2026 19:22
#include "oac.h"
#include "oac_multistream.h"
#include "oac_private.h"
#include "oac_types.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to change the order?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not addressed

int size;
int sample_size = 2;
if (format == FORMAT_S24_LE)
sample_size = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per coding style, have the statement on the same line as the if as in the original code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not addressed

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, '.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indenting is 4-space

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not addressed

src/oac_demo.c Outdated
goto failure;
}

oac_int32 wav_format_samplerate = *(oac_int32 *)(header + 24);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it say "for encoding" since wav input is for encode?

@jmvalin
Copy link
Contributor

jmvalin commented Feb 5, 2026

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use oac_int16 instead of "short" here.

case 24:
format = FORMAT_S24_LE;
break;
case 32: // Assuming float for 32-bit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't reindent the code.

Copy link
Author

@akashtc akashtc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check now

@akashtc akashtc marked this pull request as draft February 5, 2026 23:53
@akashtc akashtc self-assigned this Feb 5, 2026
@debargha
Copy link

So this patch only handles encode, correct?

@akashtc
Copy link
Author

akashtc commented Feb 17, 2026

So this patch only handles encode, correct?

Yes

@jmvalin
Copy link
Contributor

jmvalin commented Feb 18, 2026

You might want to rebase your PR. You can do it on top of main or on top of oac-next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments