Esempio n. 1
0
 void addSoundtrack(const ToonzScene &scene, int frameOffset,
                    int sceneFrameCount) {
   assert(m_status <= 2);
   m_status                       = 2;
   TXsheet::SoundProperties *prop = new TXsheet::SoundProperties();
   prop->m_frameRate              = m_fps;
   TSoundTrack *snd               = scene.getXsheet()->makeSound(prop);
   if (!snd || m_filepath.getDots() == "..") {
     m_whiteSample += sceneFrameCount * 918;
     return;
   }
   long samplePerFrame = snd->getSampleRate() / m_fps;
   TSoundTrackP snd1   = snd->extract(
       frameOffset * samplePerFrame,
       (TINT32)((frameOffset + sceneFrameCount - 1) * samplePerFrame));
   if (!m_st) {
     m_st          = TSoundTrack::create(snd1->getFormat(), m_whiteSample);
     m_whiteSample = 0;
   }
   TINT32 fromSample = m_st->getSampleCount();
   TINT32 numSample  = std::max(TINT32(sceneFrameCount * samplePerFrame),
                               snd1->getSampleCount());
   m_st = TSop::insertBlank(m_st, fromSample, numSample + m_whiteSample);
   m_st->copy(snd1, TINT32(fromSample + m_whiteSample));
   m_whiteSample = 0;
 }
