Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ogg Vorbis random noises in decoded audio #82

Closed
Zokhoi opened this issue Jun 7, 2023 · 4 comments
Closed

Ogg Vorbis random noises in decoded audio #82

Zokhoi opened this issue Jun 7, 2023 · 4 comments

Comments

@Zokhoi
Copy link

Zokhoi commented Jun 7, 2023

In my use case I have a bunch of ogg files, some of them decode to have random noises throughout the audio, while also having the decoded audio shorter than expected.

image
Upper: audio decoded with the ogg vorbis decoder
Lower: ogg file imported into Audacity directly

Here is the offending source audio file used for the example screenshot.

Code to produce the decoded audio:

import fs from "fs";
import path from "path";
import { OggVorbisDecoder } from "@wasm-audio-decoders/ogg-vorbis";
import wav from "node-wav";

/** Reads filename from command line input */
let filename = process.argv[2];
let dir = path.dirname(path.resolve(filename));

!(async ()=>{  
  let decoder = new OggVorbisDecoder();
  await decoder.ready;

  let fileBuf = fs.readFileSync(filename);
  let audio = await decoder.decodeFile(fileBuf);

  let buf = wav.encode(audio.channelData, {
    sampleRate: audio.sampleRate,
    float: true,
    bitDepth: audio.bitDepth,
  });
  fs.writeFileSync(path.resolve(dir, `test.wav`), buf);

  decoder.free();
})()

All ogg files in my collection should have been generated by the same encoder, because the collection was a pack of samples making up one entire song. However, only some of the files have this issue. The whole pack is available here (google drive).

@eshaz
Copy link
Owner

eshaz commented Jun 8, 2023

Thanks for posting this. I'll take a look. Which encoder are you using to write the Ogg Vorbis files?

@Zokhoi
Copy link
Author

Zokhoi commented Jun 8, 2023

I didn't make the ogg files so I don't know the encoder for them. For saving the wave files in the sample code it was node-wav.

@eshaz
Copy link
Owner

eshaz commented Jun 8, 2023

I found the issue for this. There is a bug in the codec-parser Ogg parsing where if there are two continued packets in a row, the previous data is not appended. The else if condition below should be moved to an if condition above it, so the previous packet data is saved. I'll get a release published for codec-parser and all the other libraries that rely on it published here soon.

https://github.com/eshaz/codec-parser/blob/master/src/containers/ogg/OggParser.js#L129-L145

This could happen to any codec using Ogg, but it doesn't seem very common to have a bunch of continued packets in a row like in the example you provided. It's still valid Ogg Vorbis, just unusual. Thanks for reporting this and providing a good example.

eshaz added a commit to eshaz/codec-parser that referenced this issue Jun 8, 2023
@eshaz eshaz closed this as completed in c1ef281 Jun 8, 2023
@eshaz
Copy link
Owner

eshaz commented Jun 8, 2023

I just published a new release of @wasm-audio-decoders/ogg-vorbis. Testing locally worked just fine and looked just like your screenshot in Audacity. Let me know if something still isn't working.

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

No branches or pull requests

2 participants