status_t AudioRemapper::convertChannelsPolicyInStereo(const void *src,
                                                      void *dst,
                                                      const size_t inFrames,
                                                      size_t *outFrames)
{
    const type *srcTyped = static_cast<const type *>(src);
    size_t frames = 0;
    uint32_t srcChannels = mSsSrc.getChannelCount();

    struct Stereo
    {
        type leftCh;
        type rightCh;
    } *dstTyped = static_cast<Stereo *>(dst);

    for (frames = 0; frames < inFrames; frames++) {

        dstTyped[frames].leftCh = convertSample(&srcTyped[srcChannels * frames], Left);
        dstTyped[frames].rightCh = convertSample(&srcTyped[srcChannels * frames], Right);
    }

    // Transformation is "iso" frames
    *outFrames = inFrames;
    return NO_ERROR;
}
Exemple #2
0
    int SampleReader::Read(float* buffer, int expectedSamples)
    {
        int samplesRead = 0;
        int bufferOffset = 0;
        while (samplesRead < expectedSamples)
        {
            int samplesToRead = min(expectedSamples - samplesRead, internalBufferSize);
            int currentSamplesRead;
            if (stream->GetChannelCount() != 2 && forceStereo)
            {
                currentSamplesRead = stream->Read(internalBuffer, DataTypeInfo::SizeOf(DataTypeInt16), samplesToRead / 2);
                for (int i = 0; i < currentSamplesRead; i++)
                {
                    float sample = convertSample(internalBuffer[i]);
                    buffer[bufferOffset++] = sample;
                    buffer[bufferOffset++] = sample;
                }
            }
            else
            {
                currentSamplesRead = stream->Read(internalBuffer, DataTypeInfo::SizeOf(DataTypeInt16), samplesToRead);
                for (int i = 0; i < currentSamplesRead; i++) buffer[bufferOffset++] = convertSample(internalBuffer[i]);
            }

            samplesRead += currentSamplesRead;
            if (currentSamplesRead < samplesToRead) break;
        }
        return samplesRead;
    }
void convertRightSamples(Sample* first, Sample* last, const mad_fixed_t* src) { 
	Sample* dst;
	for (dst = first; dst != last; ++dst) 
		dst->right = convertSample(*src++); 
} 
Exemple #4
0
// export thread
static DWORD __stdcall export_rendering_thread(void *parameter) {
  const int samples_per_sec = 44100;
  uint progress = 0;

  WAVEFORMATEX  wfxInput;
  ZeroMemory( &wfxInput, sizeof(wfxInput));
  wfxInput.wFormatTag = WAVE_FORMAT_PCM;
  wfxInput.nSamplesPerSec = samples_per_sec;
  wfxInput.wBitsPerSample =  16; 
  wfxInput.nChannels = 2;
  wfxInput.nBlockAlign = wfxInput.nChannels * (wfxInput.wBitsPerSample / 8);
  wfxInput.nAvgBytesPerSec = wfxInput.nBlockAlign * wfxInput.nSamplesPerSec;

  HRESULT hr;
  CWaveFile wavFile;

  hr = wavFile.Open((char*)parameter, &wfxInput, WAVEFILE_WRITE);
  if (FAILED(hr)) {
    goto done;
  }


  // stop playing
  song_stop_playback();

  // skip 5 seconds
  for (int samples = samples_per_sec * 5; samples > 0; samples -= 32) {
    float temp_buffer[2][32];

    // update song
    song_update(1000.0 * (double)32 / (double)samples_per_sec);

    // update effect
    vsti_update_config((float)samples_per_sec, 32);

    // call vsti process func
    vsti_process(temp_buffer[0], temp_buffer[1], 32);
  }

  song_start_playback();

  for (;;) {
    const int samples = 32;

    float temp_buffer[2][samples];
    short output_buffer[2 * samples];

    // update song
    song_update(1000.0 * (double)samples / (double)samples_per_sec);

    // update effect
    vsti_update_config((float)samples_per_sec, samples);

    // call vsti process func
    vsti_process(temp_buffer[0], temp_buffer[1], samples);

    short* output = output_buffer;
    float volume = config_get_output_volume() / 100.0;
    for (int i = 0; i < samples; i++) {
      float l = 
      output[0] = convertSample(temp_buffer[0][i] * 32767.0f * volume);
      output[1] = convertSample(temp_buffer[1][i] * 32767.0f * volume);
      output += 2;
    }

    UINT sizeWrote = 0;
    hr = wavFile.Write(sizeof(output_buffer), (BYTE*)output_buffer, &sizeWrote);

    if (!song_is_playing())
      break;

    if (!gui_is_exporting())
      break;

    uint new_progress = 100 * song_get_time() / song_get_length();
    if (new_progress != progress) {
      progress = new_progress;
      gui_update_export_progress(progress);
    }
  }

done:
  song_stop_playback();
  gui_close_export_progress();
  wavFile.Close();
  return hr;
}
Exemple #5
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to 
       application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  
  /* RCC configuration */
  RCC_Config();
  
  /* GPIO configuration */
  GPIO_Config();
  
  /* TIM4 configuration */
  TIM4_Config();
  
  /* UART4 configuration */
  UART4_Config();
  
  /* SPI3 configuration */
  SPI3_Config();
  
  /* NVIC configuration */
  NVIC_Config();
  
  /* Network Configuration */
  NET_Config();
  
  /* Configure SysTick */  
  SysTick_Config(SystemCoreClock / 1000);

  /* Infinite Loop */
  while (1) {
    if(TimerCounter >= 10) {
      TimerCounter = 0;
      
      if(SendFlag) {
        //SendFlag = False;
        
        char str[30];
        if(order++ < 90) {
          float one = NULL;
          float two = NULL;
          float thr = NULL;
            
          if(inc <= 300) {
            one = convertSample(EQ_SAMPLE[inc++]) * 1e-7;
            two = convertSample(EQ_SAMPLE[inc++]) * 1e-7;
            thr = convertSample(EQ_SAMPLE[inc++]) * 1e-7;  
          } else {
            inc = 0;            
          }
          
          sprintf(str, "%-0.7f,%-0.7f,%-0.7f\n", one, two, thr);
        } else {
          order = 0;
        }
        
        // Only when socket is established, send data
        if(getSn_SR(SOCK_TCPS) == SOCK_ESTABLISHED) {
          /* send the received data */
          send(SOCK_TCPS, (uint8*)str, strlen(str));
        }
      }
    }
    
    if(ParseUART4) {
      ParseUART4 = False;
      
      printSysCfg();
    }
    
    ProcessTcpSever();
  }
}