-
Notifications
You must be signed in to change notification settings - Fork 5
/
winsound.cc
783 lines (651 loc) · 19 KB
/
winsound.cc
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/* Synaesthesia - program to display sound graphically
Copyright (C) 1997 Paul Francis Harrison
Windows95/NT sound, CD-ROM and audio mixer routines,
(C) 1998 Nils Desle ([email protected])
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.,
675 Mass Ave, Cambridge, MA 02139, USA.
The author may be contacted at:
or
27 Bond St., Mt. Waverley, 3149, Melbourne, Australia
*/
#define WIN32_LEAN_AND_MEAN
#define __W32API_USE_DLLIMPORT__
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <mmsystem.h>
#include <winbase.h>
#include "syna.h"
/* Sound Recording ================================================= */
#if !defined(HAVE_PORTAUDIO) && !defined(HAVE_SDLAUDIO)
#define NUMBUFFERS 5
static SoundSource source;
static int inFrequency, downFactor, windowSize, pipeIn, device;
static unsigned short *dataIn;
static char* mixer;
HWAVEIN hwi;
HMIXER hmixer;
WAVEHDR buffer[NUMBUFFERS];
HANDLE blockReadySemaphore;
/* Queue of completed wave headers:
/* It should never overflow because of fixed number of buffers.
* It is larger by 1 so full and empty state can be differentiated.
*/
#define HDR_QUEUE_SIZE (NUMBUFFERS+1)
LPWAVEHDR waveHdrQueue[HDR_QUEUE_SIZE];
volatile unsigned int hdrQueueHead;
unsigned int hdrQueueTail;
/* This function is only allowed to call a few functions.
* See documentation for waveInProc.
*/
void CALLBACK SoundCallback(HWAVEIN lhwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
MMRESULT result;
if(uMsg == WIM_DATA)
{
waveHdrQueue[hdrQueueHead] = (LPWAVEHDR)dwParam1;
hdrQueueHead = (hdrQueueHead + 1) % HDR_QUEUE_SIZE;
ReleaseSemaphore(blockReadySemaphore,1,NULL);
}
}
void openSound(SoundSource source, int inFrequency, char *dspName,
char *mixerName)
{
::source = source;
::inFrequency = inFrequency;
::windowSize = 1;
mixer = mixerName;
WAVEFORMATEX format;
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = 2;
format.nSamplesPerSec = Frequency;
format.nAvgBytesPerSec = Frequency*4;
format.nBlockAlign = 4;
format.wBitsPerSample = 16;
format.cbSize = 0;
/* use this code later to find a given device!!
int numdevs = waveInGetNumDevs();
WAVEINCAPS wic;
int j=0;
for(j=0;j<numdevs;j++)
{
MMRESULT result = waveInGetDevCaps(j,&wic,sizeof(wic));
if(result != MMSYSERR_NOERROR)
{
error("querying device capabilities");
}
}
*/
// MMRESULT result = waveInOpen(&hwi, WAVE_MAPPER, &format, (DWORD_PTR) &SoundCallback, NULL, CALLBACK_FUNCTION);
MMRESULT result = waveInOpen(&hwi, 0, &format, (DWORD_PTR) &SoundCallback, NULL, CALLBACK_FUNCTION);
if(result != MMSYSERR_NOERROR)
{
if(result == MMSYSERR_ALLOCATED)
error("opening wave device for recording (device already in use)");
if(result == MMSYSERR_BADDEVICEID)
error("opening wave device for recording (bad device ID)");
if(result == MMSYSERR_NODRIVER)
error("opening wave device for recording (no driver)");
if(result == MMSYSERR_NOMEM)
error("opening wave device for recording (not enough memory)");
if(result == WAVERR_BADFORMAT)
error("opening wave device for recording (bad wave format)");
return;
}
int i;
for(i=0;i<NUMBUFFERS;i++)
{
unsigned short* tmpdata = new unsigned short[NumSamples*2];
memset(tmpdata,0,NumSamples*2*2);
buffer[i].lpData = (LPSTR) tmpdata;
buffer[i].dwBufferLength = NumSamples*2*2; // number of BYTES
buffer[i].dwFlags = 0;
}
for(i=0;i<NUMBUFFERS-1;i++)
{
result = waveInPrepareHeader(hwi,&(buffer[i]),sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR)
{
error("preparing buffer for recording");
return;
}
result = waveInAddBuffer(hwi,&(buffer[i]),sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR)
{
error("preparing buffer for recording");
return;
}
}
data = (sampleType*) buffer[0].lpData;
hdrQueueHead = 0;
hdrQueueTail = 0;
for(i=0;i<HDR_QUEUE_SIZE;i++) {
waveHdrQueue[i] = NULL;
}
blockReadySemaphore = CreateSemaphore(NULL,0,NUMBUFFERS,NULL);
if (!blockReadySemaphore)
error("Couldn't create semaphore");
result = waveInStart(hwi);
if(result != MMSYSERR_NOERROR)
{
error("Couldn't start recording");
}
}
void closeSound()
{
waveInReset(hwi);
waveInStop(hwi);
CloseHandle(blockReadySemaphore);
delete[] data;
}
int getNextFragment(void)
{
int result, i;
do {
WaitForSingleObject(blockReadySemaphore, INFINITE);
LPWAVEHDR lastWaveHdr = waveHdrQueue[hdrQueueTail];
hdrQueueTail = (hdrQueueTail + 1) % HDR_QUEUE_SIZE;
result = waveInUnprepareHeader(hwi,lastWaveHdr,sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR)
{
error("Couldn't unprepare buffer");
}
data = (sampleType*) (lastWaveHdr)->lpData;
lastWaveHdr->dwBufferLength = NumSamples*2*2;
lastWaveHdr->dwFlags = 0;
result = waveInPrepareHeader(hwi,lastWaveHdr,sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR)
{
error("Couldn't prepare buffer");
}
result = waveInAddBuffer(hwi,lastWaveHdr,sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR)
{
error("Couldn't add buffer");
}
} while (hdrQueueHead != hdrQueueTail);
return 0;
}
void setupMixer(double &loudness) {
#ifndef WIN32
int device = open(mixer,O_WRONLY);
if (device == -1)
warning("opening mixer device");
else {
if (source != SourcePipe) {
int blah = (source == SourceCD ? SOUND_MASK_CD : SOUND_MASK_LINE + SOUND_MASK_MIC);
attemptNoDie(ioctl(device,SOUND_MIXER_WRITE_RECSRC,&blah),"writing to mixer");
}
if (source == SourceCD) {
int volume;
attemptNoDie(ioctl(device,SOUND_MIXER_READ_CD,&volume),"writing to mixer");
loudness = ((volume&0xff) + volume/256) / 200.0;
} else if (source == SourceLine) {
int volume = 100*256 + 100;
attemptNoDie(ioctl(device,SOUND_MIXER_READ_LINE,&volume),"writing to mixer");
//attemptNoDie(ioctl(device,SOUND_MIXER_READ_MIC,&volume),"writing to mixer");
loudness = ((volume&0xff) + volume/256) / 200.0;
} else
loudness = 1.0;
close(device);
}
#endif
}
void setVolume(double loudness) {
//if (mixerOpen(&hmixer, 0, 0, 0, MIXER_OBJECTF_MIXER)
// != MMSYSERR_NOERROR) {
// warning("opening mixer");
// return;
//}
MIXERLINE ml;
ml.cbStruct = sizeof(ml);
ml.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
if (mixerGetLineInfo(0, &ml,
MIXER_OBJECTF_MIXER | MIXER_GETLINEINFOF_COMPONENTTYPE)
!= MMSYSERR_NOERROR)
error("setting volume (1)");
MIXERLINECONTROLS mlc;
MIXERCONTROL mc;
mlc.cbStruct = sizeof(mlc);
mlc.dwLineID = ml.dwLineID;
mlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mc.cbStruct = sizeof(mc);
mlc.cControls = 1;
mlc.cbmxctrl = sizeof(mc);
mlc.pamxctrl = &mc;
if (mixerGetLineControls(0, &mlc,
MIXER_OBJECTF_MIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE)
!= MMSYSERR_NOERROR)
error("setting volume (2)");
MIXERCONTROLDETAILS d;
d.cbStruct = sizeof(d);
d.dwControlID = mc.dwControlID;
d.cChannels = 1;
d.cMultipleItems = 0;
d.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
MIXERCONTROLDETAILS_UNSIGNED value;
value.dwValue = mc.Bounds.dwMinimum +
(DWORD)(loudness * (mc.Bounds.dwMaximum-mc.Bounds.dwMinimum));
d.paDetails = &value;
if (mixerSetControlDetails(0, &d, MIXER_OBJECTF_MIXER)
!= MMSYSERR_NOERROR)
error("setting volume (3)");
//mixerClose(hmixer);
#ifndef WIN32
int device = open(mixer,O_WRONLY);
if (device == -1)
warning("opening mixer device");
else {
int scaledLoudness = int(loudness * 100.0);
if (scaledLoudness < 0) scaledLoudness = 0;
if (scaledLoudness > 100) scaledLoudness = 100;
scaledLoudness = scaledLoudness*256 + scaledLoudness;
if (source == SourceCD) {
attemptNoDie(ioctl(device,SOUND_MIXER_WRITE_CD,&scaledLoudness),"writing to mixer");
} else if (source == SourceLine) {
attemptNoDie(ioctl(device,SOUND_MIXER_WRITE_LINE,&scaledLoudness),"writing to mixer");
attemptNoDie(ioctl(device,SOUND_MIXER_WRITE_MIC,&scaledLoudness),"writing to mixer");
} else {
attemptNoDie(ioctl(device,SOUND_MIXER_WRITE_PCM,&scaledLoudness),"writing to mixer");
}
close(device);
}
#endif
}
#endif /* !defined(HAVE_PORTAUDIO) && !defined(HAVE_SDLAUDIO) */
/* CDROM stuff ============================================== */
#ifdef HAVE_CD_PLAYER
#define CD_FRAMES 75 /* wild guess, but it seems to work...?? */
static int trackCount=0, *trackFrame = 0;
MCIDEVICEID cd_device;
bool bugfixed_pause = false; // for some weird reason, my CD player reports "Stopped" when in pause,
// so I keep my own status for this now.
void cdError(const char *str) {
//May want to print the message, but for now
delete trackFrame;
trackFrame = 0;
trackCount = 0;
}
int lastEndFrame=0;
int pausedPosition=0;
unsigned int WinMSFtoSynMSF(unsigned int WinMSF)
{
return ((MCI_MSF_MINUTE(WinMSF) * 60 * CD_FRAMES) +
(MCI_MSF_SECOND(WinMSF) * CD_FRAMES) +
MCI_MSF_FRAME(WinMSF));
}
unsigned int SynMSFtoWinMSF(unsigned int SynMSF)
{
return (SynMSF / (60*CD_FRAMES))
+ ((SynMSF / CD_FRAMES % 60) << 8)
+ ((SynMSF % CD_FRAMES) << 16);
}
void cdOpen(char* cdromName)
{
// tbd: get correct CDrom names in config screen, specify the correct one in
// cdromName, use that one in devicetype.
MCIERROR retval;
MCI_OPEN_PARMS openstruct;
bugfixed_pause = false;
openstruct.dwCallback = NULL;
openstruct.wDeviceID = NULL;
openstruct.lpstrDeviceType = (LPSTR) MCI_DEVTYPE_CD_AUDIO;
openstruct.lpstrElementName = NULL;
openstruct.lpstrAlias = NULL;
retval = mciSendCommand(cd_device,MCI_OPEN,MCI_WAIT|MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_OPEN_SHAREABLE,(DWORD_PTR)&openstruct);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdOpen) - Please make sure you have no other CD-players active!");
cdError(errorstr);
return;
}
cd_device = openstruct.wDeviceID;
MCI_SET_PARMS mciSetParms;
mciSetParms.dwTimeFormat = MCI_FORMAT_MSF;
retval = mciSendCommand(cd_device,MCI_SET,MCI_WAIT|MCI_SET_TIME_FORMAT,(DWORD_PTR)(LPVOID) &mciSetParms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdOpen)");
cdError(errorstr);
return;
}
}
void cdClose(void)
{
MCIERROR retval;
MCI_GENERIC_PARMS closestruct;
bugfixed_pause = false;
retval = mciSendCommand(cd_device,MCI_CLOSE,MCI_WAIT,(DWORD_PTR)&closestruct);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdClose)");
cdError(errorstr);
return;
}
delete[] trackFrame;
}
void getTrackInfo(void)
{
MCIERROR retval;
MCI_STATUS_PARMS parms;
delete trackFrame;
trackFrame = 0;
trackCount = 0;
parms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (getTrackInfo)");
cdError(errorstr);
return;
}
trackCount = parms.dwReturn;
int i;
trackFrame = new int[trackCount+1];
DWORD startpos;
DWORD length;
parms.dwItem = MCI_STATUS_POSITION;
parms.dwTrack = trackCount;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_TRACK|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (getTrackInfo)");
cdError(errorstr);
return;
}
startpos = WinMSFtoSynMSF(parms.dwReturn);
parms.dwItem = MCI_STATUS_LENGTH;
parms.dwTrack = trackCount;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_TRACK|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (getTrackInfo)");
cdError(errorstr);
return;
}
length = WinMSFtoSynMSF(parms.dwReturn);
trackFrame[trackCount] = startpos+length-1;
for(i=trackCount-1;i>=0;i--)
{
// determine if track is a data or audio track
parms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
parms.dwTrack = i+1;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM|MCI_TRACK,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (getTrackInfo)");
cdError(errorstr);
return;
}
DWORD tracktype = parms.dwReturn;
if(tracktype != MCI_CDA_TRACK_AUDIO)
{
trackFrame[i] = trackFrame[i+1];
}
else
{
// get start position
parms.dwItem = MCI_STATUS_POSITION;
parms.dwTrack = i+1;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_TRACK|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (getTrackInfo)");
cdError(errorstr);
return;
}
startpos = WinMSFtoSynMSF(parms.dwReturn);
trackFrame[i] = startpos;
}
}
}
int cdGetTrackCount(void)
{
return trackCount;
}
int cdGetTrackFrame(int track)
{
if (!trackFrame)
return 0;
else if (track <= 1 || track > trackCount+1)
return trackFrame[0];
else
return trackFrame[track-1];
}
void cdPlay(int frame, int endFrame)
{
MCIERROR retval;
MCI_PLAY_PARMS parms;
bugfixed_pause = false;
if (frame < 1) frame = 1;
if (endFrame < 1)
if (trackCount > 0)
endFrame = trackFrame[trackCount];
else
endFrame = 1;
lastEndFrame = endFrame;
cdStop();
parms.dwCallback = NULL;
parms.dwFrom = SynMSFtoWinMSF(frame);
parms.dwTo = SynMSFtoWinMSF(endFrame);
retval = mciSendCommand(cd_device,MCI_PLAY,MCI_NOTIFY|MCI_FROM|MCI_TO,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdPlay)");
cdError(errorstr);
return;
}
}
void cdGetStatus(int &track, int &frames, SymbolID &state)
{
MCI_STATUS_PARMS parms;
MCIERROR retval;
parms.dwItem = MCI_STATUS_MODE;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdGetStatus)");
state = NoCD; track = 1; frames = 0;
cdError(errorstr);
return;
}
DWORD cdstate = parms.dwReturn;
SymbolID oldState = state;
switch(cdstate)
{
case MCI_MODE_PAUSE:
state = Pause;
break;
case MCI_MODE_PLAY:
state = Play;
break;
case MCI_MODE_STOP:
if(bugfixed_pause == true)
{
state = Pause;
}
else
{
state = Stop;
}
break;
case MCI_MODE_OPEN:
state = Open;
return;
break;
case MCI_MODE_NOT_READY:
case MCI_MODE_RECORD:
case MCI_MODE_SEEK:
default:
state = NoCD;
return;
break;
}
parms.dwItem = MCI_STATUS_CURRENT_TRACK;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdGetStatus)");
state = NoCD; track = 1; frames = 0;
cdError(errorstr);
return;
}
track = parms.dwReturn;
parms.dwItem = MCI_STATUS_POSITION;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdGetStatus)");
state = NoCD; track = 1; frames = 0;
cdError(errorstr);
return;
}
frames = WinMSFtoSynMSF(parms.dwReturn);
if(trackFrame)
frames-=trackFrame[track-1]; // track relative frames!!!
if ((oldState == NoCD || oldState == Open) &&
(state == Pause || state == Play || state == Stop))
{
getTrackInfo();
}
if (state != Play && state != Pause)
{
track = 1;
frames = 0;
}
}
void cdStop(void)
{
MCI_GENERIC_PARMS parms;
bugfixed_pause = false;
MCIERROR retval = mciSendCommand(cd_device,MCI_STOP,MCI_WAIT,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdStop)");
cdError(errorstr);
return;
}
}
void cdPause()
{
/* turns out Windows standard CD-Rom drivers (MCICDA device) don't actually support pause
and resume. Sigh. I'll just fake a pause by doing a stop and remembering the current
position.
MCI_GENERIC_PARMS parms;
MCIERROR retval = mciSendCommand(cd_device,MCI_PAUSE,MCI_WAIT,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdPause)");
cdError(errorstr);
return;
}
*/
MCI_STATUS_PARMS parms;
MCIERROR retval;
parms.dwItem = MCI_STATUS_POSITION;
retval = mciSendCommand(cd_device,MCI_STATUS,MCI_WAIT|MCI_STATUS_ITEM,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdPause)");
cdError(errorstr);
return;
}
pausedPosition = WinMSFtoSynMSF(parms.dwReturn);
cdStop();
bugfixed_pause = true;
}
void cdResume()
{
/* resume and pause are not supported by the standard MCICDA devices in Windows.
MCI_GENERIC_PARMS parms;
MCIERROR retval = mciSendCommand(cd_device,MCI_RESUME,MCI_WAIT,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdResume)");
cdError(errorstr);
return;
}
*/
if(bugfixed_pause)
{
cdPlay(pausedPosition,lastEndFrame);
bugfixed_pause = false;
}
else
{
cdError("trying to resume a non-paused state???");
return;
}
}
void cdEject()
{
MCI_SET_PARMS parms;
MCIERROR retval = mciSendCommand(cd_device,MCI_SET,MCI_WAIT|MCI_SET_DOOR_OPEN,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdEject)");
cdError(errorstr);
return;
}
bugfixed_pause = false;
}
void cdCloseTray()
{
MCI_SET_PARMS parms;
MCIERROR retval = mciSendCommand(cd_device,MCI_SET,MCI_WAIT|MCI_SET_DOOR_CLOSED,(DWORD_PTR)&parms);
if(retval)
{
char errorstr[256];
mciGetErrorString(retval,errorstr,256);
strcat(errorstr," (cdCloseTray)");
cdError(errorstr);
return;
}
bugfixed_pause = false;
}
#endif /* HAVE_CD_PLAYER */