aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuanma Barranquero2009-01-12 16:18:31 +0000
committerJuanma Barranquero2009-01-12 16:18:31 +0000
commit24f0147080b202d6a1aedb90d4e9945deafcf2fd (patch)
treea682fbda66c09bf3481e00df05a98f7b4e3c6543 /src
parentf19fea978e39c6e279dcc116d5e7d3b6651bc527 (diff)
downloademacs-24f0147080b202d6a1aedb90d4e9945deafcf2fd.tar.gz
emacs-24f0147080b202d6a1aedb90d4e9945deafcf2fd.zip
* sound.c [WINDOWSNT] (SOUND_WARNING): New macro.
(do_play_sound): Use it. Don't pass a hardcoded buffer size to mci functions, use sizeof.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/sound.c61
2 files changed, 44 insertions, 23 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6bb7107a206..c41591aaeaf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12009-01-12 Juanma Barranquero <lekktu@gmail.com>
2
3 * sound.c [WINDOWSNT] (SOUND_WARNING): New macro.
4 (do_play_sound): Use it. Don't pass a hardcoded buffer size to mci
5 functions, use sizeof.
6
12009-01-12 Martin Rudalics <rudalics@gmx.at> 72009-01-12 Martin Rudalics <rudalics@gmx.at>
2 8
3 * keyboard.c (read_char): Fix case where last_nonmenu_event 9 * keyboard.c (read_char): Fix case where last_nonmenu_event
diff --git a/src/sound.c b/src/sound.c
index 0f6fdb8e243..8f54a7a5e98 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1215,7 +1215,7 @@ alsa_write (sd, buffer, nbytes)
1215 { 1215 {
1216 snd_pcm_uframes_t frames = (nbytes - nwritten)/fact; 1216 snd_pcm_uframes_t frames = (nbytes - nwritten)/fact;
1217 if (frames == 0) break; 1217 if (frames == 0) break;
1218 1218
1219 err = snd_pcm_writei (p->handle, buffer + nwritten, frames); 1219 err = snd_pcm_writei (p->handle, buffer + nwritten, frames);
1220 if (err < 0) 1220 if (err < 0)
1221 { 1221 {
@@ -1301,6 +1301,16 @@ alsa_init (sd)
1301 1301
1302/* BEGIN: Windows specific functions */ 1302/* BEGIN: Windows specific functions */
1303 1303
1304#define SOUND_WARNING(fun, error, text) \
1305 { \
1306 char buf[1024]; \
1307 char err_string[MAXERRORLENGTH]; \
1308 fun (error, err_string, sizeof (err_string)); \
1309 snprintf (buf, sizeof (buf), "%s\nError: %s", \
1310 text, err_string); \
1311 sound_warning (buf); \
1312 }
1313
1304static int 1314static int
1305do_play_sound (psz_file, ui_volume) 1315do_play_sound (psz_file, ui_volume)
1306 const char *psz_file; 1316 const char *psz_file;
@@ -1314,16 +1324,17 @@ do_play_sound (psz_file, ui_volume)
1314 unsigned long ui_volume_org = 0; 1324 unsigned long ui_volume_org = 0;
1315 BOOL b_reset_volume = FALSE; 1325 BOOL b_reset_volume = FALSE;
1316 1326
1317 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); 1327 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1318 memset (sz_ret_buf, 0, sizeof(sz_ret_buf)); 1328 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1319 sprintf (sz_cmd_buf, 1329 sprintf (sz_cmd_buf,
1320 "open \"%s\" alias GNUEmacs_PlaySound_Device wait", 1330 "open \"%s\" alias GNUEmacs_PlaySound_Device wait",
1321 psz_file); 1331 psz_file);
1322 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL); 1332 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1323 if (mci_error != 0) 1333 if (mci_error != 0)
1324 { 1334 {
1325 sound_warning ("The open mciSendString command failed to open\n" 1335 SOUND_WARNING (mciGetErrorString, mci_error,
1326 "the specified sound file"); 1336 "The open mciSendString command failed to open "
1337 "the specified sound file.");
1327 i_result = (int) mci_error; 1338 i_result = (int) mci_error;
1328 return i_result; 1339 return i_result;
1329 } 1340 }
@@ -1334,42 +1345,46 @@ do_play_sound (psz_file, ui_volume)
1334 { 1345 {
1335 b_reset_volume = TRUE; 1346 b_reset_volume = TRUE;
1336 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume); 1347 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume);
1337 if ( mm_result != MMSYSERR_NOERROR) 1348 if (mm_result != MMSYSERR_NOERROR)
1338 { 1349 {
1339 sound_warning ("waveOutSetVolume failed to set the volume level\n" 1350 SOUND_WARNING (waveOutGetErrorText, mm_result,
1340 "of the WAVE_MAPPER device.\n" 1351 "waveOutSetVolume failed to set the volume level "
1341 "As a result, the user selected volume level will\n" 1352 "of the WAVE_MAPPER device.\n"
1342 "not be used."); 1353 "As a result, the user selected volume level will "
1354 "not be used.");
1343 } 1355 }
1344 } 1356 }
1345 else 1357 else
1346 { 1358 {
1347 sound_warning ("waveOutGetVolume failed to obtain the original\n" 1359 SOUND_WARNING (waveOutGetErrorText, mm_result,
1360 "waveOutGetVolume failed to obtain the original "
1348 "volume level of the WAVE_MAPPER device.\n" 1361 "volume level of the WAVE_MAPPER device.\n"
1349 "As a result, the user selected volume level will\n" 1362 "As a result, the user selected volume level will "
1350 "not be used."); 1363 "not be used.");
1351 } 1364 }
1352 } 1365 }
1353 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); 1366 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1354 memset (sz_ret_buf, 0, sizeof(sz_ret_buf)); 1367 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1355 strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait"); 1368 strcpy (sz_cmd_buf, "play GNUEmacs_PlaySound_Device wait");
1356 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL); 1369 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1357 if (mci_error != 0) 1370 if (mci_error != 0)
1358 { 1371 {
1359 sound_warning ("The play mciSendString command failed to play the\n" 1372 SOUND_WARNING (mciGetErrorString, mci_error,
1360 "opened sound file."); 1373 "The play mciSendString command failed to play the "
1374 "opened sound file.");
1361 i_result = (int) mci_error; 1375 i_result = (int) mci_error;
1362 } 1376 }
1363 memset (sz_cmd_buf, 0, sizeof(sz_cmd_buf)); 1377 memset (sz_cmd_buf, 0, sizeof (sz_cmd_buf));
1364 memset (sz_ret_buf, 0, sizeof(sz_ret_buf)); 1378 memset (sz_ret_buf, 0, sizeof (sz_ret_buf));
1365 strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait"); 1379 strcpy (sz_cmd_buf, "close GNUEmacs_PlaySound_Device wait");
1366 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, 520, NULL); 1380 mci_error = mciSendString (sz_cmd_buf, sz_ret_buf, sizeof (sz_ret_buf), NULL);
1367 if (b_reset_volume == TRUE) 1381 if (b_reset_volume == TRUE)
1368 { 1382 {
1369 mm_result=waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org); 1383 mm_result = waveOutSetVolume ((HWAVEOUT) WAVE_MAPPER, ui_volume_org);
1370 if (mm_result != MMSYSERR_NOERROR) 1384 if (mm_result != MMSYSERR_NOERROR)
1371 { 1385 {
1372 sound_warning ("waveOutSetVolume failed to reset the original volume\n" 1386 SOUND_WARNING (waveOutGetErrorText, mm_result,
1387 "waveOutSetVolume failed to reset the original volume "
1373 "level of the WAVE_MAPPER device."); 1388 "level of the WAVE_MAPPER device.");
1374 } 1389 }
1375 } 1390 }