Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tsound_t.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tthread.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <errno.h></errno.h>
Toshihiro Shimizu 890ddd
#include <unistd.h></unistd.h>
Toshihiro Shimizu 890ddd
#include <queue></queue>
Toshihiro Shimizu 890ddd
#include <set></set>
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
#include <qbytearray></qbytearray>
Jeremy Bullock 6767be
#include <qaudioformat></qaudioformat>
Jeremy Bullock 6767be
#include <qbuffer></qbuffer>
Jeremy Bullock 6767be
#include <qaudiooutput></qaudiooutput>
Jeremy Bullock 6767be
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
TThread::Mutex MutexOut;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TSoundOutputDeviceImp
Shinya Kitaoka 120a6e
    : public std::enable_shared_from_this<tsoundoutputdeviceimp> {</tsoundoutputdeviceimp>
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  bool m_isPlaying;
Shinya Kitaoka 120a6e
  bool m_looped;
Shinya Kitaoka 120a6e
  TSoundTrackFormat m_currentFormat;
Shinya Kitaoka 120a6e
  std::set<int> m_supportedRate;</int>
Shinya Kitaoka 120a6e
  bool m_opened;
Jeremy Bullock 6767be
  double m_volume = 0.5;
Jeremy Bullock 6767be
Jeremy Bullock 6767be
  QAudioOutput *m_audioOutput;
Jeremy Bullock 6767be
  QBuffer *m_buffer;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TSoundOutputDeviceImp()
Shinya Kitaoka 120a6e
      : m_isPlaying(false)
Shinya Kitaoka 120a6e
      , m_looped(false)
Shinya Kitaoka 120a6e
      , m_supportedRate()
Shinya Kitaoka 120a6e
      , m_opened(false){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::set<tsoundoutputdevicelistener *=""> m_listeners;</tsoundoutputdevicelistener>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~TSoundOutputDeviceImp(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool doOpenDevice();
Shinya Kitaoka 120a6e
  bool doSetStreamFormat(const TSoundTrackFormat &format);
Shinya Kitaoka 120a6e
  bool doStopDevice();
Shinya Kitaoka 120a6e
  void play(const TSoundTrackP &st, TINT32 s0, TINT32 s1, bool loop,
Shinya Kitaoka 120a6e
            bool scrubbing);
Jeremy Bullock 6767be
  void prepareVolume(double volume);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct MyData {
Shinya Kitaoka 120a6e
  char *entireFileBuffer;
Shinya Kitaoka 120a6e
Jeremy Bullock 6767be
  quint64 totalPacketCount;
Jeremy Bullock 6767be
  quint64 fileByteCount;
Jeremy Bullock 6767be
  quint32 maxPacketSize;
Jeremy Bullock 6767be
  quint64 packetOffset;
Jeremy Bullock 6767be
  quint64 byteOffset;
Shinya Kitaoka 120a6e
  bool m_doNotify;
Shinya Kitaoka 120a6e
  void *sourceBuffer;
Jeremy Bullock 6767be
  // AudioConverterRef converter;
Shinya Kitaoka 120a6e
  std::shared_ptr<tsoundoutputdeviceimp> imp;</tsoundoutputdeviceimp>
Shinya Kitaoka 120a6e
  bool isLooping;
Shinya Kitaoka 120a6e
  MyData()
Shinya Kitaoka 120a6e
      : entireFileBuffer(0)
Shinya Kitaoka 120a6e
      , totalPacketCount(0)
Shinya Kitaoka 120a6e
      , fileByteCount(0)
Shinya Kitaoka 120a6e
      , maxPacketSize(0)
Shinya Kitaoka 120a6e
      , packetOffset(0)
Shinya Kitaoka 120a6e
      , byteOffset(0)
Shinya Kitaoka 120a6e
      , sourceBuffer(0)
Shinya Kitaoka 120a6e
      , isLooping(false)
Shinya Kitaoka 120a6e
      , m_doNotify(true) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class PlayCompletedMsg : public TThread::Message {
Shinya Kitaoka 120a6e
  std::set<tsoundoutputdevicelistener *=""> m_listeners;</tsoundoutputdevicelistener>
Shinya Kitaoka 120a6e
  MyData *m_data;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  PlayCompletedMsg(MyData *data) : m_data(data) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TThread::Message *clone() const { return new PlayCompletedMsg(*this); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onDeliver() {
Shinya Kitaoka 120a6e
    if (m_data->imp) {
Shinya Kitaoka 120a6e
      if (m_data->m_doNotify == false) return;
Shinya Kitaoka 120a6e
      m_data->m_doNotify = false;
Shinya Kitaoka 120a6e
      if (m_data->imp->m_isPlaying) m_data->imp->doStopDevice();
Shinya Kitaoka 120a6e
      std::set<tsoundoutputdevicelistener *="">::iterator it =</tsoundoutputdevicelistener>
Shinya Kitaoka 120a6e
          m_data->imp->m_listeners.begin();
Shinya Kitaoka 120a6e
      for (; it != m_data->imp->m_listeners.end(); ++it)
Shinya Kitaoka 120a6e
        (*it)->onPlayCompleted();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define checkStatus(err)                                                       \
Shinya Kitaoka 120a6e
  if (err) {                                                                   \
Shinya Kitaoka 120a6e
    printf("Error: 0x%x ->  %s: %d\n", (int)err, __FILE__, __LINE__);          \
Shinya Kitaoka 120a6e
    fflush(stdout);                                                            \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDeviceImp::doOpenDevice() {
Jeremy Bullock 6767be
  m_opened      = false;
Jeremy Bullock 6767be
  m_audioOutput = NULL;
Jeremy Bullock 6767be
  m_opened      = true;
Shinya Kitaoka 120a6e
  return m_opened;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool TSoundOutputDeviceImp::doSetStreamFormat(const TSoundTrackFormat &format) {
Shinya Kitaoka 120a6e
  if (!m_opened) doOpenDevice();
Shinya Kitaoka 120a6e
  if (!m_opened) return false;
Shinya Kitaoka 120a6e
  m_opened = true;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundOutputDevice::TSoundOutputDevice() : m_imp(new TSoundOutputDeviceImp) {
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    supportsVolume();
Shinya Kitaoka 120a6e
  } catch (TSoundDeviceException &e) {
Shinya Kitaoka 120a6e
    throw TSoundDeviceException(e.getType(), e.getMessage());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundOutputDevice::~TSoundOutputDevice() {
Shinya Kitaoka 120a6e
  stop();
Shinya Kitaoka 120a6e
  close();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDevice::installed() { return true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDevice::open(const TSoundTrackP &st) {
Shinya Kitaoka 120a6e
  if (!m_imp->doOpenDevice())
Shinya Kitaoka 120a6e
    throw TSoundDeviceException(TSoundDeviceException::UnableOpenDevice,
Shinya Kitaoka 120a6e
                                "Problem to open the output device");
Shinya Kitaoka 120a6e
  if (!m_imp->doSetStreamFormat(st->getFormat()))
Shinya Kitaoka 120a6e
    throw TSoundDeviceException(
Shinya Kitaoka 120a6e
        TSoundDeviceException::UnableOpenDevice,
Shinya Kitaoka 120a6e
        "Problem to open the output device setting some params");
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDevice::close() {
Shinya Kitaoka 120a6e
  stop();
Shinya Kitaoka 120a6e
  m_imp->m_opened = false;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
void TSoundOutputDeviceImp::prepareVolume(double volume) {
Jeremy Bullock 6767be
    m_volume = volume;
Jeremy Bullock 6767be
}
Jeremy Bullock 6767be
Jeremy Bullock 6767be
//------------------------------------------------------------------------------
Jeremy Bullock 6767be
Jeremy Bullock 6767be
void TSoundOutputDevice::prepareVolume(double volume) {
Jeremy Bullock 6767be
    m_imp->prepareVolume(volume);
Jeremy Bullock 6767be
}
Jeremy Bullock 6767be
Jeremy Bullock 6767be
//------------------------------------------------------------------------------
Jeremy Bullock 6767be
Shinya Kitaoka 120a6e
void TSoundOutputDevice::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
Shinya Kitaoka 120a6e
                              bool loop, bool scrubbing) {
Shinya Kitaoka 120a6e
  int lastSample = st->getSampleCount() - 1;
Shinya Kitaoka 120a6e
  notLessThan(0, s0);
Shinya Kitaoka 120a6e
  notLessThan(0, s1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  notMoreThan(lastSample, s0);
Shinya Kitaoka 120a6e
  notMoreThan(lastSample, s1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (s0 > s1) {
Toshihiro Shimizu 890ddd
#ifdef DEBUG
Shinya Kitaoka 120a6e
    cout << "s0 > s1; reorder" << endl;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    swap(s0, s1);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isPlaying()) {
Toshihiro Shimizu 890ddd
#ifdef DEBUG
Shinya Kitaoka 120a6e
    cout << "is playing, stop it!" << endl;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    stop();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_imp->play(st, s0, s1, loop, scrubbing);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
Shinya Kitaoka 120a6e
                                 bool loop, bool scrubbing) {
Shinya Kitaoka 120a6e
  if (!doSetStreamFormat(st->getFormat())) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  MyData *myData = new MyData();
Shinya Kitaoka 120a6e
Jeremy Bullock 6767be
  myData->imp              = shared_from_this();
Shinya Kitaoka 120a6e
  myData->totalPacketCount = s1 - s0;
Shinya Kitaoka 120a6e
  myData->fileByteCount    = (s1 - s0) * st->getSampleSize();
Shinya Kitaoka 120a6e
  myData->entireFileBuffer = new char[myData->fileByteCount];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
Shinya Kitaoka 120a6e
         myData->fileByteCount);
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
  m_isPlaying       = true;
Shinya Kitaoka 120a6e
  myData->isLooping = loop;
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
  QAudioFormat format;
Jeremy Bullock 6767be
  QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
Jeremy Bullock 6767be
Jeremy Bullock 6767be
  format.setSampleSize(st->getBitPerSample());
Jeremy Bullock 6767be
  format.setCodec("audio/pcm");
Jeremy Bullock 6767be
  format.setChannelCount(st->getChannelCount());
Jeremy Bullock 6767be
  format.setByteOrder(QAudioFormat::LittleEndian);
Jeremy Bullock 6767be
  format.setSampleType(st->getFormat().m_signedSample
Jeremy Bullock 6767be
                           ? QAudioFormat::SignedInt
Jeremy Bullock 6767be
                           : QAudioFormat::UnSignedInt);
Jeremy Bullock 6767be
  format.setSampleRate(st->getSampleRate());
Jeremy Bullock 6767be
  QList<qaudioformat::endian> sbos        = info.supportedByteOrders();</qaudioformat::endian>
Jeremy Bullock 6767be
  QList<int> sccs                         = info.supportedChannelCounts();</int>
Jeremy Bullock 6767be
  QList<int> ssrs                         = info.supportedSampleRates();</int>
Jeremy Bullock 6767be
  QList<qaudioformat::sampletype> sstypes = info.supportedSampleTypes();</qaudioformat::sampletype>
Jeremy Bullock 6767be
  QList<int> ssss                         = info.supportedSampleSizes();</int>
Jeremy Bullock 6767be
  QStringList supCodes                    = info.supportedCodecs();
Jeremy Bullock 6767be
  if (!info.isFormatSupported((format))) {
Jeremy Bullock 6767be
    format                                 = info.nearestFormat(format);
Jeremy Bullock 6767be
    int newChannels                        = format.channelCount();
Jeremy Bullock 6767be
    int newBitsPerSample                   = format.sampleSize();
Jeremy Bullock 6767be
    int newSampleRate                      = format.sampleRate();
Jeremy Bullock 6767be
    QAudioFormat::SampleType newSampleType = format.sampleType();
Jeremy Bullock 6767be
    QAudioFormat::Endian newBo             = format.byteOrder();
Jeremy Bullock 6767be
  }
Jeremy Bullock 6767be
  int test = st->getSampleCount() / st->getSampleRate();
Jeremy Bullock 6767be
  QByteArray *data =
Jeremy Bullock 6767be
      new QByteArray(myData->entireFileBuffer, myData->fileByteCount);
Jeremy Bullock 6767be
  QBuffer *newBuffer = new QBuffer;
Jeremy Bullock 6767be
  newBuffer->setBuffer(data);
Jeremy Bullock 6767be
  newBuffer->open(QIODevice::ReadOnly);
Jeremy Bullock 6767be
  newBuffer->seek(0);
Jeremy Bullock 6767be
  if (m_audioOutput == NULL) {
Jeremy Bullock 6767be
    m_audioOutput = new QAudioOutput(format, NULL);
Jeremy Bullock 6767be
  }
Jeremy Bullock 6767be
  m_audioOutput->start(newBuffer);
Jeremy Bullock 6767be
  m_audioOutput->setVolume(m_volume);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDeviceImp::doStopDevice() {
Shinya Kitaoka 120a6e
  m_isPlaying = false;
Jeremy Bullock 6767be
  m_audioOutput->stop();
Jeremy Bullock 6767be
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundOutputDevice::stop() {
Shinya Kitaoka 120a6e
  if (m_imp->m_opened == false) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_imp->doStopDevice();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundOutputDevice::attach(TSoundOutputDeviceListener *listener) {
Shinya Kitaoka 120a6e
  m_imp->m_listeners.insert(listener);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundOutputDevice::detach(TSoundOutputDeviceListener *listener) {
Shinya Kitaoka 120a6e
  m_imp->m_listeners.erase(listener);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSoundOutputDevice::getVolume() {
Jeremy Bullock 6767be
  if (m_imp->m_audioOutput != NULL)
Jeremy Bullock 6767be
  return m_imp->m_audioOutput->volume();
Jeremy Bullock 6767be
  else return m_imp->m_volume;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDevice::setVolume(double volume) {
Jeremy Bullock 6767be
  m_imp->m_volume = volume;
Jeremy Bullock 6767be
  m_imp->m_audioOutput->setVolume(volume);
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundOutputDevice::supportsVolume() { return true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
bool TSoundOutputDevice::isPlaying() const { return m_imp->m_isPlaying; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
bool TSoundOutputDevice::isLooping() { return m_imp->m_looped; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock 6767be
void TSoundOutputDevice::setLooping(bool loop) { m_imp->m_looped = loop; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrackFormat TSoundOutputDevice::getPreferredFormat(TUINT32 sampleRate,
Shinya Kitaoka 120a6e
                                                         int channelCount,
Shinya Kitaoka 120a6e
                                                         int bitPerSample) {
Shinya Kitaoka 120a6e
  TSoundTrackFormat fmt(sampleRate, bitPerSample, channelCount, true);
Shinya Kitaoka 120a6e
  return fmt;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrackFormat TSoundOutputDevice::getPreferredFormat(
Shinya Kitaoka 120a6e
    const TSoundTrackFormat &format) {
Shinya Kitaoka 120a6e
  return getPreferredFormat(format.m_sampleRate, format.m_channelCount,
Shinya Kitaoka 120a6e
                            format.m_bitPerSample);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
//                REGISTRAZIONE
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TSoundInputDeviceImp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  // ALport m_port;
Shinya Kitaoka 120a6e
  bool m_stopped;
Shinya Kitaoka 120a6e
  bool m_isRecording;
Shinya Kitaoka 120a6e
  bool m_oneShotRecording;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  long m_recordedSampleCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSoundTrackFormat m_currentFormat;
Shinya Kitaoka 120a6e
  TSoundTrackP m_st;
Shinya Kitaoka 120a6e
  std::set<int> m_supportedRate;</int>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TThread::Executor m_executor;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TSoundInputDeviceImp()
Shinya Kitaoka 120a6e
      : m_stopped(false)
Shinya Kitaoka 120a6e
      , m_isRecording(false)
Shinya Kitaoka 120a6e
      //   , m_port(NULL)
Shinya Kitaoka 120a6e
      , m_oneShotRecording(false)
Shinya Kitaoka 120a6e
      , m_recordedSampleCount(0)
Shinya Kitaoka 120a6e
      , m_st(0)
Shinya Kitaoka 120a6e
      , m_supportedRate(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~TSoundInputDeviceImp(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool doOpenDevice(const TSoundTrackFormat &format,
Shinya Kitaoka 120a6e
                    TSoundInputDevice::Source devType);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TSoundInputDeviceImp::doOpenDevice(const TSoundTrackFormat &format,
Shinya Kitaoka 120a6e
                                        TSoundInputDevice::Source devType) {
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class RecordTask : public TThread::Runnable {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TSoundInputDeviceImp *m_devImp;
Shinya Kitaoka 120a6e
  int m_ByteToSample;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  RecordTask(TSoundInputDeviceImp *devImp, int numByte)
Shinya Kitaoka 120a6e
      : TThread::Runnable(), m_devImp(devImp), m_ByteToSample(numByte){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ~RecordTask(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void run();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void RecordTask::run() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundInputDevice::TSoundInputDevice() : m_imp(new TSoundInputDeviceImp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundInputDevice::~TSoundInputDevice() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundInputDevice::installed() {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  if (alQueryValues(AL_SYSTEM, AL_DEFAULT_INPUT, 0, 0, 0, 0) <=0)
Shinya Kitaoka 120a6e
return false;
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundInputDevice::record(const TSoundTrackFormat &format,
Shinya Kitaoka 120a6e
                               TSoundInputDevice::Source type) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TSoundInputDevice::record(const TSoundTrackP &st,
Shinya Kitaoka 120a6e
                               TSoundInputDevice::Source type) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrackP TSoundInputDevice::stop() {
Shinya Kitaoka 120a6e
  TSoundTrackP st;
Shinya Kitaoka 120a6e
  return st;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
double TSoundInputDevice::getVolume() { return 0.0; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundInputDevice::setVolume(double volume) { return true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundInputDevice::supportsVolume() { return true; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrackFormat TSoundInputDevice::getPreferredFormat(TUINT32 sampleRate,
Shinya Kitaoka 120a6e
                                                        int channelCount,
Shinya Kitaoka 120a6e
                                                        int bitPerSample) {
Shinya Kitaoka 120a6e
  TSoundTrackFormat fmt;
Shinya Kitaoka 120a6e
  return fmt;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TSoundTrackFormat TSoundInputDevice::getPreferredFormat(
Shinya Kitaoka 120a6e
    const TSoundTrackFormat &format) {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
try {
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  return getPreferredFormat(format.m_sampleRate, format.m_channelCount,
Shinya Kitaoka 120a6e
                            format.m_bitPerSample);
Shinya Kitaoka 120a6e
  /*}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
catch (TSoundDeviceException &e) {
Shinya Kitaoka 120a6e
throw TSoundDeviceException( e.getType(), e.getMessage());
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TSoundInputDevice::isRecording() { return m_imp->m_isRecording; }