Author Topic: Problem decoding and converting a 6chn FLAC file  (Read 304 times)

MikaelS

  • Posts: 201
Hi,

I have problems whilst decoding and converting a 6chn FLAC file to MP3.
The decoding and conversion works fine for other FLAC files, but for this one the resulting data sounds broken, plus that the properties shows invalid data.
I use LAME as an encoder and encodes the file to a 256 kbps CBR file.

Are there any special things you need to do with 6chn FLAC's?

Ian @ un4seen

  • Administrator
  • Posts: 20724
Re: Problem decoding and converting a 6chn FLAC file
« Reply #1 on: 15 Dec '16 - 15:03 »
Standard MP3 doesn't support 6 channels, so you will need to downmix it to stereo before encoding. You can use the BASSmix add-on to do that, something like this:

Code: [Select]
decoder=BASS_StreamCreateFile(FALSE, "input.flac", 0, 0, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE); // create decoder for original file
BASS_CHANNELINFO ci;
BASS_ChannelGetInfo(decoder, &ci);
mixer=BASS_Mixer_StreamCreate(ci.freq, 2, BASS_STREAM_DECODE|BASS_MIXER_END); // create a stereo mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_DOWNMIX); // plug the decoder into the mixer with downmixing enabled
BASS_Encode_Start(mixer, "lame - output.mp3", BASS_ENCODE_AUTOFREE, NULL, 0); // set an MP3 encoder on the mixer

// processing loop
while (1) {
BYTE buf[20000]; // processing buffer
int r=BASS_ChannelGetData(mixer, buf, sizeof(buf)); // process the mixer
if (r<0) break; // done
}

BASS_StreamFree(mixer);
BASS_StreamFree(decoder);

Please see the documentation for details on the aforementioned functions. If you would prefer to just encode the first 2 channels instead of downmixing, then you can remove the BASS_MIXER_DOWNMIX flag from the BASS_Mixer_StreamAddChannel call.

MikaelS

  • Posts: 201
Re: Problem decoding and converting a 6chn FLAC file
« Reply #2 on: 16 Dec '16 - 08:10 »
Thanks Ian, I will try this!

Dev01

  • Posts: 25
Re: Problem decoding and converting a 6chn FLAC file
« Reply #3 on: 12 Jan '17 - 10:40 »
Thank you Ian for your precious snippets!