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)
6 * Robert Naumann (gonzoMD)
18 #define gprintf _snprintf
20 #define gprintf _snwprintf
24 TCHAR szTitle
[MAX_LOADSTRING
];
25 TCHAR szWindowClass
[MAX_LOADSTRING
];
27 ATOM
MyRegisterClass(HINSTANCE hInstance
);
28 ATOM
MyRegisterClass_wave(HINSTANCE hInstance
);
29 BOOL
InitInstance(HINSTANCE
, int);
30 BOOL
InitInstance_wave(HWND
, HINSTANCE
, int);
31 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
32 LRESULT CALLBACK
WndProc_wave(HWND
, UINT
, WPARAM
, LPARAM
);
34 BOOL win_first
, wout_first
;
41 HBITMAP butbmps_dis
[5];
42 WNDPROC buttons_std_proc
;
56 TCHAR file_path
[MAX_PATH
];
57 TCHAR str_pos
[MAX_LOADSTRING
];
58 TCHAR str_dur
[MAX_LOADSTRING
];
59 TCHAR str_buf
[MAX_LOADSTRING
];
60 TCHAR str_fmt
[MAX_LOADSTRING
];
61 TCHAR str_chan
[MAX_LOADSTRING
];
68 snd::audio_membuffer
*AUD_BUF
;
69 snd::audio_waveout
*AUD_OUT
;
70 snd::audio_wavein
*AUD_IN
;
74 NONCLIENTMETRICS s_info
;
82 AboutDlgProc(HWND hWnd
,
106 _tWinMain(HINSTANCE hInstance
,
107 HINSTANCE hPrevInstance
,
111 UNREFERENCED_PARAMETER(hPrevInstance
);
112 UNREFERENCED_PARAMETER(lpCmdLine
);
117 s_info
.cbSize
= sizeof( NONCLIENTMETRICS
);
119 InitCommonControls();
121 win_first
= wout_first
= FALSE
;
123 text_rect
.left
= REFRESHA_X
;
124 text_rect
.top
= REFRESHA_Y
;
125 text_rect
.right
= REFRESHA_CX
;
126 text_rect
.bottom
= REFRESHA_CY
;
128 text2_rect
.left
= REFRESHB_X
;
129 text2_rect
.top
= REFRESHB_Y
;
130 text2_rect
.right
= REFRESHB_CX
;
131 text2_rect
.bottom
= REFRESHB_CY
;
133 /* Retrieving defaul system font, and others system informations */
134 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
135 sizeof(NONCLIENTMETRICS
),
140 s_info
.lfMenuFont
.lfHeight
= 14;
142 /* Inits buttons bitmaps */
144 butbmps
[0] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_START
));
145 butbmps
[1] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_END
));
146 butbmps
[2] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_PLAY
));
147 butbmps
[3] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_STOP
));
148 butbmps
[4] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_REC
));
150 butbmps_dis
[0] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_START_DIS
));
151 butbmps_dis
[1] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_END_DIS
));
152 butbmps_dis
[2] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_PLAY_DIS
));
153 butbmps_dis
[3] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_STOP_DIS
));
154 butbmps_dis
[4] = LoadBitmap(hInstance
, MAKEINTRESOURCE(IDB_BITMAP2_REC_DIS
));
156 /* Inits audio devices and buffers */
158 snd::audio_membuffer
AUD_buffer(snd::A44100_16BIT_STEREO
);
159 snd::audio_waveout
AUD_waveout(snd::A44100_16BIT_STEREO
, AUD_buffer
);
160 snd::audio_wavein
AUD_wavein(snd::A44100_16BIT_STEREO
, AUD_buffer
);
162 AUD_buffer
.play_finished
= l_play_finished
;
163 AUD_buffer
.audio_arrival
= l_audio_arrival
;
164 AUD_buffer
.buffer_resized
= l_buffer_resized
;
166 AUD_buffer
.alloc_seconds(INITIAL_BUFREC_SECONDS
);
168 AUD_IN
= &AUD_wavein
;
169 AUD_OUT
= &AUD_waveout
;
170 AUD_BUF
= &AUD_buffer
;
172 /* Inits slider default parameters */
176 slider_max
= SLIDER_W
;
178 stopped_flag
= FALSE
;
183 samples_max
= AUD_buffer
.total_samples();
188 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
189 LoadString(hInstance
, IDC_REACTOS_SNDREC32
, szWindowClass
, MAX_LOADSTRING
);
190 LoadString(hInstance
, IDS_STRPOS
, str_pos
, MAX_LOADSTRING
);
191 LoadString(hInstance
, IDS_STRDUR
, str_dur
, MAX_LOADSTRING
);
192 LoadString(hInstance
, IDS_STRBUF
, str_buf
, MAX_LOADSTRING
);
193 LoadString(hInstance
, IDS_STRFMT
, str_fmt
, MAX_LOADSTRING
);
194 LoadString(hInstance
, IDS_STRCHAN
, str_chan
, MAX_LOADSTRING
);
195 LoadString(hInstance
, IDS_STRMONO
, str_mono
, 10);
196 LoadString(hInstance
, IDS_STRSTEREO
, str_stereo
, 10);
198 /* Registers sndrec32 window class */
199 MyRegisterClass(hInstance
);
200 MyRegisterClass_wave(hInstance
);
202 if (!InitInstance(hInstance
, nCmdShow
))
204 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
208 /* Loads key accelerators */
209 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_REACTOS_SNDREC32
));
211 /* Starts main loop */
212 while (GetMessage(&msg
, NULL
, 0, 0))
214 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
))
216 TranslateMessage(&msg
);
217 DispatchMessage(&msg
);
233 return (int)msg
.wParam
;
237 MyRegisterClass(HINSTANCE hInstance
)
241 wcex
.cbSize
= sizeof(WNDCLASSEX
);
243 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
244 wcex
.lpfnWndProc
= WndProc
;
247 wcex
.hInstance
= hInstance
;
248 wcex
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SNDREC32
));
249 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
250 wcex
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
251 wcex
.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1
);
252 wcex
.lpszClassName
= szWindowClass
;
253 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, MAKEINTRESOURCE(IDI_SNDREC32
));
255 return RegisterClassEx(&wcex
);
259 InitInstance(HINSTANCE hInstance
, int nCmdShow
)
265 hWnd
= CreateWindow(szWindowClass
,
267 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
281 ShowWindow(hWnd
, nCmdShow
);
290 MyRegisterClass_wave(HINSTANCE hInstance
)
294 wcex
.cbSize
= sizeof(WNDCLASSEX
);
296 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
297 wcex
.lpfnWndProc
= WndProc_wave
;
300 wcex
.hInstance
= hInstance
;
302 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
303 wcex
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
304 wcex
.lpszMenuName
= 0;
305 wcex
.lpszClassName
= TEXT("sndrec32_wave");
308 return RegisterClassEx(&wcex
);
312 InitInstance_wave(HWND f
,
320 hWnd
= CreateWindow(TEXT("sndrec32_wave"),
322 WS_DLGFRAME
| WS_VISIBLE
| WS_CHILD
,
337 ShowWindow(hWnd
, nCmdShow
);
347 WndProc_wave(HWND hWnd
,
357 unsigned int max_h
= (cli
.bottom
/ 2);
358 unsigned int samples
;
359 unsigned int x
, line_h
;
364 GetClientRect(hWnd
, &cli
);
367 /* Initialize hdc objects */
368 hdc
= BeginPaint(hWnd
, &ps
);
369 pen
= (HPEN
)CreatePen(PS_SOLID
, 1, WAVEBAR_COLOR
);
370 oldpen
= (HPEN
) SelectObject(hdc
, (HBRUSH
)pen
);
371 if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
373 samples
= AUD_OUT
->tot_samples_buf();
374 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
376 x
= (i
* samples
) / WAVEBAR_CX
;
377 line_h
= (AUD_OUT
->nsample(x
) * max_h
) / AUD_OUT
->samplevalue_max();
380 MoveToEx(hdc
, i
, max_h
, 0);
381 LineTo(hdc
, i
, max_h
- (line_h
* 2));
382 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
386 SetPixel(hdc
, i
, max_h
, WAVEBAR_COLOR
);
390 else if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
392 samples
= AUD_IN
->tot_samples_buf();
393 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
395 x
= (i
* samples
) / WAVEBAR_CX
;
396 line_h
= (AUD_IN
->nsample(x
) * max_h
) / AUD_IN
->samplevalue_max();
399 MoveToEx(hdc
, i
, max_h
, 0);
400 LineTo(hdc
, i
, max_h
- (line_h
* 2));
401 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
405 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
411 /* In standby mode draw a simple line */
412 MoveToEx(hdc
, 0, cli
.bottom
/ 2, 0);
413 LineTo(hdc
, WAVEBAR_CX
, cli
.bottom
/ 2);
416 SelectObject(hdc
, oldpen
);
418 EndPaint( hWnd
, &ps
);
424 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
438 TCHAR str_tmp
[MAX_LOADSTRING
];
443 long long slid_samp
= 0;
445 /* Checking for global pointers to buffer and io audio devices */
446 if ((!AUD_IN
) || (!AUD_OUT
) || (!AUD_BUF
))
448 MessageBox(0, TEXT("Buffer Error"), 0, 0);
455 /* Creating the wave bar */
456 if (!InitInstance_wave(hWnd
, hInst
, SW_SHOWNORMAL
))
458 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
462 /* Creating ALL the buttons */
463 for (int i
= 0; i
< 5; ++i
)
465 buttons
[i
] = CreateWindow(TEXT("button"),
467 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
468 BUTTONS_CX
+ (i
* (BUTTONS_W
+ ((i
== 0) ? 0 : BUTTONS_SPACE
))),
478 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
482 /* Realize the button bmp image */
483 SendMessage(buttons
[i
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[i
]);
484 UpdateWindow(buttons
[i
]);
488 /* Creating the SLIDER window */
489 slider
= CreateWindow(TRACKBAR_CLASS
,
491 WS_CHILD
| WS_VISIBLE
| TBS_NOTICKS
| TBS_HORZ
| TBS_ENABLESELRANGE
,
502 MessageBox(0, 0, TEXT( "CreateWindow() Error!" ), 0);
506 /* Sets slider limits */
510 (LPARAM
)MAKELONG(slider_min
, slider_max
));
512 UpdateWindow(slider
);
513 enable_but(BUTREC_ID
);
514 EnableWindow(slider
, FALSE
);
517 /* Implements slider logic */
520 switch (LOWORD(wParam
))
527 /* If the user touch the slider bar, set the
528 audio start position properly */
529 slider_pos
= SendMessage(slider
, TBM_GETPOS
, 0, 0);
530 slid_samp
= (__int64
)slider_pos
* (__int64
)samples_max
;
531 AUD_BUF
->set_position(AUD_BUF
->audinfo().bytes_in_samples((unsigned int)(slid_samp
/ (__int64
)slider_max
)));
532 InvalidateRect(hWnd
, &text_rect
, TRUE
);
539 wmId
= LOWORD(wParam
);
540 if ((wmId
>= 0) && (wmId
< 5) && (butdisabled
[wmId
] == TRUE
))
548 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
549 AUD_IN
->stop_recording();
551 if ((AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
552 (AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
557 enable_but(BUTREC_ID
);
558 disable_but(BUTSTART_ID
);
559 disable_but(BUTEND_ID
);
560 disable_but(BUTSTOP_ID
);
561 disable_but(BUTPLAY_ID
);
563 samples_max
= AUD_BUF
->total_samples();
566 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
568 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
569 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
574 ZeroMemory(file_path
, MAX_PATH
* sizeof(TCHAR
));
576 EnableWindow(slider
, FALSE
);
578 InvalidateRect(hWnd
, &text_rect
, TRUE
);
579 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
584 ZeroMemory(&ofn
, sizeof(ofn
));
586 ofn
.lStructSize
= sizeof(ofn
);
587 ofn
.hwndOwner
= hWnd
;
588 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
589 ofn
.lpstrFile
= file_path
;
590 ofn
.nMaxFile
= MAX_PATH
;
591 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
592 ofn
.lpstrDefExt
= TEXT("wav");
594 if (GetOpenFileName(&ofn
))
597 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
598 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
600 EnableWindow(slider
, TRUE
);
603 InvalidateRect(hWnd
, &text_rect
, TRUE
);
604 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
608 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
613 ZeroMemory(&ofn
, sizeof(ofn
));
615 ofn
.lStructSize
= sizeof(ofn
);
616 ofn
.hwndOwner
= hWnd
;
617 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
618 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
619 ofn
.lpstrFile
= file_path
;
620 ofn
.nMaxFile
= MAX_PATH
;
622 ofn
.lpstrDefExt
= TEXT("wav");
624 if (GetSaveFileName (&ofn
))
626 write_wav(file_path
);
627 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
632 case ID_EDIT_AUDIOPROPS
:
633 ShellExecute(NULL
, NULL
, _T("rundll32.exe"), _T("shell32.dll,Control_RunDLL mmsys.cpl,ShowAudioPropertySheet"), NULL
, SW_SHOWNORMAL
);
640 /* Sndrec32 buttons routines */
642 AUD_BUF
->set_position_start();
644 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
652 if (wout_first
== false)
660 disable_but(BUTSTART_ID
);
661 disable_but(BUTEND_ID
);
662 disable_but(BUTREC_ID
);
663 disable_but(BUTPLAY_ID
);
665 SetTimer(hWnd
, 1, 250, 0);
666 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
675 AUD_IN
->stop_recording();
677 /* Resetting slider position */
679 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
681 samples_max
= AUD_BUF
->samples_received();
683 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
685 enable_but(BUTSTART_ID
);
686 enable_but(BUTEND_ID
);
687 enable_but(BUTREC_ID
);
688 enable_but(BUTPLAY_ID
);
690 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
691 EnableWindow(slider
, TRUE
);
697 InvalidateRect(hWnd
, &text_rect
, TRUE
);
698 InvalidateRect(wave_win
, 0, TRUE
);
705 enable_but(BUTSTART_ID
);
706 enable_but(BUTEND_ID
);
707 enable_but(BUTREC_ID
);
708 enable_but(BUTPLAY_ID
);
713 KillTimer(hWnd
, WAVEBAR_TIMERID
);
715 InvalidateRect(hWnd
, &text_rect
, TRUE
);
720 if (win_first
== false)
728 samples_max
= AUD_BUF
->total_samples();
730 AUD_IN
->start_recording();
732 enable_but(BUTSTOP_ID
);
734 disable_but(BUTSTART_ID
);
735 disable_but(BUTEND_ID
);
736 disable_but(BUTREC_ID
);
737 disable_but(BUTPLAY_ID
);
741 EnableWindow(slider
, FALSE
);
743 SetTimer(hWnd
, 1, 150, 0);
744 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
749 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
760 KillTimer(hWnd
, WAVEBAR_TIMERID
);
762 enable_but(BUTPLAY_ID
);
763 stopped_flag
= FALSE
;
766 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
767 InvalidateRect(hWnd
, &text_rect
, TRUE
);
770 case WAVEBAR_TIMERID
:
771 InvalidateRect(wave_win
, 0, TRUE
);
772 SendMessage(wave_win
, WM_USER
, 0, 0);
778 hdc
= BeginPaint(hWnd
, &ps
);
779 font
= CreateFontIndirect(&s_info
.lfMenuFont
);
780 oldfont
= (HFONT
) SelectObject(hdc
, font
);
781 SetBkMode(hdc
, TRANSPARENT
);
783 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
788 (float)((float)AUD_BUF
->bytes_recorded() / (float)AUD_BUF
->audinfo().byte_rate()));
791 else if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
796 (float)((float)AUD_BUF
->bytes_played() / (float)AUD_BUF
->audinfo().byte_rate()));
803 (float)((((float)slider_pos
* (float)samples_max
) / (float)slider_max
) / (float)AUD_BUF
->audinfo().sample_rate()));
820 AUD_BUF
->fseconds_total());
827 AUD_BUF
->fseconds_recorded());
842 (float)((float)AUD_BUF
->mem_size() / 1024.0f
));
856 (float)((float)AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
857 AUD_BUF
->audinfo().bits(),
858 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
);
872 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
);
883 SelectObject(hdc
, oldfont
);
892 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
898 void l_play_finished(void)
902 enable_but(BUTSTART_ID
);
903 enable_but(BUTEND_ID
);
904 enable_but(BUTREC_ID
);
905 enable_but(BUTPLAY_ID
);
907 InvalidateRect(wave_win
, 0, TRUE
);
910 void l_audio_arrival(unsigned int samples_arrival
)
912 slider_pos
+= (DWORD
)((slider_max
* samples_arrival
) / samples_max
);
915 void l_buffer_resized(unsigned int new_size
)
919 VOID
enable_but(DWORD id
)
921 butdisabled
[id
] = FALSE
;
922 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[id
]);
925 VOID
disable_but(DWORD id
)
927 butdisabled
[id
] = TRUE
;
928 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps_dis
[id
]);
931 BOOL
open_wav(TCHAR
*f
)
941 DWORD bytes_recorded_in_wav
= 0;
949 FILE_ATTRIBUTE_NORMAL
,
954 TEXT("Cannot open file. CreateFile() error."),
956 MB_OK
| MB_ICONERROR
);
961 b
= ReadFile(file
, (LPVOID
)&r
, sizeof(r
), &is_read
, 0);
965 TEXT("Cannot read RIFF header."),
967 MB_OK
| MB_ICONERROR
);
973 b
= ReadFile(file
, (LPVOID
)&w
, sizeof(w
), &is_read
, 0);
977 TEXT("Cannot read WAVE header."),
979 MB_OK
| MB_ICONERROR
);
985 b
= ReadFile(file
, (LPVOID
)&d
, sizeof(d
), &is_read
, 0);
989 TEXT("Cannot read WAVE subchunk."),
991 MB_OK
| MB_ICONERROR
);
997 bytes_recorded_in_wav
= r
.chunksize
- 36;
998 if (bytes_recorded_in_wav
== 0)
1000 MessageBox(main_win
,
1001 TEXT("Cannot read file. No audio data."),
1003 MB_OK
| MB_ICONERROR
);
1009 snd::audio_format
openfmt(w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1012 AUD_BUF
->alloc_bytes(bytes_recorded_in_wav
);
1015 (LPVOID
)AUD_BUF
->audio_buffer(),
1016 bytes_recorded_in_wav
,
1020 AUD_BUF
->set_b_received(bytes_recorded_in_wav
);
1022 if ((!b
) || (is_read
!= bytes_recorded_in_wav
))
1024 MessageBox(main_win
,
1025 TEXT("Cannot read file. Error reading audio data."),
1027 MB_OK
| MB_ICONERROR
);
1037 enable_but(BUTPLAY_ID
);
1038 enable_but(BUTSTOP_ID
);
1039 enable_but(BUTSTART_ID
);
1040 enable_but(BUTEND_ID
);
1041 enable_but(BUTREC_ID
);
1043 samples_max
= AUD_BUF
->samples_received();
1061 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0);
1064 i
= MessageBox(main_win
,
1065 TEXT("File already exist. Overwrite it?"),
1067 MB_YESNO
| MB_ICONQUESTION
);
1071 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1074 MessageBox(main_win
,
1075 TEXT("File Error, CreateFile() failed."),
1077 MB_OK
| MB_ICONERROR
);
1086 r
.magic
= 0x46464952;
1087 r
.format
= 0x45564157;
1088 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1090 w
.Subchunkid
= 0x20746d66;
1091 w
.Subchunk1Size
= 16;
1093 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1094 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1095 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1096 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1097 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1099 d
.subc
= 0x61746164;
1100 d
.subc_size
= AUD_BUF
->bytes_recorded();
1102 /* Writing headers */
1103 is_writ
= WriteFile(file
, (LPCVOID
)&r
, sizeof(r
), &written
, 0);
1106 MessageBox(main_win
,
1107 TEXT("File Error, WriteFile() failed."),
1109 MB_OK
| MB_ICONERROR
);
1115 is_writ
= WriteFile(file
, (LPCVOID
)&w
, sizeof(w
), &written
, 0);
1118 MessageBox(main_win
,
1119 TEXT("File Error, WriteFile() failed."),
1121 MB_OK
| MB_ICONERROR
);
1127 is_writ
= WriteFile(file
, (LPCVOID
)&d
, sizeof(d
), &written
, 0);
1130 MessageBox(main_win
,
1131 TEXT("File Error, WriteFile() failed."),
1133 MB_OK
| MB_ICONERROR
);
1139 is_writ
= WriteFile(file
,
1140 (LPCVOID
)AUD_BUF
->audio_buffer(),
1141 AUD_BUF
->bytes_recorded(),
1146 MessageBox(main_win
,
1147 TEXT("File Error, WriteFile() failed."),
1149 MB_OK
| MB_ICONERROR
);