~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): Francois Marier, Francois Marier, Mark Purcell
  • Date: 2014-10-18 15:08:50 UTC
  • mfrom: (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20141018150850-2exfk34ckb15pcwi
Tags: 1.4.1-0.1
[ Francois Marier ]
* Non-maintainer upload
* New upstream release (closes: #759576, #741130)
  - debian/rules +PJPROJECT_VERSION := 2.2.1
  - add upstream patch to fix broken TLS support
  - add patch to fix pjproject regression

[ Mark Purcell ]
* Build-Depends:
  - sflphone-daemon + libavformat-dev, libavcodec-dev, libswscale-dev,
  libavdevice-dev, libavutil-dev
  - sflphone-gnome + libclutter-gtk-1.0-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
 
}