Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

61 rader
1.2 KiB

  1. /*
  2. * record.c:
  3. * Record some audio via the Gertboard
  4. *
  5. * Copyright (c) 2013 Gordon Henderson
  6. ***********************************************************************
  7. */
  8. #include <stdio.h>
  9. #include <sys/time.h>
  10. #include <wiringPi.h>
  11. #include <gertboard.h>
  12. #define B_SIZE 40000
  13. int main ()
  14. {
  15. int i ;
  16. struct timeval tStart, tEnd, tTaken ;
  17. unsigned char buffer [B_SIZE] ;
  18. printf ("\n") ;
  19. printf ("Gertboard demo: Recorder\n") ;
  20. printf ("========================\n") ;
  21. // Always initialise wiringPi. Use wiringPiSys() if you don't need
  22. // (or want) to run as root
  23. wiringPiSetupSys () ;
  24. // Initialise the Gertboard analog hardware at pin 100
  25. gertboardAnalogSetup (100) ;
  26. gettimeofday (&tStart, NULL) ;
  27. for (i = 0 ; i < B_SIZE ; ++i)
  28. buffer [i] = analogRead (100) >> 2 ;
  29. gettimeofday (&tEnd, NULL) ;
  30. timersub (&tEnd, &tStart, &tTaken) ;
  31. printf ("Time taken for %d reads: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
  32. gettimeofday (&tStart, NULL) ;
  33. for (i = 0 ; i < B_SIZE ; ++i)
  34. analogWrite (100, buffer [i]) ;
  35. gettimeofday (&tEnd, NULL) ;
  36. timersub (&tEnd, &tStart, &tTaken) ;
  37. printf ("Time taken for %d writes: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
  38. return 0 ;
  39. }