comparison src/sound.c @ 101141:706175eda1de

* sound.c [WINDOWSNT] (SOUND_WARNING): New macro. (do_play_sound): Use it. Don't pass a hardcoded buffer size to mci functions, use sizeof.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 12 Jan 2009 16:18:31 +0000
parents e038c1a8307c
children 877adea17756
comparison
equal deleted inserted replaced
101140:d4a656ae8ace 101141:706175eda1de
1213 1213
1214 while (nwritten < nbytes) 1214 while (nwritten < 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 {
1222 if (err == -EPIPE) 1222 if (err == -EPIPE)
1223 { /* under-run */ 1223 { /* under-run */
1299 /* END: Non Windows functions */ 1299 /* END: Non Windows functions */
1300 #else /* WINDOWSNT */ 1300 #else /* WINDOWSNT */
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
1304 static int 1314 static int
1305 do_play_sound (psz_file, ui_volume) 1315 do_play_sound (psz_file, ui_volume)
1306 const char *psz_file; 1316 const char *psz_file;
1307 unsigned long ui_volume; 1317 unsigned long ui_volume;
1308 { 1318 {
1312 char sz_ret_buf[520] = {0}; 1322 char sz_ret_buf[520] = {0};
1313 MMRESULT mm_result = MMSYSERR_NOERROR; 1323 MMRESULT mm_result = MMSYSERR_NOERROR;
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 }
1330 if ((ui_volume > 0) && (ui_volume != UINT_MAX)) 1341 if ((ui_volume > 0) && (ui_volume != UINT_MAX))
1331 { 1342 {
1332 mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org); 1343 mm_result = waveOutGetVolume ((HWAVEOUT) WAVE_MAPPER, &ui_volume_org);
1333 if (mm_result == MMSYSERR_NOERROR) 1344 if (mm_result == MMSYSERR_NOERROR)
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 }
1376 return i_result; 1391 return i_result;
1377 } 1392 }