24 #include "../core/system/log.h"
50 format.setCodec(
"audio/pcm");
52 format.setSampleType(QAudioFormat::SignedInt);
55 QAudioDeviceInfo device(QAudioDeviceInfo::defaultInputDevice());
57 QList<QAudioDeviceInfo> devices(QAudioDeviceInfo::availableDevices(QAudio::AudioInput));
58 for (
const QAudioDeviceInfo &i : devices) {
65 if (!device.isFormatSupported(format)) {
66 LogE(
"Selected device settings are not supported!");
71 if (!device.isFormatSupported(format)) {
72 LogW(
"Raw audio format not supported by backend, falling back to nearest supported");
73 format = device.nearestFormat(format);
75 if (not device.isFormatSupported(format))
77 LogW(
"Fallback failed. Probably there is no input device available. Did you connect your microphone?");
81 if (format.sampleSize() !=
sizeof(
DataFormat) * 8) {
82 LogW(
"Sample size not supported");
85 if (format.sampleType() != QAudioFormat::SignedInt) {
86 LogW(
"Sample format not supported");
119 LogI(
"Qt audio recorder closed.");
124 LogI(
"Audio device not created, cannot start it.");
129 qWarning() <<
"Error starting QAudioInput with error " <<
mAudioInput->error();
160 QByteArray rawdata =
mIODevice->readAll();
161 std::vector<DataFormat> data(rawdata.size() /
sizeof(
DataFormat));
162 memcpy(data.data(), rawdata.data(), data.size() *
sizeof(
DataFormat));
165 for (
size_t i = 0; i < data.size(); ++i) {
std::vector< PCMDataType > PacketType
Type definition of a PCM packet (vector of PCM values).
int16_t DataFormat
Data format of the input/output stream.
void start() override
Start/restart the audio device.
void pushRawData(const PacketType &data)
The implementation calls this function when new data is available.
void exit() override
Destroy the audio device.
const std::string & getDeviceName() const
Get a readable string of the name of the audio device.
AudioRecorderForQt(QObject *parent)
void init() override
Inizialize the audio device.
QAudioInput * mAudioInput
void setDeviceName(const std::string &n)
Set the device name.
int getChannelCount() const
Get the actual number of channels (1=mono, 2=stereo).
virtual void setDeviceInputGain(double volume) overridefinal
int getSamplingRate() const
Get the actual sampling rate.
virtual double getDeviceInputGain() const overridefinal
void setSamplingRate(int rate) override
static const DataFormat SIGNAL_SCALING
maximal alloed value of the stream
virtual ~AudioRecorderForQt()
static SettingsForQt & getSingleton()
Getter function for the singleton.
void stop() override
Stop the audio device.