Esempio n. 1
0
bool RDHPIRecordStream::formatSupported(RDWaveFile::Format format)
{
  HPI_FORMAT hformat;
  HPI_HISTREAM histream;
  bool found=false;

  if(card_number<0) {
    return false;
  }
  if(format==RDWaveFile::Vorbis) {
#ifdef HAVE_VORBIS
    return true;
#endif  // HAVE_VORBIS
    return false;
  }
  if(!is_open) {
    for(int i=0;i<sound_card->getCardInputStreams(card_number);i++) {
      if(HPI_InStreamOpen(hpi_subsys,card_number,i,&histream)==0) {
	found=true;
	break;
      }
    }
    if(!found) {
      return false;
    }
  }
  else {
    histream=hpi_stream;
  }
  switch(format) {
      case RDWaveFile::Pcm8:
	HPI_FormatCreate(&hformat,getChannels(),HPI_FORMAT_PCM8_UNSIGNED,
			 getSamplesPerSec(),getHeadBitRate(),0);
	state=HPI_InStreamQueryFormat(hpi_subsys,histream,&hformat);
	break;

      case RDWaveFile::Pcm16:
	HPI_FormatCreate(&hformat,getChannels(),HPI_FORMAT_PCM16_SIGNED,
			 getSamplesPerSec(),getHeadBitRate(),0);
	state=HPI_InStreamQueryFormat(hpi_subsys,histream,&hformat);
	break;

      case RDWaveFile::MpegL1:
	HPI_FormatCreate(&hformat,getChannels(),HPI_FORMAT_MPEG_L1,
			 getSamplesPerSec(),getHeadBitRate(),0);
	state=HPI_InStreamQueryFormat(hpi_subsys,histream,&hformat);
	break;

      case RDWaveFile::MpegL2:
	HPI_FormatCreate(&hformat,getChannels(),HPI_FORMAT_MPEG_L2,
			 getSamplesPerSec(),getHeadBitRate(),0);
	state=HPI_InStreamQueryFormat(hpi_subsys,histream,&hformat);
	break;

      case RDWaveFile::MpegL3:
	HPI_FormatCreate(&hformat,getChannels(),HPI_FORMAT_MPEG_L3,
			 getSamplesPerSec(),getHeadBitRate(),0);
	state=HPI_InStreamQueryFormat(hpi_subsys,histream,&hformat);
	break;

      default:
	state=1;
	break;
  }
  if(!is_open) {
    HPI_InStreamClose(hpi_subsys,histream);
  }
  if(state!=0) {
    return false;
  }
  return true;
}
Esempio n. 2
0
bool RDHPIRecordStream::recordReady()
{
  HW16 hpi_error=0;
  char hpi_text[200];

  if(debug) {
    printf("RDHPIRecordStream: received recordReady()\n");
  }
  if(!is_open) {
    return false;
  }
  if((!is_recording)&&(!is_paused)) {
    resetWave();
    if(HPI_InStreamGetInfoEx(hpi_subsys,hpi_stream,
			     &state,&buffer_size,&data_recorded,
			     &samples_recorded,&reserved)!=0) {
      if(debug) {
	printf("RDHPIRecordStream: HPI_InStreamGetInfoEx() failed\n");
      }
      return false;
    }
    fragment_size=buffer_size/4;
    if(fragment_size>192000) {  // ALSA Compatibility Limitation
      fragment_size=192000;
    }
    fragment_time=(1000*fragment_size)/(getAvgBytesPerSec());
    if(pdata!=NULL) {
      delete pdata;
    }
    pdata=(HW8 *)malloc(fragment_size);
    if(pdata==NULL) {
      if(debug) {
	printf("RDHPIRecordStream: couldn't allocate buffer\n");
      }
      return false;
    }
    switch(getFormatTag()) {
	case WAVE_FORMAT_PCM:
	  if(debug) {
	    printf("RDHPIRecordStream: using PCM%d format\n",
		   getBitsPerSample());
	  }
	  switch(getBitsPerSample()) {
	      case 8:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_PCM8_UNSIGNED,getSamplesPerSec(),
				 0,0);
		break;
	      case 16:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_PCM16_SIGNED,getSamplesPerSec(),
				 0,0);
		break;
	      case 32:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_PCM32_SIGNED,getSamplesPerSec(),
				 0,0);
		break;
	      default:
		if(debug) {
		  printf("RDHPIRecordStream: unsupported sample size\n");
		}
		return false;
	  }
	  break;

	case WAVE_FORMAT_MPEG:
	  if(debug) {
	    printf("RDHPIRecordStream: using MPEG-1 Layer %d\n",getHeadLayer());
	  }
	  switch(getHeadLayer()) {
	      case 1:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_MPEG_L1,getSamplesPerSec(),
				 getHeadBitRate(),getHeadFlags());
		break;
	      case 2:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_MPEG_L2,getSamplesPerSec(),
				 getHeadBitRate(),getHeadFlags());
		break;
	      case 3:
		HPI_FormatCreate(&format,getChannels(),
				 HPI_FORMAT_MPEG_L3,getSamplesPerSec(),
				 getHeadBitRate(),getHeadFlags());
		break;
	      default:
		HPI_AdapterClose(hpi_subsys,card_number);
		if(debug) {
		  printf("RDHPIRecordStream: invalid MPEG-1 layer\n");
		}
		return false;
	  }
	  if(getMextChunk()) {
	    setMextHomogenous(true);
	    setMextPaddingUsed(false);
	    setMextHackedBitRate(true);
	    setMextFreeFormat(false);
	    setMextFrameSize(144*getHeadBitRate()/getSamplesPerSec());
	    setMextAncillaryLength(5);
	    setMextLeftEnergyPresent(true);
	    if(getChannels()>1) {
	      setMextRightEnergyPresent(true);
	    }
	    else {
	      setMextRightEnergyPresent(false);
	    }
	    setMextPrivateDataPresent(false);
	  }
	  break;

	case WAVE_FORMAT_VORBIS:
	  if(debug) {
	    printf("RDHPIRecordStream: using OggVorbis\n");
	  }
	  HPI_FormatCreate(&format,getChannels(),
			   HPI_FORMAT_PCM16_SIGNED,getSamplesPerSec(),
			   0,0);
	  break;

	default:
	  if(debug) {
	    printf("RDHPIRecordStream: invalid format tag\n");
	  }
	  return false;
	  break;
    }
    if((hpi_error=HPI_InStreamQueryFormat(hpi_subsys,hpi_stream,
			       &format))!=0) {
      if(debug) {
	HPI_GetErrorText(hpi_error,hpi_text);
	printf("Num: %d\n",hpi_error);
	printf("RDHPIRecordStream: %s\n",hpi_text);
      }
      return false;
    }
  }
