Author Topic: join mp3 file with diffrent sample rates  (Read 70 times)

shahram

  • Posts: 2
join mp3 file with diffrent sample rates
« on: 9 Dec '17 - 15:26 »
Hi,
I wrote some codes for joining mp3 files , using bassenc and lame command line tool.
but problem is that
when files sample rate are diffrent , i get unsupported format error on BASS_Encode_SetChannel
because "The new channel must have the same sample format (rate, channels, resolution) as the old channel"
my question is:
1-is some other way for joining files ?
2-if not , how can I convert sample format of files?

Thanks

shahram

  • Posts: 2
Re: join mp3 file with diffrent sample rates
« Reply #1 on: 10 Dec '17 - 14:13 »
answering my own question.
may be it helps some one!
Code: [Select]

 procedure TForm1.Button4Click(Sender: TObject);
var
  I: Integer;
  source: HSTREAM;
  encoder: HENCODE;
  mixer: HSTREAM;
  buf: array [1 .. 204800] of byte;
  R: dword;
begin
encoder:=0;
  for I := 0 to ListBox1.items.count - 1 do

  begin
 
    source := BASS_StreamCreateFile(FALSE, PChar(ListBox1.items.strings), 0,
      0, BASS_STREAM_DECODE or BASS_UNICODE);
   if encoder= 0 then
    begin
     mixer := bassmix.BASS_Mixer_StreamCreate(44100, 2, BASS_STREAM_DECODE or bass_unicode or BASS_MIXER_NONSTOP);
    encoder := bassenc.BASS_Encode_Start(mixer,
      'lame.exe --alt-preset standard - zz.mp3',  BASS_UNICODE, nil, nil);
    end;

    plug the source into the mixer
      BASS_Mixer_StreamAddChannel(mixer, source, 0);
    if (encoder <> 0) then
    begin
      while (BASS_ChannelIsActive(source) = BASS_ACTIVE_PLAYING) do
      begin
        // getting sample data will automatically feed the encoder
        R := bass.BASS_ChannelGetData(mixer, @buf, sizeof(buf));
      end;
      BASS_StreamFree(source);

    end ;
    sleep(2000);
  end;

  if (encoder <> 0) then
    BASS_Encode_Stop(encoder);
  BASS_StreamFree(mixer);
end;     
« Last Edit: 10 Dec '17 - 14:17 by shahram »