~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/third_party/portaudio/src/os/win/pa_win_waveformat.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* 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
 * PortAudio Portable Real-Time Audio Library
 
3
 * Windows WAVEFORMAT* data structure utilities
 
4
 * portaudio.h should be included before this file.
 
5
 *
 
6
 * Copyright (c) 2007 Ross Bencina
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining
 
9
 * a copy of this software and associated documentation files
 
10
 * (the "Software"), to deal in the Software without restriction,
 
11
 * including without limitation the rights to use, copy, modify, merge,
 
12
 * publish, distribute, sublicense, and/or sell copies of the Software,
 
13
 * and to permit persons to whom the Software is furnished to do so,
 
14
 * subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
22
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 
23
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 
24
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
25
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
26
 */
 
27
 
 
28
/*
 
29
 * The text above constitutes the entire PortAudio license; however, 
 
30
 * the PortAudio community also makes the following non-binding requests:
 
31
 *
 
32
 * Any person wishing to distribute modifications to the Software is
 
33
 * requested to send the modifications to the original developer so that
 
34
 * they can be incorporated into the canonical version. It is also 
 
35
 * requested that these non-binding requests be included along with the 
 
36
 * license above.
 
37
 */
 
38
 
 
39
#include <windows.h>
 
40
#include <mmsystem.h>
 
41
 
 
42
#include "portaudio.h"
 
43
#include "pa_win_waveformat.h"
 
44
 
 
45
 
 
46
#if !defined(WAVE_FORMAT_EXTENSIBLE)
 
47
#define  WAVE_FORMAT_EXTENSIBLE         0xFFFE
 
48
#endif
 
49
 
 
50
static GUID pawin_ksDataFormatSubtypeGuidBase = 
 
51
        { (USHORT)(WAVE_FORMAT_PCM), 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 };
 
52
 
 
53
 
 
54
int PaWin_SampleFormatToLinearWaveFormatTag( PaSampleFormat sampleFormat )
 
55
{
 
56
    if( sampleFormat == paFloat32 )
 
57
        return PAWIN_WAVE_FORMAT_IEEE_FLOAT;
 
58
    
 
59
    return PAWIN_WAVE_FORMAT_PCM;
 
60
}
 
61
 
 
62
 
 
63
void PaWin_InitializeWaveFormatEx( PaWinWaveFormat *waveFormat, 
 
64
                int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate )
 
65
{
 
66
        WAVEFORMATEX *waveFormatEx = (WAVEFORMATEX*)waveFormat;
 
67
    int bytesPerSample = Pa_GetSampleSize(sampleFormat);
 
68
        unsigned long bytesPerFrame = numChannels * bytesPerSample;
 
69
        
 
70
    waveFormatEx->wFormatTag = waveFormatTag;
 
71
        waveFormatEx->nChannels = (WORD)numChannels;
 
72
        waveFormatEx->nSamplesPerSec = (DWORD)sampleRate;
 
73
        waveFormatEx->nAvgBytesPerSec = waveFormatEx->nSamplesPerSec * bytesPerFrame;
 
74
        waveFormatEx->nBlockAlign = (WORD)bytesPerFrame;
 
75
        waveFormatEx->wBitsPerSample = bytesPerSample * 8;
 
76
        waveFormatEx->cbSize = 0;
 
77
}
 
78
 
 
79
 
 
80
void PaWin_InitializeWaveFormatExtensible( PaWinWaveFormat *waveFormat, 
 
81
                int numChannels, PaSampleFormat sampleFormat, int waveFormatTag, double sampleRate,
 
82
                PaWinWaveFormatChannelMask channelMask )
 
