aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Visual/projectm
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-02-07 15:33:35 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-02-07 15:33:35 +0000
commitf8c2616ab0c874ca97decbe502c1b8290d7e82bd (patch)
treea57354ac0344433827b83596acced57c5129d81e /src/plugins/Visual/projectm
parenta0fd979bede268bd479f60eb923ab14d22c73fdf (diff)
downloadqmmp-f8c2616ab0c874ca97decbe502c1b8290d7e82bd.tar.gz
qmmp-f8c2616ab0c874ca97decbe502c1b8290d7e82bd.tar.bz2
qmmp-f8c2616ab0c874ca97decbe502c1b8290d7e82bd.zip
fixed udisks2 plugin (Closes issue 574)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3202 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Visual/projectm')
0 files changed, 0 insertions, 0 deletions
9-04-12 19:31:02 +0000 committer trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2009-04-12 19:31:02 +0000 added wave output plugin' href='/qmmp/commit/src/plugins/Output/waveout/outputwaveout.cpp?id=5b126a92737bba6264065c8ff437056c908204f5'>5b126a927
5b126a927



acb3d9b6c
5b126a927


c042c10a3
5b126a927




acb3d9b6c
5b126a927
e5e8d23c6


acb3d9b6c
8ac5efc90


c042c10a3
8ac5efc90

5b126a927


acb3d9b6c
5b126a927
8ac5efc90

5b126a927
acb3d9b6c
8ac5efc90
acb3d9b6c
5b126a927
acb3d9b6c
5b126a927
acb3d9b6c
8ac5efc90

5b126a927
acb3d9b6c
8ac5efc90

5b126a927

8bded202c
5b126a927
e7b06c4b7

5b126a927






275eddbde
5b126a927
e5e8d23c6
e7b06c4b7
c41f44356




5b126a927



3683a27d8
275eddbde
5b126a927





8ac5efc90
c41f44356

8ac5efc90
c41f44356

8ac5efc90
c41f44356

8ac5efc90
c41f44356

8ac5efc90
c41f44356
8bded202c
8ac5efc90
c41f44356
8bded202c
8ac5efc90
c41f44356

8ac5efc90




acb3d9b6c
275eddbde
e7b06c4b7
013ee07b5
5b126a927




e7b06c4b7






5b126a927



5b126a927



855bc81c0
5b126a927
8bded202c
acb3d9b6c

5b126a927
acb3d9b6c

1c390b10d
acb3d9b6c

8bded202c
acb3d9b6c



8ac5efc90
5b126a927
8ac5efc90
acb3d9b6c
5b126a927
acb3d9b6c
8ac5efc90
5b126a927
8ac5efc90


5b126a927
acb3d9b6c
8ac5efc90




5b126a927
acb3d9b6c
8ac5efc90




5b126a927
acb3d9b6c
8ac5efc90
acb3d9b6c
5b126a927
e7b06c4b7
8ac5efc90
5b126a927

acb3d9b6c


c042c10a3


acb3d9b6c
















e7b06c4b7
acb3d9b6c

5b126a927

8ac5efc90

c042c10a3
5d07e21aa
c042c10a3



5b126a927
8ac5efc90

a49047c93
8ac5efc90

acb3d9b6c
e7b06c4b7
8ac5efc90
5b126a927
39bb54dda







75c4eaf61
39bb54dda
75c4eaf61
a49047c93
39bb54dda

75c4eaf61
39bb54dda
75c4eaf61

a49047c93
75c4eaf61


