OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [dactest/] [genbell.c] - Blame information for rev 275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 232 hellwig
/*
2
 * genbell.c -- 2-operator bell sound
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <math.h>
10
 
11
 
12
#define NUM_SEC         8               /* duration */
13
 
14
#define CLK             50000000        /* clock rate */
15
#define DIV             1024            /* clock divisor */
16
#define SAMPLE_RATE     (CLK / DIV)     /* in samples/sec */
17
 
18
#define PI              M_PI
19
 
20
 
21
void prolog(void) {
22
  printf("\t.export\tsamples\n");
23
  printf("\t.export\tendsmpl\n");
24
  printf("\n");
25
  printf("samples:\n");
26
}
27
 
28
 
29
void epilog(void) {
30
  printf("endsmpl:\n");
31
}
32
 
33
 
34
void wrtsample(short sample) {
35
  static int n = 0;
36
  unsigned w = (((unsigned) sample << 16) & 0xFFFF0000) |
37
               (((unsigned) sample <<  0) & 0x0000FFFF);
38
  if (n % 4 == 0) {
39
    printf("\t.word\t");
40
    n = 0;
41
  }
42
  printf("0x%08X", w);
43
  if (n % 4 == 3) {
44
    printf("\n");
45
  } else {
46
    printf(", ");
47
  }
48
  n++;
49
}
50
 
51
 
52
int main(int argc, char *argv[]) {
53
  double f0;
54
  int n, m;
55
  double a, alpha;
56
  double b, beta;
57
  double t;
58
  double modAmpl;
59
  double modulator;
60
  double carrAmpl;
61
  double carrier;
62
  short sample;
63
  int i;
64
 
65
  if (argc != 1) {
66
    printf("usage: %s\n", argv[0]);
67
    exit(1);
68
  }
69
  f0 = 49.0;
70
  n = 5;
71
  m = 7;
72
  a = 16000.0;
73
  alpha = 0.6140;
74
  b = 10.0;
75
  beta = 0.4605;
76
  prolog();
77
  for (i = 0; i < NUM_SEC * SAMPLE_RATE; i++) {
78
    t = i * (1.0 / SAMPLE_RATE);
79
    modAmpl = b * exp(-beta * t);
80
    modulator = modAmpl * sin(2.0 * PI * m * f0 * t);
81
    carrAmpl = a * exp(-alpha * t);
82
    carrier = carrAmpl * sin(2.0 * PI * n * f0 * t + modulator);
83
    sample = floor(carrier + 0.5);
84
    wrtsample(sample);
85
  }
86
  epilog();
87
  return 0;
88
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.