r3839: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 21 Jan 2003 19:46:53 +0000 (19:46 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 21 Jan 2003 19:46:53 +0000 (19:46 +0000)
wdq2wav.cpp

index 0607f123e46d6fa0621065261bd82722dc4029b6..12aad5e301979ef2a58a9e85591ed04280e1a022 100644 (file)
@@ -8,7 +8,7 @@
 **
 **  Copyright (c) 2003 Kevin Rosenberg
 **
 **
 **  Copyright (c) 2003 Kevin Rosenberg
 **
-**  $Id: wdq2wav.cpp,v 1.12 2003/01/21 12:59:56 kevin Exp $
+**  $Id: wdq2wav.cpp,v 1.13 2003/01/21 19:46:53 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -26,7 +26,7 @@
 
 #include <wdq2wav.h>
 
 
 #include <wdq2wav.h>
 
-const char* g_szIdStr = "$Id: wdq2wav.cpp,v 1.12 2003/01/21 12:59:56 kevin Exp $";
+const char* g_szIdStr = "$Id: wdq2wav.cpp,v 1.13 2003/01/21 19:46:53 kevin Exp $";
 
 bool g_quiet = false;
 bool g_verbose = false;
 
 bool g_quiet = false;
 bool g_verbose = false;
@@ -644,7 +644,7 @@ WavFile::Play ()
     return true;
 #elif defined(LINUX)
   int fd;
     return true;
 #elif defined(LINUX)
   int fd;
-  if ((fd = open ("/dev/dsp",O_WRONLY)) < 0) {
+  if ((fd = open ("/dev/dsp",O_WRONLY)) == -1) {
     error_msg ("Error opening /dev/dsp");
     return false;
   }
     error_msg ("Error opening /dev/dsp");
     return false;
   }
@@ -652,35 +652,43 @@ WavFile::Play ()
   int format = AFMT_S16_LE;
   if (ioctl (fd, SNDCTL_DSP_SETFMT, &format) == -1) {
     error_msg ("Error setting DSP format");
   int format = AFMT_S16_LE;
   if (ioctl (fd, SNDCTL_DSP_SETFMT, &format) == -1) {
     error_msg ("Error setting DSP format");
-    close(fd); return false; }
+    close(fd); return false;
+  }
   if (format != AFMT_S16_LE) {
     error_msg ("DSP Format not set");
   if (format != AFMT_S16_LE) {
     error_msg ("DSP Format not set");
-    close(fd); return false; }
+    close(fd); return false;
+  }
   
   int channels = m_nChannels;
   if (ioctl (fd, SNDCTL_DSP_CHANNELS, &format) == -1) {
     error_msg ("Error setting number of channels");
   
   int channels = m_nChannels;
   if (ioctl (fd, SNDCTL_DSP_CHANNELS, &format) == -1) {
     error_msg ("Error setting number of channels");
-    close(fd); return false; }
+    close(fd); return false;
+  }
   if (channels != m_nChannels) {
     error_msg ("Number of channels not set");
   if (channels != m_nChannels) {
     error_msg ("Number of channels not set");
-    close(fd); return false; }
+    close(fd); return false;
+  }
 
   int speed = static_cast<int>(m_rate + 0.5);
   if (ioctl (fd, SNDCTL_DSP_SPEED, &speed) == -1) {
     error_msg ("Error setting sample rate");
 
   int speed = static_cast<int>(m_rate + 0.5);
   if (ioctl (fd, SNDCTL_DSP_SPEED, &speed) == -1) {
     error_msg ("Error setting sample rate");
-    close(fd); return false; }
-  double set_speed = speed;
-  if (fabs (set_speed - m_rate) / m_rate > 0.1) {
-    error_msg ("Sample rate not set");
-    close(fd); return false; }
+    close(fd); return false;
+  }
+  if (speed != m_rate && ! g_quiet) {
+    std::ostringstream os;
+    os << "Warning: Sample rate set to " << speed << ", not " << m_rate;
+    error_msg (os.str().c_str());
+  }
     
   if (write (fd, reinterpret_cast<char*>(m_data) + m_nHeaderBytes, m_nDataBytes) !=
       m_nDataBytes) {
     error_msg ("Error writing audio samples");
     
   if (write (fd, reinterpret_cast<char*>(m_data) + m_nHeaderBytes, m_nDataBytes) !=
       m_nDataBytes) {
     error_msg ("Error writing audio samples");
-    close(fd); return false; }
+    close(fd); return false;
+  }
 
   close (fd);
   return true;
 
   close (fd);
   return true;
+#else
 #endif
   
   return false;
 #endif
   
   return false;