コード例 #1
0
int main(){
	int A1, A2, w0, w1;
	int R;

	time_t t;
	srand((unsigned) time(&t));

	// A1 = rand() % lim + 1;
	// A2 = rand() % lim + 1;
	// w0 = rand() % lim2 + 1;
	// w1 = rand() % lim2 + 1;
	A1 = 150;
	A2 = 250;
	w0 = 25;
	w1 = 50;
	R = 250;

	writeSample("./data/sig1.dat", A1, w0, R);
	plot("./data/sig1.dat",1,"Signal 1");

	writeSample("./data/sig2.dat", A2, w1, R);
	plot("./data/sig2.dat",1, "Signal 2");

	printf("Actual f for Signal 1: %lf\n",w0/6.283);
	printf("Observed f for Signal 1: %lf\n", freq("./data/sig1.dat",R));

	printf("\nActual f for Signal 2: %lf\n",w1/6.283);
	printf("Observed f for Signal 2: %lf\n", freq("./data/sig2.dat",R));
	
	rFile(A1,w0,1000,3000);
	return 0;
}
コード例 #2
0
double error(int A, int w, int R){
	writeSample("temp", A,w,R);
	double f = freq("temp", R);
	remove("temp");

	return (w/6.283)-f;
}
コード例 #3
0
ファイル: notes_pcm.c プロジェクト: BaJIeK/brltty
static int
flushBlock (NoteDevice *device) {
  while (device->blockUsed)
    if (!writeSample(device, 0))
      return 0;

  return 1;
}
コード例 #4
0
ファイル: notes_pcm.c プロジェクト: BaJIeK/brltty
static int
pcmPlay (NoteDevice *device, unsigned char note, unsigned int duration) {
  long int sampleCount = device->sampleRate * duration / 1000;

  if (note) {
    /* A triangle waveform sounds nice, is lightweight, and avoids
     * relying too much on floating-point performance and/or on
     * expensive math functions like sin(). Considerations like
     * these are especially important on PDAs without any FPU.
     */ 

    int32_t positiveShiftsPerQuarterWave = INT32_MAX / 8;
    int32_t negativeShiftsPerQuarterWave = -positiveShiftsPerQuarterWave;

    int32_t positiveShiftsPerHalfWave = 2 * positiveShiftsPerQuarterWave;
    int32_t negativeSiftsPerHalfWave = -positiveShiftsPerHalfWave;

    int32_t positiveShiftsPerFullWave = 2 * positiveShiftsPerHalfWave;
    int32_t currentShift = 0;

    int32_t shiftsPerSample = (NOTE_FREQUENCY_TYPE)positiveShiftsPerFullWave 
                            / (NOTE_FREQUENCY_TYPE)device->sampleRate
                            * GET_NOTE_FREQUENCY(note);

    int32_t maximumAmplitude = INT16_MAX * prefs.pcmVolume / 100;
    int32_t amplitudeGranularity = positiveShiftsPerQuarterWave / maximumAmplitude;

    logMessage(LOG_DEBUG, "tone: msec=%d smct=%lu note=%d",
               duration, sampleCount, note);

    while (sampleCount > 0) {
      do {
        {
          int32_t normalizedAmplitude = positiveShiftsPerHalfWave - currentShift;

          if (normalizedAmplitude > positiveShiftsPerQuarterWave) {
            normalizedAmplitude = positiveShiftsPerHalfWave - normalizedAmplitude;
          } else if (normalizedAmplitude < negativeShiftsPerQuarterWave) {
            normalizedAmplitude = negativeSiftsPerHalfWave - normalizedAmplitude;
          }

          {
            int32_t actualAmplitude = normalizedAmplitude / amplitudeGranularity;
            if (!writeSample(device, actualAmplitude)) return 0;
            sampleCount -= 1;
          }
        }
      } while ((currentShift += shiftsPerSample) < positiveShiftsPerFullWave);

      do {
        currentShift -= positiveShiftsPerFullWave;
      } while (currentShift >= positiveShiftsPerFullWave);
    }
  } else {
    logMessage(LOG_DEBUG, "tone: msec=%d smct=%lu note=%d",
               duration, sampleCount, note);

    while (sampleCount > 0) {
      if (!writeSample(device, 0)) return 0;
      --sampleCount;
    }
  }

  return 1;
}