Author Topic: Converting audio formats  (Read 123 times)


  • Posts: 22
Converting audio formats
« on: 4 Jan '18 - 13:51 »
Hi. I am using Bass.Net for my music player and my next main problem for now is: "How do I split one file with multiple tracks to single tracks?"
Can I convert audio with bass?
Or should I search for other libraries, maybe there is already something simple for c# ?

I need this, because time to time you need to copy just one song, but not full album

Any suggestions, Please )

Ian @ un4seen

  • Administrator
  • Posts: 20499
Re: Converting audio formats
« Reply #1 on: 4 Jan '18 - 17:06 »
That sounds like it should be possible to achieve what you want with the BASSenc add-on. You would create a "decoding channel" for the source file, and then for each track set an encoder on it via BASS_Encode_Start and process the track's data with BASS_ChannelGetData. It could look something like this (in C/C++) for MP3 tracks:

Code: [Select]
decoder = BASS_StreamCreateFile(FALSE, filename, 0, 0, 0, BASS_STREAM_DECODE); // create a decoder for the source file
// process the tracks
for (n = 0; n < tracks; n++) {
char cmd[100];
snprintf(cmd, sizeof(cmd) - 1, "lame - track%d.mp3", n + 1); // build LAME command-line
DWORD encoder = BASS_Encode_Start(decoder, cmd, 0, NULL, 0); // start the encoder on the decoder
DWORD todo = BASS_ChannelSeconds2Bytes(decoder, tracksecs[n]); // get track length in bytes (from seconds)
while (todo) {
BYTE buf[20000];
int r = BASS_ChannelGetData(decoder, buf, min(todo, sizeof(buf))); // process the decoder (feeds the encoder)
if (r < 0) break; // error/end
todo -= r;
BASS_Encode_Stop(encoder); // stop the encoder

Please see the documentation for details on the mentioned function. If you happen to want to use FLAC/OGG/OPUS encoding, you could use the dedicated BASSenc_FLAC/OGG/OPUS add-on for that (instead of BASSenc and a separate encoder).