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
);
33 BOOL win_first
, wout_first
;
40 HBITMAP butbmps_dis
[5];
41 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
;
76 NONCLIENTMETRICS s_info
;
84 INT_PTR CALLBACK
AboutDlgProc(HWND hWnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
105 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
106 HINSTANCE hPrevInstance
,
111 UNREFERENCED_PARAMETER(hPrevInstance
);
112 UNREFERENCED_PARAMETER(lpCmdLine
);
118 s_info
.cbSize
= sizeof( NONCLIENTMETRICS
);
120 InitCommonControls();
122 win_first
= wout_first
= FALSE
;
124 text_rect
.left
= REFRESHA_X
;
125 text_rect
.top
= REFRESHA_Y
;
126 text_rect
.right
= REFRESHA_CX
;
127 text_rect
.bottom
= REFRESHA_CY
;
129 text2_rect
.left
= REFRESHB_X
;
130 text2_rect
.top
= REFRESHB_Y
;
131 text2_rect
.right
= REFRESHB_CX
;
132 text2_rect
.bottom
= REFRESHB_CY
;
135 // Retrieving defaul system font, and others
136 // system informations.
139 SystemParametersInfo(
140 SPI_GETNONCLIENTMETRICS
,
141 sizeof( NONCLIENTMETRICS
),
150 s_info
.lfMenuFont
.lfHeight
= 14;
153 // Inits buttons bitmaps
156 butbmps
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START
));
157 butbmps
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END
));
158 butbmps
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY
));
159 butbmps
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP
));
160 butbmps
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC
));
162 butbmps_dis
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS
));
163 butbmps_dis
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS
));
164 butbmps_dis
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS
));
165 butbmps_dis
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS
));
166 butbmps_dis
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS
));
171 // Inits audio devices and buffers
174 snd::audio_membuffer
AUD_buffer( snd::A44100_16BIT_STEREO
);
175 snd::audio_waveout
AUD_waveout( snd::A44100_16BIT_STEREO
, AUD_buffer
);
176 snd::audio_wavein
AUD_wavein( snd::A44100_16BIT_STEREO
, AUD_buffer
);
178 AUD_buffer
.play_finished
= l_play_finished
;
179 AUD_buffer
.audio_arrival
= l_audio_arrival
;
180 AUD_buffer
.buffer_resized
= l_buffer_resized
;
182 AUD_buffer
.alloc_seconds( INITIAL_BUFREC_SECONDS
);
184 AUD_IN
= &AUD_wavein
;
185 AUD_OUT
= &AUD_waveout
;
186 AUD_BUF
= &AUD_buffer
;
189 // Inits slider default parameters
194 slider_max
= SLIDER_W
;
197 stopped_flag
= FALSE
;
202 samples_max
= AUD_buffer
.total_samples();
210 LoadString( hInstance
,
211 IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
213 LoadString( hInstance
,
214 IDC_REACTOS_SNDREC32
, szWindowClass
, MAX_LOADSTRING
);
217 LoadString( hInstance
,
218 IDS_STRPOS
, str_pos
, MAX_LOADSTRING
);
221 LoadString( hInstance
,
222 IDS_STRDUR
, str_dur
, MAX_LOADSTRING
);
224 LoadString( hInstance
,
225 IDS_STRBUF
, str_buf
, MAX_LOADSTRING
);
227 LoadString( hInstance
,
228 IDS_STRFMT
, str_fmt
, MAX_LOADSTRING
);
230 LoadString( hInstance
,
231 IDS_STRCHAN
, str_chan
, MAX_LOADSTRING
);
233 LoadString( hInstance
,
234 IDS_STRMONO
, str_mono
, 10 );
236 LoadString( hInstance
,
237 IDS_STRSTEREO
, str_stereo
, 10 );
241 // Registers sndrec32 window class
244 MyRegisterClass( hInstance
);
246 MyRegisterClass_wave( hInstance
);
249 if ( !InitInstance( hInstance
, nCmdShow
))
251 MessageBox( 0, TEXT( "CreateWindow() Error!" ), TEXT( "ERROR" ), MB_ICONERROR
);
256 // Loads key accelerators
259 hAccelTable
= LoadAccelerators(hInstance
,
260 MAKEINTRESOURCE( IDC_REACTOS_SNDREC32
));
268 while ( GetMessage( &msg
, NULL
, 0, 0 ))
270 if ( !TranslateAccelerator( msg
.hwnd
, hAccelTable
, &msg
))
272 TranslateMessage( &msg
);
273 DispatchMessage( &msg
);
292 return ( int )msg
.wParam
;
299 MyRegisterClass( HINSTANCE hInstance
)
303 wcex
.cbSize
= sizeof(WNDCLASSEX
);
305 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
306 wcex
.lpfnWndProc
= WndProc
;
309 wcex
.hInstance
= hInstance
;
310 wcex
.hIcon
= LoadIcon( hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
311 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
312 wcex
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
313 wcex
.lpszMenuName
= MAKEINTRESOURCE( IDR_MENU1
);
314 wcex
.lpszClassName
= szWindowClass
;
315 wcex
.hIconSm
= LoadIcon( wcex
.hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
318 return RegisterClassEx( &wcex
);
322 InitInstance( HINSTANCE hInstance
, int nCmdShow
)
331 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
345 ShowWindow(hWnd
, nCmdShow
);
359 MyRegisterClass_wave( HINSTANCE hInstance
)
363 wcex
.cbSize
= sizeof( WNDCLASSEX
);
365 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
366 wcex
.lpfnWndProc
= WndProc_wave
;
369 wcex
.hInstance
= hInstance
;
371 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
372 wcex
.hbrBackground
= ( HBRUSH
)GetStockObject( BLACK_BRUSH
);
373 wcex
.lpszMenuName
= 0;
374 wcex
.lpszClassName
= TEXT( "sndrec32_wave" );
378 return RegisterClassEx( &wcex
);
382 InitInstance_wave( HWND f
, HINSTANCE hInstance
, int nCmdShow
)
389 TEXT( "sndrec32_wave" ),
391 WS_DLGFRAME
|WS_VISIBLE
|WS_CHILD
,
405 ShowWindow( hWnd
, nCmdShow
);
406 UpdateWindow( hWnd
);
416 WndProc_wave( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
424 unsigned int max_h
= ( cli
.bottom
/ 2 );
425 unsigned int samples
;
426 unsigned int x
, line_h
;
437 GetClientRect( hWnd
, &cli
);
445 // Initialize hdc objects
448 hdc
= BeginPaint( hWnd
, &ps
);
450 pen
= ( HPEN
) CreatePen( PS_SOLID
, 1, WAVEBAR_COLOR
);
452 SelectObject( hdc
, ( HBRUSH
)pen
);
454 if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
457 samples
= AUD_OUT
->tot_samples_buf();
460 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
463 x
= ( i
* samples
) / WAVEBAR_CX
;
465 line_h
= ( abs(AUD_OUT
->nsample( x
)) * max_h
) / AUD_OUT
->samplevalue_max();
470 MoveToEx( hdc
, i
, max_h
, 0 );
471 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
472 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
474 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
479 } else if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
) {
482 samples
= AUD_IN
->tot_samples_buf();
485 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
488 x
= ( i
* samples
) / WAVEBAR_CX
;
490 line_h
= ( AUD_IN
->nsample( x
) * max_h
) / AUD_IN
->samplevalue_max();
495 MoveToEx( hdc
, i
, max_h
, 0 );
496 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
497 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
499 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
507 // In standby mode draw a simple line.
510 MoveToEx( hdc
, 0, cli
.bottom
/ 2, 0 );
511 LineTo( hdc
, WAVEBAR_CX
, cli
.bottom
/ 2 );
518 EndPaint( hWnd
, &ps
);
530 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
543 WndProc( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
546 TCHAR str_tmp
[MAX_LOADSTRING
];
550 long long slid_samp
= 0;
555 // Checking for global pointers to buffer and
559 if (( !AUD_IN
) || ( !AUD_OUT
) || ( !AUD_BUF
))
561 MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
574 // Creating the wave bar
577 if ( !InitInstance_wave( hWnd
, hInst
, SW_SHOWNORMAL
))
581 TEXT( "CreateWindow() Error!" ),
593 // Creating ALL the buttons
596 for ( int i
= 0; i
< 5; ++ i
)
599 buttons
[i
] = CreateWindow(
602 WS_CHILD
|WS_VISIBLE
|BS_BITMAP
,
603 BUTTONS_CX
+ ( i
* (BUTTONS_W
+((i
== 0)?0:BUTTONS_SPACE
))),
604 BUTTONS_CY
, BUTTONS_W
, BUTTONS_H
, hWnd
,
610 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
617 // Realize the button bmp image
620 SendMessage(buttons
[i
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[i
]);
622 UpdateWindow( buttons
[i
] );
630 // Creating the SLIDER window
633 slider
= CreateWindow(
636 WS_CHILD
|WS_VISIBLE
|TBS_NOTICKS
|TBS_HORZ
|TBS_ENABLESELRANGE
,
637 SLIDER_CX
, SLIDER_CY
, SLIDER_W
, SLIDER_H
, hWnd
,
638 ( HMENU
)SLIDER_ID
, hInst
, 0
644 MessageBox( 0, 0, TEXT( "CreateWindow() Error!" ), 0 );
651 // Sets slider limits
659 ( LPARAM
)MAKELONG( slider_min
, slider_max
)
663 UpdateWindow( slider
);
665 enable_but( BUTREC_ID
);
667 EnableWindow( slider
, FALSE
);
677 // Implements slider logic
682 switch( LOWORD( wParam
))
694 // If the user touch the slider bar,
695 // set the audio start position properly
699 slider_pos
= SendMessage( slider
, TBM_GETPOS
, 0, 0 );
701 slid_samp
= ( __int64
)slider_pos
* ( __int64
)samples_max
;
703 AUD_BUF
->set_position(
704 AUD_BUF
->audinfo().bytes_in_samples(
705 ( unsigned int )( slid_samp
/ ( __int64
)slider_max
)
709 InvalidateRect( hWnd
, &text_rect
, TRUE
);
726 wmId
= LOWORD( wParam
);
727 wmEvent
= HIWORD( wParam
);
729 if (( wmId
>= 0 ) && ( wmId
< 5 ) && ( butdisabled
[wmId
] == TRUE
))
740 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
741 AUD_IN
->stop_recording();
744 if (( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
745 ( AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
751 enable_but( BUTREC_ID
);
752 disable_but( BUTSTART_ID
);
753 disable_but( BUTEND_ID
);
754 disable_but( BUTSTOP_ID
);
755 disable_but( BUTPLAY_ID
);
758 samples_max
= AUD_BUF
->total_samples();
761 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
763 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
764 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
769 ZeroMemory( file_path
, MAX_PATH
);
771 EnableWindow( slider
, FALSE
);
773 InvalidateRect( hWnd
, &text_rect
, TRUE
);
774 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
787 ZeroMemory( &ofn
, sizeof( ofn
));
789 ofn
.lStructSize
= sizeof( ofn
);
790 ofn
.hwndOwner
= hWnd
;
791 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
792 ofn
.lpstrFile
= file_path
;
793 ofn
.nMaxFile
= MAX_PATH
;
794 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
795 ofn
.lpstrDefExt
= TEXT("wav");
797 if( GetOpenFileName( &ofn
))
799 open_wav( file_path
);
800 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
801 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
803 EnableWindow( slider
, TRUE
);
807 InvalidateRect( hWnd
, &text_rect
, TRUE
);
808 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
817 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
824 ZeroMemory( &ofn
, sizeof( ofn
));
826 ofn
.lStructSize
= sizeof( ofn
);
827 ofn
.hwndOwner
= hWnd
;
828 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
829 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
830 ofn
.lpstrFile
= file_path
;
831 ofn
.nMaxFile
= MAX_PATH
;
833 ofn
.lpstrDefExt
= TEXT("wav");
835 if ( GetSaveFileName ( &ofn
))
837 write_wav( file_path
);
839 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
845 DestroyWindow( hWnd
);
850 // Sndrec32 buttons routines
855 AUD_BUF
->set_position_start();
859 SendMessage( slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
865 DestroyWindow( hWnd
);
870 if ( wout_first
== false )
879 disable_but( BUTSTART_ID
);
880 disable_but( BUTEND_ID
);
881 disable_but( BUTREC_ID
);
882 disable_but( BUTPLAY_ID
);
885 SetTimer( hWnd
, 1, 250, 0 );
886 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
895 AUD_IN
->stop_recording();
900 // Resetting slider position
904 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
907 samples_max
= AUD_BUF
->samples_received();
909 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
912 enable_but( BUTSTART_ID
);
913 enable_but( BUTEND_ID
);
914 enable_but( BUTREC_ID
);
915 enable_but( BUTPLAY_ID
);
917 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
918 EnableWindow( slider
, TRUE
);
924 InvalidateRect( hWnd
, &text_rect
, TRUE
);
925 InvalidateRect( wave_win
, 0, TRUE
);
932 enable_but( BUTSTART_ID
);
933 enable_but( BUTEND_ID
);
934 enable_but( BUTREC_ID
);
935 enable_but( BUTPLAY_ID
);
939 KillTimer( hWnd
, 1 );
940 KillTimer( hWnd
, WAVEBAR_TIMERID
);
942 InvalidateRect( hWnd
, &text_rect
, TRUE
);
948 if ( win_first
== false )
956 samples_max
= AUD_BUF
->total_samples();
958 AUD_IN
->start_recording();
960 enable_but( BUTSTOP_ID
);
962 disable_but( BUTSTART_ID
);
963 disable_but( BUTEND_ID
);
964 disable_but( BUTREC_ID
);
965 disable_but( BUTPLAY_ID
);
969 EnableWindow( slider
, FALSE
);
971 SetTimer( hWnd
, 1, 150, 0 );
973 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
979 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
992 KillTimer( hWnd
, 1 );
993 KillTimer( hWnd
, WAVEBAR_TIMERID
);
996 enable_but( BUTPLAY_ID
);
998 stopped_flag
= FALSE
;
1007 ( LPARAM
) slider_pos
1010 InvalidateRect( hWnd
, &text_rect
, TRUE
);
1015 case WAVEBAR_TIMERID
:
1016 InvalidateRect( wave_win
, 0, TRUE
);
1017 SendMessage( wave_win
, WM_USER
, 0, 0 );
1029 hdc
= BeginPaint(hWnd
, &ps
);
1032 font
= CreateFontIndirect( &s_info
.lfMenuFont
);
1035 SelectObject( hdc
, font
);
1037 SetBkMode( hdc
, TRANSPARENT
);
1040 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
1046 ( float )(( float )AUD_BUF
->bytes_recorded( ) / ( float )AUD_BUF
->audinfo().byte_rate( ))
1049 } else if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) {
1055 ( float )(( float )AUD_BUF
->bytes_played() / ( float )AUD_BUF
->audinfo().byte_rate( ))
1064 ( float )(((( float )slider_pos
* ( float )samples_max
) / ( float )slider_max
) / ( float )AUD_BUF
->audinfo().sample_rate())
1069 ExtTextOut( hdc
, STRPOS_X
, STRPOS_Y
, ETO_OPAQUE
,
1070 0, str_tmp
, _tcslen( str_tmp
), 0 );
1076 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1077 AUD_BUF
->fseconds_total( ));
1082 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1083 AUD_BUF
->fseconds_recorded( ));
1088 ExtTextOut( hdc
, STRDUR_X
, STRDUR_Y
, ETO_OPAQUE
,
1089 0, str_tmp
, _tcslen( str_tmp
), 0 );
1097 ( float )(( float )AUD_BUF
->mem_size() / 1024.0f
)
1101 ExtTextOut( hdc
, STRBUF_X
, STRBUF_Y
, ETO_OPAQUE
,
1102 0, str_tmp
, _tcslen( str_tmp
), 0 );
1110 ( float )(( float )AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
1111 AUD_BUF
->audinfo().bits(),
1112 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
1116 ExtTextOut( hdc
, STRFMT_X
, STRFMT_Y
, ETO_OPAQUE
,
1117 0, str_tmp
, _tcslen( str_tmp
), 0 );
1125 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
1129 ExtTextOut( hdc
, STRCHAN_X
, STRCHAN_Y
, ETO_OPAQUE
,
1130 0, str_tmp
, _tcslen( str_tmp
), 0 );
1134 DeleteObject( font
);
1136 EndPaint(hWnd
, &ps
);
1148 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
1157 void l_play_finished ( void )
1160 stopped_flag
= true;
1163 enable_but( BUTSTART_ID
);
1164 enable_but( BUTEND_ID
);
1165 enable_but( BUTREC_ID
);
1166 enable_but( BUTPLAY_ID
);
1168 InvalidateRect( wave_win
, 0, TRUE
);
1172 void l_audio_arrival ( unsigned int samples_arrival
)
1176 slider_pos
+= ( DWORD
) (( slider_max
* samples_arrival
) / samples_max
);
1181 void l_buffer_resized ( unsigned int new_size
)
1190 VOID
enable_but( DWORD id
)
1193 butdisabled
[ id
] = FALSE
;
1195 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[ id
]);
1199 VOID
disable_but( DWORD id
)
1202 butdisabled
[ id
] = TRUE
;
1204 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps_dis
[ id
]);
1223 BOOL
open_wav( TCHAR
* f
)
1235 DWORD bytes_recorded_in_wav
= 0;
1244 FILE_ATTRIBUTE_NORMAL
,
1254 TEXT("Cannot open file. CreateFile() error."),
1263 b
= ReadFile( file
, ( LPVOID
) &r
, sizeof ( r
), &is_read
, 0 );
1269 TEXT("Cannot read RIFF header."),
1274 CloseHandle( file
);
1279 b
= ReadFile( file
, ( LPVOID
) &w
, sizeof ( w
), &is_read
, 0 );
1286 TEXT("Cannot read WAVE header."),
1291 CloseHandle( file
);
1297 b
= ReadFile( file
, ( LPVOID
) &d
, sizeof ( d
), &is_read
, 0 );
1303 TEXT("Cannot read WAVE subchunk."),
1308 CloseHandle( file
);
1312 bytes_recorded_in_wav
= r
.chunksize
- 36;
1315 if ( bytes_recorded_in_wav
== 0 )
1319 TEXT("Cannot read file. No audio data."),
1324 CloseHandle( file
);
1329 snd::audio_format openfmt
1330 ( w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1337 AUD_BUF
->alloc_bytes( bytes_recorded_in_wav
);
1342 ( LPVOID
) AUD_BUF
->audio_buffer(),
1343 bytes_recorded_in_wav
,
1349 AUD_BUF
->set_b_received( bytes_recorded_in_wav
);
1352 if (( !b
) || ( is_read
!= bytes_recorded_in_wav
))
1356 TEXT("Cannot read file. Error reading audio data."),
1361 CloseHandle( file
);
1367 CloseHandle( file
);
1369 enable_but( BUTPLAY_ID
);
1370 enable_but( BUTSTOP_ID
);
1371 enable_but( BUTSTART_ID
);
1372 enable_but( BUTEND_ID
);
1373 enable_but( BUTREC_ID
);
1376 samples_max
= AUD_BUF
->samples_received();
1386 write_wav( TCHAR
* f
)
1406 FILE_ATTRIBUTE_NORMAL
,
1416 TEXT("File already exist. Overwrite it?"),
1418 MB_YESNO
|MB_ICONQUESTION
1429 FILE_ATTRIBUTE_NORMAL
,
1437 TEXT("File Error, CreateFile() failed."),
1455 r
.magic
= 0x46464952;
1458 r
.format
= 0x45564157;
1459 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1462 w
.Subchunkid
= 0x20746d66;
1464 w
.Subchunk1Size
= 16;
1466 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1467 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1468 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1469 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1470 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1473 d
.subc
= 0x61746164;
1474 d
.subc_size
= AUD_BUF
->bytes_recorded();
1483 is_writ
= WriteFile( file
, ( LPCVOID
) &r
, sizeof ( r
), &written
, 0 );
1489 TEXT("File Error, WriteFile() failed."),
1494 CloseHandle( file
);
1501 is_writ
= WriteFile( file
, ( LPCVOID
) &w
, sizeof ( w
), &written
, 0 );
1507 TEXT("File Error, WriteFile() failed."),
1512 CloseHandle( file
);
1519 is_writ
= WriteFile( file
, ( LPCVOID
) &d
, sizeof ( d
), &written
, 0 );
1526 TEXT("File Error, WriteFile() failed."),
1531 CloseHandle( file
);
1539 is_writ
= WriteFile(
1541 ( LPCVOID
) AUD_BUF
->audio_buffer(),
1542 AUD_BUF
->bytes_recorded(),
1551 TEXT("File Error, WriteFile() failed."),
1556 CloseHandle( file
);
1563 CloseHandle( file
);