示例#1
0
    void WriteDoubles(double **samples, int len, int nch, int offset, int spacing)
    {
      if(!m_file) return;

      if (m_peakbuild)
        m_peakbuild->ProcessSamples(samples,len,nch,offset,spacing);

      unsigned char *bout=m_tmpbuf.Resize(len*m_nch*(m_bps/8),false);
      // write samples to disk
      int ch;
      for (ch = 0; ch < m_nch; ch ++) // write the format's numchannels
      {
        double *in=ch < nch ? samples[ch] : samples[nch-1];  //if the input chancount is less, make sure we feed it valid inputs for the higher channels

        int x;

        if (ch < nch || (ch==1 && nch==1))
          for (x = 0; x < len; x ++) doubletomem16(in[x],bout+(x*m_nch+ch)*(m_bps/8));
        else
          for (x = 0; x < len; x ++) memset(bout+(x*m_nch+ch)*(m_bps/8),0,2);
      }

      m_file->Write(bout,m_tmpbuf.GetSize());
      if (update_disk_counters)
        update_disk_counters(0,m_tmpbuf.GetSize());

      m_lensamples+=len;

    } 
int LSFW_SimpleMediaDecoder::ReadSamples(double *buf, int length)
{
    if (m_fh)
    {
        m_isreadingblock=true;
        int rdframes=ptr_sf_readf_double(m_fh,buf,length);
        m_isreadingblock=false;
        update_disk_counters(rdframes*m_sfinfo.channels*m_bps,0);
        m_lastpos+=rdframes;
        return rdframes;
    }
    return 0;

}
示例#3
0
  int ReadSamples(double *buf, int length)
  {
    int rd=0;

    if (m_fh)
    {
      int blockAlign=m_nch*(m_bps/8);
      if (blockAlign<1)blockAlign=1; // should never happen but we hate div0's

      // see if we're at eof
      if (m_lastpos+length > m_length)
        length = m_length - m_lastpos;

      if (length > 0)
      {
        unsigned char *rdbuf=m_diskreadbuf.Resize(length*blockAlign,false);
        rd = m_fh->Read(rdbuf,length*blockAlign) / blockAlign;

        if (rd>0)
        {
          if (update_disk_counters) update_disk_counters(rd*blockAlign,0);

          if (m_bps==16) // we only support 16 bit
          {
            int x,sz=rd*m_nch;
            for (x = 0; x < sz; x ++)
            {
              buf[x]=((short)(rdbuf[0] | ((int)rdbuf[1]<<8)))/32768.0;
              rdbuf += 2;
            }
          }
          else memset(buf,0,rd*m_nch*sizeof(double));      
        }
      }
    }

    m_lastpos+=rd;

    return rd;
  }