1 | /*
|
---|
2 | * (C) Chris Wohlgemuth 2002-2003
|
---|
3 | *
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | * any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; see the file COPYING. If not, write to
|
---|
18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 | /*
|
---|
21 | * If you need another license for your project/product (commercial,
|
---|
22 | * noncommercial, whatever) contact me at
|
---|
23 | *
|
---|
24 | * http://www.os2world.com/cdwriting
|
---|
25 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
26 | *
|
---|
27 | */
|
---|
28 |
|
---|
29 | #define INCL_DOS
|
---|
30 | #define INCL_DOSERRORS
|
---|
31 | #define INCL_DOSQUEUES /* Queue values */
|
---|
32 | #define INCL_OS2MM
|
---|
33 | #define INCL_MMIOOS2
|
---|
34 |
|
---|
35 | #include <os2.h>
|
---|
36 | #include <os2me.h>
|
---|
37 | #include <sys/types.h>
|
---|
38 | #include <sys/wait.h>
|
---|
39 | #include <process.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <string.h>
|
---|
42 | #include <stdlib.h>
|
---|
43 |
|
---|
44 |
|
---|
45 | char buffer[500000]={0};
|
---|
46 |
|
---|
47 | int main(int argc, char * argv[])
|
---|
48 | {
|
---|
49 | HMMIO hmmio, hmmioTarget;
|
---|
50 | MMIOINFO mmioinfo;
|
---|
51 | MMAUDIOHEADER mmAudioHeader,mmAudioHeaderTarget;
|
---|
52 | LONG lBytesRead=0;
|
---|
53 | LONG lBytesWritten=0;
|
---|
54 | char * tracks;
|
---|
55 | ULONG rc;
|
---|
56 | char target[CCHMAXPATH]="r:\\out.wav";
|
---|
57 |
|
---|
58 | /* Set stdout to binary */
|
---|
59 | _fsetmode(stdout,"b");
|
---|
60 | fflush(stdout);
|
---|
61 |
|
---|
62 | if(argc==1)
|
---|
63 | exit(0);
|
---|
64 |
|
---|
65 | tracks=argv[1];
|
---|
66 |
|
---|
67 | memset(&mmioinfo,0, sizeof(mmioinfo));
|
---|
68 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
69 | mmioinfo.ulFlags=MMIO_READ|MMIO_DENYNONE;
|
---|
70 | /* open source */
|
---|
71 | if((hmmio=mmioOpen(argv[1], &mmioinfo,MMIO_READ))==NULLHANDLE)
|
---|
72 | {
|
---|
73 | fprintf(stderr,"mmioOpen error with file %s\n", tracks[0]);
|
---|
74 | fprintf(stderr,"DONE");
|
---|
75 | exit(1);
|
---|
76 | }
|
---|
77 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
---|
78 | rc = mmioGetHeader(hmmio, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
79 | &lBytesRead, 0, 0);
|
---|
80 | if(rc!=MMIO_SUCCESS) {
|
---|
81 | mmioClose(hmmio, 0);
|
---|
82 | fprintf(stderr,"mmioGetHeader error!\n");
|
---|
83 | exit(1);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* open target */
|
---|
87 | memset(&mmioinfo,0, sizeof(mmioinfo));
|
---|
88 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
89 | //mmioinfo.aulInfo[3] = MMIO_MEDIATYPE_AUDIO;
|
---|
90 | mmioinfo.ulFlags=MMIO_WRITE|MMIO_CREATE;
|
---|
91 | mmioinfo.fccIOProc=mmioStringToFOURCC("WAVE", MMIO_TOUPPER);
|
---|
92 | if((hmmioTarget=mmioOpen(target, &mmioinfo, MMIO_WRITE|MMIO_CREATE))==NULLHANDLE)
|
---|
93 | {
|
---|
94 | char chrError[CCHMAXPATH];
|
---|
95 | rc=mmioGetLastError(hmmioTarget);
|
---|
96 | mciGetErrorString(mmioinfo.ulErrorRet ,chrError, sizeof(chrError));
|
---|
97 | fprintf(stderr,"mmioOpen error with file %s:\n%s\n%d", target, chrError,mmioinfo.ulErrorRet);
|
---|
98 | mmioClose(hmmio,0);
|
---|
99 | exit(1);
|
---|
100 | }
|
---|
101 | #if 0
|
---|
102 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
---|
103 | rc = mmioGetHeader(hmmioTarget, &mmAudioHeaderTarget,sizeof(MMAUDIOHEADER),
|
---|
104 | &lBytesRead, 0, 0);
|
---|
105 | #endif
|
---|
106 | /* Set parameters */
|
---|
107 | rc = mmioSetHeader(hmmioTarget, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
108 | &lBytesWritten, 0, 0);
|
---|
109 |
|
---|
110 | /* convert */
|
---|
111 | lBytesWritten=0;
|
---|
112 | do{
|
---|
113 | rc=mmioRead(hmmio, buffer, sizeof(buffer));
|
---|
114 | if(rc!=0 && rc!=MMIO_ERROR) {
|
---|
115 | mmioWrite(hmmioTarget, buffer, rc);
|
---|
116 | // fwrite(buffer, sizeof(char), rc, stdout);
|
---|
117 | lBytesWritten+=rc;
|
---|
118 | }
|
---|
119 | }while(rc!=0 && rc!=MMIO_ERROR /*&& lBytesWritten <1000000*/);
|
---|
120 | if(rc==MMIO_ERROR) {
|
---|
121 | fprintf(stderr,"Error while reading audio data!\n");
|
---|
122 | fprintf(stderr,"DONE");
|
---|
123 | }
|
---|
124 |
|
---|
125 | /* close source */
|
---|
126 | mmioClose(hmmio,0);
|
---|
127 | /* close target */
|
---|
128 | mmioClose(hmmioTarget,0);
|
---|
129 | exit(0);
|
---|
130 | }
|
---|
131 |
|
---|