Exemplo n.º 1
0
/** Plays one chunk of sound to the associated stream
  @return true on success. false for end of file or error
*/
bool SoundFile::playChunk()
{
    /*
      int c;
      int ret = blockingRead(stream, tempWindowBuffer, framesPerChunk());
      if(equalLoudness()) ret = blockingRead(filteredStream, tempWindowBufferFiltered, framesPerChunk());
      if(ret < framesPerChunk()) return false;
      ret = blockingWrite(gdata->audio_stream, tempWindowBuffer, framesPerChunk());
      if(ret < framesPerChunk()) {
        fprintf(stderr, "Error writing to audio device\n");
      }

      lock();
      for(c=0; c<numChannels(); c++) {
        channels(c)->shift_left(framesPerChunk());
        toChannelBuffer(c, framesPerChunk());
    	  if(gdata->doingActive() && channels(c) == gdata->getActiveChannel()) {
          channels(c)->processChunk(currentChunk()+1);
    	  }
      }
      setCurrentChunk(currentStreamChunk());
      unlock();
      return true;
    */
    if(!setupPlayChunk()) return false;
    int ret = blockingWrite(gdata->audio_stream, tempWindowBuffer, framesPerChunk());
    if(ret < framesPerChunk()) {
        fprintf(stderr, "Error writing to audio device\n");
    }
    //setCurrentChunk(currentStreamChunk());
    return true;
}
Exemplo n.º 2
0
bool SoundFile::setupPlayChunk() {
    int c;
    int n = framesPerChunk();
    int ret = blockingRead(stream, tempWindowBuffer, n);
    if(equalLoudness()) ret = blockingRead(filteredStream, tempWindowBufferFiltered, n);
    if(ret < n) return false;

    lock();
    for(c=0; c<numChannels(); c++) {
        channels(c)->shift_left(n);
        toChannelBuffer(c, n);
        if(gdata->doingActive() && channels(c) == gdata->getActiveChannel()) {
            channels(c)->processChunk(currentChunk()+1);
        }
    }
    setCurrentChunk(currentStreamChunk());
    unlock();
    return true;
}
Exemplo n.º 3
0
void SoundFile::jumpToChunk(int chunk)
{
    //if(chunk == currentChunk()) return;
    int c;
    lock();
    int pos = chunk * framesPerChunk() - offset();
    if(pos < 0) {
        stream->jump_to_frame(0);
        if(equalLoudness()) filteredStream->jump_to_frame(0);
        for(c=0; c<numChannels(); c++)
            channels(c)->reset();
        //readN(stream, bufferSize() + pos);
        readN(bufferSize() + pos);
    } else {
        stream->jump_to_frame(pos);
        if(equalLoudness()) filteredStream->jump_to_frame(pos);
        //readN(stream, bufferSize());
        readN(bufferSize());
    }
    /*  int n = bufferSize() / framesPerChunk();
      if(chunk+offset() < n) {
        stream->jump_to_frame(0);
        for(c=0; c<numChannels(); c++)
          channels(c)->reset();
        if(chunk+offset() >= 0) {
          for(int j=0; j<chunk+offset(); j++)
            readChunk();
        }
      } else {
        //if(chunk == currentChunk()+1) { readChunk(); return; }
        stream->jump_to_frame((chunk+offset()-n) * framesPerChunk());
        for(int j=0; j<n; j++)
          readChunk();
      }
    */
    setCurrentChunk(chunk);

    //for(c=0; c<numChannels(); c++) {
    //  if(channels(c) == gdata->getActiveChannel()) channels(c)->processChunk(currentChunk());
    //}
    unlock();
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
double SoundFile::timePerChunk(void) const
{
  return double(framesPerChunk()) / double(rate());
}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
int SoundFile::currentStreamChunk(void) const
{
  return (stream->pos() - offset()) / framesPerChunk();
}
Exemplo n.º 6
0
/** Preprocess the whole sound file,
   by looping through and processing every chunk in the file.
   A progress bar is displayed in the toolbar, because this can
   be time consuming.
*/
void SoundFile::preProcess()
{
    //jumpToChunk(0);
    gdata->setDoingActiveAnalysis(true);
    myassert(firstTimeThrough == true);
    readChunk(bufferSize() - offset());
    //readChunk(framesPerChunk());
    //processNewChunk();
    //printf("preProcessing\n");
    //for(int j=0; j<numChannels(); j++)
    //  channels(j)->setframesPerChunk(toRead);

    // Create a progress bar in the status bar to tell the user we're preprocessing
    MainWindow *theMainWindow = (MainWindow*) qApp->mainWidget();
    QStatusBar *theStatusBar = theMainWindow->statusBar();
    QLabel *message = new QLabel("Preprocessing data:", theStatusBar, "message");
    //QLabel *message = new QLabel("Preprocessing data:", theMainWindow, "message");

    //QProgressBar *progress = new QProgressBar(stream->totalFrames() / framesPerChunk(), theMainWindow, "progress bar");
    Q3ProgressBar *progress = new Q3ProgressBar(stream->totalFrames() / framesPerChunk(), theStatusBar, "progress bar");
    progress->setProgress(0);
    progress->setMaximumHeight(16);


    theStatusBar->addWidget(message);
    theStatusBar->addWidget(progress);

    message->show();
    progress->show();

    int frameCount = 1;
    int updateInterval = MAX(1, progress->totalSteps() / 50); // We'll update 50 times only

    //while(read_n(toRead, stream) == toRead) { // put data in channels
    while(readChunk(framesPerChunk()) == framesPerChunk()) { // put data in channels
        //printf("pos = %d\n", stream->pos);
        //processNewChunk();
        //incrementChunkNum();
        frameCount++;

        if (frameCount % updateInterval == 0) {
            progress->setProgress(progress->progress() + updateInterval);
            qApp->processEvents();
            frameCount = 1;
        }
    }
    //printf("totalChunks=%d\n", totalChunks());
    //printf("currentChunks=%d\n", currentChunk());
    filteredStream->close();
    filteredStream->open_read(filteredFilename);
    jumpToChunk(0);


    progress->setProgress(progress->totalSteps());
    theStatusBar->removeWidget(progress);
    theStatusBar->removeWidget(message);
    delete progress;
    delete message;

    gdata->setDoingActiveAnalysis(false);
    firstTimeThrough = false;
    //printf("freqLookup.size()=%d\n", channels(0)->freqLookup.size());
}