Author Topic: Beginner questions with bass.dll  (Read 281 times)

anhbasaigon

  • Posts: 4
Beginner questions with bass.dll
« on: 15 Aug '17 - 07:22 »
Hello everyone in the forum.

I start to write a music player using bass.dll and come up with some questions that I could not solve after reading google search results. Please address me, thanks.

1. Could I use wasapi (in basswasapi) to have better music listening experience (quality), and if yes, what is the code for playing a file with wasapi output quality?

2. I want to encode a mp3 file to wav/flac file for better listening experience. Should I wait until the encoding finished to play the encoded file or I can listen to the wav/flac file during the encoding process (the code provided in document stated that if I don't use the decoding channel, i can play it but when I use Bass_ChannelPlay command, there is no sound).

3. Is it possible to encode a URL stream (mp3) to wav/flac format as said in question 2?


this is the code I come up with converting a mp3 to wav, the encoding was done very fast but nothing is played:


Code: [Select]
Private Sub EncodenPlay()
        Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
        Dim w As New EncoderWAV(stream)
        w.InputFile = Nothing
        w.OutputFile = "test.wav" ' will be a 32-bit IEEE float WAVE file, since the stream is float
        w.Start(Nothing, IntPtr.Zero, False)
        ' do the encoding
        Utils.DecodeAllData(stream, True)
        w.Stop()
        'play
        Bass.BASS_ChannelPlay(stream, False)
End Sub
« Last Edit: 15 Aug '17 - 07:52 by anhbasaigon »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Beginner questions with bass.dll
« Reply #1 on: 15 Aug '17 - 15:17 »
1. Could I use wasapi (in basswasapi) to have better music listening experience (quality), and if yes, what is the code for playing a file with wasapi output quality?

WASAPI output can be used to improve latency (due to reduced buffering) more than quality. Exclusive mode WASAPI can improve quality by making the output rate match the file's rate (and at least match the resolution/bitdepth), but shared mode WASAPI will make no difference compared to standard BASS/DirectSound output in that regard.

2. I want to encode a mp3 file to wav/flac file for better listening experience. Should I wait until the encoding finished to play the encoded file or I can listen to the wav/flac file during the encoding process (the code provided in document stated that if I don't use the decoding channel, i can play it but when I use Bass_ChannelPlay command, there is no sound).

Converting an MP3 file to WAV/FLAC will not improve quality (the WAV/FLAC file will sound identical to the MP3 file). Note it is not possible to get back any quality that was lost in the MP3 encoding process.

3. Is it possible to encode a URL stream (mp3) to wav/flac format as said in question 2?

Yes, that is possible. You would just use BASS_StreamCreateURL instead of BASS_StreamCreateFile.

this is the code I come up with converting a mp3 to wav, the encoding was done very fast but nothing is played:


Code: [Select]
Private Sub EncodenPlay()
        Dim stream As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0,BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
        Dim w As New EncoderWAV(stream)
        w.InputFile = Nothing
        w.OutputFile = "test.wav" ' will be a 32-bit IEEE float WAVE file, since the stream is float
        w.Start(Nothing, IntPtr.Zero, False)
        ' do the encoding
        Utils.DecodeAllData(stream, True)
        w.Stop()
        'play
        Bass.BASS_ChannelPlay(stream, False)
End Sub

Your BASS_StreamCreateFile call is using the BASS_STREAM_DECODE flag to create a "decoding channel", which allows you to convert the MP3 to WAV quickly. But decoding channels can't be played, ie. if you check the BASS_ChannelPlay return value you will find that the call is failing. You will need to call BASS_StreamCreateFile again without the BASS_STREAM_DECODE flag to play the file.

anhbasaigon

  • Posts: 4
Re: Beginner questions with bass.dll
« Reply #2 on: 16 Aug '17 - 02:26 »
Thank you Ian @ un4seen very much for your explanations. I got it very clear from your answers for question 2&3. For question 1, I still wonder if the exclusive Wasapi mode in Bass.dll also helps to bypass kmixer (windows sound processor) to get better sound quality apart from matching the rates as you said.

And: Can I play a file with Wasapi Output device ? (I searched for examples of playing music file using basswaspi but only found examples on audio spectrum analyzer).

Chris

  • Posts: 1808
Re: Beginner questions with bass.dll
« Reply #3 on: 16 Aug '17 - 10:31 »
No you cannot have a better sound . The quality of a  Audiofile is limited  of the compressed Codec. e.g Mp3.
The only way to enhanced the quality is possible with a good Compressor/Limiter/Enhancer.
something like this Stereo Tool/ or any other good vst compressor/Limiter.
Another possible way is to use (bass_FX.dll) it has a free Compressor/Limiter FX Effect.
it make no sense to encode a mp3 to wav or flac. The sound Quality can not be better.
« Last Edit: 16 Aug '17 - 10:45 by Chris »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Beginner questions with bass.dll
« Reply #4 on: 16 Aug '17 - 15:48 »
For question 1, I still wonder if the exclusive Wasapi mode in Bass.dll also helps to bypass kmixer (windows sound processor) to get better sound quality apart from matching the rates as you said.

Exclusive mode WASAPI will bypass Windows' mixer, but Windows' mixer is much improved in Vista (and above), so you don't really have to worry about that unless you need bit-perfect output and/or a higher sample rate than the shared output is using. It certainly isn't needed for MP3 playback.

Can I play a file with Wasapi Output device ? (I searched for examples of playing music file using basswaspi but only found examples on audio spectrum analyzer).

Yes, you can play files via WASAPI. I'm not a .Net user myself, so I'm afraid I can't advise much on that, but if you are familiar with C/C++, you could have a look at the CONTEST example included in the BASSWASAPI package. Note you will also need the BASSmix add-on.

anhbasaigon

  • Posts: 4
Re: Beginner questions with bass.dll
« Reply #5 on: 17 Aug '17 - 06:57 »
No you cannot have a better sound . The quality of a  Audiofile is limited  of the compressed Codec. e.g Mp3.
The only way to enhanced the quality is possible with a good Compressor/Limiter/Enhancer.
something like this Stereo Tool/ or any other good vst compressor/Limiter.
Another possible way is to use (bass_FX.dll) it has a free Compressor/Limiter FX Effect.
it make no sense to encode a mp3 to wav or flac. The sound Quality can not be better.

Thank you @Christ for your answer and suggestions!~

anhbasaigon

  • Posts: 4
Re: Beginner questions with bass.dll
« Reply #6 on: 17 Aug '17 - 06:58 »
Quote
Yes, you can play files via WASAPI. I'm not a .Net user myself, so I'm afraid I can't advise much on that, but if you are familiar with C/C++, you could have a look at the CONTEST example included in the BASSWASAPI package. Note you will also need the BASSmix add-on.

Thank you @Ian for your instructions ~