PDA

View Full Version : Qt and BASS library?



Khaine
3rd September 2015, 11:12
I want to record sound to file using Qt and BASS library. I previously added these libraries to my other project (main one), but I decided to not make mess there until I will be sure that code works and makes sense. It looked like that in .pro file:



LIBS += -lbass
LIBS += -LC:/BASS/x64
INCLUDEPATH += C:/BASS/c

LIBS += -lbasswasapi
LIBS += -LC:/BASSWASAPI/x64
INCLUDEPATH += C:/BASSWASAPI/c

LIBS += -lbassenc
LIBS += -LC:/BASSENC/x64
INCLUDEPATH += C:/BASSENC/c


And compiler did not say a thing about any problems with finding files after I included them (I could normally see and use their functions). I decided to make new test application to check if things I want to do there actually work, copied these include paths to new .pro file, included .h files in my SoundRecord class, and then wanted to build a clean project to see if everything works. I got this:


LNK1181: cannot open input file 'basswasapi.lib'

Same compiler, same toolset, same include paths in .pro file and it just refuses to work. It can find basswasapi.h , but for some reason it can't find actual library.

ChrisW67
4th September 2015, 23:32
Try placing the -L options in LIBS before the corresponding -l options.

Khaine
5th September 2015, 13:31
I want to make application that records sound from loopback, and I don't really have big choice of external libraries that have WASAPI wrapped. I wrote class using BASS library that is supposed to do the job, few people saw it's insides and there are most probably no coding errors in .h and .cpp files. Yet Qt totally refuses to compile it, no matter what I do - use x64 or x86 libraries, x64 or x86 compiler, and I probably tried most of the working combinations there. What compiler is supposed to be used with BASS library to make it work?

This is the closeset to sucessful compilation error log (only 4 of them):

http://s22.postimg.org/d48wlah1t/Errors.jpg

It's x64 BASS library(libraries), and I tried to compile it with Qt 5.5.0 MSVC 2013 + Visual C++ 12.0 x86 amd64 compiler. I assume that these errors are related to linking problems.

This is my .pro file:


QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

INCLUDEPATH += "D:\BASS\c"
LIBS += -L"D:\BASS\c\x64" \
-lbass

INCLUDEPATH += "D:\BASSWASAPI\c"
LIBS += -L"D:\BASSWASAPI\c\x64" \
-lbasswasapi

INCLUDEPATH += "D:\BASSENC\c"
LIBS += -L"D:\BASSENC\c\x64" \
-lbassenc

TARGET = nienazwany
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
audio_capture_bass.cpp

HEADERS += mainwindow.h \
audio_capture_bass.h

FORMS += mainwindow.ui

This is .h file of this class:


#ifndef AUDIO_CAPTURE_BASS_H
#define AUDIO_CAPTURE_BASS_H

#include <QObject>
#include "bass.h"
#include "basswasapi.h"
#include "bassenc.h"

class Audio_Capture_BASS : public QObject
{
Q_OBJECT
public:
explicit Audio_Capture_BASS(QObject *parent = 0);

signals:

public slots:

void start_recording();
void stop_recording();

private:

HSTREAM sound_stream;
static DWORD CALLBACK WasapiProc(void *buffer, DWORD length, void *user);
BASS_WASAPI_INFO info;

};

#endif // AUDIO_CAPTURE_BASS_H

And finally .cpp file:


#include "audio_capture_bass.h"

Audio_Capture_BASS::Audio_Capture_BASS(QObject *parent) : QObject(parent)
{

BASS_Init(0, 44100, 0, 0, 0); //initialization of silent BASS device
BASS_WASAPI_Init(-3, 0, 0, 0, 0.5, 0,WasapiProc, this); //initialization of default WASAPI loopback capture device
BASS_WASAPI_GetInfo(&info); //getting info about stream parameters

}


//recording function called by BASS_WASAPI_Init every 0.5 second
DWORD CALLBACK Audio_Capture_BASS::WasapiProc(void *buffer, DWORD length, void *user)
{

Audio_Capture_BASS *self = (Audio_Capture_BASS*)user;
BASS_ChannelGetData(self->sound_stream, buffer, length);
return 1;

}

void Audio_Capture_BASS::start_recording()
{

sound_stream = BASS_StreamCreate(info.freq, info.chans, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, STREAMPROC_DUMMY, 0); //creating a stream(HSTREAM)
BASS_Encode_Start(sound_stream, "output.wav", BASS_ENCODE_PCM|BASS_ENCODE_FP_16BIT|BASS_ENCODE_A UTOFREE, NULL, NULL); //adding WAV encoder to stream
BASS_WASAPI_Start(); //start WASAPI stream output

}

void Audio_Capture_BASS::stop_recording()
{

BASS_WASAPI_Stop(true); //stopping WASAPI stream output
BASS_StreamFree(sound_stream); //stopping recording stream together with encoder

}

What am I missing or what am I doing wrong? Or maybe BASS just won't work with Qt?

