Esempio n. 1
0
int32 nuiAudioDecoder::ReadDE(std::vector<void*> buffers, int32 sampleframes, nuiSampleBitFormat format)
{
    //don't increment mPosition: it's already done in ReadIN
    int32 channels = mInfo.GetChannels();
    int16* pInterleaved = NULL;
    float* pInterleavedFloat = NULL;

    int32 read = 0;
    switch (format)
    {
    case eSampleInt16:
        pInterleaved = new int16[sampleframes * channels];
        read = ReadIN((void*)pInterleaved, sampleframes, format);

        for (int32 c = 0; c < channels; c++)
        {
            int16* pDst = (int16*)(buffers[c]);
            int16* pSrc = pInterleaved + c;
            for (int32 i = 0; i < read; i++)
            {
                *(pDst++) = *pSrc;
                pSrc += channels;
            }
        }

        delete[] pInterleaved;
        break;

    case eSampleFloat32:
        pInterleavedFloat = new float[sampleframes * channels];
        read = ReadIN((void*)pInterleavedFloat, sampleframes, format);

        for (int32 c = 0; c < channels; c++)
        {
            float* pDst = (float*)(buffers[c]);
            float* pSrc = pInterleavedFloat + c;
            for (int32 i = 0; i < read; i++)
            {
                *(pDst++) = *pSrc;
                pSrc += channels;
            }
        }

        delete[] pInterleavedFloat;
        break;

    default:
        break;
    }


    return read;
}
Esempio n. 2
0
uint32 nuiChunkSampleReader::ReadDE(std::vector<void*> buffers, uint32 sampleframes, nuiSampleBitFormat format)
{
  //don't increment mPosition: it's already done in ReadIN
  const uint32 channels = mInfo.GetChannels();
  uint32 length = mInfo.GetSampleFrames();
  if (mPosition >= length)
    return 0;
  sampleframes = MIN(sampleframes, length - mPosition);
  
  if (buffers.size() != channels)
  {
    return 0;
  }
  
  bool deleteBuffer = false;
  uint32 SampleFramesRead = 0;
  switch (format)
  {
    case eSampleFloat32:
    {
      float* pFloatBuffer = NULL;
      if (channels == 1)
      {
        pFloatBuffer = (float*)(buffers[0]);
        deleteBuffer = false;
      }
      else
      {
        pFloatBuffer = new float[sampleframes * channels];
        deleteBuffer = true;
      }
      
      SampleFramesRead = ReadIN((void*)pFloatBuffer, sampleframes, format); //mPosition is incremented inside
      for (uint32 s = 0; s < SampleFramesRead; s++)
      {
        for (uint32 c = 0; c < channels; c++)
        {
          float* pDest = (float*)buffers[c];
          pDest[s] = pFloatBuffer[channels * s + c];
        }
      }
      if (deleteBuffer)
        delete[] pFloatBuffer;
    }
      break;
      
    case eSampleInt16:
    {
      int16* pIntBuffer = NULL;
      if (channels == 1)
      {
        pIntBuffer = (int16*)(buffers[0]);
        deleteBuffer = false;
      }
      else
      {
        pIntBuffer = new int16[sampleframes * channels];
        deleteBuffer = true;
      }
      
      SampleFramesRead = ReadIN((void*)pIntBuffer, sampleframes, format);//mPosition is incremented inside
      for (uint32 s = 0; s < SampleFramesRead; s++)
      {
        for (uint32 c = 0; c < channels; c++)
        {
            ((int16*)(buffers[c]))[s] = pIntBuffer[channels * s + c];
        }
      }
      if (deleteBuffer)
        delete[] pIntBuffer;
    }
      break;
      
    default:
      break;
  }
  
  
  //don't increment mPosition: it's already done in ReadIN
  return SampleFramesRead;
}