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. release_0_8_9_final-


From: Sandro Santilli
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-2237-gad25f7c
Date: Wed, 16 Dec 2015 11:53:57 +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  ad25f7cfce18e59cb71a8d95f6c8a3181f83bec3 (commit)
      from  ec6f94b03274548a1a26e563d0518d68bbb2ec20 (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=ad25f7cfce18e59cb71a8d95f6c8a3181f83bec3


commit ad25f7cfce18e59cb71a8d95f6c8a3181f83bec3
Author: Sandro Santilli <address@hidden>
Date:   Wed Dec 16 12:49:55 2015 +0100

    Provide a default mixer in base sound_handler class
    
    The algorithm is taken from the aos4 sound_handler and used
    by NullSoundHandler when no other mixer is provided.
    
    The commit also re-drops the SDL SoundHandler initialization for
    dump-gui as it should now be good to mix w/out one.
    
    See ec6f94b03274548a1a26e563d0518d68bbb2ec20 for more info

diff --git a/gui/Player.cpp b/gui/Player.cpp
index 49bb12a..617b0fa 100644
--- a/gui/Player.cpp
+++ b/gui/Player.cpp
@@ -275,6 +275,7 @@ void
 Player::init_sound()
 {
 
+#ifndef GUI_DUMP
     if (_doSound) {
         try {
 #ifdef SOUND_SDL
@@ -296,6 +297,7 @@ Player::init_sound()
                 " Will continue without sound."), ex.what());
         }
     }
+#endif
 }
 
 void
diff --git a/libsound/NullSoundHandler.h b/libsound/NullSoundHandler.h
index ac4d4b2..ed35518 100644
--- a/libsound/NullSoundHandler.h
+++ b/libsound/NullSoundHandler.h
@@ -51,9 +51,7 @@ public:
     {
         if ( _mixer ) _mixer->mix(outSamples, inSamples, nSamples, volume);
         else {
-            // cheating, just copy input to output, which in NO WAY
-            // can be considered "mixing"
-            std::copy(outSamples, outSamples+nSamples, inSamples);
+            sound_handler::mix(outSamples, inSamples, nSamples, volume);
         }
     }
 
diff --git a/libsound/sound_handler.cpp b/libsound/sound_handler.cpp
index c6dcaf4..538060b 100644
--- a/libsound/sound_handler.cpp
+++ b/libsound/sound_handler.cpp
@@ -73,6 +73,46 @@ ensurePadding(SimpleBuffer& data, media::MediaHandler* m)
     }
 }
 
+/* The volume ranges from 0 - 128 */
+#define MIX_MAXVOLUME 128
+#define ADJUST_VOLUME(s, v)    (s = (s*v)/MIX_MAXVOLUME)
+#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/MIX_MAXVOLUME)+128)
+
+void 
+mixAudio(std::uint8_t *dst, const std::uint8_t *src, std::uint32_t len, int 
volume)
+{
+       if ( volume == 0 ) return;
+
+  std::int16_t src1, src2;
+  int dst_sample;
+  const int max_audioval = ((1<<(16-1))-1);
+  const int min_audioval = -(1<<(16-1));
+
+  len /= 2;
+  while ( len-- ) 
+  {
+    src1 = ((src[0])<<8|src[1]);
+    ADJUST_VOLUME(src1, volume);
+    src2 = ((dst[0])<<8|dst[1]);
+    src += 2;
+    dst_sample = src1+src2;
+    if ( dst_sample > max_audioval ) 
+    {
+      dst_sample = max_audioval;
+    } 
+    else
+    if ( dst_sample < min_audioval ) 
+    {
+      dst_sample = min_audioval;
+    }
+    dst[1] = dst_sample & 0xFF;
+    dst_sample >>= 8;
+    dst[0] = dst_sample & 0xFF;
+    dst += 2;
+  }
+       
+}
+
 } // anonymous namespace
 
 sound_handler::StreamBlockId
@@ -761,5 +801,16 @@ sound_handler::~sound_handler()
     unplugAllInputStreams();
 }
 
+void
+sound_handler::mix(std::int16_t* outSamples, std::int16_t* inSamples, unsigned 
int nSamples, float volume)
+{
+  unsigned int nBytes = nSamples*2;
+
+  std::uint8_t *out = reinterpret_cast<std::uint8_t*>(outSamples);
+  std::uint8_t* in = reinterpret_cast<std::uint8_t*>(inSamples);
+
+  mixAudio(out, in, nBytes, static_cast<int>(MIX_MAXVOLUME*volume));
+}
+
 } // gnash.sound namespace 
 } // namespace gnash
diff --git a/libsound/sound_handler.h b/libsound/sound_handler.h
index a5dd629..ea993f3 100644
--- a/libsound/sound_handler.h
+++ b/libsound/sound_handler.h
@@ -441,7 +441,7 @@ public:
     ///       with number of channels, at each fetching.
     ///
     virtual void mix(std::int16_t* outSamples, std::int16_t* inSamples,
-                unsigned int nSamples, float volume) = 0;
+                unsigned int nSamples, float volume);
 
     /// Request to dump audio to the given filename
     //

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

Summary of changes:
 gui/Player.cpp              |    2 +
 libsound/NullSoundHandler.h |    4 +--
 libsound/sound_handler.cpp  |   51 +++++++++++++++++++++++++++++++++++++++++++
 libsound/sound_handler.h    |    2 +-
 4 files changed, 55 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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