Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions SerialPrograms/Source/CommonFramework/AudioPipeline/AudioInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#else
#error "Unsupported Qt version."
#endif


#if QT_VERSION_MAJOR != 5
#define PA_AUDIO_USE_CHANNEL_CONFIG
#endif


namespace PokemonAutomation{


Expand All @@ -45,35 +52,59 @@ const char* AUDIO_FORMAT_LABELS[] = {
void set_format(QAudioFormat& native_format, AudioChannelFormat format){
switch (format){
case AudioChannelFormat::MONO_48000:
#ifdef PA_AUDIO_USE_CHANNEL_CONFIG
if (native_format.channelConfig() != QAudioFormat::ChannelConfigMono){
native_format.setChannelConfig(QAudioFormat::ChannelConfigMono);
}
#else
if (native_format.channelCount() != 1){
native_format.setChannelCount(1);
}
#endif
if (native_format.sampleRate() != 48000){
native_format.setSampleRate(48000);
}
break;
case AudioChannelFormat::DUAL_44100:
#ifdef PA_AUDIO_USE_CHANNEL_CONFIG
if (native_format.channelConfig() != QAudioFormat::ChannelConfigStereo){
native_format.setChannelConfig(QAudioFormat::ChannelConfigStereo);
}
#else
if (native_format.channelCount() != 2){
native_format.setChannelCount(2);
}
#endif
if (native_format.sampleRate() != 44100){
native_format.setSampleRate(44100);
}
break;
case AudioChannelFormat::DUAL_48000:
#ifdef PA_AUDIO_USE_CHANNEL_CONFIG
if (native_format.channelConfig() != QAudioFormat::ChannelConfigStereo){
native_format.setChannelConfig(QAudioFormat::ChannelConfigStereo);
}
#else
if (native_format.channelCount() != 2){
native_format.setChannelCount(2);
}
#endif
if (native_format.sampleRate() != 48000){
native_format.setSampleRate(48000);
}
break;
case AudioChannelFormat::MONO_96000:
case AudioChannelFormat::INTERLEAVE_LR_96000:
case AudioChannelFormat::INTERLEAVE_RL_96000:
#ifdef PA_AUDIO_USE_CHANNEL_CONFIG
if (native_format.channelConfig() != QAudioFormat::ChannelConfigMono){
native_format.setChannelConfig(QAudioFormat::ChannelConfigMono);
}
#else
if (native_format.channelCount() != 1){
native_format.setChannelCount(1);
}
#endif
if (native_format.sampleRate() != 96000){
native_format.setSampleRate(96000);
}
Expand Down Expand Up @@ -121,18 +152,36 @@ AudioSampleFormat get_sample_format(QAudioFormat& native_format){
std::vector<AudioChannelFormat> supported_input_formats(int& preferred_index, const NativeAudioInfo& info, const std::string& display_name){
QAudioFormat preferred_format = info.preferredFormat();

std::string str = display_name + "\n";
str += "Preferred Format:\n";
str += " Channels: " + std::to_string(preferred_format.channelCount()) + "\n";
str += " Sample Rate: " + std::to_string(preferred_format.sampleRate()) + "\n";
#if QT_VERSION_MAJOR == 5
str += " Sample Format: " + std::to_string(preferred_format.sampleType()) + "\n";
#else
str += " Sample Format: " + std::to_string(preferred_format.sampleFormat()) + "\n";
#endif
global_logger_tagged().log(str);

// preferred_format.setSampleSize(16);
// preferred_format.setSampleType(QAudioFormat::SampleType::SignedInt);

int preferred_channels = preferred_format.channelCount();
int preferred_rate = preferred_format.sampleRate();
// cout << "display_name = " << display_name << endl;
// cout << "channelCount = " << preferred_format.channelCount() << endl;
// cout << "sample_rate = " << preferred_format.sample_rate() << endl;
// cout << "sampleSize = " << preferred_format.sampleSize() << endl;
// cout << "sampleFormat = " << preferred_format.sampleType() << endl;
// cout << "preferred_format = " << info.isFormatSupported(preferred_format) << endl;

#if 0
cout << "display_name = " << display_name << endl;
cout << "channelCount = " << preferred_format.channelCount() << endl;
cout << "sampleRate = " << preferred_format.sampleRate() << endl;
cout << "sampleFormat = " << (int)preferred_format.sampleFormat() << endl;
cout << "preferred_format = " << info.isFormatSupported(preferred_format) << endl;

for (const QAudioFormat::SampleFormat& format : info.supportedSampleFormats()){
cout << "supported format: " << (int)format << endl;
}
#endif

#if 0
#if QT_VERSION_MAJOR == 6 || (QT_VERSION_MAJOR == 5 && __GNUC__)
// On Qt6, "QAudioFormat::preferredFormat()" always returns stereo 44.1 kHz.
// Unlike Qt5, it does not return the native format of the device
Expand All @@ -141,6 +190,7 @@ std::vector<AudioChannelFormat> supported_input_formats(int& preferred_index, co
// mono 96000 which will be the case for standard capture cards.
preferred_channels = 1;
preferred_rate = 96000;
#endif
#endif

std::vector<AudioChannelFormat> ret;
Expand Down