⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aflibaudioedit.cc

📁 一个共享源码的音频库2
💻 CC
📖 第 1 页 / 共 2 页
字号:
      if (inp == input)      {         // Remove this specifiec segment number         removeSegment(i);      }   }}/*! \brief Gets the current number of segments that are in the audio clip list.*/intaflibAudioEdit::getNumberOfSegments(){   return (_clip_array.size());}/*! \brief Retrieves information for an audio clip segment by samples.    This function will retrieve the information for a particular audio clip segment. This will    allow the user to determine the input and output start and stop positions in samples. The    segment numbers start with 1.*/voidaflibAudioEdit::getSegment(   int segment_number,   int& input,   long long& input_start_position,   long long& input_stop_position,   long long& output_start_position,   long long& output_stop_position,   double&    factor){   set<aflibEditClip, less < aflibEditClip > >::iterator it;   int j;   input_start_position = 0;   input_stop_position = 0;   output_start_position = 0;   output_stop_position = 0;   input = 0;   if (segment_number <= (int)_clip_array.size())   {      for (it = _clip_array.begin(), j = 1; it != _clip_array.end(); it++, j++)      {         if (j == segment_number)         {            input_start_position = (*it).getStartSamplesInput();            input_stop_position = (*it).getStopSamplesInput();            output_start_position = (*it).getStartSamplesOutput();            output_stop_position = (*it).getStopSamplesOutput();            input = (*it).getInput();            factor = (*it).getSampleRateFactor();            break;         }      }   }}/*! \brief Retrieves information for an audio clip segment by seconds.    This function will retrieve the information for a particular audio clip segment. This will    allow the user to determine the input and output start and stop positions in seconds. The    segment numbers start with 1.*/voidaflibAudioEdit::getSegment(   int segment_number,   int& input,   double& input_start_seconds,   double& input_stop_seconds,   double& output_start_seconds,   double& output_stop_seconds,   double& factor){   const aflibConfig& cfg = getInputConfig();   long long start_samples_output;   long long stop_samples_output;   long long start_samples_input;   long long stop_samples_input;   getSegment(segment_number, input,      start_samples_input, stop_samples_input, start_samples_output, stop_samples_output,      factor);   // Convert seconds to samples and call samples remove function   input_start_seconds = (double)start_samples_input / cfg.getSamplesPerSecond();   input_stop_seconds = (double)stop_samples_input / cfg.getSamplesPerSecond();   output_start_seconds = (double)start_samples_output / cfg.getSamplesPerSecond();   output_stop_seconds = (double)stop_samples_output / cfg.getSamplesPerSecond();}/*! \brief Sets the input and output audio data configuration of this object.    This function overrides the aflibAudio base class function. It will change   the total samples in the output audio configuration. It will also select   the best output based on the inputs. Any conversion that needs to be done   will be done. This allows mixing of inputs with different sample rates,   endian layouts, channels, and data sizes.*/voidaflibAudioEdit::setInputConfig(const aflibConfig& cfg){   aflibConfig config = cfg;   set<aflibEditClip, less < aflibEditClip > >::iterator it_clip;   map<int, aflibAudio *, less<int> >  parent_list = getParents();   map<int, aflibAudio *, less<int> >::iterator it;   int  sample_rate = 0;   aflib_data_endian  endian = AFLIB_ENDIAN_LITTLE;   aflib_data_size    size = AFLIB_DATA_8U;   aflibConfig out_cfg(cfg);   int   chan_num = 0;   // Look at every parents data configuration   for (it = parent_list.begin(); it != parent_list.end(); it++)   {      const aflibConfig& new_cfg = ((*it).second)->getOutputConfig();      // Pick the biggest sample rate      if (new_cfg.getSamplesPerSecond() > sample_rate)      {         sample_rate = new_cfg.getSamplesPerSecond();      }      if (new_cfg.getChannels() > chan_num)      {         chan_num = new_cfg.getChannels();      }      // Pick last endian config. It does not really matter      endian = new_cfg.getDataEndian();      // Pick 16S, 16U, 8S, or 8U in that order      if (size != AFLIB_DATA_16S)      {         if (new_cfg.getSampleSize() == AFLIB_DATA_16S)         {            size = AFLIB_DATA_16S;         }         else if (new_cfg.getSampleSize() == AFLIB_DATA_16U)         {            size = AFLIB_DATA_16U;         }         else if (size != AFLIB_DATA_16U)         {            if (new_cfg.getSampleSize() == AFLIB_DATA_8S)            {               size = AFLIB_DATA_8S;            }            else if (size != AFLIB_DATA_8S)            {               size = AFLIB_DATA_8U;            }         }      }   }   // Set and Store the output configuration   out_cfg.setSamplesPerSecond(sample_rate);   out_cfg.setSampleSize(size);   out_cfg.setDataEndian(endian);   out_cfg.setChannels(chan_num);   // IF no more clips   if (_clip_array.size() == 0)   {      out_cfg.setTotalSamples(0);   }   // ELSE get stop segment from last clip and stop as total samples   else   {      it_clip = _clip_array.end();      it_clip--;      out_cfg.setTotalSamples((*it_clip).getStopSamplesOutput());   }    setOutputConfig(out_cfg);   // Set the input config to be the same as the output. This is what we need inputted   // into each input. It will force the base classes to make the conversion.   aflibAudio::setInputConfig(cfg);   aflibAudio::setOutputConfig(out_cfg);}voidaflibAudioEdit::recomputeConfig(){   // Invalidate chain so that new config gets passed up chain   setNodeProcessed(FALSE);}voidaflibAudioEdit::printClips(){   // This function is for debugging purposes. It allows one to print all the audio clip data   if (getenv("AFLIB_DEBUG"))   {      set<aflibEditClip, less < aflibEditClip > >::iterator it;      int clip_num;      cout << endl << "---------------------------------------------------------" << endl;      for (it = _clip_array.begin(), clip_num = 1; it != _clip_array.end(); it++, clip_num++)      {         cout << "Clip Number " << clip_num << endl;         cout << "Clip Input " << (*it).getInput() << endl;         cout << "Start Samples Input " << (*it).getStartSamplesInput() << endl;         cout << "Stop Samples Input " << (*it).getStopSamplesInput() << endl;         cout << "Start Samples Output " << (*it).getStartSamplesOutput() << endl;         cout << "Stop Samples Output " << (*it).getStopSamplesOutput() << endl;         cout << "Factor " << (*it).getSampleRateFactor() << endl;      }      cout << "---------------------------------------------------------" << endl;   }}/*! \brief Not Yet Implemented.*/aflibUndoRedoaflibAudioEdit::getUndoRedoStatus() const{   // Until we implement undo redo we will return none.   return(AFLIB_NONE_MODE);}/*! \brief Not Yet Implemented.*/voidaflibAudioEdit::performUndoRedo(){   // Need to undo the last action if in undo mode. If in redo mode then reapply   // the last action.}/*! \brief Main process function.    Since we have to deal with multiple inputs we override the base classes process function    with our own. This will retrieve the audio data from the proper input based on position.    It is responsible for mapping the output sample position to the correct input and    its sample position. See the base class aflibAudio::process for what the process    function is suppose to do.*/aflibData *aflibAudioEdit::process(   aflibStatus& ret_status,   long long position,   int& num_samples,   bool free_memory) {   int  list_size = 0;   aflibData * data = NULL;   long long start_input_position = 0;   ret_status = AFLIB_SUCCESS;   int use_input = -1;   set<aflibEditClip, less < aflibEditClip > >::iterator it;   long  length;   list<aflibData *> d_list;   incrementLevel();   // Check to see if chain has been preprocessed if at start of chain   examineChain();   // TBD in the future we may need to make two process calls for a data item if it   // spans both. For now if a data item spans two clips we will just read from the   // first one.   map<int, aflibAudio *, less<int> > audio_list = this->getParents();   list_size = audio_list.size();   // Go thru all clips and find which clip to use   for (it = _clip_array.begin(); it != _clip_array.end(); it++)   {      if ((position >= (*it).getStartSamplesOutput()) &&          (position < (*it).getStopSamplesOutput()))      {         start_input_position =             position - (*it).getStartSamplesOutput() +             (*it).getStartSamplesInput();         use_input = (*it).getInput();         break;      }   }   // IF no clip was found then we have reached the end of the file   if (use_input == -1)   {      ret_status = AFLIB_END_OF_FILE;   }   else   {      // IF no more parents then process since we are at the end of the chain      if (list_size == 0)      {         // IF node is not enabled then skip processing         if (getEnable() == TRUE)         {            if (num_samples == 0)               data = new aflibData(4096);            else               data = new aflibData(num_samples);            d_list.push_back(data);            ret_status = compute_segment(d_list, position);         }      }      // ELSE call parent and let it process it first then process result      else      {         data = ((aflibAudio *)audio_list[use_input])->process(            ret_status, start_input_position, num_samples, FALSE);         // ptr can be NULL if parent was not enabled         if (data == NULL)         {            if (num_samples == 0)               data = new aflibData(4096);            else               data = new aflibData(num_samples);         }         if (getEnable() == TRUE)         {            d_list.push_back(data);            ret_status = compute_segment(d_list, position);         }      }   }   // Set num_samples with correct value   if (data)   {      data->getLength(length);      num_samples = (int)length;   }   // IF caller does not want memory returned then free   if (free_memory == TRUE)   {      delete data;      data = NULL;   }   decrementLevel();   return (data);}/*! \brief Main work function.   We don't do any real processing of the data. We actually only route the data.*/aflibStatusaflibAudioEdit::compute_segment(   list<aflibData *>& data,   long long position) {   return (AFLIB_SUCCESS);}voidaflibAudioEdit::parentWasDestroyed(int parent_id){   // We need to rebuild everything if a parent was destroyed. This   // is a callback from aflibChain letting us know that an input was   // destroyed for some reason.   removeInput(parent_id);}voidaflibAudioEdit::parentWasAdded(int parent_id){   // If user has added an input to this class then we need to setup a new input   addInput(parent_id);}boolaflibAudioEdit::isDataSizeSupported(aflib_data_size size){   // This overrides the virtual function in the base class.    bool state = FALSE;    if (size == getInputConfig().getSampleSize())      state = TRUE;    return (state);} boolaflibAudioEdit::isEndianSupported(aflib_data_endian end){   // This overrides the virtual function in the base class.    bool state = FALSE;    if (end == getInputConfig().getDataEndian())      state = TRUE;    return (state);}boolaflibAudioEdit::isSampleRateSupported(int& rate){   // This overrides the virtual function in the base class. See if the rate requested   // is the rate that we have computed that we will be outputting.   int value;   bool ret_value = FALSE;   // Get the rate of the data   value = getOutputConfig().getSamplesPerSecond();    // IF same rate then TRUE else return desired rate   if (rate == value)      ret_value = TRUE;   else      rate = value;    return (ret_value);}boolaflibAudioEdit::isChannelsSupported(int& channels){   // This overrides the virtual function in the base class. See if the channels requested   // is the channels that we have computed that we will be outputting.   int value;   bool ret_value = FALSE;    // Get the number of channels of the data   value = getOutputConfig().getChannels();    // IF same number of channels then TRUE else return desired number of channels   if (channels == value)      ret_value = TRUE;   else      channels = value;    return (ret_value);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -