gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] [SCM] Gnash branch, master, updated. 34ca16c955e36d6065d4


From: Sandro Santilli
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. 34ca16c955e36d6065d418ab850684edf2e3555e
Date: Thu, 21 Oct 2010 17:32:05 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  34ca16c955e36d6065d418ab850684edf2e3555e (commit)
       via  ea37821e1290414c2a7c32507318fe20d13f5b43 (commit)
      from  858b9031533df4562d21ca69792217fa5fccf8c8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=34ca16c955e36d6065d418ab850684edf2e3555e


commit 34ca16c955e36d6065d418ab850684edf2e3555e
Author: Sandro Santilli <address@hidden>
Date:   Thu Oct 21 19:23:10 2010 +0200

    Fix build

diff --git a/libsound/WAVWriter.cpp b/libsound/WAVWriter.cpp
index 8f8eaef..866c80c 100644
--- a/libsound/WAVWriter.cpp
+++ b/libsound/WAVWriter.cpp
@@ -17,8 +17,14 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+#include "WAVWriter.h"
+#include "GnashException.h" // for SoundException
+#include "log.h" // will import boost::format too
+
+#include <cstring> // for strncpy
 #include <boost/cstdint.hpp>
 #include <fstream> // for composition (file_stream)
+#include <iostream>
 
 
 namespace gnash {
@@ -52,12 +58,13 @@ typedef struct{
 } // end of anonymous namespace
 
 /* public */
-WAVWRiter::WAVWriter(const std::string& fname)
+WAVWriter::WAVWriter(const std::string& wavefile)
 {
         file_stream.open(wavefile.c_str());
         if (file_stream.fail()) {
-            std::cerr << "Unable to write file '" << wavefile << std::endl;
-            std::exit(EXIT_FAILURE);
+            boost::format fmt = boost::format(_("Unable to write file %1%"))
+                % wavefile;
+            throw SoundException(fmt.str());
         } 
         else {
             write_wave_header(file_stream);
@@ -67,7 +74,7 @@ WAVWRiter::WAVWriter(const std::string& fname)
 }
 
 /* public */
-WAVWRiter::~WAVWriter()
+WAVWriter::~WAVWriter()
 {
     if (file_stream) file_stream.close();
 }
diff --git a/libsound/WAVWriter.h b/libsound/WAVWriter.h
index a648a9d..3af9b33 100644
--- a/libsound/WAVWriter.h
+++ b/libsound/WAVWriter.h
@@ -21,6 +21,7 @@
 #define GNASH_SOUND_WAVWRITER_H
 
 #include <fstream> // for composition (file_stream)
+#include <boost/cstdint.hpp>
 
 namespace gnash {
 namespace sound {
@@ -51,7 +52,7 @@ public:
     ///           to give interpretation of what comes back (how many
     ///           bytes per channel, which format).
     ///
-    virtual void pushSamples(boost::int16_t* from, unsigned int nSamples);
+    void pushSamples(boost::int16_t* from, unsigned int nSamples);
 
 private:
 
diff --git a/libsound/sdl/sound_handler_sdl.cpp 
b/libsound/sdl/sound_handler_sdl.cpp
index 91e0c53..eeac697 100644
--- a/libsound/sdl/sound_handler_sdl.cpp
+++ b/libsound/sdl/sound_handler_sdl.cpp
@@ -32,7 +32,6 @@
 
 #include <vector>
 #include <boost/scoped_array.hpp>
-//#include <boost/cstdint.hpp>
 #include <SDL.h>
 
 // Define this to get debugging call about pausing/unpausing audio

http://git.savannah.gnu.org/cgit//commit/?id=ea37821e1290414c2a7c32507318fe20d13f5b43


commit ea37821e1290414c2a7c32507318fe20d13f5b43
Author: Sandro Santilli <address@hidden>
Date:   Thu Oct 21 19:13:30 2010 +0200

    WAVWriter class out of sdl sound handler (for reuse by others)

diff --git a/libsound/Makefile.am b/libsound/Makefile.am
index 1f5fe62..4348b31 100644
--- a/libsound/Makefile.am
+++ b/libsound/Makefile.am
@@ -41,6 +41,7 @@ libgnashsound_la_SOURCES = \
        sound_handler.cpp \
        EmbedSound.cpp \
        EmbedSoundInst.cpp \
+       WAVWriter.cpp \
        $(NULL)
 
 noinst_HEADERS = \
@@ -50,7 +51,8 @@ noinst_HEADERS = \
        InputStream.h \
        EmbedSound.h \
        EmbedSoundInst.h \
-        AuxStream.h
+       AuxStream.h \
+       WAVWriter.h \
        $(NULL)
 
 if USE_SOUND_SDL
diff --git a/libsound/WAVWriter.cpp b/libsound/WAVWriter.cpp
new file mode 100644
index 0000000..8f8eaef
--- /dev/null
+++ b/libsound/WAVWriter.cpp
@@ -0,0 +1,126 @@
+// WAVWriter.cpp: .wav audio writer 
+//
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+//   Foundation, Inc
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include <boost/cstdint.hpp>
+#include <fstream> // for composition (file_stream)
+
+
+namespace gnash {
+namespace sound {
+
+namespace { // anonymous
+
+// Header of a wave file
+// http://ftp.iptel.org/pub/sems/doc/full/current/wav__hdr_8c-source.html
+typedef struct{
+     char rID[4];            // 'RIFF'
+     boost::uint32_t rLen;        
+     char wID[4];            // 'WAVE'
+     char fId[4];            // 'fmt '
+     boost::uint32_t pcm_header_len;   // varies...
+     boost::int16_t wFormatTag;
+     boost::int16_t nChannels;      // 1,2 for stereo data is (l,r) pairs
+     boost::uint32_t nSamplesPerSec;
+     boost::uint32_t nAvgBytesPerSec;
+     boost::int16_t nBlockAlign;      
+     boost::int16_t nBitsPerSample;
+} WAV_HDR;
+
+// Chunk of wave file
+// http://ftp.iptel.org/pub/sems/doc/full/current/wav__hdr_8c-source.html
+typedef struct{
+    char dId[4];            // 'data' or 'fact'
+    boost::uint32_t dLen;
+} CHUNK_HDR;
+
+} // end of anonymous namespace
+
+/* public */
+WAVWRiter::WAVWriter(const std::string& fname)
+{
+        file_stream.open(wavefile.c_str());
+        if (file_stream.fail()) {
+            std::cerr << "Unable to write file '" << wavefile << std::endl;
+            std::exit(EXIT_FAILURE);
+        } 
+        else {
+            write_wave_header(file_stream);
+            std::cout << "# Created 44100 16Mhz stereo wave file:\n" <<
+                    "AUDIOFILE=" << wavefile << std::endl;
+        }
+}
+
+/* public */
+WAVWRiter::~WAVWriter()
+{
+    if (file_stream) file_stream.close();
+}
+
+/* public */
+void
+WAVWriter::pushSamples(boost::int16_t* from, unsigned int nSamples)
+{
+    // NOTE: if muted, the samples will be silent already
+        boost::uint8_t* stream = reinterpret_cast<boost::uint8_t*>(from);
+        unsigned int len = nSamples*2;
+        file_stream.write((char*) stream, len);
+
+}
+
+/* private */
+void
+WAVWriter::write_wave_header(std::ofstream& outfile)
+{
+ 
+  // allocate wav header
+  WAV_HDR wav;
+  CHUNK_HDR chk;
+ 
+  // setup wav header
+  std::strncpy(wav.rID, "RIFF", 4);
+  std::strncpy(wav.wID, "WAVE", 4);
+  std::strncpy(wav.fId, "fmt ", 4);
+ 
+  wav.nBitsPerSample = 16;
+  wav.nSamplesPerSec = 44100;
+  wav.nAvgBytesPerSec = 44100;
+  wav.nAvgBytesPerSec *= wav.nBitsPerSample / 8;
+  wav.nAvgBytesPerSec *= 2;
+  wav.nChannels = 2;
+    
+  wav.pcm_header_len = 16;
+  wav.wFormatTag = 1;
+  wav.rLen = sizeof(WAV_HDR) + sizeof(CHUNK_HDR);
+  wav.nBlockAlign = 2 * wav.nBitsPerSample / 8;
+
+  // setup chunk header
+  std::strncpy(chk.dId, "data", 4);
+  chk.dLen = 0;
+ 
+  /* write riff/wav header */
+  outfile.write((char *)&wav, sizeof(WAV_HDR));
+ 
+  /* write chunk header */
+  outfile.write((char *)&chk, sizeof(CHUNK_HDR));
+ 
+}
+
+
+} // gnash.sound namespace 
+} // namespace gnash
diff --git a/libsound/WAVWriter.h b/libsound/WAVWriter.h
new file mode 100644
index 0000000..a648a9d
--- /dev/null
+++ b/libsound/WAVWriter.h
@@ -0,0 +1,72 @@
+// WAVWriter.h: .wav audio writer 
+//
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+//   Foundation, Inc
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef GNASH_SOUND_WAVWRITER_H
+#define GNASH_SOUND_WAVWRITER_H
+
+#include <fstream> // for composition (file_stream)
+
+namespace gnash {
+namespace sound {
+
+/// WAV writer class
+class WAVWriter {
+
+public:
+
+    WAVWriter(const std::string& outfile);
+
+    ~WAVWriter();
+
+    /// Write samples to file
+    //
+    /// @param from
+    ///     The buffer to read samples from.
+    ///     Buffer must be big enough to hold nSamples samples.
+    ///
+    /// @param nSamples
+    ///     The amount of samples to read.
+    ///     NOTE: this number currently refers to "mono" samples
+    ///     due to some bad design decision. It is so expected
+    ///     that the user fetches 44100 * 2 samples which has to
+    ///     be interpreted as series of left,right channel couples.
+    ///     TODO: use actual number of samples so that it's expected
+    ///           to fetch 44100 per second and let expose a function
+    ///           to give interpretation of what comes back (how many
+    ///           bytes per channel, which format).
+    ///
+    virtual void pushSamples(boost::int16_t* from, unsigned int nSamples);
+
+private:
+
+    /// File stream for dump file
+    //
+    /// TODO: move to base class ?
+    ///
+    std::ofstream file_stream;
+
+    // write a .WAV file header
+    void write_wave_header(std::ofstream& outfile);
+
+};
+
+} // gnash.sound namespace 
+} // namespace gnash
+
+#endif // GNASH_SOUND_WAVWRITER_H
diff --git a/libsound/sdl/sound_handler_sdl.cpp 
b/libsound/sdl/sound_handler_sdl.cpp
index 5195898..91e0c53 100644
--- a/libsound/sdl/sound_handler_sdl.cpp
+++ b/libsound/sdl/sound_handler_sdl.cpp
@@ -32,7 +32,7 @@
 
 #include <vector>
 #include <boost/scoped_array.hpp>
-#include <boost/cstdint.hpp>
+//#include <boost/cstdint.hpp>
 #include <SDL.h>
 
 // Define this to get debugging call about pausing/unpausing audio
@@ -41,32 +41,6 @@
 // Mixing and decoding debugging
 //#define GNASH_DEBUG_MIXING
 
-namespace { // anonymous
-
-// Header of a wave file
-// http://ftp.iptel.org/pub/sems/doc/full/current/wav__hdr_8c-source.html
-typedef struct{
-     char rID[4];            // 'RIFF'
-     boost::uint32_t rLen;        
-     char wID[4];            // 'WAVE'
-     char fId[4];            // 'fmt '
-     boost::uint32_t pcm_header_len;   // varies...
-     boost::int16_t wFormatTag;
-     boost::int16_t nChannels;      // 1,2 for stereo data is (l,r) pairs
-     boost::uint32_t nSamplesPerSec;
-     boost::uint32_t nAvgBytesPerSec;
-     boost::int16_t nBlockAlign;      
-     boost::int16_t nBitsPerSample;
-} WAV_HDR;
-
-// Chunk of wave file
-// http://ftp.iptel.org/pub/sems/doc/full/current/wav__hdr_8c-source.html
-typedef struct{
-    char dId[4];            // 'data' or 'fact'
-    boost::uint32_t dLen;
-} CHUNK_HDR;
-
-} // end of anonymous namespace
 
 namespace gnash {
 namespace sound {
@@ -141,16 +115,7 @@ SDL_sound_handler::SDL_sound_handler(media::MediaHandler* 
m,
     initAudio();
 
     if (!wavefile.empty()) {
-        file_stream.open(wavefile.c_str());
-        if (file_stream.fail()) {
-            std::cerr << "Unable to write file '" << wavefile << std::endl;
-            std::exit(EXIT_FAILURE);
-        } 
-        else {
-            write_wave_header(file_stream);
-            std::cout << "# Created 44100 16Mhz stereo wave file:\n" <<
-                    "AUDIOFILE=" << wavefile << std::endl;
-        }
+       _wavWriter.reset(new WAVWriter(wavefile));
     }
 
 }
@@ -188,7 +153,6 @@ SDL_sound_handler::~SDL_sound_handler()
 
     SDL_CloseAudio();
 
-    if (file_stream) file_stream.close();
 }
 
 
@@ -282,44 +246,6 @@ create_sound_handler_sdl(media::MediaHandler* m, const 
std::string& wave_file)
     return new SDL_sound_handler(m, wave_file);
 }
 
-// write a wave header, using the current audioSpec settings
-void
-SDL_sound_handler::write_wave_header(std::ofstream& outfile)
-{
- 
-  // allocate wav header
-  WAV_HDR wav;
-  CHUNK_HDR chk;
- 
-  // setup wav header
-  std::strncpy(wav.rID, "RIFF", 4);
-  std::strncpy(wav.wID, "WAVE", 4);
-  std::strncpy(wav.fId, "fmt ", 4);
- 
-  wav.nBitsPerSample = ((audioSpec.format == AUDIO_S16SYS) ? 16 : 0);
-  wav.nSamplesPerSec = audioSpec.freq;
-  wav.nAvgBytesPerSec = audioSpec.freq;
-  wav.nAvgBytesPerSec *= wav.nBitsPerSample / 8;
-  wav.nAvgBytesPerSec *= audioSpec.channels;
-  wav.nChannels = audioSpec.channels;
-    
-  wav.pcm_header_len = 16;
-  wav.wFormatTag = 1;
-  wav.rLen = sizeof(WAV_HDR) + sizeof(CHUNK_HDR);
-  wav.nBlockAlign = audioSpec.channels * wav.nBitsPerSample / 8;
-
-  // setup chunk header
-  std::strncpy(chk.dId, "data", 4);
-  chk.dLen = 0;
- 
-  /* write riff/wav header */
-  outfile.write((char *)&wav, sizeof(WAV_HDR));
- 
-  /* write chunk header */
-  outfile.write((char *)&chk, sizeof(CHUNK_HDR));
- 
-}
-
 void
 SDL_sound_handler::fetchSamples(boost::int16_t* to, unsigned int nSamples)
 {
@@ -327,12 +253,9 @@ SDL_sound_handler::fetchSamples(boost::int16_t* to, 
unsigned int nSamples)
     sound_handler::fetchSamples(to, nSamples);
 
     // TODO: move this to base class !
-    if (file_stream)
+    if (_wavWriter.get())
     {
-        // NOTE: if muted, the samples will be silent already
-        boost::uint8_t* stream = reinterpret_cast<boost::uint8_t*>(to);
-        unsigned int len = nSamples*2;
-        file_stream.write((char*) stream, len);
+       _wavWriter->pushSamples(to, nSamples);
 
         // now, mute all audio
         std::fill(to, to+nSamples, 0);
diff --git a/libsound/sdl/sound_handler_sdl.h b/libsound/sdl/sound_handler_sdl.h
index b6122dd..b7efb69 100644
--- a/libsound/sdl/sound_handler_sdl.h
+++ b/libsound/sdl/sound_handler_sdl.h
@@ -23,12 +23,13 @@
 
 
 #include "sound_handler.h" // for inheritance
+#include "WAVWriter.h" // for dtor visibility 
 
 #include <string>
 #include <set> // for composition (InputStreams)
-#include <fstream> // for composition (file_stream)
 #include <SDL_audio.h>
 #include <boost/thread/mutex.hpp>
+#include <boost/scoped_ptr.hpp>
 
 // Forward declarations
 namespace gnash {
@@ -50,6 +51,8 @@ private:
     /// The SDL_audio specs
     SDL_AudioSpec audioSpec;
 
+    boost::scoped_ptr<WAVWriter> _wavWriter;
+
     /// Initialize audio card
     void initAudio();
 
@@ -65,15 +68,6 @@ private:
     /// Mutex protecting _muted (defined in base class)
     mutable boost::mutex _mutedMutex;
 
-    /// File stream for dump file
-    //
-    /// TODO: move to base class ?
-    ///
-    std::ofstream file_stream;
-
-    // write a .WAV file header
-    void write_wave_header(std::ofstream& outfile);
-
     // See dox in sound_handler.h
     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
                 unsigned int nSamples, float volume);

-----------------------------------------------------------------------

Summary of changes:
 libsound/Makefile.am               |    4 +-
 libsound/WAVWriter.cpp             |  133 ++++++++++++++++++++++++++++++++++++
 libsound/WAVWriter.h               |   73 ++++++++++++++++++++
 libsound/sdl/sound_handler_sdl.cpp |   84 +----------------------
 libsound/sdl/sound_handler_sdl.h   |   14 +---
 5 files changed, 216 insertions(+), 92 deletions(-)
 create mode 100644 libsound/WAVWriter.cpp
 create mode 100644 libsound/WAVWriter.h


hooks/post-receive
-- 
Gnash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]