Esempio n. 1
0
 QMemoryAudioBufferProvider(const void *data, int frameCount, const QAudioFormat &format, qint64 startTime)
     : mStartTime(startTime)
     , mFrameCount(frameCount)
     , mFormat(format)
 {
     int numBytes = format.bytesForFrames(frameCount);
     if (numBytes > 0) {
         mBuffer = malloc(numBytes);
         if (!mBuffer) {
             // OOM, if that's likely
             mStartTime = -1;
             mFrameCount = 0;
             mFormat = QAudioFormat();
         } else {
             // Allocated, see if we have data to copy
             if (data) {
                 memcpy(mBuffer, data, numBytes);
             } else {
                 // We have to fill with the zero value..
                 switch (format.sampleType()) {
                     case QAudioFormat::SignedInt:
                         // Signed int means 0x80, 0x8000 is zero
                         // XXX this is not right for > 8 bits(0x8080 vs 0x8000)
                         memset(mBuffer, 0x80, numBytes);
                         break;
                     default:
                         memset(mBuffer, 0x0, numBytes);
                 }
             }
         }
     } else
         mBuffer = 0;
 }