Author Topic: Join multiple flac files to a single mp3  (Read 188 times)

UserAPX

  • Guest
Join multiple flac files to a single mp3
« on: 31 May '19 - 16:18 »
Hi,

I'm trying to join/append multiple flac files to a single mp3, but the output file seems not being filling. Could someone please tell me what I'm doing wrong? Here's the main part of the code:

Code: [Select]
...
int push = Bass.BASS_StreamCreatePush(44100, 2, BASSFlag.BASS_STREAM_DECODE, IntPtr.Zero);
int enc =  BassEnc_Mp3.BASS_Encode_MP3_StartFile(push, null, BASSEncode.BASS_ENCODE_AUTOFREE, "output.mp3");

for (int i = 1; i < cont; i++) // audio filenames are 1.flac, 2.flac, 3.flac...
{
   int dec = Bass.BASS_StreamCreateFile("i.ToString() + ".flac", 0, 0, BASSFlag.BASS_STREAM_DECODE);                       
   short[] data = new short[32768];
   while (Bass.BASS_ChannelIsActive(dec) == BASSActive.BASS_ACTIVE_PLAYING)
   {
      int length = Bass.BASS_ChannelGetData(dec, data, 32768);
      Bass.BASS_StreamPutData(push, data, length);
      if (length < 0) break;
   }
   Bass.BASS_StreamFree(dec);
}
...

Thanks in advance!

Ian @ un4seen

  • Administrator
  • Posts: 21973
Re: Join multiple flac files to a single mp3
« Reply #1 on: 31 May '19 - 18:01 »
You don't need the push stream for that. You can instead set the MP3 encoder directly on the FLAC decoders. You would use the first decoder's handle in the BASS_Encode_MP3_StartFile call and then use BASS_Encode_SetChannel to move the encoder to the others. Something like this:

Code: [Select]
int enc = 0;

for (int i = 1; i < cont; i++) // audio filenames are 1.flac, 2.flac, 3.flac...
{
   int dec = Bass.BASS_StreamCreateFile("i.ToString() + ".flac", 0, 0, BASSFlag.BASS_STREAM_DECODE);                       
   if (!enc)
      enc = BassEnc_Mp3.BASS_Encode_MP3_StartFile(dec, null, BASSEncode.BASS_ENCODE_DEFAULT, "output.mp3"); // set encoder on 1st decoder
   else
      BassEnc.BASS_Encode_SetChannel(enc, dec); // move encoder to new decoder
   short[] data = new short[32768];
   while (Bass.BASS_ChannelIsActive(dec) == BASSActive.BASS_ACTIVE_PLAYING)
   {
      int length = Bass.BASS_ChannelGetData(dec, data, 32768);
      if (length < 0) break;
   }
   Bass.BASS_StreamFree(dec);
}

BassEnc.BASS_Encode_Stop(enc);