9d17dc117adfd074458f33235c1c2bbca96a78b7
[reactos.git] / reactos / base / applications / sndrec32 / sndrec32.cpp
1 /*
2 * PROJECT: ReactOS Sound Record Application
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/sndrec32/sndrec32.cpp
5 * PURPOSE: Application Startup
6 * PROGRAMMERS: Marco Pagliaricci <ms_blue (at) hotmail (dot) it>
7 */
8
9 #include "stdafx.h"
10 #include "sndrec32.h"
11
12
13
14
15 //#pragma comment(lib, "comctl32.lib")
16
17
18 HINSTANCE hInst;
19 TCHAR szTitle[MAX_LOADSTRING];
20 TCHAR szWindowClass[MAX_LOADSTRING];
21
22
23 ATOM MyRegisterClass(HINSTANCE hInstance);
24 BOOL InitInstance(HINSTANCE, int);
25 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
26 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
27
28
29
30 HWND main_win;
31 HWND slider;
32 HWND buttons[5];
33 HBITMAP butbmps[5];
34 HBITMAP butbmps_dis[5];
35 WNDPROC buttons_std_proc;
36
37 BOOL butdisabled[5];
38 BOOL stopped_flag;
39 BOOL isnew;
40
41
42 DWORD slider_pos;
43 WORD slider_min;
44 WORD slider_max;
45
46 DWORD samples_max;
47
48 OPENFILENAME ofn;
49 TCHAR file_path[MAX_PATH];
50 BOOL path_set;
51
52 snd::audio_membuffer * AUD_BUF;
53 snd::audio_waveout * AUD_OUT;
54 snd::audio_wavein * AUD_IN;
55
56
57 BOOL s_recording;
58
59
60
61 int APIENTRY _tWinMain(HINSTANCE hInstance,
62 HINSTANCE hPrevInstance,
63 LPTSTR lpCmdLine,
64 int nCmdShow)
65 {
66
67 UNREFERENCED_PARAMETER(hPrevInstance);
68 UNREFERENCED_PARAMETER(lpCmdLine);
69
70
71 MSG msg;
72 HACCEL hAccelTable;
73
74 InitCommonControls();
75
76
77 butbmps[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START ));
78 butbmps[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END ));
79 butbmps[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY ));
80 butbmps[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP ));
81 butbmps[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC ));
82
83 butbmps_dis[0] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS ));
84 butbmps_dis[1] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS ));
85 butbmps_dis[2] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS ));
86 butbmps_dis[3] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS ));
87 butbmps_dis[4] = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS ));
88
89
90 snd::audio_membuffer AUD_buffer( snd::A44100_16BIT_STEREO );
91 snd::audio_waveout AUD_waveout( snd::A44100_16BIT_STEREO, AUD_buffer );
92 snd::audio_wavein AUD_wavein( snd::A44100_16BIT_STEREO, AUD_buffer );
93
94 AUD_buffer.play_finished = l_play_finished;
95 AUD_buffer.audio_arrival = l_audio_arrival;
96 AUD_buffer.buffer_resized = l_buffer_resized;
97
98 AUD_buffer.alloc_seconds( INITIAL_BUFREC_SECONDS );
99
100 AUD_IN = &AUD_wavein;
101 AUD_OUT = &AUD_waveout;
102 AUD_BUF = &AUD_buffer;
103
104
105
106 slider_pos = 0;
107 slider_min = 0;
108 slider_max = 32767;
109
110
111 stopped_flag = FALSE;
112 path_set = FALSE;
113 isnew = TRUE;
114
115
116 samples_max = AUD_buffer.total_samples();
117
118
119 LoadString(hInstance,
120 IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
121
122
123
124 LoadString(hInstance,
125 IDC_REACTOS_SNDREC32, szWindowClass, MAX_LOADSTRING);
126
127
128
129 MyRegisterClass(hInstance);
130
131
132 if (!InitInstance (hInstance, nCmdShow))
133 {
134 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
135 return FALSE;
136 }
137
138 hAccelTable = LoadAccelerators(hInstance,
139 MAKEINTRESOURCE( IDC_REACTOS_SNDREC32 ));
140
141
142
143
144
145
146 s_recording = false;
147
148
149
150
151 AUD_wavein.open();
152 AUD_waveout.open();
153
154
155
156
157
158
159 while (GetMessage(&msg, NULL, 0, 0))
160 {
161 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
162 {
163 TranslateMessage(&msg);
164 DispatchMessage(&msg);
165 }
166 }
167
168 AUD_waveout.close();
169 AUD_wavein.close();
170
171 AUD_buffer.clear();
172
173
174 return (int) msg.wParam;
175 }
176
177
178
179
180 ATOM MyRegisterClass(HINSTANCE hInstance)
181 {
182 WNDCLASSEX wcex;
183
184 wcex.cbSize = sizeof(WNDCLASSEX);
185
186 wcex.style = CS_HREDRAW | CS_VREDRAW;
187 wcex.lpfnWndProc = WndProc;
188 wcex.cbClsExtra = 0;
189 wcex.cbWndExtra = 0;
190 wcex.hInstance = hInstance;
191 wcex.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
192 wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
193 wcex.hbrBackground = (HBRUSH)( 16 );
194 wcex.lpszMenuName = MAKEINTRESOURCE( IDR_MENU1 );
195 wcex.lpszClassName = szWindowClass;
196 wcex.hIconSm = LoadIcon( wcex.hInstance, MAKEINTRESOURCE( IDI_SNDREC32 ));
197
198
199 return RegisterClassEx( &wcex );
200 }
201
202 BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
203 {
204 HWND hWnd;
205
206 hInst = hInstance;
207
208 hWnd = CreateWindow(
209 szWindowClass,
210 szTitle,
211 WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
212 CW_USEDEFAULT,
213 CW_USEDEFAULT,
214 MAINWINDOW_W,
215 MAINWINDOW_H,
216 NULL, NULL,
217 hInstance, NULL
218 );
219
220 if (!hWnd)
221 {
222 return FALSE;
223 }
224
225 ShowWindow(hWnd, nCmdShow);
226 UpdateWindow(hWnd);
227
228 main_win = hWnd;
229
230
231 return TRUE;
232 }
233
234
235 //
236 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
237 {
238 int wmId, wmEvent;
239 RECT rect;
240 PAINTSTRUCT ps;
241 HDC hdc;
242
243
244 //
245 // Checking for global pointers to buffer and
246 // io audio devices.
247 //
248
249 if (( !AUD_IN ) || ( !AUD_OUT ) || ( !AUD_BUF ))
250 {
251 MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
252 return 1;
253 }
254
255
256 switch (message)
257 {
258
259
260 case WM_CREATE:
261
262
263
264 //
265 // Creating ALL the buttons
266 //
267
268 for ( int i = 0; i < 5; ++ i )
269 {
270
271 buttons[i] = CreateWindow(
272 TEXT("button"),
273 TEXT(""),
274 WS_CHILD|WS_VISIBLE|BS_BITMAP,
275 BUTTONS_CX + ( i * (BUTTONS_W+((i == 0)?0:BUTTONS_SPACE))),
276 BUTTONS_CY, BUTTONS_W, BUTTONS_H, hWnd,
277 (HMENU)i, hInst, 0
278 );
279
280 if ( !buttons[i] )
281 {
282 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
283 return FALSE;
284
285 }
286
287
288 //
289 // Realize the button bmp image
290 //
291
292 SendMessage(buttons[i], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[i]);
293
294 UpdateWindow( buttons[i] );
295
296 disable_but( i );
297
298 }
299
300
301 //
302 // Creating the SLIDER window
303 //
304
305 slider = CreateWindow(
306 TRACKBAR_CLASS,
307 TEXT(""),
308 WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ|TBS_ENABLESELRANGE,
309 SLIDER_CX, SLIDER_CY, SLIDER_W, SLIDER_H, hWnd,
310 (HMENU)SLIDER_ID, hInst, 0
311 );
312
313
314 if ( !slider )
315 {
316 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
317 return FALSE;
318
319 }
320
321
322 //
323 // Sets slider limits
324 //
325
326
327 SendMessage(
328 slider,
329 TBM_SETRANGE,
330 (WPARAM)TRUE,
331 (LPARAM)MAKELONG(slider_min,slider_max)
332 );
333
334
335 UpdateWindow( slider );
336
337 enable_but( BUTREC_ID );
338
339 EnableWindow( slider, FALSE );
340
341
342
343
344 break;
345
346
347
348 //
349 // Implements slider logic
350 //
351
352 case WM_HSCROLL :
353 {
354 switch( LOWORD( wParam ))
355 {
356
357 case SB_ENDSCROLL:
358 break;
359
360 case SB_PAGERIGHT:
361 case SB_PAGELEFT:
362 case TB_THUMBTRACK:
363
364
365 //
366 // If the user touch the slider bar,
367 // set the audio start position properly
368 //
369
370
371 slider_pos = SendMessage( slider, TBM_GETPOS, 0, 0 );
372
373
374 AUD_BUF->set_position(
375 AUD_BUF->audinfo().bytes_in_samples(
376 (( slider_pos * samples_max ) / slider_max )
377 )
378 );
379
380
381 break;
382
383 }
384
385 break;
386 }
387
388
389
390
391
392
393 case WM_COMMAND:
394
395 wmId = LOWORD( wParam );
396 wmEvent = HIWORD( wParam );
397
398 if (( wmId >= 0 ) && ( wmId < 5 ) && ( butdisabled[wmId] == TRUE ))
399 break;
400
401 switch (wmId)
402 {
403
404 case ID_NEW:
405
406 if ( !isnew )
407 {
408
409 if ( AUD_IN->current_status() == snd::WAVEIN_RECORDING )
410 AUD_IN->stop_recording();
411
412
413 if (( AUD_OUT->current_status() == snd::WAVEOUT_PLAYING ) ||
414 ( AUD_OUT->current_status() == snd::WAVEOUT_PAUSED ))
415 AUD_OUT->stop();
416
417
418 AUD_BUF->reset();
419
420 enable_but( BUTREC_ID );
421 disable_but( BUTSTART_ID );
422 disable_but( BUTEND_ID );
423 disable_but( BUTSTOP_ID );
424 disable_but( BUTPLAY_ID );
425
426
427 samples_max = AUD_BUF->total_samples();
428 slider_pos = 0;
429
430 SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
431
432 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_GRAYED );
433 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_GRAYED );
434
435 isnew = TRUE;
436
437 ZeroMemory( file_path, MAX_PATH );
438
439 EnableWindow( slider, FALSE );
440
441 }
442
443
444
445 break;
446
447
448
449
450 case ID_FILE_OPEN:
451
452 ZeroMemory( &ofn, sizeof( ofn ));
453
454 ofn.lStructSize = sizeof( ofn );
455 ofn.hwndOwner = hWnd;
456 ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
457 ofn.lpstrFile = file_path;
458 ofn.nMaxFile = MAX_PATH;
459 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
460 ofn.lpstrDefExt = TEXT("wav");
461
462 if( GetOpenFileName( &ofn ))
463 {
464 open_wav( file_path );
465 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
466 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
467
468 EnableWindow( slider, TRUE );
469
470 }
471
472 break;
473
474
475
476
477 case ID__ABOUT:
478
479
480
481 break;
482
483
484 case ID_FILE_SAVEAS:
485
486 ZeroMemory( &ofn, sizeof( ofn ));
487
488 ofn.lStructSize = sizeof( ofn );
489 ofn.hwndOwner = hWnd ;
490 ofn.Flags = OFN_OVERWRITEPROMPT;
491 ofn.lpstrFilter = TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
492 ofn.lpstrFile = file_path;
493 ofn.nMaxFile = MAX_PATH;
494
495 ofn.lpstrDefExt = TEXT("wav");
496
497 if ( GetSaveFileName ( &ofn ))
498 {
499 write_wav( file_path );
500
501 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVE, MF_ENABLED );
502 }
503
504 break;
505
506 case ID_EXIT:
507 DestroyWindow( hWnd );
508 break;
509
510
511 //
512 // Sndrec32 buttons routines
513 //
514
515 case BUTSTART_ID:
516
517 AUD_BUF->set_position_start();
518
519 slider_pos = 0;
520
521 SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
522
523 break;
524
525
526 case BUTEND_ID:
527 //Beep(300,200);
528 break;
529
530 case BUTPLAY_ID:
531
532 AUD_OUT->play();
533
534 disable_but( BUTSTART_ID );
535 disable_but( BUTEND_ID );
536 disable_but( BUTREC_ID );
537 disable_but( BUTPLAY_ID );
538
539
540 SetTimer( hWnd, 1, 250, 0 );
541
542 break;
543
544 case BUTSTOP_ID:
545 if ( s_recording )
546 {
547 s_recording = FALSE;
548
549 AUD_IN->stop_recording();
550
551
552
553 //
554 // Resetting slider position
555 //
556
557 slider_pos = 0;
558 SendMessage(slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos);
559
560
561 samples_max = AUD_BUF->samples_received();
562
563 EnableMenuItem((HMENU)IDR_MENU1, ID_FILE_SAVEAS, MF_ENABLED );
564
565
566 enable_but( BUTSTART_ID );
567 enable_but( BUTEND_ID );
568 enable_but( BUTREC_ID );
569 enable_but( BUTPLAY_ID );
570
571 EnableMenuItem( GetMenu( hWnd ), ID_FILE_SAVEAS, MF_ENABLED );
572 EnableWindow( slider, TRUE );
573
574
575
576 } else {
577
578 AUD_OUT->pause();
579
580 enable_but( BUTSTART_ID );
581 enable_but( BUTEND_ID );
582 enable_but( BUTREC_ID );
583 enable_but( BUTPLAY_ID );
584
585 }
586
587 KillTimer( hWnd, 1 );
588
589 break;
590
591 case BUTREC_ID:
592
593 s_recording = TRUE;
594
595 samples_max = AUD_BUF->total_samples();
596
597 AUD_IN->start_recording();
598
599 enable_but( BUTSTOP_ID );
600
601 disable_but( BUTSTART_ID );
602 disable_but( BUTEND_ID );
603 disable_but( BUTREC_ID );
604 disable_but( BUTPLAY_ID );
605
606 isnew = FALSE;
607
608 EnableWindow( slider, FALSE );
609
610 SetTimer( hWnd, 1, 150, 0 );
611
612 break;
613
614
615 default:
616 return DefWindowProc(hWnd, message, wParam, lParam);
617 }
618 break;
619
620
621 case WM_TIMER:
622
623 if ( stopped_flag )
624 {
625 KillTimer(hWnd, 1);
626 slider_pos = 0;
627
628 enable_but( BUTPLAY_ID );
629
630 stopped_flag = FALSE;
631 }
632
633 SendMessage( slider, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) slider_pos );
634
635
636
637 break;
638
639
640
641 case WM_PAINT:
642
643 InvalidateRect( hWnd, &rect, TRUE );
644 hdc = BeginPaint(hWnd, &ps);
645
646 EndPaint(hWnd, &ps);
647 break;
648 case WM_DESTROY:
649 PostQuitMessage(0);
650 break;
651 default:
652 return DefWindowProc(hWnd, message, wParam, lParam);
653 }
654 return 0;
655 }
656
657
658
659
660
661 void l_play_finished ( void )
662 {
663
664 stopped_flag = true;
665
666
667 enable_but( BUTSTART_ID );
668 enable_but( BUTEND_ID );
669 enable_but( BUTREC_ID );
670 enable_but( BUTPLAY_ID );
671
672
673
674 }
675
676 void l_audio_arrival ( unsigned int samples_arrival )
677 {
678
679
680 slider_pos += (DWORD) (( slider_max * samples_arrival ) / samples_max );
681
682
683 }
684
685 void l_buffer_resized ( unsigned int new_size )
686 {
687
688
689
690
691
692 }
693
694 VOID enable_but( DWORD id )
695 {
696
697 butdisabled[ id ] = FALSE;
698
699 SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps[ id ]);
700
701
702 }
703 VOID disable_but( DWORD id )
704 {
705
706 butdisabled[ id ] = TRUE;
707
708 SendMessage(buttons[ id ], BM_SETIMAGE, ( WPARAM )IMAGE_BITMAP, ( LPARAM )butbmps_dis[ id ]);
709
710 }
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727 BOOL open_wav( TCHAR * f )
728 {
729
730
731 HANDLE file;
732
733 riff_hdr r;
734 wave_hdr w;
735 data_chunk d;
736
737 BOOL b;
738
739 DWORD bytes_recorded_in_wav = 0;
740 DWORD is_read = 0;
741
742
743 file = CreateFile(
744 f,
745 GENERIC_READ,
746 0, 0,
747 OPEN_EXISTING,
748 FILE_ATTRIBUTE_NORMAL,
749 0
750 );
751
752
753
754 if ( !file )
755 {
756 MessageBox(
757 main_win,
758 TEXT("Cannot open file. CreateFile() error."),
759 TEXT("ERROR"),
760 MB_OK|MB_ICONERROR
761 );
762
763 return FALSE;
764 }
765
766
767 b = ReadFile( file, ( LPVOID ) &r, sizeof ( r ), &is_read, 0 );
768
769 if ( !b )
770 {
771 MessageBox(
772 main_win,
773 TEXT("Cannot read RIFF header."),
774 TEXT("ERROR"),
775 MB_OK|MB_ICONERROR
776 );
777
778 CloseHandle( file );
779 return FALSE;
780 }
781
782
783 b = ReadFile( file, ( LPVOID ) &w, sizeof ( w ), &is_read, 0 );
784
785
786 if ( !b )
787 {
788 MessageBox(
789 main_win,
790 TEXT("Cannot read WAVE header."),
791 TEXT("ERROR"),
792 MB_OK|MB_ICONERROR
793 );
794
795 CloseHandle( file );
796 return FALSE;
797 }
798
799
800
801 b = ReadFile( file, ( LPVOID ) &d, sizeof ( d ), &is_read, 0 );
802
803 if ( !b )
804 {
805 MessageBox(
806 main_win,
807 TEXT("Cannot read WAVE subchunk."),
808 TEXT("ERROR"),
809 MB_OK|MB_ICONERROR
810 );
811
812 CloseHandle( file );
813 return FALSE;
814 }
815
816 bytes_recorded_in_wav = r.chunksize - 36;
817
818
819 if ( bytes_recorded_in_wav == 0 )
820 {
821 MessageBox(
822 main_win,
823 TEXT("Cannot read file. No audio data."),
824 TEXT("ERROR"),
825 MB_OK|MB_ICONERROR
826 );
827
828 CloseHandle( file );
829 return FALSE;
830 }
831
832
833 snd::audio_format openfmt
834 ( w.SampleRate, w.BitsPerSample, w.NumChannels );
835
836
837
838 AUD_BUF->clear();
839
840
841 AUD_BUF->alloc_bytes( bytes_recorded_in_wav );
842
843
844 b = ReadFile(
845 file,
846 ( LPVOID ) AUD_BUF->audio_buffer(),
847 bytes_recorded_in_wav,
848 &is_read,
849 0
850 );
851
852
853 AUD_BUF->set_b_received( bytes_recorded_in_wav );
854
855
856 if (( !b ) || ( is_read != bytes_recorded_in_wav ))
857 {
858 MessageBox(
859 main_win,
860 TEXT("Cannot read file. Error reading audio data."),
861 TEXT("ERROR"),
862 MB_OK|MB_ICONERROR
863 );
864
865 CloseHandle( file );
866
867 AUD_BUF->reset();
868 return FALSE;
869 }
870
871 CloseHandle( file );
872
873 enable_but( BUTPLAY_ID );
874 enable_but( BUTSTOP_ID );
875 enable_but( BUTSTART_ID );
876 enable_but( BUTEND_ID );
877 enable_but( BUTREC_ID );
878
879
880 samples_max = AUD_BUF->samples_received();
881
882 isnew = FALSE;
883
884 return TRUE;
885
886 }
887
888
889 BOOL
890 write_wav( TCHAR * f )
891 {
892
893 HANDLE file;
894
895
896 DWORD written;
897 BOOL is_writ;
898 int i;
899 riff_hdr r;
900 wave_hdr w;
901 data_chunk d;
902
903
904
905 file = CreateFile(
906 f,
907 GENERIC_WRITE,
908 0, 0,
909 CREATE_NEW,
910 FILE_ATTRIBUTE_NORMAL,
911 0
912 );
913
914
915
916 if ( !file )
917 {
918 i = MessageBox(
919 main_win,
920 TEXT("File already exist. Overwrite it?"),
921 TEXT("Warning"),
922 MB_YESNO|MB_ICONQUESTION
923 );
924
925 if ( i == IDYES )
926 {
927
928 file = CreateFile(
929 f,
930 GENERIC_WRITE,
931 0, 0,
932 CREATE_ALWAYS,
933 FILE_ATTRIBUTE_NORMAL,
934 0
935 );
936
937 if ( !file )
938 {
939 MessageBox(
940 main_win,
941 TEXT("File Error, CreateFile() failed."),
942 TEXT("ERROR"),
943 MB_OK|MB_ICONERROR
944 );
945
946
947 return FALSE;
948
949 }
950
951
952 } else
953 return FALSE;
954 }
955
956
957
958
959 r.magic = 0x46464952;
960
961
962 r.format = 0x45564157;
963 r.chunksize = 36 + AUD_BUF->bytes_recorded();
964
965
966 w.Subchunkid = 0x20746d66;
967
968 w.Subchunk1Size = 16;
969 w.AudioFormat = 1;
970 w.NumChannels = AUD_BUF->audinfo().channels();
971 w.SampleRate = AUD_BUF->audinfo().sample_rate();
972 w.ByteRate = AUD_BUF->audinfo().byte_rate();
973 w.BlockAlign = AUD_BUF->audinfo().block_align();
974 w.BitsPerSample = AUD_BUF->audinfo().bits();
975
976
977 d.subc = 0x61746164;
978 d.subc_size = AUD_BUF->bytes_recorded();
979
980
981
982 //
983 // Writing headers
984 //
985
986
987 is_writ = WriteFile( file, ( LPCVOID ) &r, sizeof ( r ), &written, 0 );
988
989 if ( !is_writ )
990 {
991 MessageBox(
992 main_win,
993 TEXT("File Error, WriteFile() failed."),
994 TEXT("ERROR"),
995 MB_OK|MB_ICONERROR
996 );
997
998 CloseHandle( file );
999
1000 return FALSE;
1001
1002 }
1003
1004
1005 is_writ = WriteFile( file, ( LPCVOID ) &w, sizeof ( w ), &written, 0 );
1006
1007 if ( !is_writ )
1008 {
1009 MessageBox(
1010 main_win,
1011 TEXT("File Error, WriteFile() failed."),
1012 TEXT("ERROR"),
1013 MB_OK|MB_ICONERROR
1014 );
1015
1016 CloseHandle( file );
1017
1018 return FALSE;
1019
1020 }
1021
1022
1023 is_writ = WriteFile( file, ( LPCVOID ) &d, sizeof ( d ), &written, 0 );
1024
1025
1026 if ( !is_writ )
1027 {
1028 MessageBox(
1029 main_win,
1030 TEXT("File Error, WriteFile() failed."),
1031 TEXT("ERROR"),
1032 MB_OK|MB_ICONERROR
1033 );
1034
1035 CloseHandle( file );
1036
1037 return FALSE;
1038
1039 }
1040
1041
1042
1043 is_writ = WriteFile(
1044 file,
1045 ( LPCVOID ) AUD_BUF->audio_buffer(),
1046 AUD_BUF->bytes_recorded(),
1047 &written,
1048 0
1049 );
1050
1051 if ( !is_writ )
1052 {
1053 MessageBox(
1054 main_win,
1055 TEXT("File Error, WriteFile() failed."),
1056 TEXT("ERROR"),
1057 MB_OK|MB_ICONERROR
1058 );
1059
1060 CloseHandle( file );
1061
1062 return FALSE;
1063
1064 }
1065
1066
1067 CloseHandle( file );
1068
1069 return TRUE;
1070 }