From 0f51d28732d3adc58319cd4b5f9bb5ec2516c40a Mon Sep 17 00:00:00 2001
From: Erik Hofman <erik@ehofman.com>
Date: Fri, 27 May 2016 11:37:47 +0200
Subject: [PATCH] Remove unused sample queue code

---
 simgear/sound/CMakeLists.txt    |   3 -
 simgear/sound/openal_test4.cxx  |  75 -------------------
 simgear/sound/sample_group.hxx  |   1 -
 simgear/sound/sample_openal.hxx |   1 +
 simgear/sound/sample_queue.cxx  | 126 --------------------------------
 simgear/sound/sample_queue.hxx  |  96 ------------------------
 6 files changed, 1 insertion(+), 301 deletions(-)
 delete mode 100644 simgear/sound/openal_test4.cxx
 delete mode 100644 simgear/sound/sample_queue.cxx
 delete mode 100644 simgear/sound/sample_queue.hxx

diff --git a/simgear/sound/CMakeLists.txt b/simgear/sound/CMakeLists.txt
index a15c9110..c2538938 100644
--- a/simgear/sound/CMakeLists.txt
+++ b/simgear/sound/CMakeLists.txt
@@ -3,7 +3,6 @@ include (SimGearComponent)
 set(HEADERS 
     sample_group.hxx
     sample_openal.hxx
-    sample_queue.hxx
     soundmgr_openal.hxx
     xmlsound.hxx
     readwav.hxx
@@ -12,7 +11,6 @@ set(HEADERS
 set(SOURCES 
     sample_group.cxx
     sample_openal.cxx
-    sample_queue.cxx
     soundmgr_openal.cxx
     xmlsound.cxx
     readwav.cxx
@@ -42,5 +40,4 @@ endfunction()
 create_test(openal_test1)
 create_test(openal_test2)
 create_test(openal_test3)
-create_test(openal_test4)
 endif()
diff --git a/simgear/sound/openal_test4.cxx b/simgear/sound/openal_test4.cxx
deleted file mode 100644
index eaf2bcab..00000000
--- a/simgear/sound/openal_test4.cxx
+++ /dev/null
@@ -1,75 +0,0 @@
-#include <stdio.h>
-#ifdef _WIN32
-#include <windows.h>
-#define sleep(x) Sleep(x*1000)
-#else
-#include <unistd.h>
-#endif
-
-#include <simgear/debug/logstream.hxx>
-#include <simgear/misc/sg_path.hxx>
-
-#include "soundmgr_openal.hxx"
-#include "sample_group.hxx"
-#include "sample_openal.hxx"
-
-int main( int argc, char *argv[] ) {
-    SGSampleQueue *squeue;
-    SGSampleGroup *sgr;
-    SGSoundMgr *smgr;
-    SGGeod pos;
-
-    smgr = new SGSoundMgr;
-
-    smgr->bind();
-    smgr->select_device("OSS Default");
-    smgr->init();
-    sgr = smgr->find("default", true);
-    smgr->set_volume(0.9);
-    smgr->activate();
-    smgr->set_position( SGVec3d::fromGeod(SGGeod()), SGGeod() );
-
-    void *data;
-    size_t len;
-    int freq, fmt;
-    std::string file = SRC_DIR"/jet.wav";
-    smgr->load(file, &data, &fmt, &len, &freq);
-
-    squeue = new SGSampleQueue( freq, fmt );
-    squeue->set_volume(1.0);
-  
-    sgr->add(squeue, "queue");
-
-    squeue->add(  data, len );
-    squeue->add(  data, len );
-    squeue->play();
-    printf("playing queue\n");
-
-    smgr->update(1.0);
-    sleep(10);
-    smgr->update(10.0);
-
-    printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
-    pos = SGGeod::fromDeg(9.99,-9.99);
-    sgr->set_position_geod( SGGeod::fromDeg(10,-10) );
-    smgr->set_position( SGVec3d::fromGeod(pos), pos );
-
-    squeue->add(  data, len );
-    squeue->add(  data, len );
-    squeue->play( true ); // play looped
-    printf("playing queue\n");
-
-    smgr->update(1.0);
-    sleep(10);
-    smgr->update(10.0);
-
-    squeue->stop();
-    smgr->update(1.0);
-    sleep(1);
-
-    sgr->remove("queue");
-    smgr->unbind();
-    sleep(2);
-
-    delete smgr;
-}
diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx
index f87cb1dc..4d307dd9 100644
--- a/simgear/sound/sample_group.hxx
+++ b/simgear/sound/sample_group.hxx
@@ -37,7 +37,6 @@
 #include <simgear/structure/exception.hxx>
 
 #include "sample_openal.hxx"
-#include "sample_queue.hxx"
 
 
 typedef std::map < std::string, SGSharedPtr<SGSoundSample> > sample_map;
diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx
index 34a54064..286379fa 100644
--- a/simgear/sound/sample_openal.hxx
+++ b/simgear/sound/sample_openal.hxx
@@ -30,6 +30,7 @@
 #ifndef _SG_SAMPLE_HXX
 #define _SG_SAMPLE_HXX 1
 
+#include <simgear/math/SGMath.hxx>
 #include <simgear/props/props.hxx>
      
 enum {
diff --git a/simgear/sound/sample_queue.cxx b/simgear/sound/sample_queue.cxx
deleted file mode 100644
index 30e1c550..00000000
--- a/simgear/sound/sample_queue.cxx
+++ /dev/null
@@ -1,126 +0,0 @@
-
-// queue.cxx -- Audio sample encapsulation class
-// 
-// Written by Curtis Olson, started April 2004.
-// Modified to match the new SoundSystem by Erik Hofman, October 2009
-//
-// Copyright (C) 2004  Curtis L. Olson - http://www.flightgear.org/~curt
-// Copyright (C) 2009 Erik Hofman <erik@ehofman.com>
-//
-// 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 2 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 Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//
-// $Id$
-
-#ifdef HAVE_CONFIG_H
-#  include <simgear_config.h>
-#endif
-
-#include <cstdlib>	// rand()
-#include <cstring>
-
-#include <simgear/debug/logstream.hxx>
-#include <simgear/structure/exception.hxx>
-#include <simgear/misc/sg_path.hxx>
-
-#include "soundmgr_openal.hxx"
-#include "sample_queue.hxx"
-#include "soundmgr_openal_private.hxx"
-
-using std::string;
-
-//
-// SGSampleQueue
-//
-
-// empty constructor
-SGSampleQueue::SGSampleQueue( int freq, int format ) :
-    _refname(random_string()),
-    _playing(false)
-{
-    set_frequency( freq );
-    set_format_AL( format );
-    _buffers.clear();
-}
-
-SGSampleQueue::~SGSampleQueue() {
-    stop();
-}
-
-void SGSampleQueue::stop()
-{
-#ifdef ENABLE_SOUND
-    ALint num;
-    alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num);
-    for (int i=0; i<num; i++) {
-        ALuint buffer;
-        alSourceUnqueueBuffers(_source, 1, &buffer);
-        alDeleteBuffers(1, &buffer);
-    }
-    _buffers.clear();
-#endif
-    _playing = false;
-    _changed = true;
-}
-
-void SGSampleQueue::add( const void* smp_data, size_t len )
-{
-#ifdef ENABLE_SOUND
-    const ALvoid *data = (const ALvoid *)smp_data;
-    ALuint buffer;
-    ALint num;
-
-    if ( _valid_source )
-    {
-       alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num);
-       if (num > 1) {
-           alSourceUnqueueBuffers(_source, 1, &buffer);
-       } else {
-           alGenBuffers(1, &buffer);
-       }
-       alBufferData(buffer, get_format_AL(), data, len, get_frequency());
-    }
-    else
-    {
-        alGenBuffers(1, &buffer);
-        alBufferData(buffer, get_format_AL(), data, len, get_frequency());
-        _buffers.push_back(buffer);
-    }
-#endif
-}
-
-void SGSampleQueue::set_source( unsigned int sid )
-{
-    SGSoundSample::set_source(sid);
-#ifdef ENABLE_SOUND
-    ALuint num = _buffers.size();
-    for (unsigned int i=0; i < num; i++)
-    {
-        ALuint buffer = _buffers[i];
-        alSourceQueueBuffers(_source, 1, &buffer);
-    }
-    _buffers.clear();
-#endif
-}
-
-string SGSampleQueue::random_string() {
-      static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz"
-                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-      string rstr = "Queued sample: ";
-      for (int i=0; i<10; i++) {
-          rstr.push_back( r[rand() % strlen(r)] );
-      }
-
-      return rstr;
-}
diff --git a/simgear/sound/sample_queue.hxx b/simgear/sound/sample_queue.hxx
deleted file mode 100644
index 20de3a87..00000000
--- a/simgear/sound/sample_queue.hxx
+++ /dev/null
@@ -1,96 +0,0 @@
-///@file
-/// Provides a sample queue encapsulation
-//
-// based on sample.hxx
-// 
-// Copyright (C) 2010 Erik Hofman <erik@ehofman.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library 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
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
-
-#ifndef _SG_QUEUE_HXX
-#define _SG_QUEUE_HXX 1
-
-#include <string>
-#include <vector>
-
-#include <simgear/compiler.h>
-#include <simgear/structure/SGReferenced.hxx>
-#include <simgear/structure/SGSharedPtr.hxx>
-
-#include "sample_openal.hxx"
-
-/**
- * manages everything we need to know for an individual audio sample
- */
-
-class SGSampleQueue : public SGSoundSample {
-public:
-
-
-     /**
-      * Empty constructor, can be used to read data to the systems
-      * memory and not to the driver.
-      * @param freq sample frequentie of the samples
-      * @param format OpenAL format id of the data
-      */
-    SGSampleQueue(int freq, int format = SG_SAMPLE_MONO8);
-
-    /**
-     * Destructor
-     */
-    ~SGSampleQueue ();
-
-    /**
-     * Schedule this audio sample to stop playing.
-     */
-    virtual void stop();
-
-    /**
-     * Queue new data for this audio sample.
-     *
-     * @param data  Pointer to a memory block containg this audio sample data.
-     * @param len   Length of the sample buffer in bytes.
-     */
-    void add( const void* data, size_t len );
-
-    /**
-     * Set the source id of this source.
-     *
-     * @param sid OpenAL source-id
-     */
-    virtual void set_source(unsigned int sid);
-
-    /**
-     * Test if the buffer-id of this audio sample may be passed to OpenAL.
-     *
-     * @return false for sample queue
-     */
-    inline bool is_valid_buffer() const { return false; }
-
-    inline virtual bool is_queue() const { return true; }
-
-private:
-    std::string _refname;	// sample name
-    std::vector<unsigned int> _buffers;
-
-    bool _playing;
-
-    std::string random_string();
-};
-
-
-#endif // _SG_QUEUE_HXX
-
-
-- 
2.39.5