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
,
356 unsigned int max_h
= (cli
.bottom
/ 2);
357 unsigned int samples
;
358 unsigned int x
, line_h
;
363 GetClientRect(hWnd
, &cli
);
366 /* Initialize hdc objects */
367 hdc
= BeginPaint(hWnd
, &ps
);
368 pen
= (HPEN
)CreatePen(PS_SOLID
, 1, WAVEBAR_COLOR
);
369 SelectObject(hdc
, (HBRUSH
)pen
);
370 if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
372 samples
= AUD_OUT
->tot_samples_buf();
373 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
375 x
= (i
* samples
) / WAVEBAR_CX
;
376 line_h
= (AUD_OUT
->nsample(x
) * max_h
) / AUD_OUT
->samplevalue_max();
379 MoveToEx(hdc
, i
, max_h
, 0);
380 LineTo(hdc
, i
, max_h
- (line_h
* 2));
381 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
385 SetPixel(hdc
, i
, max_h
, WAVEBAR_COLOR
);
389 else if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
391 samples
= AUD_IN
->tot_samples_buf();
392 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
394 x
= (i
* samples
) / WAVEBAR_CX
;
395 line_h
= (AUD_IN
->nsample(x
) * max_h
) / AUD_IN
->samplevalue_max();
398 MoveToEx(hdc
, i
, max_h
, 0);
399 LineTo(hdc
, i
, max_h
- (line_h
* 2));
400 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
404 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
410 /* In standby mode draw a simple line */
411 MoveToEx(hdc
, 0, cli
.bottom
/ 2, 0);
412 LineTo(hdc
, WAVEBAR_CX
, cli
.bottom
/ 2);
416 EndPaint( hWnd
, &ps
);
422 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
436 TCHAR str_tmp
[MAX_LOADSTRING
];
440 long long slid_samp
= 0;
442 /* Checking for global pointers to buffer and io audio devices */
443 if ((!AUD_IN
) || (!AUD_OUT
) || (!AUD_BUF
))
445 MessageBox(0, TEXT("Buffer Error"), 0, 0);
452 /* Creating the wave bar */
453 if (!InitInstance_wave(hWnd
, hInst
, SW_SHOWNORMAL
))
455 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
459 /* Creating ALL the buttons */
460 for (int i
= 0; i
< 5; ++i
)
462 buttons
[i
] = CreateWindow(TEXT("button"),
464 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
465 BUTTONS_CX
+ (i
* (BUTTONS_W
+ ((i
== 0) ? 0 : BUTTONS_SPACE
))),
475 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
479 /* Realize the button bmp image */
480 SendMessage(buttons
[i
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[i
]);
481 UpdateWindow(buttons
[i
]);
485 /* Creating the SLIDER window */
486 slider
= CreateWindow(TRACKBAR_CLASS
,
488 WS_CHILD
| WS_VISIBLE
| TBS_NOTICKS
| TBS_HORZ
| TBS_ENABLESELRANGE
,
499 MessageBox(0, 0, TEXT( "CreateWindow() Error!" ), 0);
503 /* Sets slider limits */
507 (LPARAM
)MAKELONG(slider_min
, slider_max
));
509 UpdateWindow(slider
);
510 enable_but(BUTREC_ID
);
511 EnableWindow(slider
, FALSE
);
514 /* Implements slider logic */
517 switch (LOWORD(wParam
))
524 /* If the user touch the slider bar, set the
525 audio start position properly */
526 slider_pos
= SendMessage(slider
, TBM_GETPOS
, 0, 0);
527 slid_samp
= (__int64
)slider_pos
* (__int64
)samples_max
;
528 AUD_BUF
->set_position(AUD_BUF
->audinfo().bytes_in_samples((unsigned int)(slid_samp
/ (__int64
)slider_max
)));
529 InvalidateRect(hWnd
, &text_rect
, TRUE
);
536 wmId
= LOWORD(wParam
);
537 if ((wmId
>= 0) && (wmId
< 5) && (butdisabled
[wmId
] == TRUE
))
545 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
546 AUD_IN
->stop_recording();
548 if ((AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
549 (AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
554 enable_but(BUTREC_ID
);
555 disable_but(BUTSTART_ID
);
556 disable_but(BUTEND_ID
);
557 disable_but(BUTSTOP_ID
);
558 disable_but(BUTPLAY_ID
);
560 samples_max
= AUD_BUF
->total_samples();
563 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
565 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
566 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
571 ZeroMemory(file_path
, MAX_PATH
* sizeof(TCHAR
));
573 EnableWindow(slider
, FALSE
);
575 InvalidateRect(hWnd
, &text_rect
, TRUE
);
576 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
581 ZeroMemory(&ofn
, sizeof(ofn
));
583 ofn
.lStructSize
= sizeof(ofn
);
584 ofn
.hwndOwner
= hWnd
;
585 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
586 ofn
.lpstrFile
= file_path
;
587 ofn
.nMaxFile
= MAX_PATH
;
588 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
589 ofn
.lpstrDefExt
= TEXT("wav");
591 if (GetOpenFileName(&ofn
))
594 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
595 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
597 EnableWindow(slider
, TRUE
);
600 InvalidateRect(hWnd
, &text_rect
, TRUE
);
601 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
605 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
610 ZeroMemory(&ofn
, sizeof(ofn
));
612 ofn
.lStructSize
= sizeof(ofn
);
613 ofn
.hwndOwner
= hWnd
;
614 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
615 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
616 ofn
.lpstrFile
= file_path
;
617 ofn
.nMaxFile
= MAX_PATH
;
619 ofn
.lpstrDefExt
= TEXT("wav");
621 if (GetSaveFileName (&ofn
))
623 write_wav(file_path
);
624 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
629 case ID_EDIT_AUDIOPROPS
:
630 ShellExecute( NULL
, NULL
, _T("rundll32.exe"), _T("shell32.dll,Control_RunDLL mmsys.cpl,ShowAudioPropertySheet"), NULL
, SW_SHOWNORMAL
);
634 DestroyWindow( hWnd
);
637 /* Sndrec32 buttons routines */
639 AUD_BUF
->set_position_start();
641 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
649 if (wout_first
== false)
657 disable_but(BUTSTART_ID
);
658 disable_but(BUTEND_ID
);
659 disable_but(BUTREC_ID
);
660 disable_but(BUTPLAY_ID
);
662 SetTimer(hWnd
, 1, 250, 0);
663 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
672 AUD_IN
->stop_recording();
674 /* Resetting slider position */
676 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
678 samples_max
= AUD_BUF
->samples_received();
680 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
682 enable_but(BUTSTART_ID
);
683 enable_but(BUTEND_ID
);
684 enable_but(BUTREC_ID
);
685 enable_but(BUTPLAY_ID
);
687 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
688 EnableWindow(slider
, TRUE
);
694 InvalidateRect(hWnd
, &text_rect
, TRUE
);
695 InvalidateRect(wave_win
, 0, TRUE
);
702 enable_but(BUTSTART_ID
);
703 enable_but(BUTEND_ID
);
704 enable_but(BUTREC_ID
);
705 enable_but(BUTPLAY_ID
);
710 KillTimer(hWnd
, WAVEBAR_TIMERID
);
712 InvalidateRect(hWnd
, &text_rect
, TRUE
);
717 if (win_first
== false)
725 samples_max
= AUD_BUF
->total_samples();
727 AUD_IN
->start_recording();
729 enable_but(BUTSTOP_ID
);
731 disable_but(BUTSTART_ID
);
732 disable_but(BUTEND_ID
);
733 disable_but(BUTREC_ID
);
734 disable_but(BUTPLAY_ID
);
738 EnableWindow(slider
, FALSE
);
740 SetTimer(hWnd
, 1, 150, 0);
741 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
746 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
757 KillTimer(hWnd
, WAVEBAR_TIMERID
);
759 enable_but(BUTPLAY_ID
);
760 stopped_flag
= FALSE
;
763 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
764 InvalidateRect(hWnd
, &text_rect
, TRUE
);
767 case WAVEBAR_TIMERID
:
768 InvalidateRect(wave_win
, 0, TRUE
);
769 SendMessage(wave_win
, WM_USER
, 0, 0);
775 hdc
= BeginPaint(hWnd
, &ps
);
776 font
= CreateFontIndirect(&s_info
.lfMenuFont
);
777 SelectObject(hdc
, font
);
778 SetBkMode(hdc
, TRANSPARENT
);
780 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
785 (float)((float)AUD_BUF
->bytes_recorded() / (float)AUD_BUF
->audinfo().byte_rate()));
788 else if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
793 (float)((float)AUD_BUF
->bytes_played() / (float)AUD_BUF
->audinfo().byte_rate()));
800 (float)((((float)slider_pos
* (float)samples_max
) / (float)slider_max
) / (float)AUD_BUF
->audinfo().sample_rate()));
817 AUD_BUF
->fseconds_total());
824 AUD_BUF
->fseconds_recorded());
839 (float)((float)AUD_BUF
->mem_size() / 1024.0f
));
853 (float)((float)AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
854 AUD_BUF
->audinfo().bits(),
855 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
);
869 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
);
888 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
894 void l_play_finished(void)
898 enable_but(BUTSTART_ID
);
899 enable_but(BUTEND_ID
);
900 enable_but(BUTREC_ID
);
901 enable_but(BUTPLAY_ID
);
903 InvalidateRect(wave_win
, 0, TRUE
);
906 void l_audio_arrival(unsigned int samples_arrival
)
908 slider_pos
+= (DWORD
)((slider_max
* samples_arrival
) / samples_max
);
911 void l_buffer_resized(unsigned int new_size
)
915 VOID
enable_but(DWORD id
)
917 butdisabled
[id
] = FALSE
;
918 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[id
]);
921 VOID
disable_but(DWORD id
)
923 butdisabled
[id
] = TRUE
;
924 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps_dis
[id
]);
927 BOOL
open_wav(TCHAR
*f
)
937 DWORD bytes_recorded_in_wav
= 0;
945 FILE_ATTRIBUTE_NORMAL
,
950 TEXT("Cannot open file. CreateFile() error."),
952 MB_OK
| MB_ICONERROR
);
957 b
= ReadFile(file
, (LPVOID
)&r
, sizeof(r
), &is_read
, 0);
961 TEXT("Cannot read RIFF header."),
963 MB_OK
| MB_ICONERROR
);
969 b
= ReadFile(file
, (LPVOID
)&w
, sizeof(w
), &is_read
, 0);
973 TEXT("Cannot read WAVE header."),
975 MB_OK
| MB_ICONERROR
);
981 b
= ReadFile(file
, (LPVOID
)&d
, sizeof(d
), &is_read
, 0);
985 TEXT("Cannot read WAVE subchunk."),
987 MB_OK
| MB_ICONERROR
);
993 bytes_recorded_in_wav
= r
.chunksize
- 36;
994 if (bytes_recorded_in_wav
== 0)
997 TEXT("Cannot read file. No audio data."),
999 MB_OK
| MB_ICONERROR
);
1005 snd::audio_format
openfmt(w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1008 AUD_BUF
->alloc_bytes(bytes_recorded_in_wav
);
1011 (LPVOID
)AUD_BUF
->audio_buffer(),
1012 bytes_recorded_in_wav
,
1016 AUD_BUF
->set_b_received(bytes_recorded_in_wav
);
1018 if ((!b
) || (is_read
!= bytes_recorded_in_wav
))
1020 MessageBox(main_win
,
1021 TEXT("Cannot read file. Error reading audio data."),
1023 MB_OK
| MB_ICONERROR
);
1033 enable_but(BUTPLAY_ID
);
1034 enable_but(BUTSTOP_ID
);
1035 enable_but(BUTSTART_ID
);
1036 enable_but(BUTEND_ID
);
1037 enable_but(BUTREC_ID
);
1039 samples_max
= AUD_BUF
->samples_received();
1057 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0);
1060 i
= MessageBox(main_win
,
1061 TEXT("File already exist. Overwrite it?"),
1063 MB_YESNO
| MB_ICONQUESTION
);
1067 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1070 MessageBox(main_win
,
1071 TEXT("File Error, CreateFile() failed."),
1073 MB_OK
| MB_ICONERROR
);
1082 r
.magic
= 0x46464952;
1083 r
.format
= 0x45564157;
1084 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1086 w
.Subchunkid
= 0x20746d66;
1087 w
.Subchunk1Size
= 16;
1089 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1090 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1091 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1092 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1093 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1095 d
.subc
= 0x61746164;
1096 d
.subc_size
= AUD_BUF
->bytes_recorded();
1098 /* Writing headers */
1099 is_writ
= WriteFile(file
, (LPCVOID
)&r
, sizeof(r
), &written
, 0);
1102 MessageBox(main_win
,
1103 TEXT("File Error, WriteFile() failed."),
1105 MB_OK
| MB_ICONERROR
);
1111 is_writ
= WriteFile(file
, (LPCVOID
)&w
, sizeof(w
), &written
, 0);
1114 MessageBox(main_win
,
1115 TEXT("File Error, WriteFile() failed."),
1117 MB_OK
| MB_ICONERROR
);
1123 is_writ
= WriteFile(file
, (LPCVOID
)&d
, sizeof(d
), &written
, 0);
1126 MessageBox(main_win
,
1127 TEXT("File Error, WriteFile() failed."),
1129 MB_OK
| MB_ICONERROR
);
1135 is_writ
= WriteFile(file
,
1136 (LPCVOID
)AUD_BUF
->audio_buffer(),
1137 AUD_BUF
->bytes_recorded(),
1142 MessageBox(main_win
,
1143 TEXT("File Error, WriteFile() failed."),
1145 MB_OK
| MB_ICONERROR
);