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
18 TCHAR szTitle
[MAX_LOADSTRING
];
19 TCHAR szWindowClass
[MAX_LOADSTRING
];
22 ATOM
MyRegisterClass( HINSTANCE hInstance
);
23 ATOM
MyRegisterClass_wave( HINSTANCE hInstance
);
24 BOOL
InitInstance( HINSTANCE
, int );
25 BOOL
InitInstance_wave( HWND
, HINSTANCE
, int );
26 LRESULT CALLBACK
WndProc( HWND
, UINT
, WPARAM
, LPARAM
);
27 LRESULT CALLBACK
WndProc_wave( HWND
, UINT
, WPARAM
, LPARAM
);
29 BOOL win_first
, wout_first
;
36 HBITMAP butbmps_dis
[5];
37 WNDPROC buttons_std_proc
;
52 TCHAR file_path
[MAX_PATH
];
53 TCHAR str_pos
[MAX_LOADSTRING
];
54 TCHAR str_dur
[MAX_LOADSTRING
];
55 TCHAR str_buf
[MAX_LOADSTRING
];
56 TCHAR str_fmt
[MAX_LOADSTRING
];
57 TCHAR str_chan
[MAX_LOADSTRING
];
64 snd::audio_membuffer
* AUD_BUF
;
65 snd::audio_waveout
* AUD_OUT
;
66 snd::audio_wavein
* AUD_IN
;
72 NONCLIENTMETRICS s_info
;
80 INT_PTR CALLBACK
AboutDlgProc(HWND hWnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
101 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
102 HINSTANCE hPrevInstance
,
107 UNREFERENCED_PARAMETER(hPrevInstance
);
108 UNREFERENCED_PARAMETER(lpCmdLine
);
114 s_info
.cbSize
= sizeof( NONCLIENTMETRICS
);
116 InitCommonControls();
118 win_first
= wout_first
= FALSE
;
120 text_rect
.left
= REFRESHA_X
;
121 text_rect
.top
= REFRESHA_Y
;
122 text_rect
.right
= REFRESHA_CX
;
123 text_rect
.bottom
= REFRESHA_CY
;
125 text2_rect
.left
= REFRESHB_X
;
126 text2_rect
.top
= REFRESHB_Y
;
127 text2_rect
.right
= REFRESHB_CX
;
128 text2_rect
.bottom
= REFRESHB_CY
;
131 // Retrieving defaul system font, and others
132 // system informations.
135 SystemParametersInfo(
136 SPI_GETNONCLIENTMETRICS
,
137 sizeof( NONCLIENTMETRICS
),
146 s_info
.lfMenuFont
.lfHeight
= 14;
149 // Inits buttons bitmaps
152 butbmps
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START
));
153 butbmps
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END
));
154 butbmps
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY
));
155 butbmps
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP
));
156 butbmps
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC
));
158 butbmps_dis
[0] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_START_DIS
));
159 butbmps_dis
[1] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_END_DIS
));
160 butbmps_dis
[2] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_PLAY_DIS
));
161 butbmps_dis
[3] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_STOP_DIS
));
162 butbmps_dis
[4] = LoadBitmap( hInstance
, MAKEINTRESOURCE( IDB_BITMAP2_REC_DIS
));
167 // Inits audio devices and buffers
170 snd::audio_membuffer
AUD_buffer( snd::A44100_16BIT_STEREO
);
171 snd::audio_waveout
AUD_waveout( snd::A44100_16BIT_STEREO
, AUD_buffer
);
172 snd::audio_wavein
AUD_wavein( snd::A44100_16BIT_STEREO
, AUD_buffer
);
174 AUD_buffer
.play_finished
= l_play_finished
;
175 AUD_buffer
.audio_arrival
= l_audio_arrival
;
176 AUD_buffer
.buffer_resized
= l_buffer_resized
;
178 AUD_buffer
.alloc_seconds( INITIAL_BUFREC_SECONDS
);
180 AUD_IN
= &AUD_wavein
;
181 AUD_OUT
= &AUD_waveout
;
182 AUD_BUF
= &AUD_buffer
;
185 // Inits slider default parameters
190 slider_max
= SLIDER_W
;
193 stopped_flag
= FALSE
;
198 samples_max
= AUD_buffer
.total_samples();
206 LoadString( hInstance
,
207 IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
209 LoadString( hInstance
,
210 IDC_REACTOS_SNDREC32
, szWindowClass
, MAX_LOADSTRING
);
213 LoadString( hInstance
,
214 IDS_STRPOS
, str_pos
, MAX_LOADSTRING
);
217 LoadString( hInstance
,
218 IDS_STRDUR
, str_dur
, MAX_LOADSTRING
);
220 LoadString( hInstance
,
221 IDS_STRBUF
, str_buf
, MAX_LOADSTRING
);
223 LoadString( hInstance
,
224 IDS_STRFMT
, str_fmt
, MAX_LOADSTRING
);
226 LoadString( hInstance
,
227 IDS_STRCHAN
, str_chan
, MAX_LOADSTRING
);
229 LoadString( hInstance
,
230 IDS_STRMONO
, str_mono
, 10 );
232 LoadString( hInstance
,
233 IDS_STRSTEREO
, str_stereo
, 10 );
237 // Registers sndrec32 window class
240 MyRegisterClass( hInstance
);
242 MyRegisterClass_wave( hInstance
);
245 if ( !InitInstance( hInstance
, nCmdShow
))
247 MessageBox( 0, TEXT( "CreateWindow() Error!" ), TEXT( "ERROR" ), MB_ICONERROR
);
252 // Loads key accelerators
255 hAccelTable
= LoadAccelerators(hInstance
,
256 MAKEINTRESOURCE( IDC_REACTOS_SNDREC32
));
264 while ( GetMessage( &msg
, NULL
, 0, 0 ))
266 if ( !TranslateAccelerator( msg
.hwnd
, hAccelTable
, &msg
))
268 TranslateMessage( &msg
);
269 DispatchMessage( &msg
);
288 return ( int )msg
.wParam
;
295 MyRegisterClass( HINSTANCE hInstance
)
299 wcex
.cbSize
= sizeof(WNDCLASSEX
);
301 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
302 wcex
.lpfnWndProc
= WndProc
;
305 wcex
.hInstance
= hInstance
;
306 wcex
.hIcon
= LoadIcon( hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
307 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
308 wcex
.hbrBackground
= GetSysColorBrush(COLOR_BTNFACE
);
309 wcex
.lpszMenuName
= MAKEINTRESOURCE( IDR_MENU1
);
310 wcex
.lpszClassName
= szWindowClass
;
311 wcex
.hIconSm
= LoadIcon( wcex
.hInstance
, MAKEINTRESOURCE( IDI_SNDREC32
));
314 return RegisterClassEx( &wcex
);
318 InitInstance( HINSTANCE hInstance
, int nCmdShow
)
327 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
341 ShowWindow(hWnd
, nCmdShow
);
355 MyRegisterClass_wave( HINSTANCE hInstance
)
359 wcex
.cbSize
= sizeof( WNDCLASSEX
);
361 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
362 wcex
.lpfnWndProc
= WndProc_wave
;
365 wcex
.hInstance
= hInstance
;
367 wcex
.hCursor
= LoadCursor( NULL
, IDC_ARROW
);
368 wcex
.hbrBackground
= ( HBRUSH
)GetStockObject( BLACK_BRUSH
);
369 wcex
.lpszMenuName
= 0;
370 wcex
.lpszClassName
= TEXT( "sndrec32_wave" );
374 return RegisterClassEx( &wcex
);
378 InitInstance_wave( HWND f
, HINSTANCE hInstance
, int nCmdShow
)
385 TEXT( "sndrec32_wave" ),
387 WS_DLGFRAME
|WS_VISIBLE
|WS_CHILD
,
401 ShowWindow( hWnd
, nCmdShow
);
402 UpdateWindow( hWnd
);
412 WndProc_wave( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
420 unsigned int max_h
= ( cli
.bottom
/ 2 );
421 unsigned int samples
;
422 unsigned int x
, line_h
;
433 GetClientRect( hWnd
, &cli
);
441 // Initialize hdc objects
444 hdc
= BeginPaint( hWnd
, &ps
);
446 pen
= ( HPEN
) CreatePen( PS_SOLID
, 1, WAVEBAR_COLOR
);
448 SelectObject( hdc
, ( HBRUSH
)pen
);
450 if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
)
453 samples
= AUD_OUT
->tot_samples_buf();
456 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
459 x
= ( i
* samples
) / WAVEBAR_CX
;
461 line_h
= ( AUD_OUT
->nsample( x
) * max_h
) / AUD_OUT
->samplevalue_max();
466 MoveToEx( hdc
, i
, max_h
, 0 );
467 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
468 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
470 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
475 } else if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
) {
478 samples
= AUD_IN
->tot_samples_buf();
481 for ( unsigned int i
= 0; i
< WAVEBAR_CX
; ++i
)
484 x
= ( i
* samples
) / WAVEBAR_CX
;
486 line_h
= ( AUD_IN
->nsample( x
) * max_h
) / AUD_IN
->samplevalue_max();
491 MoveToEx( hdc
, i
, max_h
, 0 );
492 LineTo( hdc
, i
, max_h
- ( line_h
* 2 ));
493 LineTo( hdc
, i
, max_h
+ ( line_h
* 2 ));
495 SetPixel( hdc
, i
, max_h
, WAVEBAR_COLOR
);
503 // In standby mode draw a simple line.
506 MoveToEx( hdc
, 0, cli
.bottom
/ 2, 0 );
507 LineTo( hdc
, WAVEBAR_CX
, cli
.bottom
/ 2 );
514 EndPaint( hWnd
, &ps
);
526 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
539 WndProc( HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
542 TCHAR str_tmp
[MAX_LOADSTRING
];
546 long long slid_samp
= 0;
551 // Checking for global pointers to buffer and
555 if (( !AUD_IN
) || ( !AUD_OUT
) || ( !AUD_BUF
))
557 MessageBox( 0, TEXT("Buffer Error"), 0, 0 );
570 // Creating the wave bar
573 if ( !InitInstance_wave( hWnd
, hInst
, SW_SHOWNORMAL
))
577 TEXT( "CreateWindow() Error!" ),
589 // Creating ALL the buttons
592 for ( int i
= 0; i
< 5; ++ i
)
595 buttons
[i
] = CreateWindow(
598 WS_CHILD
|WS_VISIBLE
|BS_BITMAP
,
599 BUTTONS_CX
+ ( i
* (BUTTONS_W
+((i
== 0)?0:BUTTONS_SPACE
))),
600 BUTTONS_CY
, BUTTONS_W
, BUTTONS_H
, hWnd
,
606 MessageBox(0, 0, TEXT("CreateWindow() Error!"), 0);
613 // Realize the button bmp image
616 SendMessage(buttons
[i
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[i
]);
618 UpdateWindow( buttons
[i
] );
626 // Creating the SLIDER window
629 slider
= CreateWindow(
632 WS_CHILD
|WS_VISIBLE
|TBS_NOTICKS
|TBS_HORZ
|TBS_ENABLESELRANGE
,
633 SLIDER_CX
, SLIDER_CY
, SLIDER_W
, SLIDER_H
, hWnd
,
634 ( HMENU
)SLIDER_ID
, hInst
, 0
640 MessageBox( 0, 0, TEXT( "CreateWindow() Error!" ), 0 );
647 // Sets slider limits
655 ( LPARAM
)MAKELONG( slider_min
, slider_max
)
659 UpdateWindow( slider
);
661 enable_but( BUTREC_ID
);
663 EnableWindow( slider
, FALSE
);
673 // Implements slider logic
678 switch( LOWORD( wParam
))
690 // If the user touch the slider bar,
691 // set the audio start position properly
695 slider_pos
= SendMessage( slider
, TBM_GETPOS
, 0, 0 );
697 slid_samp
= ( __int64
)slider_pos
* ( __int64
)samples_max
;
699 AUD_BUF
->set_position(
700 AUD_BUF
->audinfo().bytes_in_samples(
701 ( unsigned int )( slid_samp
/ ( __int64
)slider_max
)
705 InvalidateRect( hWnd
, &text_rect
, TRUE
);
722 wmId
= LOWORD( wParam
);
724 if (( wmId
>= 0 ) && ( wmId
< 5 ) && ( butdisabled
[wmId
] == TRUE
))
735 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
736 AUD_IN
->stop_recording();
739 if (( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) ||
740 ( AUD_OUT
->current_status() == snd::WAVEOUT_PAUSED
))
746 enable_but( BUTREC_ID
);
747 disable_but( BUTSTART_ID
);
748 disable_but( BUTEND_ID
);
749 disable_but( BUTSTOP_ID
);
750 disable_but( BUTPLAY_ID
);
753 samples_max
= AUD_BUF
->total_samples();
756 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
758 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_GRAYED
);
759 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_GRAYED
);
764 ZeroMemory( file_path
, MAX_PATH
* sizeof(TCHAR
) );
766 EnableWindow( slider
, FALSE
);
768 InvalidateRect( hWnd
, &text_rect
, TRUE
);
769 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
782 ZeroMemory( &ofn
, sizeof( ofn
));
784 ofn
.lStructSize
= sizeof( ofn
);
785 ofn
.hwndOwner
= hWnd
;
786 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
787 ofn
.lpstrFile
= file_path
;
788 ofn
.nMaxFile
= MAX_PATH
;
789 ofn
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
790 ofn
.lpstrDefExt
= TEXT("wav");
792 if( GetOpenFileName( &ofn
))
794 open_wav( file_path
);
795 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
796 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
798 EnableWindow( slider
, TRUE
);
802 InvalidateRect( hWnd
, &text_rect
, TRUE
);
803 InvalidateRect( hWnd
, &text2_rect
, TRUE
);
812 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, AboutDlgProc
);
819 ZeroMemory( &ofn
, sizeof( ofn
));
821 ofn
.lStructSize
= sizeof( ofn
);
822 ofn
.hwndOwner
= hWnd
;
823 ofn
.Flags
= OFN_OVERWRITEPROMPT
;
824 ofn
.lpstrFilter
= TEXT("Audio Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0");
825 ofn
.lpstrFile
= file_path
;
826 ofn
.nMaxFile
= MAX_PATH
;
828 ofn
.lpstrDefExt
= TEXT("wav");
830 if ( GetSaveFileName ( &ofn
))
832 write_wav( file_path
);
834 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVE
, MF_ENABLED
);
840 DestroyWindow( hWnd
);
845 // Sndrec32 buttons routines
850 AUD_BUF
->set_position_start();
854 SendMessage( slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
860 DestroyWindow( hWnd
);
865 if ( wout_first
== false )
874 disable_but( BUTSTART_ID
);
875 disable_but( BUTEND_ID
);
876 disable_but( BUTREC_ID
);
877 disable_but( BUTPLAY_ID
);
880 SetTimer( hWnd
, 1, 250, 0 );
881 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
890 AUD_IN
->stop_recording();
895 // Resetting slider position
899 SendMessage(slider
, TBM_SETPOS
, (WPARAM
) TRUE
, (LPARAM
) slider_pos
);
902 samples_max
= AUD_BUF
->samples_received();
904 EnableMenuItem((HMENU
)IDR_MENU1
, ID_FILE_SAVEAS
, MF_ENABLED
);
907 enable_but( BUTSTART_ID
);
908 enable_but( BUTEND_ID
);
909 enable_but( BUTREC_ID
);
910 enable_but( BUTPLAY_ID
);
912 EnableMenuItem( GetMenu( hWnd
), ID_FILE_SAVEAS
, MF_ENABLED
);
913 EnableWindow( slider
, TRUE
);
919 InvalidateRect( hWnd
, &text_rect
, TRUE
);
920 InvalidateRect( wave_win
, 0, TRUE
);
927 enable_but( BUTSTART_ID
);
928 enable_but( BUTEND_ID
);
929 enable_but( BUTREC_ID
);
930 enable_but( BUTPLAY_ID
);
934 KillTimer( hWnd
, 1 );
935 KillTimer( hWnd
, WAVEBAR_TIMERID
);
937 InvalidateRect( hWnd
, &text_rect
, TRUE
);
943 if ( win_first
== false )
951 samples_max
= AUD_BUF
->total_samples();
953 AUD_IN
->start_recording();
955 enable_but( BUTSTOP_ID
);
957 disable_but( BUTSTART_ID
);
958 disable_but( BUTEND_ID
);
959 disable_but( BUTREC_ID
);
960 disable_but( BUTPLAY_ID
);
964 EnableWindow( slider
, FALSE
);
966 SetTimer( hWnd
, 1, 150, 0 );
968 SetTimer( hWnd
, WAVEBAR_TIMERID
, WAVEBAR_TIMERTIME
, 0 );
974 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
987 KillTimer( hWnd
, 1 );
988 KillTimer( hWnd
, WAVEBAR_TIMERID
);
991 enable_but( BUTPLAY_ID
);
993 stopped_flag
= FALSE
;
1002 ( LPARAM
) slider_pos
1005 InvalidateRect( hWnd
, &text_rect
, TRUE
);
1010 case WAVEBAR_TIMERID
:
1011 InvalidateRect( wave_win
, 0, TRUE
);
1012 SendMessage( wave_win
, WM_USER
, 0, 0 );
1024 hdc
= BeginPaint(hWnd
, &ps
);
1027 font
= CreateFontIndirect( &s_info
.lfMenuFont
);
1030 SelectObject( hdc
, font
);
1032 SetBkMode( hdc
, TRANSPARENT
);
1035 if ( AUD_IN
->current_status() == snd::WAVEIN_RECORDING
)
1041 ( float )(( float )AUD_BUF
->bytes_recorded( ) / ( float )AUD_BUF
->audinfo().byte_rate( ))
1044 } else if ( AUD_OUT
->current_status() == snd::WAVEOUT_PLAYING
) {
1050 ( float )(( float )AUD_BUF
->bytes_played() / ( float )AUD_BUF
->audinfo().byte_rate( ))
1059 ( float )(((( float )slider_pos
* ( float )samples_max
) / ( float )slider_max
) / ( float )AUD_BUF
->audinfo().sample_rate())
1064 ExtTextOut( hdc
, STRPOS_X
, STRPOS_Y
, ETO_OPAQUE
,
1065 0, str_tmp
, _tcslen( str_tmp
), 0 );
1071 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1072 AUD_BUF
->fseconds_total( ));
1077 gprintf( str_tmp
, MAX_LOADSTRING
, str_dur
,
1078 AUD_BUF
->fseconds_recorded( ));
1083 ExtTextOut( hdc
, STRDUR_X
, STRDUR_Y
, ETO_OPAQUE
,
1084 0, str_tmp
, _tcslen( str_tmp
), 0 );
1092 ( float )(( float )AUD_BUF
->mem_size() / 1024.0f
)
1096 ExtTextOut( hdc
, STRBUF_X
, STRBUF_Y
, ETO_OPAQUE
,
1097 0, str_tmp
, _tcslen( str_tmp
), 0 );
1105 ( float )(( float )AUD_BUF
->audinfo().sample_rate() / 1000.0f
),
1106 AUD_BUF
->audinfo().bits(),
1107 AUD_BUF
->audinfo().channels() == 2 ? str_mono
: str_stereo
1111 ExtTextOut( hdc
, STRFMT_X
, STRFMT_Y
, ETO_OPAQUE
,
1112 0, str_tmp
, _tcslen( str_tmp
), 0 );
1120 AUD_BUF
->audinfo().channels() == 2 ? str_stereo
: str_mono
1124 ExtTextOut( hdc
, STRCHAN_X
, STRCHAN_Y
, ETO_OPAQUE
,
1125 0, str_tmp
, _tcslen( str_tmp
), 0 );
1129 DeleteObject( font
);
1131 EndPaint(hWnd
, &ps
);
1143 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
1152 void l_play_finished ( void )
1155 stopped_flag
= true;
1158 enable_but( BUTSTART_ID
);
1159 enable_but( BUTEND_ID
);
1160 enable_but( BUTREC_ID
);
1161 enable_but( BUTPLAY_ID
);
1163 InvalidateRect( wave_win
, 0, TRUE
);
1167 void l_audio_arrival ( unsigned int samples_arrival
)
1171 slider_pos
+= ( DWORD
) (( slider_max
* samples_arrival
) / samples_max
);
1176 void l_buffer_resized ( unsigned int new_size
)
1185 VOID
enable_but( DWORD id
)
1188 butdisabled
[ id
] = FALSE
;
1190 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps
[ id
]);
1194 VOID
disable_but( DWORD id
)
1197 butdisabled
[ id
] = TRUE
;
1199 SendMessage(buttons
[ id
], BM_SETIMAGE
, ( WPARAM
)IMAGE_BITMAP
, ( LPARAM
)butbmps_dis
[ id
]);
1218 BOOL
open_wav( TCHAR
* f
)
1230 DWORD bytes_recorded_in_wav
= 0;
1239 FILE_ATTRIBUTE_NORMAL
,
1249 TEXT("Cannot open file. CreateFile() error."),
1258 b
= ReadFile( file
, ( LPVOID
) &r
, sizeof ( r
), &is_read
, 0 );
1264 TEXT("Cannot read RIFF header."),
1269 CloseHandle( file
);
1274 b
= ReadFile( file
, ( LPVOID
) &w
, sizeof ( w
), &is_read
, 0 );
1281 TEXT("Cannot read WAVE header."),
1286 CloseHandle( file
);
1292 b
= ReadFile( file
, ( LPVOID
) &d
, sizeof ( d
), &is_read
, 0 );
1298 TEXT("Cannot read WAVE subchunk."),
1303 CloseHandle( file
);
1307 bytes_recorded_in_wav
= r
.chunksize
- 36;
1310 if ( bytes_recorded_in_wav
== 0 )
1314 TEXT("Cannot read file. No audio data."),
1319 CloseHandle( file
);
1324 snd::audio_format openfmt
1325 ( w
.SampleRate
, w
.BitsPerSample
, w
.NumChannels
);
1332 AUD_BUF
->alloc_bytes( bytes_recorded_in_wav
);
1337 ( LPVOID
) AUD_BUF
->audio_buffer(),
1338 bytes_recorded_in_wav
,
1344 AUD_BUF
->set_b_received( bytes_recorded_in_wav
);
1347 if (( !b
) || ( is_read
!= bytes_recorded_in_wav
))
1351 TEXT("Cannot read file. Error reading audio data."),
1356 CloseHandle( file
);
1362 CloseHandle( file
);
1364 enable_but( BUTPLAY_ID
);
1365 enable_but( BUTSTOP_ID
);
1366 enable_but( BUTSTART_ID
);
1367 enable_but( BUTEND_ID
);
1368 enable_but( BUTREC_ID
);
1371 samples_max
= AUD_BUF
->samples_received();
1381 write_wav( TCHAR
* f
)
1401 FILE_ATTRIBUTE_NORMAL
,
1411 TEXT("File already exist. Overwrite it?"),
1413 MB_YESNO
|MB_ICONQUESTION
1424 FILE_ATTRIBUTE_NORMAL
,
1432 TEXT("File Error, CreateFile() failed."),
1450 r
.magic
= 0x46464952;
1453 r
.format
= 0x45564157;
1454 r
.chunksize
= 36 + AUD_BUF
->bytes_recorded();
1457 w
.Subchunkid
= 0x20746d66;
1459 w
.Subchunk1Size
= 16;
1461 w
.NumChannels
= AUD_BUF
->audinfo().channels();
1462 w
.SampleRate
= AUD_BUF
->audinfo().sample_rate();
1463 w
.ByteRate
= AUD_BUF
->audinfo().byte_rate();
1464 w
.BlockAlign
= AUD_BUF
->audinfo().block_align();
1465 w
.BitsPerSample
= AUD_BUF
->audinfo().bits();
1468 d
.subc
= 0x61746164;
1469 d
.subc_size
= AUD_BUF
->bytes_recorded();
1478 is_writ
= WriteFile( file
, ( LPCVOID
) &r
, sizeof ( r
), &written
, 0 );
1484 TEXT("File Error, WriteFile() failed."),
1489 CloseHandle( file
);
1496 is_writ
= WriteFile( file
, ( LPCVOID
) &w
, sizeof ( w
), &written
, 0 );
1502 TEXT("File Error, WriteFile() failed."),
1507 CloseHandle( file
);
1514 is_writ
= WriteFile( file
, ( LPCVOID
) &d
, sizeof ( d
), &written
, 0 );
1521 TEXT("File Error, WriteFile() failed."),
1526 CloseHandle( file
);
1534 is_writ
= WriteFile(
1536 ( LPCVOID
) AUD_BUF
->audio_buffer(),
1537 AUD_BUF
->bytes_recorded(),
1546 TEXT("File Error, WriteFile() failed."),
1551 CloseHandle( file
);
1558 CloseHandle( file
);