Git Product home page Git Product logo

Comments (6)

Guichaguri avatar Guichaguri commented on August 25, 2024

I think it's a problem with the stream implementation.

Because of the way the metadata of these chiptune files work, libopenmpt needs to receive the whole file before it's able to properly convert it.

The duplex stream implementation reads and buffers the whole stream before starting to write data, and that seems pretty broken at the moment.

You can try reading the whole request stream first to a buffer and then creating a chiptune readable stream from it (something similar to the speaker example), that should work as expected.

from node-chiptune.

Kaydax avatar Kaydax commented on August 25, 2024

Yah even when passing in buffered data into the chiptune decoder, it still outputted choppy audio

Current Code:

var buffer = fs.readFileSync("{path to mod file}")

var chiptuneDecoder = chiptune(buffer, {
  channels: 2, // 2 channels (stereo)
  sampleRate: 48000 // 48,000 Hz sample rate
});

var lameEncoder = new lame.Encoder({
  // input
  channels: 2,
  bitDepth: 16,
  sampleRate: 48000,

  // output
  bitRate: 128,
  outSampleRate: 48000,
  mode: lame.STEREO
});

var outputStream = fs.createWriteStream('out.mp3');
chiptuneDecoder.pipe(lameEncoder);
lameEncoder.pipe(outputStream);

from node-chiptune.

Kaydax avatar Kaydax commented on August 25, 2024

I also tried exactly what your example did by just using fs.readfile, and it still output the same laggy audio. If you want a preview of what it sounds like I will attach the output
out.zip

from node-chiptune.

Kaydax avatar Kaydax commented on August 25, 2024

I even tried just outputting the raw PCM data to a file, and it is still choppy, so it isn't anything wrong with the conversion from PCM to mp3 nor just adding the WAVE header with wav.

from node-chiptune.

Kaydax avatar Kaydax commented on August 25, 2024

Ok so even more testing shows that if I set node-chiptune to process 4 channels, it works without issue and produces clean audio

from node-chiptune.

Kaydax avatar Kaydax commented on August 25, 2024

Ok so here is the code I have now. I can now output a clean mp3 using lame, but you still need to fix this issue as it's very weird that it does this.

//This is the example code using fs.readFile, this can be replaced with request to grab the data

fs.readFile("{input file}", function(err, data) {
  var chiptuneDecoder = chiptune(data, {
    channels: 4, // 2 channels (stereo)
    sampleRate: 48000 // 48,000 Hz sample rate
  });

  var lameEncoder = new lame.Encoder({
    // input
    channels: 2,
    bitDepth: 16,
    sampleRate: 96000,

    // output
    bitRate: 128,
    outSampleRate: 48000,
    mode: lame.STEREO
  });

  var outputStream = fs.createWriteStream('out.mp3');
  chiptuneDecoder.pipe(lameEncoder);
  lameEncoder.pipe(outputStream);
});

from node-chiptune.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.