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)
9 #define gprintf _snprintf
11 #define gprintf _snwprintf
22 TCHAR szTitle
[MAX_LOADSTRING
];
23 TCHAR szWindowClass
[MAX_LOADSTRING
];
26 ATOM
MyRegisterClass( HINSTANCE hInstance
);
27 ATOM
MyRegisterClass_wave( HINSTANCE hInstance
);
28 BOOL
InitInstance( HINSTANCE
, int );
29 BOOL
InitInstance_wave( HWND
, HINSTANCE
, int );
30 LRESULT CALLBACK
WndProc( HWND
, UINT
, WPARAM
, LPARAM
);
31 LRESULT CALLBACK
WndProc_wave( HWND
, UINT
, WPARAM
, LPARAM
);
32 INT_PTR CALLBACK
About( HWND
, UINT
, WPARAM
, LPARAM
);
34 BOOL win_first
, wout_first
;
41 HBITMAP butbmps_dis
[5];
42 WNDPROC buttons_std_proc
;
57 TCHAR file_path
[MAX_PATH
];
58 TCHAR str_pos
[MAX_LOADSTRING
];
59 TCHAR str_dur
[MAX_LOADSTRING
];
60 TCHAR str_buf
[MAX_LOADSTRING
];
61 TCHAR str_fmt
[MAX_LOADSTRING
];
62 TCHAR str_chan
[MAX_LOADSTRING
];
69 snd::audio_membuffer
* AUD_BUF
;
70 snd::audio_waveout
* AUD_OUT
;
71 snd::audio_wavein
* AUD_IN
;
77 NONCLIENTMETRICS s_info
;
88 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
89 HINSTANCE hPrevInstance
,
94 UNREFERENCED_PARAMETER(hPrevInstance
);
95 UNREFERENCED_PARAMETER(lpCmdLine
);
101 s_info
.cbSize
= sizeof( NONCLIENTMETRICS
);
103 InitCommonControls();
105 win_first
= wout_first
= FALSE
;
107 text_rect
.left
= REFRESHA_X
;
108 text_rect
.top
= REFRESHA_Y
;
109 text_rect
.right
= REFRESHA_CX
;
110 text_rect
.bottom
= REFRESHA_CY
;
112 text2_rect
.left
= REFRESHB_X
;
113 text2_rect
.top
= REFRESHB_Y
;
114 text2_rect
.right
= REFRESHB_CX
;
115 text2_rect
.bottom
= REFRESHB_CY
;
118 // Retrieving defaul system font, and others
119 // system informations.
122 SystemParametersInfo(
123 SPI_GETNONCLIENTMETRICS
,
124 sizeof( NONCLIENTMETRICS
),
133 s_info
.lfMenuFont
.lfHeight
= 14;
136 // Inits buttons bitmaps
139 butbmps
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START
));
140 butbmps
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END
));
141 butbmps
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY
));
142 butbmps
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP
));
143 butbmps
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC
));
145 butbmps_dis
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS
));
146 butbmps_dis
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS
));
147 butbmps_dis
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS
));
148 butbmps_dis
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS
));
149 butbmps_dis
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS
));
154 // Inits audio devices and buffers
157 snd::audio_membuffer
AUD_buffer( snd::A44100_16BIT_STEREO
);
158 snd::audio_waveout
AUD_waveout( snd::A44100_16BIT_STEREO
, AUD_buffer
);
159 snd::audio_wavein
AUD_wavein( snd::A44100_16BIT_STEREO
, AUD_buffer
);
161 AUD_buffer
.play_finished
= l_play_finished
;
162 AUD_buffer
.audio_arrival
= l_audio_arrival
;
163 AUD_buffer
.buffer_resized
= l_buffer_resized
;
165 AUD_buffer
.alloc_seconds( INITIAL_BUFREC_SECONDS
);
167 AUD_IN
= &AUD_wavein
;
168 AUD_OUT
= &AUD_waveout
;
169 AUD_BUF
= &AUD_buffer
;
172 // Inits slider default parameters
177 slider_max
= SLIDER_W
;
180 stopped_flag
= FALSE
;
185 samples_max
= AUD_buffer
.total_samples();
193 LoadString( hInstance
,
194 IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
196 LoadString( hInstance
,
197 IDC_REACTOS_SNDREC32
, szWindowClass
, MAX_LOADSTRING
);
200 LoadString( hInstance
,
201 IDS_STRPOS
, str_pos
, MAX_LOADSTRING
);
204 LoadString( hInstance
,
205 IDS_STRDUR
, str_dur
, MAX_LOADSTRING
);
207 LoadString( hInstance
,
208 IDS_STRBUF
, str_buf
, MAX_LOADSTRING
);
210 LoadString( hInstance
,
211 IDS_STRFMT
, str_fmt
, MAX_LOADSTRING
);
213 LoadString( hInstance
,
214 IDS_STRCHAN
, str_chan
, MAX_LOADSTRING
);
216 LoadString( hInstance
,
217 IDS_STRMONO
, str_mono
, 10 );
219 LoadString( hInstance
,
220 IDS_STRSTEREO
, str_stereo
, 10 );
224 // Registers sndrec32 window class
227 MyRegisterClass( hInstance
);
229 MyRegisterClass_wave( hInstance
);
232 if ( !InitInstance( hInstance
, nCmdShow
))
234 MessageBox( 0, TEXT( "CreateWindow() Error!" ), TEXT( "ERROR" ), MB_ICONERROR
);
239 // Loads key accelerators
242 hAccelTable
= LoadAccelerators(hInstance
,
243 MAKEINTRESOURCE( IDC_REACTOS_SNDREC32
));
251 while ( GetMessage( &msg
, NULL
, 0, 0 ))
253 if ( !TranslateAccelerator( msg
.hwnd
, hAccelTable
, &msg
))
255 TranslateMessage( &msg
);
256 DispatchMessage( &msg
);
275 return ( int )msg
.wParam
;
282 MyRegisterClass( HINSTANCE hInstance
)
286 wcex
.cbSize
= sizeof(WNDCLASSEX
);
288 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
289 wcex
.lpfnWndProc
= WndProc
;
292 wcex
.hInstance
= hInstance
;
293 wcex
.hIcon
= LoadIcon( hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
294 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
295 wcex
.hbrBackground
= (HBRUSH
)( 16 );
296 wcex
.lpszMenuName
= MAKEINTRESOURCE( IDR_MENU1
);
297 wcex
.lpszClassName
= szWindowClass
;
298 wcex
.hIconSm
= LoadIcon( wcex
.hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
301 return RegisterClassEx( &wcex
);
305 InitInstance( HINSTANCE hInstance
, int nCmdShow
)
314 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
328 ShowWindow(hWnd
, nCmdShow
);
342 MyRegisterClass_wave( HINSTANCE hInstance
)
346 wcex
.cbSize
= sizeof( WNDCLASSEX
);
348 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
349 wcex
.lpfnWndProc
= WndProc_wave
;
352 wcex
.hInstance
= hInstance
;
354 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
355 wcex
.hbrBackground
= ( HBRUSH
)GetStockObject( BLACK_BRUSH
);
356 wcex
.lpszMenuName
= 0;
357 wcex
.lpszClassName
= TEXT( "sndrec32_wave" );
361 return RegisterClassEx( &wcex
);
365 InitInstance_wave( HWND f
, HINSTANCE hInstance
, int nCmdShow
)
372 TEXT( "sndrec32_wave" ),
374 WS_DLGFRAME
|WS_VISIBLE
|WS_CHILD
,
388 ShowWindow( hWnd
, nCmdShow
);
389 UpdateWindow( hWnd
);
399 WndProc_wave( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
407 unsigned int max_h
= ( cli
.bottom
/ 2 );
408 unsigned int samples
;
409 unsigned int x
, line_h
;
420 GetClientRect( hWnd
, &cli
);
428 // Initialize hdc objects
431 hdc
= BeginPaint( hWnd
, &ps
);
433 pen
= ( HPEN
) CreatePen( PS_SOLID
, 1, WAVEBAR_COLOR
);
435 SelectObject( hdc
, ( HBRUSH
)pen
);
437 if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
440 samples
= AUD_OUT
->tot_samples_buf();
443 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
446 x
= ( i
* samples
) / WAVEBAR_CX
;
448 line_h
= ( abs(AUD_OUT
->nsample( x
)) * max_h
) / AUD_OUT
->samplevalue_max();
453 MoveToEx( hdc
, i
, max_h
, 0 );
454 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
455 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
457 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
462 } else if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
) {
465 samples
= AUD_IN
->tot_samples_buf();
468 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
471 x
= ( i
* samples
) / WAVEBAR_CX
;
473 line_h
= ( AUD_IN
->nsample( x
) * max_h
) / AUD_IN
->samplevalue_max();
478 MoveToEx( hdc
, i
, max_h
, 0 );
479 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
480 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
482 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
490 // In standby mode draw a simple line.
493 MoveToEx( hdc
, 0, cli
.bottom
/ 2, 0 );
494 LineTo( hdc
, WAVEBAR_CX
, cli
.bottom
/ 2 );
501 EndPaint( hWnd
, &ps
);
513 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
526 WndProc( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
529 TCHAR str_tmp
[MAX_LOADSTRING
];
533 long long slid_samp
= 0;
538 // Checking for global pointers to buffer and
542 if (( !AUD_IN
) || ( !AUD_OUT
) || ( !AUD_BUF
))
544 MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
557 // Creating the wave bar
560 if ( !InitInstance_wave( hWnd
, hInst
, SW_SHOWNORMAL
))
564 TEXT( "CreateWindow() Error!" ),
576 // Creating ALL the buttons
579 for ( int i
= 0; i
< 5; ++ i
)
582 buttons
[i
] = CreateWindow(
585 WS_CHILD
|WS_VISIBLE
|BS_BITMAP
,
586 BUTTONS_CX
+ ( i
* (BUTTONS_W
+((i
== 0)?0:BUTTONS_SPACE
))),
587 BUTTONS_CY
, BUTTONS_W
, BUTTONS_H
, hWnd
,
593 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
600 // Realize the button bmp image
603 SendMessage(buttons
[i
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[i
]);
605 UpdateWindow( buttons
[i
] );
613 // Creating the SLIDER window
616 slider
= CreateWindow(
619 WS_CHILD
|WS_VISIBLE
|TBS_NOTICKS
|TBS_HORZ
|TBS_ENABLESELRANGE
,
620 SLIDER_CX
, SLIDER_CY
, SLIDER_W
, SLIDER_H
, hWnd
,
621 ( HMENU
)SLIDER_ID
, hInst
, 0
627 MessageBox( 0, 0, TEXT( "CreateWindow() Error!" ), 0 );
634 // Sets slider limits
642 ( LPARAM
)MAKELONG( slider_min
, slider_max
)
646 UpdateWindow( slider
);
648 enable_but( BUTREC_ID
);
650 EnableWindow( slider
, FALSE
);
660 // Implements slider logic
665 switch( LOWORD( wParam
))
677 // If the user touch the slider bar,
678 // set the audio start position properly
682 slider_pos
= SendMessage( slider
, TBM_GETPOS
, 0, 0 );
684 slid_samp
= ( __int64
)slider_pos
* ( __int64
)samples_max
;
686 AUD_BUF
->set_position(
687 AUD_BUF
->audinfo().bytes_in_samples(
688 ( unsigned int )( slid_samp
/ ( __int64
)slider_max
)
692 InvalidateRect( hWnd
, &text_rect
, TRUE
);
709 wmId
= LOWORD( wParam
);
710 wmEvent
= HIWORD( wParam
);
712 if (( wmId
>= 0 ) && ( wmId
< 5 ) && ( butdisabled
[wmId
] == TRUE
))
723 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
724 AUD_IN
->stop_recording();
727 if (( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
728 ( AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
734 enable_but( BUTREC_ID
);
735 disable_but( BUTSTART_ID
);
736 disable_but( BUTEND_ID
);
737 disable_but( BUTSTOP_ID
);
738 disable_but( BUTPLAY_ID
);
741 samples_max
= AUD_BUF
->total_samples();
744 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
746 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
747 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
752 ZeroMemory( file_path
, MAX_PATH
);
754 EnableWindow( slider
, FALSE
);
756 InvalidateRect( hWnd
, &text_rect
, TRUE
);
757 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
770 ZeroMemory( &ofn
, sizeof( ofn
));
772 ofn
.lStructSize
= sizeof( ofn
);
773 ofn
.hwndOwner
= hWnd
;
774 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
775 ofn
.lpstrFile
= file_path
;
776 ofn
.nMaxFile
= MAX_PATH
;
777 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
778 ofn
.lpstrDefExt
= TEXT("wav");
780 if( GetOpenFileName( &ofn
))
782 open_wav( file_path
);
783 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
784 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
786 EnableWindow( slider
, TRUE
);
790 InvalidateRect( hWnd
, &text_rect
, TRUE
);
791 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
807 ZeroMemory( &ofn
, sizeof( ofn
));
809 ofn
.lStructSize
= sizeof( ofn
);
810 ofn
.hwndOwner
= hWnd
;
811 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
812 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
813 ofn
.lpstrFile
= file_path
;
814 ofn
.nMaxFile
= MAX_PATH
;
816 ofn
.lpstrDefExt
= TEXT("wav");
818 if ( GetSaveFileName ( &ofn
))
820 write_wav( file_path
);
822 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
828 DestroyWindow( hWnd
);
833 // Sndrec32 buttons routines
838 AUD_BUF
->set_position_start();
842 SendMessage( slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
848 DestroyWindow( hWnd
);
853 if ( wout_first
== false )
862 disable_but( BUTSTART_ID
);
863 disable_but( BUTEND_ID
);
864 disable_but( BUTREC_ID
);
865 disable_but( BUTPLAY_ID
);
868 SetTimer( hWnd
, 1, 250, 0 );
869 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
878 AUD_IN
->stop_recording();
883 // Resetting slider position
887 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
890 samples_max
= AUD_BUF
->samples_received();
892 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
895 enable_but( BUTSTART_ID
);
896 enable_but( BUTEND_ID
);
897 enable_but( BUTREC_ID
);
898 enable_but( BUTPLAY_ID
);
900 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
901 EnableWindow( slider
, TRUE
);
907 InvalidateRect( hWnd
, &text_rect
, TRUE
);
908 InvalidateRect( wave_win
, 0, TRUE
);
915 enable_but( BUTSTART_ID
);
916 enable_but( BUTEND_ID
);
917 enable_but( BUTREC_ID
);
918 enable_but( BUTPLAY_ID
);
922 KillTimer( hWnd
, 1 );
923 KillTimer( hWnd
, WAVEBAR_TIMERID
);
925 InvalidateRect( hWnd
, &text_rect
, TRUE
);
931 if ( win_first
== false )
939 samples_max
= AUD_BUF
->total_samples();
941 AUD_IN
->start_recording();
943 enable_but( BUTSTOP_ID
);
945 disable_but( BUTSTART_ID
);
946 disable_but( BUTEND_ID
);
947 disable_but( BUTREC_ID
);
948 disable_but( BUTPLAY_ID
);
952 EnableWindow( slider
, FALSE
);
954 SetTimer( hWnd
, 1, 150, 0 );
956 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
962 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
975 KillTimer( hWnd
, 1 );
976 KillTimer( hWnd
, WAVEBAR_TIMERID
);
979 enable_but( BUTPLAY_ID
);
981 stopped_flag
= FALSE
;
990 ( LPARAM
) slider_pos
993 InvalidateRect( hWnd
, &text_rect
, TRUE
);
998 case WAVEBAR_TIMERID
:
999 InvalidateRect( wave_win
, 0, TRUE
);
1000 SendMessage( wave_win
, WM_USER
, 0, 0 );
1012 hdc
= BeginPaint(hWnd
, &ps
);
1015 font
= CreateFontIndirect( &s_info
.lfMenuFont
);
1018 SelectObject( hdc
, font
);
1020 SetBkMode( hdc
, TRANSPARENT
);
1023 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
1029 ( float )(( float )AUD_BUF
->bytes_recorded( ) / ( float )AUD_BUF
->audinfo().byte_rate( ))
1032 } else if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) {
1038 ( float )(( float )AUD_BUF
->bytes_played() / ( float )AUD_BUF
->audinfo().byte_rate( ))
1047 ( float )(((( float )slider_pos
* ( float )samples_max
) / ( float )slider_max
) / ( float )AUD_BUF
->audinfo().sample_rate())
1052 ExtTextOut( hdc
, STRPOS_X
, STRPOS_Y
, ETO_OPAQUE
,
1053 0, str_tmp
, _tcslen( str_tmp
), 0 );
1059 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1060 AUD_BUF
->fseconds_total( ));
1065 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1066 AUD_BUF
->fseconds_recorded( ));
1071 ExtTextOut( hdc
, STRDUR_X
, STRDUR_Y
, ETO_OPAQUE
,
1072 0, str_tmp
, _tcslen( str_tmp
), 0 );
1080 ( float )(( float )AUD_BUF
->mem_size() / 1024.0f
)
1084 ExtTextOut( hdc
, STRBUF_X
, STRBUF_Y
, ETO_OPAQUE
,
1085 0, str_tmp
, _tcslen( str_tmp
), 0 );
1093 ( float )(( float )AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
1094 AUD_BUF
->audinfo().bits(),
1095 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
1099 ExtTextOut( hdc
, STRFMT_X
, STRFMT_Y
, ETO_OPAQUE
,
1100 0, str_tmp
, _tcslen( str_tmp
), 0 );
1108 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
1112 ExtTextOut( hdc
, STRCHAN_X
, STRCHAN_Y
, ETO_OPAQUE
,
1113 0, str_tmp
, _tcslen( str_tmp
), 0 );
1117 DeleteObject( font
);
1119 EndPaint(hWnd
, &ps
);
1131 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
1140 void l_play_finished ( void )
1143 stopped_flag
= true;
1146 enable_but( BUTSTART_ID
);
1147 enable_but( BUTEND_ID
);
1148 enable_but( BUTREC_ID
);
1149 enable_but( BUTPLAY_ID
);
1151 InvalidateRect( wave_win
, 0, TRUE
);
1155 void l_audio_arrival ( unsigned int samples_arrival
)
1159 slider_pos
+= ( DWORD
) (( slider_max
* samples_arrival
) / samples_max
);
1164 void l_buffer_resized ( unsigned int new_size
)
1173 VOID
enable_but( DWORD id
)
1176 butdisabled
[ id
] = FALSE
;
1178 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[ id
]);
1182 VOID
disable_but( DWORD id
)
1185 butdisabled
[ id
] = TRUE
;
1187 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps_dis
[ id
]);
1206 BOOL
open_wav( TCHAR
* f
)
1218 DWORD bytes_recorded_in_wav
= 0;
1227 FILE_ATTRIBUTE_NORMAL
,
1237 TEXT("Cannot open file. CreateFile() error."),
1246 b
= ReadFile( file
, ( LPVOID
) &r
, sizeof ( r
), &is_read
, 0 );
1252 TEXT("Cannot read RIFF header."),
1257 CloseHandle( file
);
1262 b
= ReadFile( file
, ( LPVOID
) &w
, sizeof ( w
), &is_read
, 0 );
1269 TEXT("Cannot read WAVE header."),
1274 CloseHandle( file
);
1280 b
= ReadFile( file
, ( LPVOID
) &d
, sizeof ( d
), &is_read
, 0 );
1286 TEXT("Cannot read WAVE subchunk."),
1291 CloseHandle( file
);
1295 bytes_recorded_in_wav
= r
.chunksize
- 36;
1298 if ( bytes_recorded_in_wav
== 0 )
1302 TEXT("Cannot read file. No audio data."),
1307 CloseHandle( file
);
1312 snd::audio_format openfmt
1313 ( w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1320 AUD_BUF
->alloc_bytes( bytes_recorded_in_wav
);
1325 ( LPVOID
) AUD_BUF
->audio_buffer(),
1326 bytes_recorded_in_wav
,
1332 AUD_BUF
->set_b_received( bytes_recorded_in_wav
);
1335 if (( !b
) || ( is_read
!= bytes_recorded_in_wav
))
1339 TEXT("Cannot read file. Error reading audio data."),
1344 CloseHandle( file
);
1350 CloseHandle( file
);
1352 enable_but( BUTPLAY_ID
);
1353 enable_but( BUTSTOP_ID
);
1354 enable_but( BUTSTART_ID
);
1355 enable_but( BUTEND_ID
);
1356 enable_but( BUTREC_ID
);
1359 samples_max
= AUD_BUF
->samples_received();
1369 write_wav( TCHAR
* f
)
1389 FILE_ATTRIBUTE_NORMAL
,
1399 TEXT("File already exist. Overwrite it?"),
1401 MB_YESNO
|MB_ICONQUESTION
1412 FILE_ATTRIBUTE_NORMAL
,
1420 TEXT("File Error, CreateFile() failed."),
1438 r
.magic
= 0x46464952;
1441 r
.format
= 0x45564157;
1442 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1445 w
.Subchunkid
= 0x20746d66;
1447 w
.Subchunk1Size
= 16;
1449 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1450 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1451 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1452 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1453 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1456 d
.subc
= 0x61746164;
1457 d
.subc_size
= AUD_BUF
->bytes_recorded();
1466 is_writ
= WriteFile( file
, ( LPCVOID
) &r
, sizeof ( r
), &written
, 0 );
1472 TEXT("File Error, WriteFile() failed."),
1477 CloseHandle( file
);
1484 is_writ
= WriteFile( file
, ( LPCVOID
) &w
, sizeof ( w
), &written
, 0 );
1490 TEXT("File Error, WriteFile() failed."),
1495 CloseHandle( file
);
1502 is_writ
= WriteFile( file
, ( LPCVOID
) &d
, sizeof ( d
), &written
, 0 );
1509 TEXT("File Error, WriteFile() failed."),
1514 CloseHandle( file
);
1522 is_writ
= WriteFile(
1524 ( LPCVOID
) AUD_BUF
->audio_buffer(),
1525 AUD_BUF
->bytes_recorded(),
1534 TEXT("File Error, WriteFile() failed."),
1539 CloseHandle( file
);
1546 CloseHandle( file
);