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(main_win
, 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
= CreateWindowEx(WS_EX_STATICEDGE
,
321 TEXT("sndrec32_wave"),
323 WS_VISIBLE
| WS_CHILD
,
338 ShowWindow(hWnd
, nCmdShow
);
348 WndProc_wave(HWND hWnd
,
358 unsigned int max_h
= (cli
.bottom
/ 2);
359 unsigned int samples
;
360 unsigned int x
, line_h
;
365 GetClientRect(hWnd
, &cli
);
369 /* Initialize hdc objects */
370 hdc
= BeginPaint(hWnd
, &ps
);
371 pen
= (HPEN
)CreatePen(PS_SOLID
, 1, WAVEBAR_COLOR
);
372 oldpen
= (HPEN
) SelectObject(hdc
, (HBRUSH
)pen
);
373 if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
375 samples
= AUD_OUT
->tot_samples_buf();
376 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
378 x
= (i
* samples
) / WAVEBAR_CX
;
379 line_h
= (AUD_OUT
->nsample(x
) * max_h
) / AUD_OUT
->samplevalue_max();
382 MoveToEx(hdc
, i
, max_h
, 0);
383 LineTo(hdc
, i
, max_h
- (line_h
* 2));
384 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
388 SetPixel(hdc
, i
, max_h
, WAVEBAR_COLOR
);
392 else if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
394 samples
= AUD_IN
->tot_samples_buf();
395 for (unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
397 x
= (i
* samples
) / WAVEBAR_CX
;
398 line_h
= (AUD_IN
->nsample(x
) * max_h
) / AUD_IN
->samplevalue_max();
401 MoveToEx(hdc
, i
, max_h
, 0);
402 LineTo(hdc
, i
, max_h
- (line_h
* 2));
403 LineTo(hdc
, i
, max_h
+ (line_h
* 2));
407 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
413 /* In standby mode draw a simple line */
414 MoveToEx(hdc
, 0, cli
.bottom
/ 2, 0);
415 LineTo(hdc
, WAVEBAR_CX
, cli
.bottom
/ 2);
418 SelectObject(hdc
, oldpen
);
420 EndPaint( hWnd
, &ps
);
427 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
441 TCHAR str_tmp
[MAX_LOADSTRING
];
446 long long slid_samp
= 0;
448 /* Checking for global pointers to buffer and io audio devices */
449 if ((!AUD_IN
) || (!AUD_OUT
) || (!AUD_BUF
))
451 MessageBox(0, TEXT("Buffer Error"), 0, 0);
458 /* Creating the wave bar */
459 if (!InitInstance_wave(hWnd
, hInst
, SW_SHOWNORMAL
))
461 MessageBox(0, TEXT("CreateWindow() Error!"), TEXT("ERROR"), MB_ICONERROR
);
465 /* Creating ALL the buttons */
466 for (int i
= 0; i
< 5; ++i
)
468 buttons
[i
] = CreateWindow(TEXT("button"),
470 WS_CHILD
| WS_VISIBLE
| BS_BITMAP
,
471 BUTTONS_CX
+ (i
* (BUTTONS_W
+ ((i
== 0) ? 0 : BUTTONS_SPACE
))),
481 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
485 /* Realize the button bmp image */
486 SendMessage(buttons
[i
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[i
]);
487 UpdateWindow(buttons
[i
]);
491 /* Creating the SLIDER window */
492 slider
= CreateWindow(TRACKBAR_CLASS
,
494 WS_CHILD
| WS_VISIBLE
| TBS_NOTICKS
| TBS_HORZ
| TBS_ENABLESELRANGE
,
505 MessageBox(0, 0, TEXT( "CreateWindow() Error!" ), 0);
509 /* Sets slider limits */
513 (LPARAM
)MAKELONG(slider_min
, slider_max
));
515 UpdateWindow(slider
);
516 enable_but(BUTREC_ID
);
517 EnableWindow(slider
, FALSE
);
520 /* Implements slider logic */
523 switch (LOWORD(wParam
))
530 /* If the user touch the slider bar, set the
531 audio start position properly */
532 slider_pos
= SendMessage(slider
, TBM_GETPOS
, 0, 0);
533 slid_samp
= (__int64
)slider_pos
* (__int64
)samples_max
;
534 AUD_BUF
->set_position(AUD_BUF
->audinfo().bytes_in_samples((unsigned int)(slid_samp
/ (__int64
)slider_max
)));
535 InvalidateRect(hWnd
, &text_rect
, TRUE
);
542 wmId
= LOWORD(wParam
);
543 if ((wmId
>= 0) && (wmId
< 5) && (butdisabled
[wmId
] == TRUE
))
551 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
552 AUD_IN
->stop_recording();
554 if ((AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
555 (AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
560 enable_but(BUTREC_ID
);
561 disable_but(BUTSTART_ID
);
562 disable_but(BUTEND_ID
);
563 disable_but(BUTSTOP_ID
);
564 disable_but(BUTPLAY_ID
);
566 samples_max
= AUD_BUF
->total_samples();
569 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
571 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
572 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
577 ZeroMemory(file_path
, MAX_PATH
* sizeof(TCHAR
));
579 EnableWindow(slider
, FALSE
);
581 InvalidateRect(hWnd
, &text_rect
, TRUE
);
582 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
587 ZeroMemory(&ofn
, sizeof(ofn
));
589 ofn
.lStructSize
= sizeof(ofn
);
590 ofn
.hwndOwner
= hWnd
;
591 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
592 ofn
.lpstrFile
= file_path
;
593 ofn
.nMaxFile
= MAX_PATH
;
594 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
595 ofn
.lpstrDefExt
= TEXT("wav");
597 if (GetOpenFileName(&ofn
))
600 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
601 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
603 EnableWindow(slider
, TRUE
);
606 InvalidateRect(hWnd
, &text_rect
, TRUE
);
607 InvalidateRect(hWnd
, &text2_rect
, TRUE
);
611 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
616 ZeroMemory(&ofn
, sizeof(ofn
));
618 ofn
.lStructSize
= sizeof(ofn
);
619 ofn
.hwndOwner
= hWnd
;
620 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
621 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
622 ofn
.lpstrFile
= file_path
;
623 ofn
.nMaxFile
= MAX_PATH
;
625 ofn
.lpstrDefExt
= TEXT("wav");
627 if (GetSaveFileName (&ofn
))
629 write_wav(file_path
);
630 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
635 case ID_EDIT_AUDIOPROPS
:
636 ShellExecute(NULL
, NULL
, _T("rundll32.exe"), _T("shell32.dll,Control_RunDLL mmsys.cpl,ShowAudioPropertySheet"), NULL
, SW_SHOWNORMAL
);
643 /* Sndrec32 buttons routines */
645 AUD_BUF
->set_position_start();
647 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
655 if (wout_first
== false)
663 disable_but(BUTSTART_ID
);
664 disable_but(BUTEND_ID
);
665 disable_but(BUTREC_ID
);
666 disable_but(BUTPLAY_ID
);
668 SetTimer(hWnd
, 1, 250, 0);
669 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
678 AUD_IN
->stop_recording();
680 /* Resetting slider position */
682 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
684 samples_max
= AUD_BUF
->samples_received();
686 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
688 enable_but(BUTSTART_ID
);
689 enable_but(BUTEND_ID
);
690 enable_but(BUTREC_ID
);
691 enable_but(BUTPLAY_ID
);
693 EnableMenuItem(GetMenu(hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
694 EnableWindow(slider
, TRUE
);
700 InvalidateRect(hWnd
, &text_rect
, TRUE
);
701 InvalidateRect(wave_win
, 0, TRUE
);
708 enable_but(BUTSTART_ID
);
709 enable_but(BUTEND_ID
);
710 enable_but(BUTREC_ID
);
711 enable_but(BUTPLAY_ID
);
716 KillTimer(hWnd
, WAVEBAR_TIMERID
);
718 InvalidateRect(hWnd
, &text_rect
, TRUE
);
723 if (win_first
== false)
731 samples_max
= AUD_BUF
->total_samples();
733 AUD_IN
->start_recording();
735 enable_but(BUTSTOP_ID
);
737 disable_but(BUTSTART_ID
);
738 disable_but(BUTEND_ID
);
739 disable_but(BUTREC_ID
);
740 disable_but(BUTPLAY_ID
);
744 EnableWindow(slider
, FALSE
);
746 SetTimer(hWnd
, 1, 150, 0);
747 SetTimer(hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0);
752 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
763 KillTimer(hWnd
, WAVEBAR_TIMERID
);
765 enable_but(BUTPLAY_ID
);
766 stopped_flag
= FALSE
;
769 SendMessage(slider
, TBM_SETPOS
, (WPARAM
)TRUE
, (LPARAM
)slider_pos
);
770 InvalidateRect(hWnd
, &text_rect
, TRUE
);
773 case WAVEBAR_TIMERID
:
774 InvalidateRect(wave_win
, 0, TRUE
);
775 SendMessage(wave_win
, WM_USER
, 0, 0);
781 hdc
= BeginPaint(hWnd
, &ps
);
782 font
= CreateFontIndirect(&s_info
.lfMenuFont
);
783 oldfont
= (HFONT
) SelectObject(hdc
, font
);
784 SetBkMode(hdc
, TRANSPARENT
);
786 if (AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
791 (float)((float)AUD_BUF
->bytes_recorded() / (float)AUD_BUF
->audinfo().byte_rate()));
794 else if (AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
799 (float)((float)AUD_BUF
->bytes_played() / (float)AUD_BUF
->audinfo().byte_rate()));
806 (float)((((float)slider_pos
* (float)samples_max
) / (float)slider_max
) / (float)AUD_BUF
->audinfo().sample_rate()));
823 AUD_BUF
->fseconds_total());
830 AUD_BUF
->fseconds_recorded());
845 (float)((float)AUD_BUF
->mem_size() / 1024.0f
));
859 (float)((float)AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
860 AUD_BUF
->audinfo().bits(),
861 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
);
875 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
);
886 SelectObject(hdc
, oldfont
);
895 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
901 void l_play_finished(void)
905 enable_but(BUTSTART_ID
);
906 enable_but(BUTEND_ID
);
907 enable_but(BUTREC_ID
);
908 enable_but(BUTPLAY_ID
);
910 InvalidateRect(wave_win
, 0, TRUE
);
913 void l_audio_arrival(unsigned int samples_arrival
)
915 slider_pos
+= (DWORD
)((slider_max
* samples_arrival
) / samples_max
);
918 void l_buffer_resized(unsigned int new_size
)
922 VOID
enable_but(DWORD id
)
924 butdisabled
[id
] = FALSE
;
925 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps
[id
]);
928 VOID
disable_but(DWORD id
)
930 butdisabled
[id
] = TRUE
;
931 SendMessage(buttons
[id
], BM_SETIMAGE
, (WPARAM
)IMAGE_BITMAP
, (LPARAM
)butbmps_dis
[id
]);
934 BOOL
open_wav(TCHAR
*f
)
944 DWORD bytes_recorded_in_wav
= 0;
952 FILE_ATTRIBUTE_NORMAL
,
957 TEXT("Cannot open file. CreateFile() error."),
959 MB_OK
| MB_ICONERROR
);
964 b
= ReadFile(file
, (LPVOID
)&r
, sizeof(r
), &is_read
, 0);
968 TEXT("Cannot read RIFF header."),
970 MB_OK
| MB_ICONERROR
);
976 b
= ReadFile(file
, (LPVOID
)&w
, sizeof(w
), &is_read
, 0);
980 TEXT("Cannot read WAVE header."),
982 MB_OK
| MB_ICONERROR
);
988 b
= ReadFile(file
, (LPVOID
)&d
, sizeof(d
), &is_read
, 0);
992 TEXT("Cannot read WAVE subchunk."),
994 MB_OK
| MB_ICONERROR
);
1000 bytes_recorded_in_wav
= r
.chunksize
- 36;
1001 if (bytes_recorded_in_wav
== 0)
1003 MessageBox(main_win
,
1004 TEXT("Cannot read file. No audio data."),
1006 MB_OK
| MB_ICONERROR
);
1012 snd::audio_format
openfmt(w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1015 AUD_BUF
->alloc_bytes(bytes_recorded_in_wav
);
1018 (LPVOID
)AUD_BUF
->audio_buffer(),
1019 bytes_recorded_in_wav
,
1023 AUD_BUF
->set_b_received(bytes_recorded_in_wav
);
1025 if ((!b
) || (is_read
!= bytes_recorded_in_wav
))
1027 MessageBox(main_win
,
1028 TEXT("Cannot read file. Error reading audio data."),
1030 MB_OK
| MB_ICONERROR
);
1040 enable_but(BUTPLAY_ID
);
1041 enable_but(BUTSTOP_ID
);
1042 enable_but(BUTSTART_ID
);
1043 enable_but(BUTEND_ID
);
1044 enable_but(BUTREC_ID
);
1046 samples_max
= AUD_BUF
->samples_received();
1064 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0);
1067 i
= MessageBox(main_win
,
1068 TEXT("File already exist. Overwrite it?"),
1070 MB_YESNO
| MB_ICONQUESTION
);
1074 file
= CreateFile(f
, GENERIC_WRITE
, 0, 0, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1077 MessageBox(main_win
,
1078 TEXT("File Error, CreateFile() failed."),
1080 MB_OK
| MB_ICONERROR
);
1089 r
.magic
= 0x46464952;
1090 r
.format
= 0x45564157;
1091 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1093 w
.Subchunkid
= 0x20746d66;
1094 w
.Subchunk1Size
= 16;
1096 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1097 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1098 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1099 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1100 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1102 d
.subc
= 0x61746164;
1103 d
.subc_size
= AUD_BUF
->bytes_recorded();
1105 /* Writing headers */
1106 is_writ
= WriteFile(file
, (LPCVOID
)&r
, sizeof(r
), &written
, 0);
1109 MessageBox(main_win
,
1110 TEXT("File Error, WriteFile() failed."),
1112 MB_OK
| MB_ICONERROR
);
1118 is_writ
= WriteFile(file
, (LPCVOID
)&w
, sizeof(w
), &written
, 0);
1121 MessageBox(main_win
,
1122 TEXT("File Error, WriteFile() failed."),
1124 MB_OK
| MB_ICONERROR
);
1130 is_writ
= WriteFile(file
, (LPCVOID
)&d
, sizeof(d
), &written
, 0);
1133 MessageBox(main_win
,
1134 TEXT("File Error, WriteFile() failed."),
1136 MB_OK
| MB_ICONERROR
);
1142 is_writ
= WriteFile(file
,
1143 (LPCVOID
)AUD_BUF
->audio_buffer(),
1144 AUD_BUF
->bytes_recorded(),
1149 MessageBox(main_win
,
1150 TEXT("File Error, WriteFile() failed."),
1152 MB_OK
| MB_ICONERROR
);