#if HPI_VER < 0x00030500
  HPI_DataCreate(&hpi_data,&format,pdata,fragment_size);
#endif
  HPI_InStreamSetFormat(hpi_subsys,hpi_stream,&format);
  HPI_InStreamStart(hpi_subsys,hpi_stream);
//  clock->start(2*fragment_time/3);
  clock->start(100);
  is_ready=true;
  is_recording=false;
  is_paused=false;
  stopping=false;
  emit isStopped(false);
  emit ready();
  emit stateChanged(card_number,stream_number,1);  // RecordReady
  if(debug) {
    printf("RDHPIRecordStream: emitted isStopped(false)\n");
    printf("RDHPIRecordStream: emitted ready()\n");
    printf("RDHPIRecordStream: emitted stateChanged(%d,%d,RDHPIRecordStream::RecordReady)\n",card_number,stream_number);
  }

  return true;
}
Esempio n. 3
0
bool AsiHpiDevice::start(QString *err)
{
#ifdef ASIHPI
    hpi_err_t herr;
    struct hpi_format fmt;
    uint16_t state=0;
    uint32_t buffer_size=0;
    uint32_t data_recorded=0;
    uint32_t samples_recorded=0;
    uint32_t aux_data_recorded=0;

    hpi_handle_t handle;
    short lvls[HPI_MAX_CHANNELS];

    //
    // Open Mixer
    //
    if(HpiLog(HPI_MixerOpen(NULL,asihpi_adapter_index,&asihpi_mixer))==0) {

        //
        // Input Gain
        //
        if(HPI_MixerGetControl(NULL,asihpi_mixer,
                               HPI_SOURCENODE_LINEIN,asihpi_input_index,
                               HPI_DESTNODE_NONE,0,HPI_CONTROL_VOLUME,
                               &handle)==0) {
            for(unsigned i=0; i<HPI_MAX_CHANNELS; i++) {
                lvls[i]=asihpi_input_gain*100;
            }
            HpiLog(HPI_VolumeSetGain(NULL,handle,lvls));
        }

        //
        // Input Source
        //
        if(HpiLog(HPI_MixerGetControl(NULL,asihpi_mixer,0,0,
                                      HPI_DESTNODE_ISTREAM,asihpi_input_index,
                                      HPI_CONTROL_MULTIPLEXER,&handle))==0) {
            HpiLog(HPI_Multiplexer_SetSource(NULL,handle,asihpi_input_source,
                                             asihpi_input_index));
        }

        //
        // Input Type
        //
        if((HpiLog(HPI_MixerGetControl(NULL,asihpi_mixer,
                                       HPI_SOURCENODE_LINEIN,asihpi_input_index,
                                       HPI_DESTNODE_NONE,0,
                                       HPI_CONTROL_MULTIPLEXER,&handle)))==0) {
            HpiLog(HPI_Multiplexer_SetSource(NULL,handle,asihpi_input_type,
                                             asihpi_input_index));
        }

        //
        // Channel Mode
        //
        if((HpiLog(HPI_MixerGetControl(NULL,asihpi_mixer,0,0,
                                       HPI_DESTNODE_ISTREAM,asihpi_input_index,
                                       HPI_CONTROL_CHANNEL_MODE,
                                       &handle)))==0) {
            HpiLog(HPI_ChannelModeSet(NULL,handle,asihpi_channel_mode));
        }

        //
        // Input Meter
        //
        if((HpiLog(HPI_MixerGetControl(NULL,asihpi_mixer,0,0,HPI_DESTNODE_ISTREAM,
                                       asihpi_input_index,HPI_CONTROL_METER,&asihpi_input_meter)))==0) {
            asihpi_meter_timer->start(100);
        }
    }

    //
    // Open Input Stream
    //
    if((herr=HPI_InStreamOpen(NULL,asihpi_adapter_index,asihpi_input_index,&asihpi_input_stream))!=0) {
        *err=tr("HPI error")+": "+hpi_strerror(herr);
        return false;
    }

    //
    // Find Supported Format
    //
    MakeFormat(&fmt,HPI_FORMAT_PCM32_FLOAT);
    if((herr=HPI_InStreamQueryFormat(NULL,asihpi_input_stream,&fmt))!=0) {
        *err=tr("HPI error")+": "+hpi_strerror(herr);
        return false;
    }

    //
    // Set Format
    //
    if((herr=HPI_InStreamSetFormat(NULL,asihpi_input_stream,&fmt))!=0) {
        *err=tr("HPI error")+": "+hpi_strerror(herr);
        return false;
    }

    //
    // Start input stream
    //
    if((herr=HPI_InStreamStart(NULL,asihpi_input_stream))!=0) {
        *err=tr("HPI error")+": "+hpi_strerror(herr);
        return false;
    }

    //
    // Create PCM buffer
    //
    if((herr=HPI_InStreamGetInfoEx(NULL,asihpi_input_stream,&state,&buffer_size,
                                   &data_recorded,&samples_recorded,
                                   &aux_data_recorded))!=0) {
        *err=tr("HPI error")+": "+hpi_strerror(herr);
        return false;
    }
    asihpi_pcm_buffer=new uint8_t[buffer_size];

    asihpi_read_timer->start(ASIHPI_READ_INTERVAL);

    return true;
#else
    return false;
#endif  // ASIHPI
}