83
{
 
84
        WAVEFORMATEX *waveFormatEx = (WAVEFORMATEX*)waveFormat;
 
85
    int bytesPerSample = Pa_GetSampleSize(sampleFormat);
 
86
        unsigned long bytesPerFrame = numChannels * bytesPerSample;
 
87
    GUID guid;
 
88
 
 
89
        waveFormatEx->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
 
90
        waveFormatEx->nChannels = (WORD)numChannels;
 
91
        waveFormatEx->nSamplesPerSec = (DWORD)sampleRate;
 
92
        waveFormatEx->nAvgBytesPerSec = waveFormatEx->nSamplesPerSec * bytesPerFrame;
 
93
        waveFormatEx->nBlockAlign = (WORD)bytesPerFrame;
 
94
        waveFormatEx->wBitsPerSample = bytesPerSample * 8;
 
95
        waveFormatEx->cbSize = 22;
 
96
 
 
97
        *((WORD*)&waveFormat->fields[PAWIN_INDEXOF_WVALIDBITSPERSAMPLE]) =
 
98
                        waveFormatEx->wBitsPerSample;
 
99
 
 
100
        *((DWORD*)&waveFormat->fields[PAWIN_INDEXOF_DWCHANNELMASK]) = channelMask;
 
101
                
 
102
    guid = pawin_ksDataFormatSubtypeGuidBase;
 
103
    guid.Data1 = (USHORT)waveFormatTag;
 
104
    *((GUID*)&waveFormat->fields[PAWIN_INDEXOF_SUBFORMAT]) = guid;
 
105
}
 
106
 
 
107
 
 
108
PaWinWaveFormatChannelMask PaWin_DefaultChannelMask( int numChannels )
 
109
{
 
110
        switch( numChannels ){
 
111
                case 1:
 
112
                        return PAWIN_SPEAKER_MONO;
 
113
                case 2:
 
114
                        return PAWIN_SPEAKER_STEREO; 
 
115
                case 3:
 
116
            return PAWIN_SPEAKER_FRONT_LEFT | PAWIN_SPEAKER_FRONT_CENTER | PAWIN_SPEAKER_FRONT_RIGHT;
 
117
                case 4:
 
118
                        return PAWIN_SPEAKER_QUAD;
 
119
                case 5:
 
120
            return PAWIN_SPEAKER_QUAD | PAWIN_SPEAKER_FRONT_CENTER;
 
121
                case 6:
 
122
            /* The meaning of the PAWIN_SPEAKER_5POINT1 flag has changed over time:
 
123
                http://msdn2.microsoft.com/en-us/library/aa474707.aspx
 
124
               We use PAWIN_SPEAKER_5POINT1 (not PAWIN_SPEAKER_5POINT1_SURROUND)
 
125
               because on some cards (eg Audigy) PAWIN_SPEAKER_5POINT1_SURROUND 
 
126
               results in a virtual mixdown placing the rear output in the 
 
127
               front _and_ rear speakers.
 
128
            */
 
129
                        return PAWIN_SPEAKER_5POINT1; 
 
130
        /* case 7: */
 
131
                case 8:
 
132
                        return PAWIN_SPEAKER_7POINT1;
 
133
        }
 
134
 
 
135
    /* Apparently some Audigy drivers will output silence 
 
136
       if the direct-out constant (0) is used. So this is not ideal.    
 
137
    */
 
138
        return  PAWIN_SPEAKER_DIRECTOUT;
 
139
 
 
140
    /* Note that Alec Rogers proposed the following as an alternate method to 
 
141
        generate the default channel mask, however it doesn't seem to be an improvement
 
142
        over the above, since some drivers will matrix outputs mapping to non-present
 
143
        speakers accross multiple physical speakers.
 
144
 
 
145
        if(nChannels==1) {
 
146
            pwfFormat->dwChannelMask = SPEAKER_FRONT_CENTER;
 
147
        }
 
148
        else {
 
149
            pwfFormat->dwChannelMask = 0;
 
150
            for(i=0; i<nChannels; i++)
 
151
                pwfFormat->dwChannelMask = (pwfFormat->dwChannelMask << 1) | 0x1;
 
152
        }
 
153
    */
 
154
}