MP3 Encoder for juce

Hi, anyone know of an mp3 encoder that won’t cause this to happen in JUCE:

    if (bitrateIndex == 0)
    {
        jassertfalse; // This means the file is using "free format". Apparently very few decoders
                      // support this mode, and this one certainly doesn't handle it correctly!
        frameSize = 0;
        return ParseSuccessful::no;
    }

I’ve tried 4 now, even exporting mp3 from Live but keep hitting this issue.

Also, I think the comment “Apparently very few decoders support this mode” may no longer be accurate as most encoders seem to generate these type of files. Perhaps it’s time up update the MP3 decoder in JUCE to support this.

thx

Solution for Windows… needs precompiled LAME encoder:

        auto TEMP = File::getSpecialLocation(File::SpecialLocationType::tempDirectory).getFullPathName() + File::getSeparatorString();
        auto LAME_EXE = File(TEMP + "lame.exe");

        if (!LAME_EXE.existsAsFile())
        {
            int size(0);
            auto data = BinaryData::getNamedResource(String("lame.exe").replace(".", "_").replace("-", "").toRawUTF8(), size);
            if (size > 0)
                if (LAME_EXE.create().ok())
                    LAME_EXE.appendData(data, size);
        }

        // Add metadata...
        WavMetadata.set("id3title", String());
        WavMetadata.set("id3artist", String());
        WavMetadata.set("id3album", String());

        std::unique_ptr<LAMEEncoderAudioFormat> format;
        format.reset(new LAMEEncoderAudioFormat(LAME_EXE));
        std::unique_ptr<AudioFormatWriter> writer;
        writer.reset(format->createWriterFor(new FileOutputStream(outFile), 44100, 2, 16, WavMetadata, 23)); // CBR 320 Kbps
        if (writer != nullptr)
            writer->writeFromAudioSampleBuffer(buffer, 0, buffer.getNumSamples());

In this example I have added lame.exe to the resources. It is extracted and copied to the system temporary directory. You might want to install lame in a known directory and call the executable directly from there.

1 Like

Hi, is there a solution for Mac?

Also, can the JUCE devs comment on why the mp3 decoder supplied with JUCE is so limited? thx

Just do the same thing but using the mac version of lame.

1 Like