Author Topic: Converting audio formats  (Read 631 times)

HardRock

  • Posts: 29
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: 21024
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).

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #2 on: 24 Jan '18 - 11:32 »
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).

Thx, for advice.

I am trying to use this code in C# with BASS.NET but on row:
Code: [Select]
int encoder = BassEnc.BASS_Encode_Start(decoder, cmd, 0, null, IntPtr.Zero);

getting error that dll bassenc not found. I double check that all needed dlls copied to a build folder and they all there
even have updated all dlls to newest version and still nothing helps (

****

Just tried another thing.
All dlls from BASS for BASS.NET are in folders x86 and x64, but bassenc works fine only when I copy it to root folder where bass.net.dll and project *.exe file
Is this bug in BASS or BASS.NET? Maybe wrong including path ? because playing files works fine with out any "dancing around"
« Last Edit: 24 Jan '18 - 11:42 by HardRock »

Ian @ un4seen

  • Administrator
  • Posts: 21024
Re: Converting audio formats
« Reply #3 on: 24 Jan '18 - 13:44 »
How are you loading the DLLs in the "x86" and "x64" folders? If you aren't already doing so, you could try using the BassEnc.LoadMe(path) method to load the appropriate BASSENC.DLL file.

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #4 on: 24 Jan '18 - 13:55 »
How are you loading the DLLs in the "x86" and "x64" folders? If you aren't already doing so, you could try using the BassEnc.LoadMe(path) method to load the appropriate BASSENC.DLL file.

Built project structure looks like:

Debug
    x86
        bass.dll
        bassenc.dll
        ...
    x64
        bass.dll
        bassenc.dll
        ...
    Bass.Net.dll

and it getting error that bassenc.dll not found

but if I move bassenc.dll near Bass.Net.dll than it will work

In the same time playing files works without moving any dlls
« Last Edit: 24 Jan '18 - 14:24 by HardRock »

radio42

  • Posts: 4613
Re: Converting audio formats
« Reply #5 on: 24 Jan '18 - 15:13 »
I assume you need to explicitly load the BASSenc.dll from the correct respective folder, as by default .Net will just look for the dll in the current binary folder of your application.
Note, that ot .Net, nor BASS nor Bass.Net does know anything about your x86/x64 sub-folders.
E.g. take a look to the "LoadMe(string path)" with the BASSenc namespace.

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #6 on: 24 Jan '18 - 16:51 »
I assume you need to explicitly load the BASSenc.dll from the correct respective folder, as by default .Net will just look for the dll in the current binary folder of your application.
Note, that ot .Net, nor BASS nor Bass.Net does know anything about your x86/x64 sub-folders.
E.g. take a look to the "LoadMe(string path)" with the BASSenc namespace.

Indeed that is problem in my project ) sorry for that.
I configure this part almost year ago, and already forget how it was )

By the way, about my main question,
I found in docs method:
BaseEncoder.EncodeFile Method (String, String, BaseEncoder, BaseEncoder.ENCODEFILEPROC, Boolean, Boolean, Boolean, Int64, Int64)

I think this is the way, only one problem is that I can't make it work with custom params for FLAC encoder
 

radio42

  • Posts: 4613
Re: Converting audio formats
« Reply #7 on: 24 Jan '18 - 22:30 »
Why?

The EncoderFLAC class comes with the following properties:
- FLAC_UseCustomOptionsOnly
- FLAC_CustomOptions

What is missing?

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #8 on: 25 Jan '18 - 09:35 »
Why?

The EncoderFLAC class comes with the following properties:
- FLAC_UseCustomOptionsOnly
- FLAC_CustomOptions

What is missing?

It doesn't work when I set some params, like:
Code: [Select]
FLAC_CustomOptions = "--skip=1:00 --until=+1:23.45";
FLAC_UseCustomOptionsOnly = true; // or false

Encoder returning true, but it doesn't create result track file
I already tried few combinations, and still no result


radio42

  • Posts: 4613
Re: Converting audio formats
« Reply #9 on: 25 Jan '18 - 20:16 »
When you set the property FLAC_UseCustomOptionsOnly to true, this mean you MUST provide ALL parameters yourself, incl. the input format and output file etc.!
Else leave it to false.
In addition I guess the vales you are using doesn't make sense, as you don't provide a plain input file, as such skipping the first minute and only encoding a certain part wouldn't make sense.
To achieve only a partial encoding, take a look to this BASS.NET helper method (BaseEncoder.EncodeFile):
http://www.bass.radio42.com/help/html/2977da93-00df-32c7-a165-5930b3b87cac.htm

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #10 on: 26 Jan '18 - 08:28 »
When you set the property FLAC_UseCustomOptionsOnly to true, this mean you MUST provide ALL parameters yourself, incl. the input format and output file etc.!
Else leave it to false.
In addition I guess the vales you are using doesn't make sense, as you don't provide a plain input file, as such skipping the first minute and only encoding a certain part wouldn't make sense.
To achieve only a partial encoding, take a look to this BASS.NET helper method (BaseEncoder.EncodeFile):
http://www.bass.radio42.com/help/html/2977da93-00df-32c7-a165-5930b3b87cac.htm

Thx BaseEncoder.EncodeFile works great, we really need search in http://www.bass.radio42.com/help/ BASS.NET docs :)
cause all are there but I not seen it in the first time

radio42

  • Posts: 4613
Re: Converting audio formats
« Reply #11 on: 26 Jan '18 - 21:04 »

HardRock

  • Posts: 29
Re: Converting audio formats
« Reply #12 on: 30 Jan '18 - 17:33 »
Here comes the search: http://www.bass.radio42.com/help/index.php

Thx :) Now I think may be it was there all the time, but I don't saw that )
« Last Edit: 30 Jan '18 - 18:22 by HardRock »