Process audio sounds from microphone using Qt - qt

I am developing a sound processing application using Qt as a front end.
How can I get data samples from the microphone? I tried overriding qint64 writeData(const char *data, qint64 len) in QIODevice, but I was unable to get data samples.

Use QAudioInput class.
see : QAudioInput Class ref in Qt Doc

Related

Convert raw v4l2 buffer to QVideoframe in qt

I will get raw video data from the V4L2 driver using VIDIOC_DQBUF, I wanted to render this frame in qt using QVideoFrame(which construct video frame) and QLabel/QPaint(for rendering a video frame).
QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, QVideoFrame::PixelFormat format)
Constructs a video frame from a buffer with the given pixel format and size in pixels.
Qvideoframe from Qt
As of now, I’m using QImage to rendering RGB24 and QImage supports the only RGB format. However raw video frame which is received from VIDIOC_DQBUF is having different color formats and QVideoFrame support most of them.
Queries:
How to use QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, QVideoFrame::PixelFormat format) for v4l2 buffer ?
How I can use map(), bits() and mappedBytes() function so that, I can get QVideoFrame constructed for given raw video data?
How I can use QPaint/QLabel to render QVideoFrame?
Regards,
Kulakrni
Lets reverse the order.
How I can use QPaint/QLabel to render QVideoFrame?
You can not. You need to use a QAbstractVideoSurface() derived class. In QML, this is VideoOutput. If you want a single image, then QVideoFrame is not the correct class to use for QPaint/QLabel.
How I can use map(), bits() and mappedBytes() function so that, I can get QVideoFrame constructed for given raw video data?
These functions are your interface to the QAbstractVideoSurface. It depends on how you want to store the VL4 buffer. Are you copying/translating it or are you mapping it directly; then there are ownership issues which this API attempts to address.
How to use QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, QVideoFrame::PixelFormat format) for v4l2 buffer
You need to sub-class a QAbstractVideoBuffer by either copying/translating the data and keeping it with the class or provide a reference if you are using zero-copy of some sort.
By default, QML Camera and QCamera will find and use /dev/videoX which is a v4l device, via GStreamer. This class should already do the right thing to supply a VideoOutput widget.
See: Qt Video overview

cannot convert cont char* to LPCWSTR

I am stuck with an error in QT compiler however it works fine with VS2010. the error states that
I have seen other posts related to the same error but non has resolved my problem in QT. I have tried _T,L or TEXT but still not working
bq. error: C2664: 'HANDLE
LoadImageW(HINSTANCE,LPCWSTR,UINT,int,int,UINT)' : cannot convert
argument 2 from 'const char *' to 'LPCWSTR' Types pointed to are
unrelated; conversion requires reinterpret_cast, C-style cast or
function-style cast
my code is as below
Bitmap::Bitmap(std::string const& file_name) {
bitmap_ = static_cast<HBITMAP>(::LoadImage(0, file_name.c_str(), IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION));
}
please share if you have any idea to resolve this
Qt does not include a compiler. On Windows you're probably either compiling with mingw or Visual C++. Either way, the issue is that you're calling a function that expects a wide character string but you're trying to hand it an 8-bit character string.
For compatibility reasons, Win32 uses a different set of API functions if you have _UNICODE defined. In your case, you do have _UNICODE defined. You can continue using the 8-bit std::string but simply change the method from LoadImage() to LoadImageA(). Or if you don't mind changing your Bitmap class, you could switch from std::string to std::wstring to take advantage of Windows' Unicode features.
But perhaps the larger question is why use Win32 to load bitmaps and std::string if you're using Qt? Qt's QImage class and QString class provide a full-featured, cross-platform strings and image loaders. Like any comprehensive framework, Qt works best if you only use external features on an as-needed basis.
I'm not sure if this method is the best, but I've used them on my projects and it works fine, see:
char *source = "Hello world";
WCHAR target[size];
MultiByteToWideChar(CP_ACP, 0, source, -1, target, size);
LPCWSTR final = target;
MessageBox(0, final, TEXT("title"), 0); //Sample usage

connect QProcess with QProgressbar

i have this code but it is not working.i am trying to update progressbar while my video is converting.video conversion is fine but progessbar is not updating
void MainWindow::on_pushButton_clicked()
{
QString alienpath="ffmpeg";
QStringList argument;
argument<<"-i"<<ui->lineEdit->text()<<"/home/suraj/a.flv";
QProcess *alien=new QProcess(this);
alien->start(alienpath,argument);
int p;
p=alien->readAll().toInt();
ui->progressBar->setMaximum(0);
ui->progressBar->setMinimum(100);
ui->progressBar->setValue(p);
}
plz help
First, your progressbar seems to be never updated after it was configured in your code. You may want to use QTimer or readyRead/readyReadStandardOutput signal connecting to some slot in MainWindow or C++11 lambda, but I'm not sure what the output will contain in each time, so I can't tell if this will work.
Second, your toInt() is likely to fail. It works only if your output contains pure number like 67; the application usually produces a lot of output. Use QRegExp or QRegularExpression (Qt5) to extract digits and convert only them. toInt() supports checking if a conversion error has occured, see documentation.

Signal emitting a structure

This question is in my mind for many days but i got cleared till now
if i try to send a signal of a structure say
struct radarStruct
{
unsigned char *Data;
unsigned int rate;
unsigned int timeStamp;
float timeSec;
};
shall i emit the signal like
signals:
void radarGeneratorData(const radarStruct &);
or
signals:
void radarGeneratorData(radarStruct *);
More: what about the unsigned char *Data , whether the signal will make a deep copy of it ??
similar for a unsigned char *data how i can send the signal .
Friends please help me clear this , the best way to send a structure through signals & slot mechanism ..
Thnks in advance
This mainly depends on your requirement.
If you want to send the structure over to another object and "share" the structure, you would need to send the structure as a pointer so that changes are reflected at source. If not then you would want to send it as a const ref.
For either methods remember you need to Q_DECLARE_METATYPE(YourStructType) before you can use the structure in signal / slot arguments.
As for when a deep copy occurs / when a routine call back equivalent process happens, you can have a read through
Signaling failure in qt slots
Single Thread communication and Cross-Threaded communication differ within themselves and the output would again depend on your usage.

Phonon VideoWidget playback from updated QBuffer

I'm trying to create a video player that can decrypt video data in memory and play it without ever storing the decrypted data on the hard drive. I'm using the Qt Framework with the Video Widget and a QBuffer. I decrypt the first segment of the video and store it in a QBuffer and start playback. This works but after setCurrentSource is called, all data written to the QBuffer is ignored.
I believe this has to do with the different backends. Is it possible to achieve playback directly from memory in Qt (pyQt) and if not are there any alternatives?
QFile file ("/Users/user/video.mov");
file.open(QIODevice::ReadOnly);
QByteArray array1;
QByteArray array2;
QBuffer *playbackBuffer = new QBuffer();
playbackBuffer->open(QBuffer::ReadWrite);
array1 = file.read(10000000);
array2 = file.read(10000000);
playbackBuffer->write(array1);
videoMedia->setCurrentSource(playbackBuffer);
videoOutput->play();
playbackBuffer->write(array2);

Resources