Skip to content

Commit

Permalink
default Sample Rate to PA default (most likely 44100 Hz), Bug #1087002
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Jan 15, 2013
1 parent 345fa60 commit c1d37e8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions mixxx/src/sounddevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SoundDevice
virtual int open() = 0;
virtual int close() = 0;
virtual QString getError() const = 0;
virtual unsigned int getDefaultSampleRate() const = 0;
int getNumOutputChannels() const;
int getNumInputChannels() const;
SoundDeviceError addOutput(const AudioOutput &out);
Expand Down
3 changes: 3 additions & 0 deletions mixxx/src/sounddeviceportaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SoundDevicePortAudio : public SoundDevice
float *output, short *in,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags);
virtual unsigned int getDefaultSampleRate() const {
return (unsigned int)m_deviceInfo->defaultSampleRate;
}
private:
/** PortAudio stream for this device. */
PaStream *m_pStream;
Expand Down
3 changes: 1 addition & 2 deletions mixxx/src/soundmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,12 @@ void SoundManager::checkConfig() {
m_config.loadDefaults(this, SoundManagerConfig::API | SoundManagerConfig::DEVICES);
}
if (!m_config.checkSampleRate(*this)) {
m_config.setSampleRate(SoundManagerConfig::kDefaultSampleRate);
m_config.setSampleRate(SoundManagerConfig::kFallbackSampleRate);
m_config.loadDefaults(this, SoundManagerConfig::OTHER);
}
// latency checks itself for validity on SMConfig::setLatency()
}


QHash<AudioOutput, const CSAMPLE*> SoundManager::requestBuffer(
QList<AudioOutput> outputs, unsigned long iFramesPerBuffer,
SoundDevice* device, double streamTime /* = 0 */) {
Expand Down
28 changes: 18 additions & 10 deletions mixxx/src/soundmanagerconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
const unsigned int SoundManagerConfig::kMaxLatency = 7;

const QString SoundManagerConfig::kDefaultAPI = QString("None");
const unsigned int SoundManagerConfig::kDefaultSampleRate = 48000;
// Sample Rate even the cheap sound Devices will support most likely
const unsigned int SoundManagerConfig::kFallbackSampleRate = 48000;
// latency=5 means about 21 ms of latency which is default in trunk r2453 -- bkgood
const int SoundManagerConfig::kDefaultLatency = 5;

SoundManagerConfig::SoundManagerConfig()
: m_api("None")
, m_sampleRate(kDefaultSampleRate)
, m_latency(kDefaultLatency) {
SoundManagerConfig::SoundManagerConfig() :
m_api("None"),
m_sampleRate(kFallbackSampleRate),
m_latency(kDefaultLatency) {
m_configFile = QFileInfo(CmdlineArgs::Instance().getSettingsPath() + SOUNDMANAGERCONFIG_FILENAME);
}

Expand Down Expand Up @@ -166,7 +167,7 @@ unsigned int SoundManagerConfig::getSampleRate() const {

void SoundManagerConfig::setSampleRate(unsigned int sampleRate) {
// making sure we don't divide by zero elsewhere
m_sampleRate = sampleRate != 0 ? sampleRate : kDefaultSampleRate;
m_sampleRate = sampleRate != 0 ? sampleRate : kFallbackSampleRate;
}

/**
Expand Down Expand Up @@ -315,28 +316,35 @@ void SoundManagerConfig::loadDefaults(SoundManager *soundManager, unsigned int f
#endif
}
}

unsigned int defaultSampleRate = kFallbackSampleRate;
if (flags & SoundManagerConfig::DEVICES) {
clearOutputs();
clearInputs();
QList<SoundDevice*> outputDevices = soundManager->getDeviceList(m_api, true, false);
if (!outputDevices.isEmpty()) {
foreach (SoundDevice *device, outputDevices) {
if (device->getNumOutputChannels() < 2) continue;
if (device->getNumOutputChannels() < 2) {
continue;
}
AudioOutput masterOut(AudioPath::MASTER, 0);
addOutput(device->getInternalName(), masterOut);
defaultSampleRate = device->getDefaultSampleRate();
break;
}
}
}
if (flags & SoundManagerConfig::OTHER) {
QList<unsigned int> sampleRates = soundManager->getSampleRates(m_api);
if (sampleRates.contains(kDefaultSampleRate)) {
m_sampleRate = kDefaultSampleRate;
if (sampleRates.contains(defaultSampleRate)) {
m_sampleRate = defaultSampleRate;
} else if (sampleRates.contains(kFallbackSampleRate)) {
m_sampleRate = kFallbackSampleRate;
} else if (!sampleRates.isEmpty()) {
m_sampleRate = sampleRates.first();
} else {
qWarning() << "got empty sample rate list from SoundManager, this is a bug";
m_sampleRate = kDefaultSampleRate;
m_sampleRate = kFallbackSampleRate;
}
m_latency = kDefaultLatency;
}
Expand Down
2 changes: 1 addition & 1 deletion mixxx/src/soundmanagerconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SoundManagerConfig {
};
static const unsigned int kMaxLatency;
static const QString kDefaultAPI;
static const unsigned int kDefaultSampleRate;
static const unsigned int kFallbackSampleRate;
static const int kDefaultLatency;

SoundManagerConfig();
Expand Down

0 comments on commit c1d37e8

Please sign in to comment.