gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11507: Fixed Audio sound when using


From: Andrea Palmatè
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11507: Fixed Audio sound when using AHI
Date: Fri, 11 Sep 2009 18:59:21 +0200
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11507
committer: Andrea Palmatè <address@hidden>
branch nick: gnash
timestamp: Fri 2009-09-11 18:59:21 +0200
message:
  Fixed Audio sound when using AHI
modified:
  libsound/aos4/sound_handler_ahi.cpp
  libsound/aos4/sound_handler_ahi.h
=== modified file 'libsound/aos4/sound_handler_ahi.cpp'
--- a/libsound/aos4/sound_handler_ahi.cpp       2009-06-28 17:11:37 +0000
+++ b/libsound/aos4/sound_handler_ahi.cpp       2009-09-11 16:59:21 +0000
@@ -48,7 +48,7 @@
 
 #define PLAYERTASK_NAME       "Gnash audio task"
 #define PLAYERTASK_PRIORITY   20
-#define RESET_TIME 30 * 1000
+#define RESET_TIME 20 * 1000
 
 #define BUFSIZE                7056 * 4
 #define AHI_BUF_SIZE   28224u
@@ -59,6 +59,11 @@
 // Mixing and decoding debugging
 //#define GNASH_DEBUG_MIXING
 
+/* 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)
+
 int audioTaskID;
 
 static int
@@ -365,6 +370,9 @@
 {
        if (!_closing)
        {
+               AHIRequest *req = AHIios[AHICurBuf];
+               UWORD AHIOtherBuf = AHICurBuf^1;
+
            boost::mutex::scoped_lock lock(_mutex);
        if (!_closing) 
        {
@@ -386,69 +394,112 @@
                std::fill(to, to+nSamples, 0);
        }
 
-           // If nothing is left to play there is no reason to keep polling.
-       if ( ! hasInputStreams() )
-           {
+               //memcpy(BufferPointer, inSamples, nBytes);
+               memcpy(BufferPointer, to, nSamples*2);
+
+               if (AHIReqSent[AHICurBuf])
+               {
+                       if (req->ahir_Std.io_Data)
+                       {
+                               IExec->WaitIO((struct IORequest *)req);
+                               req->ahir_Std.io_Data = NULL;
+
+                               IExec->GetMsg(AHImp);
+                               IExec->GetMsg(AHImp);
+                       }
+               }
+
+               req->ahir_Std.io_Message.mn_Node.ln_Pri = 127;
+               req->ahir_Std.io_Command        = CMD_WRITE;
+               req->ahir_Std.io_Offset         = 0;
+               req->ahir_Frequency             = (ULONG) 44100;
+               req->ahir_Volume                = 0x10000;          // Full 
volume
+               req->ahir_Position              = 0x8000;           // Centered
+               req->ahir_Std.io_Data           = PlayBuffer[AHIOtherBuf];
+               req->ahir_Std.io_Length         = (ULONG) nSamples*2; //BUFSIZE;
+               req->ahir_Type                          = AHIST_S16S;
+               req->ahir_Link                  = (AHIReqSent[AHIOtherBuf] && 
!IExec->CheckIO((IORequest *) AHIios[AHIOtherBuf])) ? AHIios[AHIOtherBuf] : 
NULL;
+
+               IExec->SendIO( (struct IORequest *) req);
+
+               AHIReqSent[AHICurBuf] = true;
+               AHICurBuf = AHIOtherBuf;
+
+               BufferPointer = PlayBuffer[AHICurBuf];
+       }
+
+
+    // If nothing is left to play there is no reason to keep polling.
+       if ( ! hasInputStreams() )
+    {
 #ifdef GNASH_DEBUG_AOS4_AUDIO_PAUSING
-           log_debug("Pausing AOS4 Audio...");
+           log_debug("Pausing AOS4 Audio...");
 #endif
-                       sound_handler::pause();
-       }
-       }
+               sound_handler::pause();
+       }
+}
+
+void 
+AOS4_sound_handler::MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, 
boost::uint32_t len, int volume)
+{
+       boost::uint16_t format;
+
+       if ( volume == 0 ) 
+       {
+               return;
+       }
+
+       format = AHIST_S16S;
+
+       /* Actually we have a fixed audio format */
+       switch (format) 
+       {
+               case AHIST_S16S:
+               {
+                       boost::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;
+                       }
+               }
+               break;
+       }
+       
 }
 
 void
 AOS4_sound_handler::mix(boost::int16_t* outSamples, boost::int16_t* inSamples, 
unsigned int nSamples, float volume)
 {
-    unsigned int nBytes = nSamples*2;
-
        if (!_closing)
        {
-               memcpy(BufferPointer, inSamples, nBytes);
-               BufferPointer += nBytes;
-               BufferFill    += nBytes;
-
-               if (BufferFill >= BUFSIZE)
-               {
-                       //while (!AHIReqSent[AHICurBuf] || 
IExec->CheckIO((struct IORequest *) AHIios[AHICurBuf]))
-                       {
-                               //printf("playing: Buffer:%d - Bufsize: 
%d\n",BufferFill, BUFSIZE);
-                               AHIRequest *req = AHIios[AHICurBuf];
-                               UWORD AHIOtherBuf = AHICurBuf^1;
-
-                               if (AHIReqSent[AHICurBuf])
-                               {
-                                       if (req->ahir_Std.io_Data)
-                                       {
-                                               IExec->WaitIO((struct IORequest 
*)req);
-                                               req->ahir_Std.io_Data = NULL;
-
-                                               IExec->GetMsg(AHImp);
-                                               IExec->GetMsg(AHImp);
-                                       }
-                               }
-
-                               req->ahir_Std.io_Message.mn_Node.ln_Pri = 127;
-                               req->ahir_Std.io_Command        = CMD_WRITE;
-                               req->ahir_Std.io_Offset         = 0;
-                               req->ahir_Frequency             = (ULONG) 44100;
-                               req->ahir_Volume                = 0x10000;      
    // Full volume
-                               req->ahir_Position              = 0x8000;       
    // Centered
-                               req->ahir_Std.io_Data           = 
PlayBuffer[AHIOtherBuf];
-                               req->ahir_Std.io_Length         = (ULONG) 
BUFSIZE;
-                               req->ahir_Type                          = 
AHIST_S16S;
-                               req->ahir_Link                  = 
(AHIReqSent[AHIOtherBuf] && !IExec->CheckIO((IORequest *) AHIios[AHIOtherBuf])) 
? AHIios[AHIOtherBuf] : NULL;
-
-                               IExec->SendIO( (struct IORequest *) req);
-
-                               AHIReqSent[AHICurBuf] = true;
-                               AHICurBuf = AHIOtherBuf;
-
-                               BufferPointer = PlayBuffer[AHICurBuf];
-                               BufferFill = 0;
-                       }
-                       //signals = IExec->Wait(1 << AHImp->mp_SigBit);
-               }
+           unsigned int nBytes = nSamples*2;
+
+           boost::uint8_t *out = reinterpret_cast<boost::uint8_t*>(outSamples);
+       boost::uint8_t* in = reinterpret_cast<boost::uint8_t*>(inSamples);
+
+           MixAudio(out, in, nBytes, MIX_MAXVOLUME*volume);
        }
 }
 

=== modified file 'libsound/aos4/sound_handler_ahi.h'
--- a/libsound/aos4/sound_handler_ahi.h 2009-06-28 15:49:26 +0000
+++ b/libsound/aos4/sound_handler_ahi.h 2009-09-11 16:59:21 +0000
@@ -107,6 +107,8 @@
     void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
                 unsigned int nSamples, float volume);
 
+       void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, 
boost::uint32_t len, int volume);
+
 public:
 
     AOS4_sound_handler();


reply via email to

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