コード例 #1
0
ファイル: player.cpp プロジェクト: jabouzi/qsalat
// forward
void Player::next()
{
    playing = 1;
    videoPlayer->mediaObject()->setCurrentSource(getAudio());
    play();
    
}
コード例 #2
0
ファイル: soloud_audiosource.cpp プロジェクト: scoopr/soloud
	void AudioSourceInstance::seek(float aSeconds, float *mScratch, int mScratchSize)
	{
		float offset = aSeconds - mStreamTime;
		if (offset < 0)
		{
			if (rewind() == 0)
			{
				// can't do generic seek backwards unless we can rewind.
				return;
			}
			offset = aSeconds;
		}
		int samples_to_discard = (int)floor(mSamplerate * offset);

		while (samples_to_discard)
		{
			int samples = mScratchSize / 2;
			if (samples > samples_to_discard)
				samples = samples_to_discard;
			getAudio(mScratch, samples);
			samples_to_discard -= samples;
		}

		mStreamTime = aSeconds;
	}
コード例 #3
0
ファイル: audio_manager.cpp プロジェクト: jesuslou/SDL_Engine
void CAudioManager::playAudio( const char * path ) {
  Mix_Chunk *audio = getAudio( path );
  if( audio ) {
    Mix_PlayChannel( -1, audio, 0 );
  } else {
    printf( "CAudioManager:: audio '%s' not loaded!\n", path );
  }
}
コード例 #4
0
ファイル: audio_manager.cpp プロジェクト: jesuslou/SDL_Engine
Mix_Chunk* CAudioManager::loadAudio( const char * path ) {
  Mix_Chunk *new_audio = getAudio( path );
  if( !new_audio ) {
    new_audio = Mix_LoadWAV( path );
    if( !new_audio ) {
      printf( "CAudioManager::Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError( ) );
    } else {
      m_audios[ path ] = new_audio;
    }
  }
  return new_audio;
}
コード例 #5
0
void AudioMixer::_movieCallback(void *udata, uint8_t *stream, uint32_t len)
{
    auto pmve = (MvePlayer*)(udata);
    if (pmve->samplesLeft() <= 0)
    {
        Logger::debug("AUDIO") << "buffer underrun?" << std::endl;
        Mix_HookMusic(NULL, NULL);
        return;
    }

    pmve->getAudio(stream, len);
}
コード例 #6
0
ファイル: player.cpp プロジェクト: jabouzi/qsalat
void Player::loadFiles(QStringList list)
{
    sources.clear();
    if (list.size() > 0)
    {
        init();    
        for (int i = 0; i < list.size(); i++)
        {            
            Phonon::MediaSource source(list.at(i));
            sources.insert(i,source);            
        }    
        playButton->setEnabled(true);    
        //addButton->setEnabled(true);
        videoPlayer->mediaObject()->setCurrentSource(getAudio());
        play();
    }
}
コード例 #7
0
ファイル: player.cpp プロジェクト: jabouzi/qsalat
// load media files
void Player::load()
{    
    sources.clear();
    QStringList list = QFileDialog::getOpenFileNames(this,tr("Open one or more files"),".",tr("audios (*.mp3 *.wma *.ogg *.wave *.midi *.avi *.mpeg *.mpg *.wmv *.divx *.xvid *.mp4 *.flv *.ogv)"));
    if (list.size() > 0)
    {
        init();    
        for (int i = 0; i < list.size(); i++)
        {            
            Phonon::MediaSource source(list.at(i));
            sources.insert(i,source);            
        }    
        playButton->setEnabled(true);    
        //addButton->setEnabled(true);
        videoPlayer->mediaObject()->setCurrentSource(getAudio());
        play();
    }
}
コード例 #8
0
ファイル: simple_decoder.c プロジェクト: casibbald/kamaelia
int main(int argc, char *argv[]) {
   bool decoding = TRUE;
   ogg_vorbis_context * oggVorbisContext;
   source_buffer * sourceBuffer;
   decode_buffer * decodeBuffer;

   oggVorbisContext = newOggVorbisContext();
   sourceBuffer = newSourceBuffer(stdin,BUFSIZE);
   while(decoding) {
      decodeBuffer = getAudio(oggVorbisContext);
      switch (decodeBuffer->status) {
         case NEEDDATA:
            readData(sourceBuffer);
            if (sourceBuffer->bytes > 0)
               sendBytesForDecode(oggVorbisContext, sourceBuffer);
            else
               decoding = FALSE;
            break;
         case HAVEDATA:
            /* We have to use the contents of the decodeBuffer befor asking
              for more bytes, or else we lose the contents, this could mean just
              buffering */
            fwrite(decodeBuffer->buffer,sizeof(char),decodeBuffer->len,stdout);
            break;
         case NORMAL:
            /* Just so that we can signify normal status */
            break;
         default: /* Unknown status, exit */
            decoding = FALSE;
            break;
      }
      free(decodeBuffer);
   }
   free(sourceBuffer);
   free(oggVorbisContext);
   return 0;
}
コード例 #9
0
int main(int argc, char *argv[])
{
  /*****
   * boolean value indicates when to break main loop
   * (and thus finish this configuration tool)
   *****/
  int request_finish = 0;

  int current         = 0; /***** menu related variables */
  int menu_items      = 7;
  enum state status[] = {invalid, invalid, inactive, inactive, inactive, inactive, invalid};

  WINDOW *mainscr; /***** ncurses related variables */
  int i, j;

  /* ***** detect available mixer devices */

  mixer_devices = scanMixerDevices();
  if (mixer_devices == NULL || mixer_devices->count == 0)
  {
    /* ***** no mixer devices available -> exit! */

    fprintf(stderr, "No mixer devices available!\n");
    fprintf(stderr, "Please purchase a sound card and install it!\n");
    exit(-1);
  }
  else
  {
    if (mixer_devices->count == 1) /***** exactly one mixer device available */
    {
      setMixer(mixer_devices->name[0]); /***** set this mixer */

      if (initMixer() == MIXER_OK) /***** if mixer is ok, keep it */
      {
	status[0] = ok;
	status[2] = invalid;
      }
      else                         /***** otherwise, exit!*/
      {
	fprintf(stderr, "Couldn't init the only available mixer device: /dev/%s\n",
		mixer_devices->name[0]);
	exit(-1);
      }
    }
    else /* ***** more than one device available! */
    {
      /* ***** use /dev/mixer as default if it exists */

      for (i = 0; i < mixer_devices->count; i++)
      {
	if (strcmp(mixer_devices->name[i], "mixer") == 0)
	{
	  setMixer("mixer");
	  if (initMixer() == MIXER_OK)
	  {
	    status[0] = ok;
	    status[2] = invalid;
	  }
	  else
	    noMixer();
	
	  break;
	}
      }
    }
  }

  /* ***** detect available audio devices */

  audio_devices = scanAudioDevices();
  if (audio_devices == NULL || audio_devices->count == 0)
  {
    /* ***** no audio devices available! */

    fprintf(stderr, "No audio device available that\n");
    fprintf(stderr, "supports 16bit recording!\n");
    fprintf(stderr, "Please purchase a sound card and install it!\n");
    exit(-1);
  }
  else
  {
    if (audio_devices->count == 1) /***** exactly one audio device available */
    {
      setAudio(audio_devices->name[0]); /***** set this audio device */

      if (initAudio() == AUDIO_OK) /***** if audio device is ok, keep it */
      {
	status[1] = ok;
      }
      else                         /***** otherwise, exit!*/
      {
	fprintf(stderr, "Couldn't init the only available audio device: /dev/%s\n",
		audio_devices->name[0]);
	exit(-1);
      }
    }
    else /* ***** more than one device available! */
    {
      /* ***** use /dev/dspW as default if it exists */

      for (i = 0; i < audio_devices->count; i++)
      {
	if (strcmp(audio_devices->name[i], "dspW") == 0)
	{
	  setAudio("dspW");
	  if (initAudio() == AUDIO_OK)
	    status[1] = ok;
	  else
	    noAudio();
	
	  break;
	}
      }
    }
  }

  /*****
   * if mixer and audio device have been selected successfully,
   * set menu cursor to next available menu item
   *****/
  if (status[0] == ok && status[1] == ok)
    current = 2;

  /***** ignore Ctrl-C */

  signal(SIGINT, SIG_IGN);

  /* ***** ncurses stuff */

  initscr();      /* initialize the curses library */

  if (color_term != -1) /***** define dialog color pairs if terminal supports colors */
   {
      start_color ();
      if ((color_term = has_colors ()))
      {
         color_term = 1;
         init_pair (1, COLOR_WHITE, COLOR_BLUE);
         init_pair (2, COLOR_YELLOW, COLOR_BLUE);
         init_pair (3, COLOR_BLUE, COLOR_YELLOW);
         init_pair (4, COLOR_YELLOW, COLOR_CYAN);
      }
   }
   else
      color_term = 0;

  keypad(stdscr, TRUE);  /* enable keyboard mapping */
  scrollok (stdscr, FALSE);
  cbreak();              /* take input chars one at a time, no wait for \n */
  noecho();              /* don't echo input */
  refresh();

  mainscr = popupWindow(COLS, LINES); /***** dialog window that contains the main menu */
  leaveok (mainscr, FALSE);

  while (!request_finish)
  {
    wattrset (mainscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

    /*****
     * draw a box around the dialog window
     * and empty it.
     *****/
    box(mainscr, 0, 0);
    for (i = 1; i < COLS-1; i++)
      for (j = 1; j < LINES-1; j++)
	mvwaddch(mainscr, j, i, ' ');

    /***** dialog header */

    mvwaddstr(mainscr, 1, 2, "CVoiceControl");
    mvwaddstr(mainscr, 1, COLS - strlen("(c) 2000 Daniel Kiecza") - 2, "(c) 2000 Daniel Kiecza");
    mvwaddseparator(mainscr, 2, COLS);

    mvwaddstr(mainscr, 3, (COLS / 2) - (strlen ("Recording Device Configuration Tool") / 2),
	      "Recording Device Configuration Tool");
    mvwaddseparator(mainscr, 4, COLS);

    /***** main menu */

    mvwaddstr(mainscr, 5, 2, "Please Select:");

    setHighlight(mainscr, status[0], current == 0);
    mvwaddstr(mainscr, 7,5,"Select Mixer Device");
    if (mixerOK() == MIXER_OK)
    {
      mvwaddstr(mainscr, 7,24," ("); waddstr(mainscr, getMixer()); waddstr(mainscr, ")");
    }
    else
      mvwaddstr(mainscr, 7,24," (none selected!)");

    setHighlight(mainscr, status[1], current == 1);
    mvwaddstr(mainscr, 8,5,"Select Audio Device");
    if (audioOK() == AUDIO_OK)
    {
      mvwaddstr(mainscr, 8,24," ("); waddstr(mainscr, getAudio()); waddstr(mainscr, ")");
    }
    else
      mvwaddstr(mainscr, 8,24," (none selected!)");

    setHighlight(mainscr, status[2], current == 2);
    mvwaddstr(mainscr,  9,5,"Adjust Mixer Levels");
    setHighlight(mainscr, status[3], current == 3);
    mvwaddstr(mainscr, 10,5,"Calculate Recording Thresholds");
    setHighlight(mainscr, status[4], current == 4);
    mvwaddstr(mainscr, 11,5,"Estimate Characteristics of Recording Channel");
    setHighlight(mainscr, status[5], current == 5);
    mvwaddstr(mainscr, 12,5,"Write Configuration");
    setHighlight(mainscr, status[6], current == 6);
    mvwaddstr(mainscr, 13,5,"Exit");

    wmove(mainscr, 5, 17);  /***** set cursor to an appropriate location */
    wrefresh(mainscr);     /***** refresh the dialog */

    /* process the command keystroke */

    switch(getch())
    {
    case KEY_UP:   /***** cursor up */
      current = (current == 0 ? menu_items - 1 : current - 1);
      while(status[current] == inactive)
	current = (current == 0 ? menu_items - 1 : current - 1);
      break;
    case KEY_DOWN: /***** cursor down */
      current = (current == menu_items-1 ? 0 : current + 1);
      while(status[current] == inactive)
	current = (current == menu_items-1 ? 0 : current + 1);
      break;
    case ENTER:    /***** handle menu selections */
    case BLANK:
      switch (current)
      {
      case 0: /***** select mixer device */
	status[0] = invalid;
	status[2] = inactive;
	status[3] = inactive;
	status[4] = inactive;
	status[5] = inactive;
	noMixer();
	if (selectMixer() == MIXER_OK)
	{
	  status[0] = ok;
	  status[2] = invalid;
	}
	break;
      case 1: /***** select audio device */
	status[1] = invalid;
	status[3] = inactive;
	status[4] = inactive;
	status[5] = inactive;
	noAudio();
	if (selectAudio() == AUDIO_OK)
	  status[1] = ok;
	break;
      case 2: /***** adjust mixer levels */
	if (adjustMixerLevels())
	{
	  status[2] = ok;
	  status[3] = invalid;
	  status[4] = invalid;
	}
	break;
      case 3: /***** calculate recording thresholds */
	if (calculateThresholds())
	  status[3] = ok;
	else
	  status[3] = invalid;
	break;
      case 4: /***** estimate the characteristics of the recording channel */
	if (estimateChannelMean())
	  status[4] = ok;
	else
	  status[4] = invalid;
	break;
      case 5: /***** save configuration! */
	if (saveConfiguration())
	{
	  status[5] = ok;
	  status[6] = ok;
	}
	break;
      case 6: /***** leave program */
	if (status[6] == ok  ||  (status[6] != ok && safeExit()))
	{
	  wrefresh(mainscr);     /***** refresh the dialog */
  	  request_finish = 1;
	  delwin(mainscr);   /***** delete ncurses dialog window */
	 }
	break;
      }
      break;
    }

    /***** if the configuration is done, activate the menu item "Save Configuration" */

    if (status[0] != ok || status[1] != ok ||
	status[2] != ok || status[3] != ok ||
	status[4] != ok)
      status[5] = inactive;
    else if (status[5] != ok)
      status[5] = invalid;
  }

  endwin();               /* we're done */

  /***** free memory used by the list of mixer and audio devices */

  if (mixer_devices != NULL)
  {
    for (i = 0; i < mixer_devices->count; i++)
      free(mixer_devices->name[i]);
    free(mixer_devices->name);
    free(mixer_devices);
  }

  if (audio_devices != NULL)
  {
    for (i = 0; i < audio_devices->count; i++)
      free(audio_devices->name[i]);
    free(audio_devices->name);
    free(audio_devices);
  }

  exit(0);
}
コード例 #10
0
int saveConfiguration()
{
  char *home;        /***** config file related variables */
  char *config_dir;
  char *config_file;
  FILE *f;

  int retval = 0;  /***** return value */

  int width = 60, height = 11, i, j;               /***** ncurses related variables */
  WINDOW *savescr = popupWindow (width, height);

  wattrset (savescr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

  /*****
   * draw a box around the dialog window
   * and empty it.
   *****/
  werase (savescr);
  box (savescr, 0, 0);
  for (i = 1; i < width-1; i++)
    for (j = 1; j < height-1; j++)
      mvwaddch(savescr, j, i, ' ');

  /***** dialog header */

  mvwaddstr(savescr, 1, 2, "Save Configuration:");
  mvwaddseparator(savescr, 2, width);

  /***** dialog message */

  mvwaddstr(savescr, 4, 2, "Your configuration will be saved to");
  mvwaddstrcntr(savescr, 6, width, "~/.cvoicecontrol/config");
  mvwaddstrcntr(savescr, 8, width, "Press any key to proceed ...");

  wmove(savescr, 1, 22);  /***** set cursor to an appropriate location */
  wrefresh (savescr);     /***** refresh the dialog */
  getch();                  /***** wait for keyboard reaction */

  /***** clear dialog */

  for (i = 1; i < width-1; i++)
    for (j = 3; j < height-1; j++)
      mvwaddch(savescr, j, i, ' ');

  wmove(savescr, 1, 22);  /***** set cursor to an appropriate location */
  wrefresh (savescr);     /***** refresh the dialog */

  /***** retrieve home directory */

  home = getenv("HOME");
  if (home != NULL)
  {
    FILE *f;

    /***** make sure the config_dir "~/.cvoicecontrol/" exists */

    config_dir = malloc(strlen(home) + strlen("/.cvoicecontrol/") + 1);
    strcpy(config_dir, home);
    strcat(config_dir, "/.cvoicecontrol/");

    if ((f = fopen(config_dir, "r")) == NULL)
    {
      char *command = malloc(strlen("mkdir ") + strlen(config_dir) + 1);
      strcpy(command, "mkdir ");
      strcat(command, config_dir);
      system(command);

      if ((f = fopen(config_dir, "r")) == NULL)
      {
	free(config_dir);
	config_dir = malloc(strlen("/tmp/") + 1);
	strcpy(config_dir, "/tmp/");
      }

      free(command);
    }
    fclose(f);

    free(home);
  }
  else /***** couldn't retrieve home directory -> store results in /tmp/ */
  {
    config_dir = malloc(strlen("/tmp/") + 1);
    strcpy(config_dir, "/tmp/");
  }

  /***** tell user if home directory couldn't be retrieved and /tmp/ is used instead */

  if (strcmp(config_dir, "/tmp/") == 0)
  {
    mvwaddstr(savescr, 4, 2, "Failed to retrieve your home directory,");
    mvwaddstr(savescr, 5, 2, "please contact your local system admin!");
    mvwaddstr(savescr, 6, 2, "Configuration will be stored to /tmp/ instead!");

    wmove(savescr, 1, 22);  /***** set cursor to an appropriate location */
    wrefresh (savescr);     /***** refresh the dialog */
    getch();                /***** wait for keyboard reaction */
  }

  /***** config_file = config_dir+"config" */

  config_file = malloc(strlen(config_dir) + strlen("config") + 1);
  strcpy(config_file, config_dir);
  strcat(config_file, "config");
  free (config_dir);

  if ((f = fopen(config_file, "w")) == NULL) /***** failed to write config file */
  {
    /***** clear dialog */

    for (i = 1; i < width-1; i++)
      for (j = 3; j < height-1; j++)
	mvwaddch(savescr, j, i, ' ');

    /***** dialog message */

    mvwaddstr(savescr, 5, 2, "Failed to create your configuration file! Oops!");
    mvwaddstr(savescr, 6, 2, "What's going on?");
    mvwaddstrcntr(savescr, 8, width, "Press any key to return to menu ...");

    wmove(savescr, 1, 22);  /***** set cursor to an appropriate location */
    wrefresh (savescr);     /***** refresh the dialog */
    getch();                /***** wait for keyboard reaction */

    retval = 0;  /***** set return value to ERROR */
    goto saveConfigurationReturn;
  }

  /***** output configuration information to config file */

  fprintf(f, "Mixer Device    = %s\n", getMixer());
  fprintf(f, "Audio Device    = %s\n", getAudio());
  fprintf(f, "Mic Level       = %d\n", mic_level);
  fprintf(f, "IGain Level     = %d\n", igain_level);
  fprintf(f, "Record Level    = %d\n", rec_level);
  fprintf(f, "Stop Level      = %d\n", stop_level);
  fprintf(f, "Silence Level   = %d\n", silence_level);
  fprintf(f, "Channel Mean    =");
  for (i = 0; i < FEAT_VEC_SIZE; i++)
    fprintf(f, " %6.5f", channel_mean[i]);
  fprintf(f, "\n");
  fclose(f);

  /***** clear dialog */

  for (i = 1; i < width-1; i++)
    mvwaddch(savescr, 1, i, ' ');
  for (i = 1; i < width-1; i++)
    for (j = 3; j < height-1; j++)
      mvwaddch(savescr, j, i, ' ');

  /***** update dialog to tell user that the configuration has been saved successfully */

  mvwaddstr(savescr, 1, 2, "Success!");

  mvwaddstr(savescr, 4, 2, "Your configuration has been saved successfully to");
  mvwaddstr(savescr, 5, 4, config_file);
  mvwaddstr(savescr, 7, 2, "CVoiceControl is now ready to use!");
  mvwaddstrcntr(savescr, 9, width, "Press any key to return to menu ...");

  retval = 1; /***** set return value to ok */

  wmove(savescr, 1, 11);  /***** set cursor to an appropriate location */
  wrefresh (savescr);     /***** refresh the dialog */
  getch();                /***** wait for keyboard reaction */

 saveConfigurationReturn:

  free(config_file);
  return(retval);
}