![]() |
Mixxx
|
00001 /*************************************************************************** 00002 sounddevice.cpp 00003 ------------------- 00004 begin : Sun Aug 12, 2007, past my bedtime 00005 copyright : (C) 2007 Albert Santoni 00006 email : gamegod \a\t users.sf.net 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include <QtDebug> 00019 #include <QtCore> 00020 #include "soundmanagerutil.h" 00021 #include "soundmanager.h" 00022 #include "sounddevice.h" 00023 00024 SoundDevice::SoundDevice(ConfigObject<ConfigValue> * config, SoundManager * sm) 00025 { 00026 m_pConfig = config; 00027 m_pSoundManager = sm; 00028 m_strInternalName = "Unknown Soundcard"; 00029 m_strDisplayName = "Unknown Soundcard"; 00030 m_iNumOutputChannels = 2; 00031 m_iNumInputChannels = 2; 00032 m_dSampleRate = 44100.0f; 00033 } 00034 00035 SoundDevice::~SoundDevice() 00036 { 00037 00038 } 00039 00040 QString SoundDevice::getInternalName() const 00041 { 00042 return m_strInternalName; 00043 } 00044 00045 QString SoundDevice::getDisplayName() const 00046 { 00047 return m_strDisplayName; 00048 } 00049 00050 QString SoundDevice::getHostAPI() const 00051 { 00052 return m_hostAPI; 00053 } 00054 00055 int SoundDevice::getNumInputChannels() const 00056 { 00057 return m_iNumInputChannels; 00058 } 00059 00060 int SoundDevice::getNumOutputChannels() const 00061 { 00062 return m_iNumOutputChannels; 00063 } 00064 00065 void SoundDevice::setHostAPI(QString api) 00066 { 00067 m_hostAPI = api; 00068 } 00069 00070 void SoundDevice::setSampleRate(double sampleRate) { 00071 if (sampleRate <= 0.0) { 00072 // this is the default value used elsewhere in this file 00073 sampleRate = 44100.0; 00074 } 00075 m_dSampleRate = sampleRate; 00076 } 00077 00078 void SoundDevice::setFramesPerBuffer(unsigned int framesPerBuffer) { 00079 if (framesPerBuffer * 2 > (unsigned int) MAX_BUFFER_LEN) { 00080 // framesPerBuffer * 2 because a frame will generally end up 00081 // being 2 samples and MAX_BUFFER_LEN is a number of samples 00082 // this isn't checked elsewhere, so... 00083 qFatal("framesPerBuffer too big in " 00084 "SoundDevice::setFramesPerBuffer(uint)"); 00085 } 00086 m_framesPerBuffer = framesPerBuffer; 00087 } 00088 00089 SoundDeviceError SoundDevice::addOutput(const AudioOutput &out) 00090 { 00091 //Check if the output channels are already used 00092 foreach (AudioOutput myOut, m_audioOutputs) { 00093 if (out.channelsClash(myOut)) { 00094 return SOUNDDEVICE_ERROR_DUPLICATE_OUTPUT_CHANNEL; 00095 } 00096 } 00097 if (out.getChannelGroup().getChannelBase() 00098 + out.getChannelGroup().getChannelCount() > getNumOutputChannels()) { 00099 return SOUNDDEVICE_ERROR_EXCESSIVE_OUTPUT_CHANNEL; 00100 } 00101 m_audioOutputs.append(out); 00102 return SOUNDDEVICE_ERROR_OK; 00103 } 00104 00105 void SoundDevice::clearOutputs() 00106 { 00107 m_audioOutputs.clear(); 00108 } 00109 00110 SoundDeviceError SoundDevice::addInput(const AudioInput &in) 00111 { 00112 // DON'T check if the input channels are already used, there's no reason 00113 // we can't send the same inputted samples to different places in mixxx. 00114 // -- bkgood 20101108 00115 if (in.getChannelGroup().getChannelBase() 00116 + in.getChannelGroup().getChannelCount() > getNumInputChannels()) { 00117 return SOUNDDEVICE_ERROR_EXCESSIVE_INPUT_CHANNEL; 00118 } 00119 m_audioInputs.append(in); 00120 return SOUNDDEVICE_ERROR_OK; 00121 } 00122 00123 void SoundDevice::clearInputs() 00124 { 00125 m_audioInputs.clear(); 00126 } 00127 00128 bool SoundDevice::operator==(const SoundDevice &other) const 00129 { 00130 return this->getInternalName() == other.getInternalName(); 00131 } 00132 00133 bool SoundDevice::operator==(const QString &other) const 00134 { 00135 return getInternalName() == other; 00136 }