Esempio n. 2
0
void LWSaveSoundTrackParser::operator()(Message &msg) {
  unsigned int id;
  QString shMemId;

  TUINT32 sampleRate;
  TINT32 sCount;
  int bps, chanCount;
  bool signedSample;

  msg >> id >> sampleRate >> bps >> chanCount >> sCount >> signedSample;

  // Retrieve the soundtrack buffer
  TSoundTrackP st =
      TSoundTrack::create(sampleRate, bps, chanCount, sCount, signedSample);
  t32bitsrv::BufferExchanger exch((UCHAR *)st->getRawData());
  tipc::readShMemBuffer(*stream(), msg, &exch);

  // Write the soundtrack
  try {
    writers.find(id).value()->saveSoundTrack(st.getPointer());
    msg << QString("ok");
  } catch (...) {
    msg << QString("err");
  }
}
Esempio n. 3
0
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
                                 bool loop, bool scrubbing) {
  if (!doOpenDevice(st->getFormat())) return;

  MyData *myData = new MyData();

  myData->imp              = this;
  myData->totalPacketCount = s1 - s0;
  myData->fileByteCount    = (s1 - s0) * st->getSampleSize();
  myData->entireFileBuffer = new char[myData->fileByteCount];

  memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
         myData->fileByteCount);

  //	myData->maxPacketSize = fileASBD.mFramesPerPacket *
  // fileASBD.mBytesPerFrame;
  {
    // TThread::ScopedLock sl(MutexOut);
    m_isPlaying = true;
  }
  myData->isLooping = loop;

  // cout << "total packet count = " << myData->totalPacketCount <<endl;
  // cout << "filebytecount " << myData->fileByteCount << endl;

  m_data = myData;
  SDL_PauseAudio(0);
}
Esempio n. 4
0
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
                                 bool loop, bool scrubbing) {
  if (!doSetStreamFormat(st->getFormat())) return;

  MyData *myData = new MyData();

  myData->imp              = shared_from_this();
  myData->totalPacketCount = s1 - s0;
  myData->fileByteCount    = (s1 - s0) * st->getSampleSize();
  myData->entireFileBuffer = new char[myData->fileByteCount];

  memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
         myData->fileByteCount);

  m_isPlaying       = true;
  myData->isLooping = loop;

  QAudioFormat format;
  QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

  format.setSampleSize(st->getBitPerSample());
  format.setCodec("audio/pcm");
  format.setChannelCount(st->getChannelCount());
  format.setByteOrder(QAudioFormat::LittleEndian);
  format.setSampleType(st->getFormat().m_signedSample
                           ? QAudioFormat::SignedInt
                           : QAudioFormat::UnSignedInt);
  format.setSampleRate(st->getSampleRate());
  QList<QAudioFormat::Endian> sbos        = info.supportedByteOrders();
  QList<int> sccs                         = info.supportedChannelCounts();
  QList<int> ssrs                         = info.supportedSampleRates();
  QList<QAudioFormat::SampleType> sstypes = info.supportedSampleTypes();
  QList<int> ssss                         = info.supportedSampleSizes();
  QStringList supCodes                    = info.supportedCodecs();
  if (!info.isFormatSupported((format))) {
    format                                 = info.nearestFormat(format);
    int newChannels                        = format.channelCount();
    int newBitsPerSample                   = format.sampleSize();
    int newSampleRate                      = format.sampleRate();
    QAudioFormat::SampleType newSampleType = format.sampleType();
    QAudioFormat::Endian newBo             = format.byteOrder();
  }
  int test = st->getSampleCount() / st->getSampleRate();
  QByteArray *data =
      new QByteArray(myData->entireFileBuffer, myData->fileByteCount);
  QBuffer *newBuffer = new QBuffer;
  newBuffer->setBuffer(data);
  newBuffer->open(QIODevice::ReadOnly);
  newBuffer->seek(0);
  if (m_audioOutput == NULL) {
    m_audioOutput = new QAudioOutput(format, NULL);
  }
  m_audioOutput->start(newBuffer);
  m_audioOutput->setVolume(m_volume);
}
Esempio n. 5
0
TSoundTrackP TSoundTrack::create(TUINT32 sampleRate, int bitPerSample,
                                 int channelCount, TINT32 sampleCount,
                                 bool signedSample) {
  TSoundTrackP st;
  int type = bitPerSample + channelCount;
  switch (type) {
  case TRK_M8:
    if (signedSample)
      st = new TSoundTrackMono8Signed(sampleRate, channelCount, sampleCount);
    else
      st = new TSoundTrackMono8Unsigned(sampleRate, channelCount, sampleCount);
    break;
  case TRK_S8:
    if (signedSample)
      st = new TSoundTrackStereo8Signed(sampleRate, channelCount, sampleCount);
    else
      st =
          new TSoundTrackStereo8Unsigned(sampleRate, channelCount, sampleCount);
    break;

  case TRK_M16:
    st = new TSoundTrackMono16(sampleRate, channelCount, sampleCount);
    break;

  case TRK_S16:
    st = new TSoundTrackStereo16(sampleRate, channelCount, sampleCount);
    break;

  case TRK_M24:
    st = new TSoundTrackMono24(sampleRate, channelCount, sampleCount);
    break;

  case TRK_S24:
    st = new TSoundTrackStereo24(sampleRate, channelCount, sampleCount);
    break;

  default:
    std::string s;
    s = "Type " + std::to_string(sampleRate) + " Hz " +
        std::to_string(bitPerSample) + " bits ";
    if (channelCount == 1)
      s += "mono: ";
    else
      s += "stereo: ";
    s += "Unsupported\n";

    throw TException(s);
  }

  if (!st->getRawData()) {
    return 0;
  }
  return st;
}
Esempio n. 6
0
void TSoundOutputDevice::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
                              bool loop, bool scrubbing) {
  // TThread::ScopedLock sl(MutexOut);
  int lastSample = st->getSampleCount() - 1;
  notLessThan(0, s0);
  notLessThan(0, s1);

  notMoreThan(lastSample, s0);
  notMoreThan(lastSample, s1);

  if (s0 > s1) {
#ifdef DEBUG
    cout << "s0 > s1; reorder" << endl;
#endif
    swap(s0, s1);
  }

  if (isPlaying()) {
#ifdef DEBUG
    cout << "is playing, stop it!" << endl;
#endif
    stop();
  }
  m_imp->play(st, s0, s1, loop, scrubbing);
}
Esempio n. 7
0
bool TSoundOutputDevice::open(const TSoundTrackP &st) {
  if (!m_imp->doOpenDevice(st->getFormat()))
    throw TSoundDeviceException(
        TSoundDeviceException::UnableOpenDevice,
        "Problem to open the output device setting some params");
  return true;
}
Esempio n. 8
0
 void startScene(const ToonzScene &scene, int r) {
   m_flash.cleanCachedImages();
   m_flash.setBackgroundColor(m_bgColor);
   TXsheet::SoundProperties *prop = new TXsheet::SoundProperties();
   prop->m_frameRate              = m_fps;
   TSoundTrackP snd               = scene.getXsheet()->makeSound(prop);
   if (snd) {
     if (m_useMarkers) {
       long samplePerFrame = snd->getSampleRate() / m_fps;
       snd = snd->extract((TINT32)(m_renderRange.first * samplePerFrame),
                          (TINT32)(m_renderRange.second * samplePerFrame));
     }
     m_flash.putSound(snd, 0);
   }
   if (m_sceneIndex == 0 && m_sceneCount == 1) {
     if (m_renderRange.first == m_renderRange.second)
       m_frameCountLoader = 0;
     else
       m_frameCountLoader = 1;
   } else if (m_sceneIndex == 0)
     m_frameCountLoader = m_renderRange.second - m_renderRange.first + 1;
   m_sceneIndex++;
 }
Esempio n. 9
0
  void start(const ToonzScene &scene) {
    m_status      = 3;
    m_alphaNeeded = scene.getProperties()->getBgColor().m < 255;
    assert(m_started == false);
    m_started = true;
    if (TSystem::doesExistFileOrLevel(m_filepath))
      TSystem::removeFileOrLevel(m_filepath);

    m_lw = TLevelWriterP(m_filepath);
    m_lw->setFrameRate(m_fps);
    if (m_lw->getProperties() && m_fileOptions)
      m_lw->getProperties()->setProperties(m_fileOptions);

    if (m_st) m_lw->saveSoundTrack(m_st.getPointer());
  }