Beispiel #1
0
MP_Status_t IMP_PutPariBigInt(MP_Link_pt link, MP_ApInt_t mp_number) 
{
  GEN number = (GEN) mp_number;
  long length = lgef(number) - 2; /* in "limbs" */
  long sign = signe(number); 

  /* Put the length and sign */
  ERR_CHK(IMP_PutSint32(link, (sign < 0 ? -length : length)));
 
  if (link->link_bigint_format == MP_PARI)
  {
    /* for pari - bigints can use the vector put */
    ERR_CHK(IMP_PutUint32Vector(link, (MP_Uint32_t *) &number[2], length));
  }
  else
  {
    /* we put the numbers in the gmp format */
    /* which is very similar to the pari format, except that in pari,
       limbs are in descending order, and not in ascending, as in gmp */
    GEN ptr = number + length + 1;
    number++;

    for (;ptr > number; ptr--)
      ERR_CHK(IMP_PutLong(link, ptr));
  }

  /* done */
  return MP_ClearError(link);
}
Beispiel #2
0
MP_Status_t IMP_GetPariBigInt(MP_Link_pt link, MP_ApInt_t *mp_number)
{
  long length, sign = 1;
  GEN number, ptr;

  /* first, we get the effective length and the sign */
  ERR_CHK(IMP_GetLong(link, &length));

  if (length < 0)
  {
    sign = -1;
    length = -length;
  }
  else if (length == 0)
  {
    sign = 0;
  }

  /* Initialize the number */
  number = IMP_AllocCgeti(length+2);
  setlgef(number, length+2);
  setsigne(number, sign);

  /* Get the actual data */
  if (length > 0)
  {
    if (link->link_bigint_format == MP_PARI)
    {
      ptr = &(number[2]);
      ERR_CHK(IMP_GetUint32Vector(link, (MP_Uint32_t **) &ptr, length));
    }
    else
    {
      number++;
      ptr = number + length;
      for (; ptr > number; ptr--)
        ERR_CHK(IMP_GetLong(link, ptr));
      number--;
    }
  }

  *mp_number = (MP_ApInt_t) number;
  return MP_ClearError(link);
}
// ----------------------------------------------------------
void ofxAudioUnitMixer::setInputVolume(float volume, int bus)
// ----------------------------------------------------------
{
  ERR_CHK(AudioUnitSetParameter(*_unit, 
                                kMultiChannelMixerParam_Volume, 
                                kAudioUnitScope_Input, 
                                bus, 
                                volume,
                                0), 
          "setting mixer input gain");
}
// ----------------------------------------------------------
void ofxAudioUnitMixer::setOutputVolume(float volume)
// ----------------------------------------------------------
{
  ERR_CHK(AudioUnitSetParameter(*_unit, 
                                kMultiChannelMixerParam_Volume, 
                                kAudioUnitScope_Output, 
                                0, 
                                volume,
                                0), 
          "setting mixer output gain");
}
// ----------------------------------------------------------
float ofxAudioUnitMixer::getOutputLevel()
// ----------------------------------------------------------
{	
	AudioUnitParameterValue level;
	ERR_CHK(AudioUnitGetParameter(*_unit,
																kMultiChannelMixerParam_PreAveragePower,
																kAudioUnitScope_Output,
																0,
																&level),
					"getting mixer output level");
	return level;
}
// ----------------------------------------------------------
void ofxAudioUnitNetSend::setFormat(unsigned int formatIndex)
// ----------------------------------------------------------
{
	UInt32 format = formatIndex;
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAUNetSendProperty_TransmissionFormatIndex,
															 kAudioUnitScope_Global,
															 0,
															 &format,
															 sizeof(format)),
					"setting net send format");
}
// ----------------------------------------------------------
void ofxAudioUnitNetSend::setPort(unsigned int portNumber)
// ----------------------------------------------------------
{
	UInt32 pNum = portNumber;
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAUNetSendProperty_PortNum, 
															 kAudioUnitScope_Global,
															 0,
															 &pNum,
															 sizeof(pNum)),
					"setting net send port number");
}
// ----------------------------------------------------------
void ofxAudioUnitFilePlayer::play()
// ----------------------------------------------------------
{
	if(!(region.mTimeStamp.mFlags & kAudioTimeStampSampleTimeValid))
	{
		cout << "ofxAudioUnitFilePlayer has no file to play" << endl;
		return;
	}
	
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAudioUnitProperty_ScheduledFileIDs,
															 kAudioUnitScope_Global,
															 0, 
															 fileID, 
															 sizeof(fileID)),
					"setting file player's file ID");
	
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAudioUnitProperty_ScheduledFileRegion,
															 kAudioUnitScope_Global,
															 0,
															 &region,
															 sizeof(region)),
					"setting file player region");
	
	AudioTimeStamp startTime = {0};
	startTime.mFlags = kAudioTimeStampSampleTimeValid;
	startTime.mSampleTime = -1;
	
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAudioUnitProperty_ScheduleStartTimeStamp,
															 kAudioUnitScope_Global,
															 0,
															 &startTime,
															 sizeof(startTime)),
					"setting file player start time");
}
// ----------------------------------------------------------
ofxAudioUnitSpeechSynth::ofxAudioUnitSpeechSynth()
// ----------------------------------------------------------
{
	_desc = speechDesc;
	initUnit();
	UInt32 dataSize = sizeof(SpeechChannel);
	
	ERR_CHK(AudioUnitGetProperty(*_unit,
															 kAudioUnitProperty_SpeechChannel,
															 kAudioUnitScope_Global,
															 0,
															 &_channel,
															 &dataSize),
					"getting speech channel");
}
// ----------------------------------------------------------
void ofxAudioUnitNetSend::setName(std::string name)
// ----------------------------------------------------------
{
	CFStringRef serviceName = CFStringCreateWithCString(kCFAllocatorDefault,
																											name.c_str(),
																											kCFStringEncodingUTF8);
	
	ERR_CHK(AudioUnitSetProperty(*_unit,
															 kAUNetSendProperty_ServiceName,
															 kAudioUnitScope_Global,
															 0,
															 &serviceName,
															 sizeof(serviceName)),
					"setting net send service name");
	
	CFRelease(serviceName);
}
// ----------------------------------------------------------
void ofxAudioUnitMixer::setPan(float pan, int bus)
// ----------------------------------------------------------
{
#ifndef __MAC_10_7
	static bool printedSetPanOSVersionMessage = false;
	if(!printedSetPanOSVersionMessage)
	{
		cout << "ofxAudioUnitMixer's setPan() is only available"
		<< " on OS X 10.7 and up" << endl;
		printedSetPanOSVersionMessage = true;
	}
#else
  ERR_CHK(AudioUnitSetParameter(*_unit,
                                kMultiChannelMixerParam_Pan,
                                kAudioUnitScope_Input,
                                bus,
                                pan,
                                0),
          "setting mixer pan");
#endif
}
Beispiel #12
0
int main(int argc, char **argv)
{
    struct sigaction *act = malloc(sizeof(struct sigaction));
    ERR_CHK(act == NULL);
    ERR_CHK(sigaction(2, NULL, act) != 0);
    act->sa_handler = (void *)h;
    ERR_CHK(sigaction(2, act, NULL));
    int i;
    p_count = 0;
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "x") == 0)
            p_count++;
    }
    int in_copy = dup(STDIN_FILENO);
    int out_copy = dup(STDOUT_FILENO);
    int **pipes = calloc(p_count + 1, sizeof(int *));
    ERR_CHK(pipes == NULL);
    for (i = 0; i < p_count + 1; i++)
    {
        pipes[i] = calloc(2, sizeof(int));
        ERR_CHK(pipes[i] == NULL);
        ERR_CHK(pipe(pipes[i]) == -1);
    }
    p_num = 0;
    ppid = fork();
    ERR_CHK(ppid == -1);
    if (ppid == 0)
    {
        setsid();
    for (i = 1; i < argc; i++)
    {
        int a_count = 0;
        while (strcmp(argv[i + a_count], "x") != 0)
        {
            a_count++;
        }
        char **a_values = calloc(a_count + 1, sizeof(char *));
        ERR_CHK(a_values == NULL);
        int j;
        for (j = 0; j < a_count; j++)
        {
            a_values[j] = calloc(strlen(argv[i + j]) + 1, sizeof(char));
            ERR_CHK(a_values[j] == NULL);
            sprintf(a_values[j], "%s", argv[i + j]);
        }
        int *fds = calloc(2, sizeof(int));
        ERR_CHK(pipe(fds) == -1);
        int f_res = fork();
        ERR_CHK(f_res == -1);
        if (f_res == 0)
        {
            if (p_num == 0)
            {
                ERR_CHK(dup2(in_copy, STDIN_FILENO) == -1);
            }
            else
            {
                ERR_CHK(dup2(pipes[p_num][0], STDIN_FILENO) == -1);
            }
            if (p_num == p_count - 1)
            {
                ERR_CHK(dup2(out_copy, STDOUT_FILENO) == -1);
            }
            else
            {
                ERR_CHK(dup2(pipes[p_num + 1][1], STDOUT_FILENO) == -1);
            }
            ERR_CHK(execve(a_values[0], a_values, NULL) == -1);
        }
        else
        {
            p_num++;
            for (j = 0; j < a_count; j++)
                free(a_values[j]);
            free(a_values);
        }
        i += a_count;
    }
    }
    wait(NULL);
    return 0;
}