anda_skoa
5th September 2015, 14:18
Yet Qt totally refuses to compile it

Qt is a set of libraries, it doesn't compile anything.



This is the closeset to sucessful compilation error log (only 4 of them):
I assume that these errors are related to linking problems.

Yes.

As you can see these are all for symbols of the BASS library, the symbols of the other two seem to be found nicely.
Check that the problematic library is actually where you think it is and named the way your pro file expects.

If that is OK, try moving the LIBS statement for it to a place after the other two.



Or maybe BASS just won't work with Qt?
Your Qt code compiled just fine (otherwise you wouldn't reach the linker stage).

Cheers,
_

Khaine
5th September 2015, 14:30
Check that the problematic library is actually where you think it is and named the way your pro file expects.

If that is OK, try moving the LIBS statement for it to a place after the other two.

Yes, it is where it is. QMake don't report any errors. I moved this statement to the end and nothing changes.

anda_skoa
5th September 2015, 14:46
Just to verify that the other two libraries are found correctly, could you try building with the problematic lines commented out?

Cheers,
_

Khaine
5th September 2015, 14:56
Just to verify that the other two libraries are found correctly, could you try building with the problematic lines commented out?

Cheers,
_

I did. It compiles and run but program crashes instantly. There are no objects of this class created, it's only included in mainwindow. Rest of the program is empty.

anda_skoa
5th September 2015, 16:00
I did. It compiles and run but program crashes instantly.
Right, that was to be expected.

But since the functions from the other two libraries got resolved correctly it is a strong indication that the compiler and bitness are correct.

I am out of ideas, but I don't use Windows a lot so there might be still things to check.

Cheers,
_

Khaine
5th September 2015, 16:08
What can it be actually? What may be wrong if program crashes right away even without creating any object of this class?

anda_skoa
5th September 2015, 16:25
What may be wrong if program crashes right away even without creating any object of this class?

That is likely just a side effect of using uninitialized data structures, e.g. sounds_stream.

Cheers,
_

Khaine
5th September 2015, 16:27
So what do you propose to resolve it? Define it within constructor? There is no object of this class anyway. Not even declaration. It has no actual reason to crash. Header is included in mainwindow.h and that's all.

anda_skoa
5th September 2015, 17:22
It has no actual reason to crash.
Accessing an unitialized variable has undefined behavior, so yes, crashing is likely.
[/quote]



So what do you propose to resolve it?

Likely solved by executing the code you currently have commented out.

Why spend time fixing a problem that might not exist once you get the linking problem resolved?

Cheers,
_

Khaine
5th September 2015, 17:38
Why spend time fixing a problem that might not exist once you get the linking problem resolved?

I agree, but still - how to resolve linking problem? I tried most of the Qt toolsets and tried to add these libraries through "Add library", and nothing worked so far.

ChrisW67
5th September 2015, 21:31
Firstly, i would switch the backslashes for forward slashes in the paths so that the warnings from qmake about these do not obscure anything important

LIBS += -L"D:/BASS/c/x64" -lbass
Etc. Rerun. Qmake and nmake.

I would check that "D:/BASS/c/x64" contains a file "bass.lib". I woulb be fussy about the capitalisation of the file name just to be sure. If Bass needs to be "installed" after being built then make sure that has happenned and you are using the installed files in their installed paths.

I would try to compile a single file program with a main() and call to Bass_Init() and nothing else.

Khaine
5th September 2015, 22:48
http://s24.postimg.org/y0w9741wl/LNKError.jpg

Unfortunately even this doesn't work. Insides of .pro file:


QT += core
QT -= gui

TARGET = Unnamed
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

INCLUDEPATH += "D:/BASS/c"
LIBS += -L"D:/BASS/c" \
-lbass

ChrisW67
6th September 2015, 21:27
The problem is that the library does not exist anywhere you have told the linker to look. This really has nothing much to do with Qt. Post a directory listing of the content of the the d:/bass/c folder.

Khaine
6th September 2015, 23:28
11357

You have to forgive me polish version of Windows, but if only Qt wants .lib file, then it's there for sure.

ChrisW67
8th September 2015, 10:27
Is that a 32-bit or 64-bit lib file? Are you building a 32- or 64-bit application?

Khaine
8th September 2015, 11:02
It's all 32 bits right now. Error in console application says now:


Cannot obtain a handle to the inferior: The parameter is incorrect.

And error for simple Qt widgets app:


Starting C:\Users\Michal\Documents\build-nienazwany-Desktop_Qt_5_5_0_MSVC2013_32bit-Release\release\nienazwany.exe...
The program has unexpectedly finished.
C:\Users\Michal\Documents\build-nienazwany-Desktop_Qt_5_5_0_MSVC2013_32bit-Release\release\nienazwany.exe crashed

And this is what debugger says about it:

http://s28.postimg.org/i7wb66sm5/debug.jpg (http://postimg.org/image/mh118cvvd/full/)
images hosting (http://postimage.org/)