39bb54dda
08f658b63







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
                                                                             
                                                                             
                                                                             













                                                                             
                                                                             

                                                                              
                   
                    



                    



                           
                              


                                                        
                                                     




                                                                            
                                                                                                              
  


                          
                          


                                                                            
                                                                                        

                                    


            
                   
  

                  
 
                                
                                                       
                                
 
                                                        
 
                                                                            

                       
 
                                                                            

                       

  
                                          
  

                        






                                
                                                                                       
  
                      
                        




                                                          



                                      
                              
                                       





                                                                                            
                             

                                                            
                               

                                                                          
                            

                                                                             
                         

                                                                     
                           
                                                                        
                      
                      
                                                               
                      
             

                                                         




                           
                                     
                                           
                                             
                 




                                






                                                                                   



                                                                  



                         
                                   
 
 

                                                                                      
 

                                                                                                              
                       

                  
 



                                                                                                             
      
 
                                 
                                                                                                                                
 
                                                                                                                         
                   
 


                                                          
 
                                                                              




                           
 
                                                                      




                           
 
                                
                       
                                
 
                           
                

  


                                


                                                                                      
















                                                                                     
                       

  

                                   

             
                                               
                                    



                                                                           
 

                                                     
                       

      
                                 
                        
            
  







                                
                                                         
  
                                                                     
                                     

  
                                             
  

                        
                                              


                                                       
  







                                                                                               
/***************************************************************************
 *   Copyright (C) 2009-2019 by Ilya Kotov                                 *
 *   forkotov02@ya.ru                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include <QObject>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

#include <qmmp/buffer.h>
#include <qmmp/visual.h>
#include "outputwaveout.h"

#define MAX_WAVEBLOCKS    256

static CRITICAL_SECTION  cs;
static HWAVEOUT          dev                    = NULL;
static unsigned int      ScheduledBlocks        = 0;
static int               PlayedWaveHeadersCount = 0;          // free index
static WAVEHDR*          PlayedWaveHeaders [MAX_WAVEBLOCKS];



static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
    Q_UNUSED(hWave);
    Q_UNUSED(dwInstance);
    Q_UNUSED(dwParam2);
    if (uMsg == WOM_DONE)
    {
        EnterCriticalSection (&cs);
        PlayedWaveHeaders [PlayedWaveHeadersCount++] = (WAVEHDR*) dwParam1;
        ScheduledBlocks--;                        // decrease the number of USED blocks
        LeaveCriticalSection (&cs);
    }
}

static void
free_memory (void)
{
    WAVEHDR*  wh;
    HGLOBAL   hg;

    EnterCriticalSection (&cs);
    wh = PlayedWaveHeaders [--PlayedWaveHeadersCount];
    LeaveCriticalSection (&cs);

    waveOutUnprepareHeader (dev, wh, sizeof (WAVEHDR));

    hg = GlobalHandle (wh -> lpData);       // Deallocate the buffer memory
    GlobalUnlock (hg);
    GlobalFree   (hg);

    hg = GlobalHandle (wh);                 // Deallocate the header memory
    GlobalUnlock (hg);
    GlobalFree   (hg);
}

OutputWaveOut::OutputWaveOut() : Output()
{
    m_totalWritten = 0;
    m_frameSize = 0;
}

OutputWaveOut::~OutputWaveOut()
{
    uninitialize();
}

bool OutputWaveOut::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format)
{
    Q_UNUSED(format);
    m_totalWritten = 0;
    if (!waveOutGetNumDevs ())
    {
        qWarning("OutputWaveOut: no audio device found");
        return false;
    }
    WAVEFORMATEX fmt;
    UINT deviceID = WAVE_MAPPER;

    fmt.wFormatTag = WAVE_FORMAT_PCM;
    fmt.wBitsPerSample  = 16;
    fmt.nChannels       = map.count();
    fmt.nSamplesPerSec  = (unsigned long)(freq);
    fmt.nBlockAlign     = fmt.nChannels * fmt.wBitsPerSample/8;
    fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nChannels * fmt.wBitsPerSample/8;

    switch (waveOutOpen (&dev, deviceID, &fmt, (DWORD)wave_callback, 0, CALLBACK_FUNCTION))
    {
    case MMSYSERR_ALLOCATED:
        qWarning("OutputWaveOut: Device is already open.");
        return false;
    case MMSYSERR_BADDEVICEID:
        qWarning("OutputWaveOut: The specified device is out of range.");
        return false;
    case MMSYSERR_NODRIVER:
        qWarning("OutputWaveOut: There is no audio driver in this system.");
        return false;
    case MMSYSERR_NOMEM:
        qWarning("OutputWaveOut: Unable to allocate sound memory.");
        return false;
    case WAVERR_BADFORMAT:
        qWarning("OutputWaveOut: This audio format is not supported.");
        return false;
    case WAVERR_SYNC:
        qWarning("OutputWaveOut: The device is synchronous.");
        return false;
    default:
        qWarning("OutputWaveOut: Unknown media error.");
        return false;
    case MMSYSERR_NOERROR:
        break;
    }

    waveOutReset (dev);
    InitializeCriticalSection (&cs);
    configure(freq, map, Qmmp::PCM_S16LE);
    m_frameSize = channels() * sampleSize();
    return true;
}


qint64 OutputWaveOut::latency()
{
    MMTIME mmtime;
    mmtime.wType = TIME_SAMPLES;

    if(waveOutGetPosition(dev, &mmtime, sizeof(MMTIME)) != MMSYSERR_NOERROR)
        return 0;

    return (m_totalWritten / m_frameSize - mmtime.u.sample) * 1000 / sampleRate();
}

qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len)
{
    HGLOBAL    hg;
    HGLOBAL    hg2;
    LPWAVEHDR  wh;
    void*      allocptr;
    len = qMin(len, (qint64)1024);


    while (PlayedWaveHeadersCount > 0)                        // free used blocks ...
        free_memory ();

    if (ScheduledBlocks >= sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders)) // wait for a free block ...
    {
        usleep(50000);
        return 0;
    }

    if ((hg2 = GlobalAlloc (GMEM_MOVEABLE, len)) == NULL)   // allocate some memory for a copy of the buffer
    {
        qWarning("OutputWaveOut: GlobalAlloc failed");
        return 0;
    }

    allocptr = GlobalLock (hg2);
    CopyMemory (allocptr, data, len);                         // Here we can call any modification output functions we want....

    if ((hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL) // now make a header and WRITE IT!
        return -1;

    wh                   = (wavehdr_tag*)GlobalLock (hg);
    wh->dwBufferLength   = len;
    wh->lpData           = (CHAR *)allocptr;

    if (waveOutPrepareHeader (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
    {
        GlobalUnlock (hg);
        GlobalFree   (hg);
        return -1;
    }

    if (waveOutWrite (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
    {
        GlobalUnlock (hg);
        GlobalFree   (hg);
        return -1;
    }

    EnterCriticalSection (&cs);
    ScheduledBlocks++;
    LeaveCriticalSection (&cs);

    m_totalWritten += len;
    return len;
}

void OutputWaveOut::drain()
{
    while (ScheduledBlocks > 0)
        Sleep(10);
    while (PlayedWaveHeadersCount > 0)                        // free used blocks ...
        free_memory();
}

void OutputWaveOut::suspend()
{
    waveOutPause(dev);
}

void OutputWaveOut::resume()
{
    waveOutRestart(dev);
}

void OutputWaveOut::reset()
{
   while (PlayedWaveHeadersCount > 0)                        // free used blocks ...
      free_memory ();
   waveOutReset (dev);
   m_totalWritten = 0;
}

void OutputWaveOut::uninitialize()
{
    if (dev)
    {
        waveOutReset(dev); // reset the device
        while (ScheduledBlocks > 0)
            Sleep (10);

        while (PlayedWaveHeadersCount > 0)         // free used blocks ...
            free_memory ();

        waveOutReset (dev);      // reset the device
        waveOutClose (dev);      // close the device
        dev = nullptr;
    }

    DeleteCriticalSection (&cs);
    m_totalWritten = 0;
    return;
}

/***** MIXER *****/
VolumeWaveOut::VolumeWaveOut()
{}

VolumeWaveOut::~VolumeWaveOut()
{}

void VolumeWaveOut::setVolume(const VolumeSettings &vol)
{
    DWORD data = (vol.right*0xFFFF/100 << 16) | vol.left*0xFFFF/100;
    waveOutSetVolume(nullptr, data);
}

VolumeSettings VolumeWaveOut::volume() const
{
    VolumeSettings vol;
    DWORD data;
    waveOutGetVolume(nullptr, (PDWORD)&data);
    vol.left = (long)LOWORD(data) * 100 / 0xFFFF + 1;
    vol.right = (long)HIWORD(data) * 100 / 0xFFFF + 1;
    return vol;
}