~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/third_party/portaudio/src/hostapi/oss/recplay.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * recplay.c
 
3
 * Phil Burk
 
4
 * Minimal record and playback test.
 
5
 * 
 
6
 */
 
7
#include <stdio.h>
 
8
#include <unistd.h>
 
9
#include <stdlib.h>
 
10
#ifndef __STDC__
 
11
/* #include <getopt.h> */
 
12
#endif /* __STDC__ */
 
13
#include <fcntl.h>
 
14
#ifdef __STDC__
 
15
#include <string.h>
 
16
#else /* __STDC__ */
 
17
#include <strings.h>
 
18
#endif /* __STDC__ */
 
19
#include <sys/soundcard.h>
 
20
 
 
21
#define NUM_BYTES   (64*1024)
 
22
#define BLOCK_SIZE   (4*1024)
 
23
 
 
24
#define AUDIO "/dev/dsp"
 
25
 
 
26
char buffer[NUM_BYTES];
 
27
 
 
28
int audioDev = 0;
 
29
 
 
30
main (int argc, char *argv[])
 
31
{
 
32
    int   numLeft;
 
33
    char *ptr;
 
34
    int   num;
 
35
    int   samplesize;
 
36
 
 
37
    /********** RECORD ********************/
 
38
    /* Open audio device. */
 
39
    audioDev = open (AUDIO, O_RDONLY, 0);
 
40
    if (audioDev == -1)
 
41
    {
 
42
        perror (AUDIO);
 
43
        exit (-1);
 
44
    }
 
45
 
 
46
    /* Set to 16 bit samples. */
 
47
    samplesize = 16;
 
48
    ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
 
49
    if (samplesize != 16)
 
50
    {
 
51
        perror("Unable to set the sample size.");
 
52
        exit(-1);
 
53
    }
 
54
 
 
55
    /* Record in blocks */
 
56
    printf("Begin recording.\n");
 
57
    numLeft = NUM_BYTES;
 
58
    ptr = buffer;
 
59
    while( numLeft >= BLOCK_SIZE )
 
60
    {
 
61
        if ( (num = read (audioDev, ptr, BLOCK_SIZE)) < 0 )
 
62
        {
 
63
            perror (AUDIO);
 
64
            exit (-1);
 
65
        }
 
66
        else
 
67
        {
 
68
            printf("Read %d bytes\n", num);
 
69
            ptr += num;
 
70
            numLeft -= num;
 
71
        }
 
72
    }
 
73
 
 
74
    close( audioDev );
 
75
 
 
76
    /********** PLAYBACK ********************/
 
77
    /* Open audio device for writing. */
 
78
    audioDev = open (AUDIO, O_WRONLY, 0);
 
79
    if (audioDev == -1)
 
80
    {
 
81
        perror (AUDIO);
 
82
        exit (-1);
 
83
    }
 
84
 
 
85
    /* Set to 16 bit samples. */
 
86
    samplesize = 16;
 
87
    ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
 
88
    if (samplesize != 16)
 
89
    {
 
90
        perror("Unable to set the sample size.");
 
91
        exit(-1);
 
92
    }
 
93
 
 
94
    /* Play in blocks */
 
95
    printf("Begin playing.\n");
 
96
    numLeft = NUM_BYTES;
 
97
    ptr = buffer;
 
98
    while( numLeft >= BLOCK_SIZE )
 
99
    {
 
100
        if ( (num = write (audioDev, ptr, BLOCK_SIZE)) < 0 )
 
101
        {
 
102
            perror (AUDIO);
 
103
            exit (-1);
 
104
        }
 
105
        else
 
106
        {
 
107
            printf("Wrote %d bytes\n", num);
 
108
            ptr += num;
 
109
            numLeft -= num;
 
110
        }
 
111
    }
 
112
 
 
113
    close( audioDev );
 
114
}