Example #1
0
bool WaveTrack::InitBlock(WaveBlock * b)
{
   wxASSERT(b);

   BlockFile *f = b->f;

   if (!f->OpenWriting())
      return false;

   f->Write(headerTag, headerTagLen);

   /*
    * This code shouldn't be needed because UpdateSummaries
    * always writes exactly what's needed.

    sampleCount slen = summary64KLen + summary256Len;
    sampleType *tempSamples = new sampleType[slen];
    for(int i=0; i<slen; i++)
    tempSamples[i] = 0;
    f->Write((void *)tempSamples, sizeof(sampleType) * slen);
    delete[] tempSamples;
    */

   f->Close();

   return true;
}
Example #2
0
void WaveTrack::AppendAlias(wxString fullPath,
                            sampleCount start,
                            sampleCount len, int channel)
{
   WaveBlock *newBlock = new WaveBlock();
   newBlock->start = numSamples;
   newBlock->len = len;
   newBlock->f =
       dirManager->NewAliasBlockFile(totalHeaderLen,
                                     fullPath, start, len, channel);

   InitBlock(newBlock);

   BlockFile *f = newBlock->f;

   sampleType *buffer = new sampleType[len];
   Read(buffer, newBlock, 0, len);

   wxASSERT(f);
   bool opened = f->OpenWriting();
   wxASSERT(opened);
   UpdateSummaries(buffer, newBlock, len);
   f->Close();

   delete[]buffer;

   block->Add(newBlock);
   numSamples += newBlock->len;

   envelope.SetTrackLen(numSamples / rate);
}
Example #3
0
void WaveTrack::CopyWrite(sampleType * buffer, WaveBlock * b,
                          sampleCount start, sampleCount len)
{
   // Usually we don't write to an existing block; to support Undo,
   // we copy the old block entirely into memory, dereference it,
   // make the change, and then write the new block to disk.

   wxASSERT(b);
   wxASSERT(b->len <= maxSamples);
   wxASSERT(start + len <= b->len);

   dirty++;                     // forces redraw

   sampleType *newBuffer = 0;

   newBuffer = new sampleType[maxSamples];
   wxASSERT(newBuffer);

   Read(newBuffer, b, 0, b->len);

   for (int i = 0; i < len; i++)
      newBuffer[start + i] = buffer[i];

   BlockFile *oldBlockFile = b->f;
   b->f = dirManager->NewBlockFile();
   bool inited = InitBlock(b);
   wxASSERT(inited);

   buffer = newBuffer;
   start = 0;
   len = b->len;

   dirManager->Deref(oldBlockFile);

   // Write the block

   BlockFile *f = b->f;

   wxASSERT(f);
   bool opened = f->OpenWriting();
   wxASSERT(opened);

   f->SeekTo(totalHeaderLen + (start * sizeof(sampleType)));

   f->Write((void *) buffer, len * sizeof(sampleType));

   UpdateSummaries(buffer, b, len);

   if (newBuffer)
      delete[]newBuffer;

   f->Close();
}
Example #4
0
void WaveTrack::Read64K(sampleType * buffer, WaveBlock * b,
                        sampleCount start, sampleCount len)
{
   wxASSERT(b);
   wxASSERT(start >= 0);
   wxASSERT(start + len <= ((b->len + 65535) / 65536));
   start *= 2;
   len *= 2;

   BlockFile *f = b->f;
   bool opened = f->OpenReadHeader();
   wxASSERT(opened);

   f->SeekTo(headerTagLen + start * sizeof(sampleType));

   int result = f->Read((void *) buffer, (int) (len * sizeof(sampleType)));
   wxASSERT(result == (int) (len * sizeof(sampleType)));

   f->Close();
}
Example #5
0
void WaveTrack::FirstWrite(sampleType * buffer, WaveBlock * b,
                           sampleCount len)
{
   wxASSERT(b);
   wxASSERT(b->len <= maxSamples);

   dirty++;                     // forces redraw

   BlockFile *f = b->f;

   wxASSERT(f);
   bool opened = f->OpenWriting();
   wxASSERT(opened);

   f->SeekTo(totalHeaderLen);
   f->Write((void *) buffer, len * sizeof(sampleType));

   UpdateSummaries(buffer, b, len);

   f->Close();
}
Example #6
0
void WaveTrack::Read(sampleType * buffer, WaveBlock * b,
                     sampleCount start, sampleCount len)
{
   wxASSERT(b);
   wxASSERT(start >= 0);
   wxASSERT(start + len <= b->len);

   BlockFile *f = b->f;
   bool opened = f->OpenReadData();
   wxASSERT(opened);

   f->SeekTo(totalHeaderLen + (start * sizeof(sampleType)));

   int result = f->Read((void *) buffer, (int) (len * sizeof(sampleType)));

   if (result != (int) (len * sizeof(sampleType))) {
      printf("Expected to read %d bytes, got %d bytes.\n",
             len * sizeof(sampleType), result);
   }

   wxASSERT(result == (int) (len * sizeof(sampleType)));

   f->Close();
}