Permalink
Browse files

Add opton in speaker test screen

Add option to play audio using highest available feature as reported by the audio card. This is useful to determine what your alsa buffer size should be for example
  • Loading branch information...
1 parent 49c69c6 commit e44b025b8a723cb089e7961233d3b232f959fb41 @jyavenard jyavenard committed Dec 13, 2010
@@ -6,8 +6,8 @@ using namespace std;
#include <sys/types.h>
#include <byteswap.h>
-#define LOC QString("AO: ")
-#define LOC_ERR QString("AO, ERROR: ")
+#define LOC QString("AOUtil: ")
+#define LOC_ERR QString("AOUtil, ERROR: ")
#if ARCH_X86
static int has_sse2 = -1;
@@ -634,21 +634,23 @@ void AudioOutputUtil::MuteChannel(int obits, int channels, int ch,
#if HAVE_BIGENDIAN
#define LE_SHORT(v) bswap_16(v)
+#define LE_INT(v) bswap_32(v)
#else
#define LE_SHORT(v) (v)
+#define LE_INT(v) (v)
#endif
char *AudioOutputUtil::GeneratePinkSamples(char *frames, int channels,
- int channel,
- int count)
+ int channel, int count, int bits)
{
pink_noise_t pink;
- initialize_pink_noise(&pink, 16);
-
+ initialize_pink_noise(&pink, bits);
+
double res;
int32_t ires;
int16_t *samp16 = (int16_t*) frames;
+ int32_t *samp32 = (int32_t*) frames;
while (count-- > 0)
{
@@ -658,11 +660,17 @@ char *AudioOutputUtil::GeneratePinkSamples(char *frames, int channels,
{
res = generate_pink_noise_sample(&pink) * 0x03fffffff; /* Don't use MAX volume */
ires = res;
- *samp16++ = LE_SHORT(ires >> 16);
+ if (bits == 16)
+ *samp16++ = LE_SHORT(ires >> 16);
+ else
+ *samp32++ = LE_INT(ires);
}
else
{
- *samp16++ = 0;
+ if (bits == 16)
+ *samp16++ = 0;
+ else
+ *samp32++ = 0;
}
}
}
@@ -20,7 +20,7 @@ class MPUBLIC AudioOutputUtil
static void MuteChannel(int obits, int channels, int ch,
void *buffer, int bytes);
static char *GeneratePinkSamples(char *frames, int channels,
- int channel, int count);
+ int channel, int count, int bits = 16);
};
#endif
@@ -89,6 +89,10 @@ SPDIFEncoder::SPDIFEncoder(QString muxer, AVCodecContext *ctx)
av_write_header(m_oc);
+ VERBOSE(VB_AUDIO, LOC + QString("Creating %1 encoder (%2, %3Hz)")
+ .arg(muxer).arg(ff_codec_id_string((CodecID)codec->codec_type))
+ .arg(codec->sample_rate));
+
m_complete = true;
}
@@ -21,6 +21,11 @@
#include "audiogeneralsettings.h"
#include "mythdialogbox.h"
+extern "C" {
+#include "libavformat/avformat.h"
+}
+
+
class TriggeredItem : public TriggeredConfigurationGroup
{
public:
@@ -489,14 +494,20 @@ void AudioConfigSettings::StartAudioTest()
AudioTestThread::AudioTestThread(QObject *parent,
QString main, QString passthrough,
int channels,
- AudioOutputSettings settings) :
+ AudioOutputSettings settings,
+ bool hd) :
m_parent(parent), m_channels(channels), m_device(main),
- m_passthrough(passthrough), m_interrupted(false), m_channel(-1)
+ m_passthrough(passthrough), m_interrupted(false), m_channel(-1), m_hd(hd)
{
- m_audioOutput = AudioOutput::OpenAudio(m_device,
- m_passthrough,
- FORMAT_S16, m_channels,
- 0, 48000,
+ /* initialize libavcodec, and register all codecs and formats */
+ av_register_all();
+
+ m_format = hd ? settings.BestSupportedFormat() : FORMAT_S16;
+ m_samplerate = hd ? settings.BestSupportedRate() : 48000;
+
+ m_audioOutput = AudioOutput::OpenAudio(m_device, m_passthrough,
+ m_format, m_channels,
+ 0, m_samplerate,
AUDIOOUTPUT_VIDEO,
true, false, 0, &settings);
if (result().isEmpty())
@@ -551,7 +562,7 @@ void AudioTestThread::run()
if (m_audioOutput)
{
- char *frames_in = new char[m_channels * 1024 * sizeof(int16_t) + 15];
+ char *frames_in = new char[m_channels * 1024 * sizeof(int32_t) + 15];
char *frames = (char *)(((long)frames_in + 15) & ~0xf);
m_audioOutput->Pause(false);
@@ -609,19 +620,24 @@ void AudioTestThread::run()
QCoreApplication::postEvent(
m_parent, new ChannelChangedEvent(channel,
m_channel < 0));
+ VERBOSE(VB_AUDIO, QString("AudioTest: %1 (%2->%3)")
+ .arg(channel).arg(i).arg(current));
}
+
// play sample sound for about 3s
- for (int j = 0; j < 144 && !m_interrupted; j++)
+ int top = m_samplerate / 1000 * 3;
+ for (int j = 0; j < top && !m_interrupted; j++)
{
AudioOutputUtil::GeneratePinkSamples(frames, m_channels,
- current, 1000);
+ current, 1000,
+ m_hd ? 32 : 16);
if (!m_audioOutput->AddFrames(frames, 1000, -1))
{
VERBOSE(VB_AUDIO, "AddAudioData() "
"Audio buffer overflow, audio data lost!");
}
- usleep(20000); // a tad less than 1/48th of
- // a second to avoid underruns
+ // a tad less than 1/48th of a second to avoid underruns
+ usleep((1000000 / m_samplerate) * 1000);
}
m_audioOutput->Drain();
m_audioOutput->Pause(true);
@@ -643,12 +659,14 @@ AudioTest::AudioTest(QString main, QString passthrough,
m_channels(channels),
m_frontleft(NULL), m_frontright(NULL), m_center(NULL),
m_surroundleft(NULL), m_surroundright(NULL),
- m_rearleft(NULL), m_rearright(NULL), m_lfe(NULL)
-
+ m_rearleft(NULL), m_rearright(NULL), m_lfe(NULL),
+ m_main(main), m_passthrough(passthrough), m_settings(settings),
+ m_quality(false)
{
setLabel(QObject::tr("Audio Configuration Testing"));
- m_at = new AudioTestThread(this, main, passthrough, channels, settings);
+ m_at = new AudioTestThread(this, main, passthrough, channels,
+ settings, m_quality);
if (!m_at->result().isEmpty())
{
QString msg = main + QObject::tr(" is invalid or not "
@@ -730,6 +748,15 @@ AudioTest::AudioTest(QString main, QString passthrough,
addChild(middlegroup);
addChild(reargroup);
addChild(m_button);
+
+ m_hd = new TransCheckBoxSetting();
+ m_hd->setLabel(QObject::tr("Use Highest Quality Mode"));
+ m_hd->setHelpText(QObject::tr("Use the highest audio quality settings "
+ "supported by your audio card. This will be "
+ "a good place to start troubleshooting "
+ "potential errors"));
+ addChild(m_hd);
+ connect(m_hd, SIGNAL(valueChanged(QString)), this, SLOT(togglequality()));
}
AudioTest::~AudioTest()
@@ -772,17 +799,37 @@ void AudioTest::toggle(QString str)
}
return;
}
- int channel = str.toInt();
if (m_at->isRunning())
{
m_at->cancel();
m_at->wait();
}
+
+ int channel = str.toInt();
m_at->setChannel(channel);
m_at->start();
}
+void AudioTest::togglequality()
+{
+ if (m_at->isRunning())
+ {
+ toggle("start");
+ }
+
+ m_quality = m_hd->boolValue();
+ delete m_at;
+ m_at = new AudioTestThread(this, m_main, m_passthrough, m_channels,
+ m_settings, m_quality);
+ if (!m_at->result().isEmpty())
+ {
+ QString msg = QObject::tr("Audio device is invalid or not useable.");
+ MythPopupBox::showOkPopup(
+ GetMythMainWindow(), QObject::tr("Warning"), msg);
+ }
+}
+
bool AudioTest::event(QEvent *event)
{
if (event->type() != ChannelChangedEvent::kEventType)
@@ -148,7 +148,7 @@ class AudioTestThread : public QThread
public:
AudioTestThread(QObject *parent, QString main, QString passthrough,
- int channels, AudioOutputSettings settings);
+ int channels, AudioOutputSettings settings, bool hd);
~AudioTestThread();
void cancel();
@@ -159,13 +159,16 @@ class AudioTestThread : public QThread
void run();
private:
- QObject *m_parent;
- AudioOutput *m_audioOutput;
- int m_channels;
- QString m_device;
- QString m_passthrough;
- bool m_interrupted;
- int m_channel;
+ QObject *m_parent;
+ AudioOutput *m_audioOutput;
+ int m_channels;
+ QString m_device;
+ QString m_passthrough;
+ bool m_interrupted;
+ int m_channel;
+ bool m_hd;
+ int m_samplerate;
+ AudioFormat m_format;
};
class AudioTest : public VerticalConfigurationGroup
@@ -178,18 +181,25 @@ class AudioTest : public VerticalConfigurationGroup
bool event(QEvent *event);
private:
- int m_channels ;
- TransButtonSetting *m_frontleft;
- TransButtonSetting *m_frontright;
- TransButtonSetting *m_center;
- TransButtonSetting *m_surroundleft;
- TransButtonSetting *m_surroundright;
- TransButtonSetting *m_rearleft;
- TransButtonSetting *m_rearright;
- TransButtonSetting *m_lfe;
- AudioTestThread *m_at;
- TransButtonSetting *m_button;
+ int m_channels;
+ TransButtonSetting *m_frontleft;
+ TransButtonSetting *m_frontright;
+ TransButtonSetting *m_center;
+ TransButtonSetting *m_surroundleft;
+ TransButtonSetting *m_surroundright;
+ TransButtonSetting *m_rearleft;
+ TransButtonSetting *m_rearright;
+ TransButtonSetting *m_lfe;
+ AudioTestThread *m_at;
+ TransButtonSetting *m_button;
+ TransCheckBoxSetting *m_hd;
+ QString m_main;
+ QString m_passthrough;
+ AudioOutputSettings m_settings;
+ bool m_quality;
+
private slots:
void toggle(QString str);
+ void togglequality(void);
};
#endif

0 comments on commit e44b025

Please sign in to comment.