1 /* PROJECT: ReactOS sndrec32
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/sndrec32/sndrec32.cpp
4 * PURPOSE: Sound recording
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
16 #define gprintf _snprintf
18 #define gprintf _snwprintf
22 TCHAR szTitle
[MAX_LOADSTRING
];
23 TCHAR szWindowClass
[MAX_LOADSTRING
];
25 ATOM
MyRegisterClass(HINSTANCE hInstance
);
26 ATOM
MyRegisterClass_wave(HINSTANCE hInstance
);
27 BOOL
InitInstance(HINSTANCE
, int);
28 BOOL
InitInstance_wave(HWND
, HINSTANCE
, int);
29 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
30 LRESULT CALLBACK
WndProc_wave(HWND
, UINT
, WPARAM
, LPARAM
);
32 BOOL win_first
, wout_first
;
39 HBITMAP butbmps_dis
[5];
40 WNDPROC buttons_std_proc
;
54 TCHAR file_path
[MAX_PATH
];
55 TCHAR str_pos
[MAX_LOADSTRING
];
56 TCHAR str_dur
[MAX_LOADSTRING
];
57 TCHAR str_buf
[MAX_LOADSTRING
];
58 TCHAR str_fmt
[MAX_LOADSTRING
];
59 TCHAR str_chan
[MAX_LOADSTRING
];
66 snd::audio_membuffer
*AUD_BUF
;
67 snd::audio_waveout
*AUD_OUT
;
68 snd::audio_wavein
*AUD_IN
;
72 NONCLIENTMETRICS s_info
;
80 AboutDlgProc(HWND hWnd
,
104 _tWinMain(HINSTANCE hInstance
,
105 HINSTANCE hPrevInstance
,
109 UNREFERENCED_PARAMETER(hPrevInstance
);
110 UNREFERENCED_PARAMETER(lpCmdLine
);
115 s_info
.cbSize
= sizeof( NONCLIENTMETRICS
);
117 InitCommonControls();
119 win_first
= wout_first
= FALSE
;
121 text_rect
.left
= REFRESHA_X
;
122 text_rect
.top
= REFRESHA_Y
;
123 text_rect
.right
= REFRESHA_CX
;
124 text_rect
.bottom
= REFRESHA_CY
;
126 text2_rect
.left
= REFRESHB_X
;
127 text2_rect
.top
= REFRESHB_Y
;
128 text2_rect
.right
= REFRESHB_CX
;
129 text2_rect
.bottom
= REFRESHB_CY
;
131 /* Retrieving defaul system font, and others system informations */
132 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
133 sizeof(NONCLIENTMETRICS
),
138 s_info
.lfMenuFont
.lfHeight
= 14;
140 /* Inits buttons bitmaps */
142 butbmps
[0] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_START
));
143 butbmps
[1] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_END
));
144 butbmps
[2] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_PLAY
));
145 butbmps
[3] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_STOP
));
146 butbmps
[4] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_REC
));
148 butbmps_dis
[0] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_START_DIS
));
149 butbmps_dis
[1] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_END_DIS
));
150 butbmps_dis
[2] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_PLAY_DIS
));
151 butbmps_dis
[3] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_STOP_DIS
));
152 butbmps_dis
[4] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_REC_DIS
));
154 /* Inits audio devices and buffers */
156 snd::audio_membuffer
AUD_buffer(snd::A44100_16BIT_STEREO
);
157 snd::audio_waveout
AUD_waveout(snd::A44100_16BIT_STEREO
, AUD_buffer
);
158 snd::audio_wavein
AUD_wavein(snd::A44100_16BIT_STEREO
, AUD_buffer
);
160 AUD_buffer
.play_finished
= l_play_finished
;
161 AUD_buffer
.audio_arrival
= l_audio_arrival
;
162 AUD_buffer
.buffer_resized
= l_buffer_resized
;
164 AUD_buffer
.alloc_seconds(INITIAL_BUFREC_SECONDS
);
166 AUD_IN
= &AUD_wavein
;
167 AUD_OUT
= &AUD_waveout
;
168 AUD_BUF
= &AUD_buffer
;
170 /* Inits slider default parameters */
174 slider_max
= SLIDER_W
;
176 stopped_flag
= FALSE
;
181 samples_max
= AUD_buffer
.total_samples();
186 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
187 LoadString(hInstance
, IDC_REACTOS_SNDREC32
, szWindowClass
, MAX_LOADSTRING
);
188 LoadString(hInstance
, IDS_STRPOS
, str_pos
, MAX_LOADSTRING
);
189 LoadString(hInstance
, IDS_STRDUR
, str_dur
, MAX_LOADSTRING
);
190 LoadString(hInstance
, IDS_STRBUF
, str_buf
, MAX_LOADSTRING
);
191 LoadString(hInstance
, IDS_STRFMT
, str_fmt
, MAX_LOADSTRING
);
192 LoadString(hInstance
, IDS_STRCHAN
, str_chan
, MAX_LOADSTRING
);
193 LoadString(hInstance
, IDS_STRMONO
, str_mono
, 10);
194 LoadString(hInstance
, IDS_STRSTEREO
, str_stereo
, 10);
196 /* Registers sndrec32 window class */
197 MyRegisterClass(hInstance
);
198 MyRegisterClass_wave(hInstance
);
200 if (!InitInstance(hInstance
, nCmdShow
))
202 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
206 /* Loads key accelerators */
207 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_REACTOS_SNDREC32
));
209 /* Starts main loop */
210 while (GetMessage(&msg
, NULL
, 0, 0))
212 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
))
214 TranslateMessage(&msg
);
215 DispatchMessage(&msg
);
231 return (int)msg
.wParam
;
235 MyRegisterClass(HINSTANCE hInstance
)
239 wcex
.cbSize
= sizeof(WNDCLASSEX
);
241 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
242 wcex
.lpfnWndProc
= WndProc
;
245 wcex
.hInstance
= hInstance
;
246 wcex
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SNDREC32
));
247 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
248 wcex
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
249 wcex
.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1
);
250 wcex
.lpszClassName
= szWindowClass
;
251 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, MAKEINTRESOURCE(IDI_SNDREC32
));
253 return RegisterClassEx(&wcex
);
257 InitInstance(HINSTANCE hInstance
, int nCmdShow
)
263 hWnd
= CreateWindow(szWindowClass
,
265 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
279 ShowWindow(hWnd
, nCmdShow
);
288 MyRegisterClass_wave(HINSTANCE hInstance
)
292 wcex
.cbSize
= sizeof(WNDCLASSEX
);
294 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
295 wcex
.lpfnWndProc
= WndProc_wave
;
298 wcex
.hInstance
= hInstance
;
300 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
301 wcex
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
302 wcex
.lpszMenuName
= 0;
303 wcex
.lpszClassName
= TEXT("sndrec32_wave");
306 return RegisterClassEx(&wcex
);
310 InitInstance_wave(HWND f
,
318 hWnd
= CreateWindow(TEXT("sndrec32_wave"),
320 WS_DLGFRAME
| WS_VISIBLE
| WS_CHILD
,
335 ShowWindow(hWnd
, nCmdShow
);
345 WndProc_wave(HWND hWnd
,
354 unsigned int max_h
= (cli
.bottom
/ 2);
355 unsigned int samples
;
356 unsigned int x
, line_h
;
361 GetClientRect(hWnd
, &cli
);
364 /* Initialize hdc objects */
365 hdc
= BeginPaint(hWnd
, &ps
);
366 pen
= (HPEN
)CreatePen(PS_SOLID
, 1, WAVEBAR_COLOR
);
367 SelectObject(hdc
, (HBRUSH
)pen
);
368 if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
370 samples
= AUD_OUT
->tot_samples_buf();
371 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
373 x
= (i
* samples
) / WAVEBAR_CX
;
374 line_h
= (AUD_OUT
->nsample(x
) * max_h
) / AUD_OUT
->samplevalue_max();
377 MoveToEx(hdc
, i
, max_h
, 0);
378 LineTo(hdc
, i
, max_h
- (line_h
* 2));
379 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
383 SetPixel(hdc
, i
, max_h
, WAVEBAR_COLOR
);
387 else if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
389 samples
= AUD_IN
->tot_samples_buf();
390 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
392 x
= (i
* samples
) / WAVEBAR_CX
;
393 line_h
= (AUD_IN
->nsample(x
) * max_h
) / AUD_IN
->samplevalue_max();
396 MoveToEx(hdc
, i
, max_h
, 0);
397 LineTo(hdc
, i
, max_h
- (line_h
* 2));
398 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
402 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
408 /* In standby mode draw a simple line */
409 MoveToEx(hdc
, 0, cli
.bottom
/ 2, 0);
410 LineTo(hdc
, WAVEBAR_CX
, cli
.bottom
/ 2);
414 EndPaint( hWnd
, &ps
);
420 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
434 TCHAR str_tmp
[MAX_LOADSTRING
];
438 long long slid_samp
= 0;
440 /* Checking for global pointers to buffer and io audio devices */
441 if ((!AUD_IN
) || (!AUD_OUT
) || (!AUD_BUF
))
443 MessageBox(0, TEXT("Buffer Error"), 0, 0);
450 /* Creating the wave bar */
451 if (!InitInstance_wave(hWnd
, hInst
, SW_SHOWNORMAL
))
453 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
457 /* Creating ALL the buttons */
458 for (int i
= 0; i
< 5; ++i
)
460 buttons
[i
] = CreateWindow(TEXT("button"),
462 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
463 BUTTONS_CX
+ (i
* (BUTTONS_W
+ ((i
== 0) ? 0 : BUTTONS_SPACE
))),
473 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
477 /* Realize the button bmp image */
478 SendMessage(buttons
[i
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[i
]);
479 UpdateWindow(buttons
[i
]);
483 /* Creating the SLIDER window */
484 slider
= CreateWindow(TRACKBAR_CLASS
,
486 WS_CHILD
| WS_VISIBLE
| TBS_NOTICKS
| TBS_HORZ
| TBS_ENABLESELRANGE
,
497 MessageBox(0, 0, TEXT( "CreateWindow() Error!" ), 0);
501 /* Sets slider limits */
505 (LPARAM
)MAKELONG(slider_min
, slider_max
));
507 UpdateWindow(slider
);
508 enable_but(BUTREC_ID
);
509 EnableWindow(slider
, FALSE
);
512 /* Implements slider logic */
515 switch (LOWORD(wParam
))
522 /* If the user touch the slider bar, set the
523 audio start position properly */
524 slider_pos
= SendMessage(slider
, TBM_GETPOS
, 0, 0);
525 slid_samp
= (__int64
)slider_pos
* (__int64
)samples_max
;
526 AUD_BUF
->set_position(AUD_BUF
->audinfo().bytes_in_samples((unsigned int)(slid_samp
/ (__int64
)slider_max
)));
527 InvalidateRect(hWnd
, &text_rect
, TRUE
);
534 wmId
= LOWORD(wParam
);
535 if ((wmId
>= 0) && (wmId
< 5) && (butdisabled
[wmId
] == TRUE
))
543 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
544 AUD_IN
->stop_recording();
546 if ((AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
547 (AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
552 enable_but(BUTREC_ID
);
553 disable_but(BUTSTART_ID
);
554 disable_but(BUTEND_ID
);
555 disable_but(BUTSTOP_ID
);
556 disable_but(BUTPLAY_ID
);
558 samples_max
= AUD_BUF
->total_samples();
561 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
563 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
564 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
569 ZeroMemory(file_path
, MAX_PATH
* sizeof(TCHAR
));
571 EnableWindow(slider
, FALSE
);
573 InvalidateRect(hWnd
, &text_rect
, TRUE
);
574 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
579 ZeroMemory(&ofn
, sizeof(ofn
));
581 ofn
.lStructSize
= sizeof(ofn
);
582 ofn
.hwndOwner
= hWnd
;
583 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
584 ofn
.lpstrFile
= file_path
;
585 ofn
.nMaxFile
= MAX_PATH
;
586 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
587 ofn
.lpstrDefExt
= TEXT("wav");
589 if (GetOpenFileName(&ofn
))
592 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
593 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
595 EnableWindow(slider
, TRUE
);
598 InvalidateRect(hWnd
, &text_rect
, TRUE
);
599 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
603 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
608 ZeroMemory(&ofn
, sizeof(ofn
));
610 ofn
.lStructSize
= sizeof(ofn
);
611 ofn
.hwndOwner
= hWnd
;
612 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
613 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
614 ofn
.lpstrFile
= file_path
;
615 ofn
.nMaxFile
= MAX_PATH
;
617 ofn
.lpstrDefExt
= TEXT("wav");
619 if (GetSaveFileName (&ofn
))
621 write_wav(file_path
);
622 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
630 /* Sndrec32 buttons routines */
632 AUD_BUF
->set_position_start();
634 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
642 if (wout_first
== false)
650 disable_but(BUTSTART_ID
);
651 disable_but(BUTEND_ID
);
652 disable_but(BUTREC_ID
);
653 disable_but(BUTPLAY_ID
);
655 SetTimer(hWnd
, 1, 250, 0);
656 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
665 AUD_IN
->stop_recording();
667 /* Resetting slider position */
669 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
671 samples_max
= AUD_BUF
->samples_received();
673 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
675 enable_but(BUTSTART_ID
);
676 enable_but(BUTEND_ID
);
677 enable_but(BUTREC_ID
);
678 enable_but(BUTPLAY_ID
);
680 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
681 EnableWindow(slider
, TRUE
);
687 InvalidateRect(hWnd
, &text_rect
, TRUE
);
688 InvalidateRect(wave_win
, 0, TRUE
);
695 enable_but(BUTSTART_ID
);
696 enable_but(BUTEND_ID
);
697 enable_but(BUTREC_ID
);
698 enable_but(BUTPLAY_ID
);
703 KillTimer(hWnd
, WAVEBAR_TIMERID
);
705 InvalidateRect(hWnd
, &text_rect
, TRUE
);
710 if (win_first
== false)
718 samples_max
= AUD_BUF
->total_samples();
720 AUD_IN
->start_recording();
722 enable_but(BUTSTOP_ID
);
724 disable_but(BUTSTART_ID
);
725 disable_but(BUTEND_ID
);
726 disable_but(BUTREC_ID
);
727 disable_but(BUTPLAY_ID
);
731 EnableWindow(slider
, FALSE
);
733 SetTimer(hWnd
, 1, 150, 0);
734 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
739 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
750 KillTimer(hWnd
, WAVEBAR_TIMERID
);
752 enable_but(BUTPLAY_ID
);
753 stopped_flag
= FALSE
;
756 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
757 InvalidateRect(hWnd
, &text_rect
, TRUE
);
760 case WAVEBAR_TIMERID
:
761 InvalidateRect(wave_win
, 0, TRUE
);
762 SendMessage(wave_win
, WM_USER
, 0, 0);
768 hdc
= BeginPaint(hWnd
, &ps
);
769 font
= CreateFontIndirect(&s_info
.lfMenuFont
);
770 SelectObject(hdc
, font
);
771 SetBkMode(hdc
, TRANSPARENT
);
773 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
778 (float)((float)AUD_BUF
->bytes_recorded() / (float)AUD_BUF
->audinfo().byte_rate()));
781 else if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
786 (float)((float)AUD_BUF
->bytes_played() / (float)AUD_BUF
->audinfo().byte_rate()));
793 (float)((((float)slider_pos
* (float)samples_max
) / (float)slider_max
) / (float)AUD_BUF
->audinfo().sample_rate()));
810 AUD_BUF
->fseconds_total());
817 AUD_BUF
->fseconds_recorded());
832 (float)((float)AUD_BUF
->mem_size() / 1024.0f
));
846 (float)((float)AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
847 AUD_BUF
->audinfo().bits(),
848 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
);
862 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
);
881 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
887 void l_play_finished(void)
891 enable_but(BUTSTART_ID
);
892 enable_but(BUTEND_ID
);
893 enable_but(BUTREC_ID
);
894 enable_but(BUTPLAY_ID
);
896 InvalidateRect(wave_win
, 0, TRUE
);
899 void l_audio_arrival(unsigned int samples_arrival
)
901 slider_pos
+= (DWORD
)((slider_max
* samples_arrival
) / samples_max
);
904 void l_buffer_resized(unsigned int new_size
)
908 VOID
enable_but(DWORD id
)
910 butdisabled
[id
] = FALSE
;
911 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[id
]);
914 VOID
disable_but(DWORD id
)
916 butdisabled
[id
] = TRUE
;
917 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps_dis
[id
]);
920 BOOL
open_wav(TCHAR
*f
)
930 DWORD bytes_recorded_in_wav
= 0;
938 FILE_ATTRIBUTE_NORMAL
,
943 TEXT("Cannot open file. CreateFile() error."),
945 MB_OK
| MB_ICONERROR
);
950 b
= ReadFile(file
, (LPVOID
)&r
, sizeof(r
), &is_read
, 0);
954 TEXT("Cannot read RIFF header."),
956 MB_OK
| MB_ICONERROR
);
962 b
= ReadFile(file
, (LPVOID
)&w
, sizeof(w
), &is_read
, 0);
966 TEXT("Cannot read WAVE header."),
968 MB_OK
| MB_ICONERROR
);
974 b
= ReadFile(file
, (LPVOID
)&d
, sizeof(d
), &is_read
, 0);
978 TEXT("Cannot read WAVE subchunk."),
980 MB_OK
| MB_ICONERROR
);
986 bytes_recorded_in_wav
= r
.chunksize
- 36;
987 if (bytes_recorded_in_wav
== 0)
990 TEXT("Cannot read file. No audio data."),
992 MB_OK
| MB_ICONERROR
);
998 snd::audio_format
openfmt(w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1001 AUD_BUF
->alloc_bytes(bytes_recorded_in_wav
);
1004 (LPVOID
)AUD_BUF
->audio_buffer(),
1005 bytes_recorded_in_wav
,
1009 AUD_BUF
->set_b_received(bytes_recorded_in_wav
);
1011 if ((!b
) || (is_read
!= bytes_recorded_in_wav
))
1013 MessageBox(main_win
,
1014 TEXT("Cannot read file. Error reading audio data."),
1016 MB_OK
| MB_ICONERROR
);
1026 enable_but(BUTPLAY_ID
);
1027 enable_but(BUTSTOP_ID
);
1028 enable_but(BUTSTART_ID
);
1029 enable_but(BUTEND_ID
);
1030 enable_but(BUTREC_ID
);
1032 samples_max
= AUD_BUF
->samples_received();
1050 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0);
1053 i
= MessageBox(main_win
,
1054 TEXT("File already exist. Overwrite it?"),
1056 MB_YESNO
| MB_ICONQUESTION
);
1060 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1063 MessageBox(main_win
,
1064 TEXT("File Error, CreateFile() failed."),
1066 MB_OK
| MB_ICONERROR
);
1075 r
.magic
= 0x46464952;
1076 r
.format
= 0x45564157;
1077 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1079 w
.Subchunkid
= 0x20746d66;
1080 w
.Subchunk1Size
= 16;
1082 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1083 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1084 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1085 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1086 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1088 d
.subc
= 0x61746164;
1089 d
.subc_size
= AUD_BUF
->bytes_recorded();
1091 /* Writing headers */
1092 is_writ
= WriteFile(file
, (LPCVOID
)&r
, sizeof(r
), &written
, 0);
1095 MessageBox(main_win
,
1096 TEXT("File Error, WriteFile() failed."),
1098 MB_OK
| MB_ICONERROR
);
1104 is_writ
= WriteFile(file
, (LPCVOID
)&w
, sizeof(w
), &written
, 0);
1107 MessageBox(main_win
,
1108 TEXT("File Error, WriteFile() failed."),
1110 MB_OK
| MB_ICONERROR
);
1116 is_writ
= WriteFile(file
, (LPCVOID
)&d
, sizeof(d
), &written
, 0);
1119 MessageBox(main_win
,
1120 TEXT("File Error, WriteFile() failed."),
1122 MB_OK
| MB_ICONERROR
);
1128 is_writ
= WriteFile(file
,
1129 (LPCVOID
)AUD_BUF
->audio_buffer(),
1130 AUD_BUF
->bytes_recorded(),
1135 MessageBox(main_win
,
1136 TEXT("File Error, WriteFile() failed."),
1138 MB_OK
| MB_ICONERROR
);