convert line ends
[canaan.git] / prj / tech / libsrc / sndutil / strmmain.c
bloba426b6459e7ff98689225c95e522c7e1787f17c3
1 //
2 // sample C code using sound utilities & LG sound library
3 // Pat McElhatton August 26 '96
4 //
6 #include <windows.h>
7 #include <lg.h>
8 #include <res.h>
9 #include <mprintf.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <lgsound.h>
13 #include <wappapi.h>
14 #include <appapi.h>
15 #include <appagg.h>
16 #include <utilmain.h>
17 #include <timelog.h>
19 #include <sndutil.h>
20 #include <utilmain.h>
22 static BOOL donePlaying = FALSE;
24 static void
25 endItAll( ISndSample *pSample,
26 void *pCBData )
28 donePlaying = TRUE;
30 ISndSample_Release( pSample );
34 LRESULT FAR PASCAL WndProc (HWND hWnd, UINT iMessage, WPARAM wParam,
35 LPARAM lParam)
37 switch (iMessage)
39 case WM_COMMAND: // process menu items
40 break ;
41 case WM_DESTROY:
42 PostQuitMessage (0) ;
43 break ;
44 default: // default windows message processing
45 return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
47 return (0L) ;
51 #define APPNAME "stream"
53 int LGAPI
54 AppMain( int argc,
55 const char **argv )
57 ISndMixer *pMixer;
58 int nTimer;
59 HWND hWnd ; // a handle to a message
60 MSG msg ; // a message
61 WNDCLASS wndclass ; // the window class
62 IWinApp *pWinApp;
63 HINSTANCE hInstance;
64 uchar *pBuffer;
65 ISndSample *pSample;
66 int32 startOff;
68 if ( argc < 2 ) {
69 mprintf("%s\n%s\n",
70 "USAGE: stream <fname1> play a file in stream mode",
71 " if fname does not have an extension, .wav extension is added.");
72 exit( 1 );
75 TIMELOG_INIT( 8192 );
76 hInstance = GetModuleHandle( NULL );
78 // load data into window class struct.
79 wndclass.style = CS_HREDRAW | CS_VREDRAW ;
80 wndclass.lpfnWndProc = WndProc ;
81 wndclass.cbClsExtra = 0 ;
82 wndclass.cbWndExtra = 0 ;
83 wndclass.hInstance = hInstance ;
84 wndclass.hIcon = LoadIcon (hInstance, APPNAME) ;
85 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
86 wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
87 wndclass.lpszMenuName = APPNAME;
88 wndclass.lpszClassName = APPNAME;
90 // register the window class
91 if (!RegisterClass (&wndclass)) {
92 return FALSE ;
95 hWnd = CreateWindow ( // create the program's window here
96 APPNAME, // class name
97 APPNAME, // window name
98 WS_OVERLAPPEDWINDOW, // window style
99 CW_USEDEFAULT, // x position on screen
100 CW_USEDEFAULT, // y position on screen
101 50, // width of window
102 50, // height of window
103 NULL, // parent window handle (null = none)
104 NULL, // menu handle (null = class menu)
105 hInstance, // instance handle
106 NULL) ; // lpstr (null = not used)
108 pWinApp = AppGetObj( IWinApp );
109 IWinApp_SetMainWnd( pWinApp, hWnd );
110 SafeRelease( pWinApp );
112 ShowWindow (hWnd, SW_SHOW) ;
113 UpdateWindow (hWnd) ; // send first WM_PAINT message
115 pMixer = SoundInit();
117 //SoundPlayFile( argv[1], pMixer, 127, 64 );
118 pBuffer = NULL;
119 pSample = CreateSoundFileStreamer( pMixer, argv[1], pBuffer, 65536, endItAll, NULL );
120 if ( argc > 2 ) {
121 startOff = atoi( argv[2] );
122 ISndSample_SetPosition( pSample, startOff );
124 ISndSample_Play( pSample );
126 nTimer = SetTimer( hWnd, 1, 60, NULL ); // send timer events every 60 milliseconds
127 while (GetMessage (&msg, NULL, 0, 0)) { // the message loop
128 //mprintf( "message loop\n" );
129 TranslateMessage( &msg ) ;
130 SoundRecur( pMixer );
131 DispatchMessage( &msg ) ;
132 if ( donePlaying ) {
133 KillTimer( hWnd, nTimer );
134 break;
137 TIMELOG_DUMP( "sndlog.txt" );
138 return msg.wParam ;
142 tResult LGAPI AppCreateObjects(int argc, const char * argv[])
144 GenericApplicationCreate( argc, argv, "streamer", NULL );
146 return NOERROR;