Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / examples / Gertboard / record.c @ 32:cadb9025f1e0

History | View | Annotate | Download (1.22 KB)

1
/*
2
 * record.c:
3
 *        Record some audio via the Gertboard
4
 *
5
 *        Copyright (c) 2013 Gordon Henderson
6
 ***********************************************************************
7
 */
8

    
9
#include <stdio.h>
10
#include <sys/time.h>
11

    
12
#include <wiringPi.h>
13
#include <gertboard.h>
14

    
15
#define        B_SIZE        40000
16

    
17
int main ()
18
{
19
  int i ;
20
  struct timeval tStart, tEnd, tTaken ;
21
  unsigned char buffer [B_SIZE] ;
22

    
23
  printf ("\n") ;
24
  printf ("Gertboard demo: Recorder\n") ;
25
  printf ("========================\n") ;
26

    
27
// Always initialise wiringPi. Use wiringPiSys() if you don't need
28
//        (or want) to run as root
29

    
30
  wiringPiSetupSys () ;
31

    
32
// Initialise the Gertboard analog hardware at pin 100
33

    
34
  gertboardAnalogSetup (100) ;
35

    
36
  gettimeofday (&tStart, NULL) ;
37

    
38
  for (i = 0 ; i < B_SIZE ; ++i)
39
    buffer [i] = analogRead (100) >> 2 ;
40

    
41
  gettimeofday (&tEnd, NULL) ;
42
  
43
  timersub (&tEnd, &tStart, &tTaken) ;
44

    
45
  printf ("Time taken for %d  reads: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
46

    
47
  gettimeofday (&tStart, NULL) ;
48

    
49
  for (i = 0 ; i < B_SIZE ; ++i)
50
   analogWrite (100, buffer [i]) ;
51

    
52
  gettimeofday (&tEnd, NULL) ;
53
  
54
  timersub (&tEnd, &tStart, &tTaken) ;
55

    
56
  printf ("Time taken for %d writes: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
57

    
58
  return 0 ;
59
}
60