From: Anders B. <vr-...@us...> - 2005-03-24 11:48:00
|
Update of /cvsroot/alpp/openalpp/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14023/tests Modified Files: CMakeLists.txt README moving.cpp multiple.cpp simple.cpp testfstream.cpp testmic.cpp testsend.cpp teststream.cpp Added Files: one_ten_b.ogg test1.ogg test2.ogg test3.ogg Log Message: Ogg streaming revised by Dewitt Colclough [de...@tw...]. Index: teststream.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/teststream.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** teststream.cpp 11 Nov 2004 07:57:58 -0000 1.10 --- teststream.cpp 24 Mar 2005 11:47:49 -0000 1.11 *************** *** 1,63 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where a soundfile is loaded using alutLoadWav and streamed over a UDP socket ! * to a receiver that will read the datastream and play it. ! * A sound Source is created and connected to the UDP stream of data ! */ ! #include <cc++/socket.h> ! #include <cc++/thread.h> ! #include <openalpp/alpp.h> ! ! using namespace openalpp; ! ! int main(int argc,char **argv) { ! // Buffersize in #samples. <-- This has changed from earlier releases! ! unsigned int buffersize=4096; ! if(argc>1) ! buffersize=atoi(argv[1]); ! ! try { ! // Create a socket and listen for streamed data ! ost::UDPSocket socket(ost::InetAddress("127.0.0.1"),33333); ! ! // Create a soundstream that will read its data from the socket ! // Unless you want to send lots of data, it's a good idea to go for a ! // low rate and/or small sample format. ! NetStream stream(&socket,Mono16,44100,buffersize); ! ! // Create a soundsource that uses the net-streamed soundstream. ! Source source(stream); ! ! source.SetAmbient(); ! source.Play(); ! std::cout << "Press return to continue\n"; ! std::cin.get(); ! source.Stop(); ! } catch(openalpp::Error e) { ! std::cerr << e << "\n"; ! } catch(...) { ! std::cerr << "Unknown error!\n"; ! } ! return 0; ! } --- 1,63 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where a soundfile is loaded using alutLoadWav and streamed over a UDP socket ! * to a receiver that will read the datastream and play it. ! * A sound Source is created and connected to the UDP stream of data ! */ ! #include <cc++/socket.h> ! #include <cc++/thread.h> ! #include <openalpp/alpp.h> ! ! using namespace openalpp; ! ! int main(int argc,char **argv) { ! // Buffersize in #samples. <-- This has changed from earlier releases! ! unsigned int buffersize=4096; ! if(argc>1) ! buffersize=atoi(argv[1]); ! ! try { ! // Create a socket and listen for streamed data ! ost::UDPSocket socket(ost::InetAddress("127.0.0.1"),33333); ! ! // Create a soundstream that will read its data from the socket ! // Unless you want to send lots of data, it's a good idea to go for a ! // low rate and/or small sample format. ! NetStream stream(&socket,Mono16,44100,buffersize); ! ! // Create a soundsource that uses the net-streamed soundstream. ! Source source(stream); ! ! source.SetAmbient(); ! source.Play(); ! std::cout << "Press return to continue\n"; ! std::cin.get(); ! source.Stop(); ! } catch(openalpp::Error e) { ! std::cerr << e << "\n"; ! } catch(...) { ! std::cerr << "Unknown error!\n"; ! } ! return 0; ! } --- NEW FILE: test1.ogg --- (This appears to be a binary file; contents omitted.) Index: multiple.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/multiple.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** multiple.cpp 11 Nov 2004 07:57:58 -0000 1.1 --- multiple.cpp 24 Mar 2005 11:47:49 -0000 1.2 *************** *** 1,66 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! #include <string> ! #include <vector> ! ! using namespace openalpp; ! ! int main() ! { ! openalpp::ref_ptr<Sample> sample; ! ! std::cerr << "Loads a sample at the time, plays it for a while, then loads another one etc.." << std::endl; ! try { ! ! std::vector<std::string> file_vector; ! ! file_vector.push_back("a.wav"); ! file_vector.push_back("high-e.wav"); ! file_vector.push_back("low-e.wav"); ! ! openalpp::ref_ptr<Source> source = new Source; ! unsigned int delay = 500; ! for(int i = 0; i < 10; i++) { ! if (sample.valid()) { ! source->stop(); ! } ! std::string file = file_vector[i % file_vector.size()]; ! std::cerr << "Loading and playing " << file << " for " << delay/1000.0 << " seconds" << std::endl; ! sample = new Sample(file); ! source->setSound(sample.get()); ! source->setGain(1); ! source->setLooping(); ! source->play(); ! usleep(delay*1000); // Wait for delay milliseconds ! } ! } catch(Error e) { ! std::cerr << e << "\n"; ! } ! ! return 0; ! } ! --- 1,66 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! #include <string> ! #include <vector> ! ! using namespace openalpp; ! ! int main() ! { ! openalpp::ref_ptr<Sample> sample; ! ! std::cerr << "Loads a sample at the time, plays it for a while, then loads another one etc.." << std::endl; ! try { ! ! std::vector<std::string> file_vector; ! ! file_vector.push_back("a.wav"); ! file_vector.push_back("high-e.wav"); ! file_vector.push_back("low-e.wav"); ! ! openalpp::ref_ptr<Source> source = new Source; ! unsigned int delay = 500; ! for(int i = 0; i < 10; i++) { ! if (sample.valid()) { ! source->stop(); ! } ! std::string file = file_vector[i % file_vector.size()]; ! std::cerr << "Loading and playing " << file << " for " << delay/1000.0 << " seconds" << std::endl; ! sample = new Sample(file); ! source->setSound(sample.get()); ! source->setGain(1); ! source->setLooping(); ! source->play(); ! usleep(delay*1000); // Wait for delay milliseconds ! } ! } catch(Error e) { ! std::cerr << e << "\n"; ! } ! ! return 0; ! } ! Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/CMakeLists.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CMakeLists.txt 2 Mar 2004 07:50:27 -0000 1.3 --- CMakeLists.txt 24 Mar 2005 11:47:49 -0000 1.4 *************** *** 1,44 **** ! LINK_DIRECTORIES(../src) ! ! FIND_LIBRARY(EXTRALIBS openal ${LIBDIRS}) ! ! IF(CCGNU_FOUND) ! FIND_LIBRARY(CCGNULIB ccgnu2 ${LIBDIRS}) ! IF(CCGNULIB) ! FIND_LIBRARY(THREADLIB pthread ${LIBDIRS}) ! FIND_LIBRARY(DLLIB dl ${LIBDIRS}) ! SET(EXTRALIBS ${EXTRALIBS} ${CCGNULIB} ${DLLIB} ${THREADLIB}) ! ENDIF(CCGNULIB) ! ! IF(PORTAUDIO_FOUND) ! FIND_LIBRARY(PALIB portaudio ${LIBDIRS}) ! IF(PALIB) ! SET(EXTRALIBS ${EXTRALIBS} ${PALIB}) ! ENDIF(PALIB) ! ENDIF(PORTAUDIO_FOUND) ! ! IF(VORBIS_FOUND) ! FIND_LIBRARY(VORBISFILELIB vorbisfile ${LIBDIRS}) ! FIND_LIBRARY(VORBISLIB vorbis ${LIBDIRS}) ! FIND_LIBRARY(OGGLIB ogg ${LIBDIRS}) ! IF(VORBISLIB) ! SET(EXTRALIBS ${EXTRALIBS} ${VORBISFILELIB} ${VORBISLIB} ${OGGLIB}) ! ENDIF(VORBISLIB) ! ENDIF(VORBIS_FOUND) ! ENDIF(CCGNU_FOUND) ! ! IF(CCGNU_FOUND) ! ADD_EXECUTABLE(moving moving.cpp) ! TARGET_LINK_LIBRARIES(moving openalpp ${EXTRALIBS}) ! ADD_EXECUTABLE(simple simple.cpp) ! TARGET_LINK_LIBRARIES(simple openalpp ${EXTRALIBS}) ! ADD_EXECUTABLE(testmic testmic.cpp) ! TARGET_LINK_LIBRARIES(testmic openalpp ${EXTRALIBS}) ! # ADD_EXECUTABLE(testsend testsend.cpp) ! # TARGET_LINK_LIBRARIES(testsend openalpp ${EXTRALIBS}) ! # ADD_EXECUTABLE(teststream teststream.cpp) ! # TARGET_LINK_LIBRARIES(teststream openalpp ${EXTRALIBS}) ! ENDIF(CCGNU_FOUND) ! ADD_EXECUTABLE(testfstream testfstream.cpp) ! ! TARGET_LINK_LIBRARIES(testfstream openalpp ${EXTRALIBS}) --- 1,44 ---- ! LINK_DIRECTORIES(../src) ! ! FIND_LIBRARY(EXTRALIBS openal ${LIBDIRS}) ! ! IF(CCGNU_FOUND) ! FIND_LIBRARY(CCGNULIB ccgnu2 ${LIBDIRS}) ! IF(CCGNULIB) ! FIND_LIBRARY(THREADLIB pthread ${LIBDIRS}) ! FIND_LIBRARY(DLLIB dl ${LIBDIRS}) ! SET(EXTRALIBS ${EXTRALIBS} ${CCGNULIB} ${DLLIB} ${THREADLIB}) ! ENDIF(CCGNULIB) ! ! IF(PORTAUDIO_FOUND) ! FIND_LIBRARY(PALIB portaudio ${LIBDIRS}) ! IF(PALIB) ! SET(EXTRALIBS ${EXTRALIBS} ${PALIB}) ! ENDIF(PALIB) ! ENDIF(PORTAUDIO_FOUND) ! ! IF(VORBIS_FOUND) ! FIND_LIBRARY(VORBISFILELIB vorbisfile ${LIBDIRS}) ! FIND_LIBRARY(VORBISLIB vorbis ${LIBDIRS}) ! FIND_LIBRARY(OGGLIB ogg ${LIBDIRS}) ! IF(VORBISLIB) ! SET(EXTRALIBS ${EXTRALIBS} ${VORBISFILELIB} ${VORBISLIB} ${OGGLIB}) ! ENDIF(VORBISLIB) ! ENDIF(VORBIS_FOUND) ! ENDIF(CCGNU_FOUND) ! ! IF(CCGNU_FOUND) ! ADD_EXECUTABLE(moving moving.cpp) ! TARGET_LINK_LIBRARIES(moving openalpp ${EXTRALIBS}) ! ADD_EXECUTABLE(simple simple.cpp) ! TARGET_LINK_LIBRARIES(simple openalpp ${EXTRALIBS}) ! ADD_EXECUTABLE(testmic testmic.cpp) ! TARGET_LINK_LIBRARIES(testmic openalpp ${EXTRALIBS}) ! # ADD_EXECUTABLE(testsend testsend.cpp) ! # TARGET_LINK_LIBRARIES(testsend openalpp ${EXTRALIBS}) ! # ADD_EXECUTABLE(teststream teststream.cpp) ! # TARGET_LINK_LIBRARIES(teststream openalpp ${EXTRALIBS}) ! ENDIF(CCGNU_FOUND) ! ADD_EXECUTABLE(testfstream testfstream.cpp) ! ! TARGET_LINK_LIBRARIES(testfstream openalpp ${EXTRALIBS}) Index: testmic.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/testmic.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** testmic.cpp 11 Nov 2004 07:57:58 -0000 1.13 --- testmic.cpp 24 Mar 2005 11:47:49 -0000 1.14 *************** *** 1,96 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where sound is streamed from a microphone. ! */ ! #include "openalpp/alpp.h" ! #include <iostream> ! ! using namespace openalpp; ! ! #ifndef M_PI ! #define M_PI 3.14159265358979323846 ! #endif ! ! int main() { ! ! #ifdef ALPP_USE_PORTAUDIO ! ! ! try { ! InputDevice mic; ! ! Source source(mic); ! source.setGain(2); ! //source.SetLooping(); ! source.play(); ! usleep(3000*1000); ! ! float limits[2] = {0.5,-0.5}; ! //float delay=10; ! //float time=0,angle=0; ! ! source.setPosition(limits[0],0.0,0.0); ! source.play(); ! ! //const int no_laps=5; ! ! std::cerr << "Moving sound 5 times..." << std::endl; ! ! // Do a cheat time loop. ! #if 0 ! while(angle<(M_PI*no_laps)) { ! usleep(delay*1000); // Wait for delay milliseconds ! ! time +=delay/1000; // Calculate the time in the loop ! angle=M_PI *time; // What is the resulting angle ! ! // Calculate a new position ! std::cerr << cos(angle) << ", " << sin(angle) << std::endl; ! source.setPosition(limits[0]*cos(0),0.0,limits[1]*sin(0)); ! } ! #else ! std::cerr << "Moved to the left" << std::endl; ! source.setPosition(-0.5,0.0,0); ! usleep(3000*1000); ! std::cerr << "Moved to the right" << std::endl; ! source.setPosition(+0.5,0.0,0); ! usleep(3000*1000); ! #endif ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! ! ! std::cerr << "Press return to continue\n"; ! ! std::cin.get(); ! #else ! std::cerr << "Use of portaudio is not compiled to the project" << std::endl; ! std::cerr << "Look into the config.h and modify that if you inted to use PortAudio" << std::endl; ! #endif ! ! return 0; ! ! } ! --- 1,96 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where sound is streamed from a microphone. ! */ ! #include "openalpp/alpp.h" ! #include <iostream> ! ! using namespace openalpp; ! ! #ifndef M_PI ! #define M_PI 3.14159265358979323846 ! #endif ! ! int main() { ! ! #ifdef ALPP_USE_PORTAUDIO ! ! ! try { ! InputDevice mic; ! ! Source source(mic); ! source.setGain(2); ! //source.SetLooping(); ! source.play(); ! usleep(3000*1000); ! ! float limits[2] = {0.5,-0.5}; ! //float delay=10; ! //float time=0,angle=0; ! ! source.setPosition(limits[0],0.0,0.0); ! source.play(); ! ! //const int no_laps=5; ! ! std::cerr << "Moving sound 5 times..." << std::endl; ! ! // Do a cheat time loop. ! #if 0 ! while(angle<(M_PI*no_laps)) { ! usleep(delay*1000); // Wait for delay milliseconds ! ! time +=delay/1000; // Calculate the time in the loop ! angle=M_PI *time; // What is the resulting angle ! ! // Calculate a new position ! std::cerr << cos(angle) << ", " << sin(angle) << std::endl; ! source.setPosition(limits[0]*cos(0),0.0,limits[1]*sin(0)); ! } ! #else ! std::cerr << "Moved to the left" << std::endl; ! source.setPosition(-0.5,0.0,0); ! usleep(3000*1000); ! std::cerr << "Moved to the right" << std::endl; ! source.setPosition(+0.5,0.0,0); ! usleep(3000*1000); ! #endif ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! ! ! std::cerr << "Press return to continue\n"; ! ! std::cin.get(); ! #else ! std::cerr << "Use of portaudio is not compiled to the project" << std::endl; ! std::cerr << "Look into the config.h and modify that if you inted to use PortAudio" << std::endl; ! #endif ! ! return 0; ! ! } ! --- NEW FILE: test2.ogg --- (This appears to be a binary file; contents omitted.) Index: simple.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/simple.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** simple.cpp 19 Nov 2004 07:47:55 -0000 1.15 --- simple.cpp 24 Mar 2005 11:47:49 -0000 1.16 *************** *** 1,65 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Simple example for using OpenAL++. ! * Plays a file bee.wav in the background. ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! ! using namespace openalpp; ! ! ! int main(int argc,char **argv) { ! ! std::string file; ! file = "bee.wav"; ! ! if (argc > 1) ! file = argv[1]; ! ! std::cout << "Playing " << file << "\n"; ! ! try { ! openalpp::ref_ptr<Source> bgsound = new Source; //(file); // Create source and load sound ! bgsound->stop(); ! openalpp::ref_ptr<Sample> sample = new Sample(file); ! bgsound->setSound(sample.get()); ! bgsound->setGain(0.6f); // Lower gain (volume) ! bgsound->setLooping(); ! bgsound->setAmbient(); // Make sound ambient (i.e. not attenuated) ! bgsound->play(); // Start playing ! ! ! std::cerr << "Press return to stop: " << std::endl; ! ! std::string str; ! std::getline(std::cin, str); ! bgsound->stop(); ! std::cerr << "Done " << std::endl; ! ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! return 0; ! } --- 1,65 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Simple example for using OpenAL++. ! * Plays a file bee.wav in the background. ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! ! using namespace openalpp; ! ! ! int main(int argc,char **argv) { ! ! std::string file; ! file = "bee.wav"; ! ! if (argc > 1) ! file = argv[1]; ! ! std::cout << "Playing " << file << "\n"; ! ! try { ! openalpp::ref_ptr<Source> bgsound = new Source; //(file); // Create source and load sound ! bgsound->stop(); ! openalpp::ref_ptr<Sample> sample = new Sample(file); ! bgsound->setSound(sample.get()); ! bgsound->setGain(0.6f); // Lower gain (volume) ! bgsound->setLooping(); ! bgsound->setAmbient(); // Make sound ambient (i.e. not attenuated) ! bgsound->play(); // Start playing ! ! ! std::cerr << "Press return to stop: " << std::endl; ! ! std::string str; ! std::getline(std::cin, str); ! bgsound->stop(); ! std::cerr << "Done " << std::endl; ! ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! return 0; ! } --- NEW FILE: one_ten_b.ogg --- (This appears to be a binary file; contents omitted.) Index: moving.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/moving.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** moving.cpp 11 Nov 2004 07:57:58 -0000 1.14 --- moving.cpp 24 Mar 2005 11:47:49 -0000 1.15 *************** *** 1,71 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * ! * Simple example for using OpenAL++. ! * Plays a file bee.wav and moves it left right. ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! ! ! using namespace openalpp; ! ! #ifndef M_PI ! #define M_PI 3.14159265358979323846 ! #endif ! ! ! int main() { ! try { ! openalpp::ref_ptr<Source> beesound = new Source("bee.wav"); ! beesound->setGain(1); ! beesound->setLooping(); ! ! float limits[2] = {5,-15}; ! float delay=10; ! float time=0,angle=0; ! ! beesound->setPosition(limits[0],0.0,0.0); ! beesound->play(); ! ! const int no_laps=5; ! ! std::cerr << "Moving sound 5 laps..." << std::endl; ! ! // Do a cheat time loop. ! while(angle<(M_PI*2.0*no_laps)) { ! usleep(delay*1000); // Wait for delay milliseconds ! ! time +=delay/1000; // Calculate the time in the loop ! angle=M_PI *time; // What is the resulting angle ! ! // Calculate a new position ! beesound->setPosition(limits[0]*cos(angle),0.0,limits[1]*sin(angle)); ! } ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! return 0; ! } ! --- 1,71 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * ! * Simple example for using OpenAL++. ! * Plays a file bee.wav and moves it left right. ! */ ! #include <openalpp/alpp.h> ! #include <iostream> ! ! ! using namespace openalpp; ! ! #ifndef M_PI ! #define M_PI 3.14159265358979323846 ! #endif ! ! ! int main() { ! try { ! openalpp::ref_ptr<Source> beesound = new Source("bee.wav"); ! beesound->setGain(1); ! beesound->setLooping(); ! ! float limits[2] = {5,-15}; ! float delay=10; ! float time=0,angle=0; ! ! beesound->setPosition(limits[0],0.0,0.0); ! beesound->play(); ! ! const int no_laps=5; ! ! std::cerr << "Moving sound 5 laps..." << std::endl; ! ! // Do a cheat time loop. ! while(angle<(M_PI*2.0*no_laps)) { ! usleep(delay*1000); // Wait for delay milliseconds ! ! time +=delay/1000; // Calculate the time in the loop ! angle=M_PI *time; // What is the resulting angle ! ! // Calculate a new position ! beesound->setPosition(limits[0]*cos(angle),0.0,limits[1]*sin(angle)); ! } ! } catch(Error e) { ! std::cerr << e << "\n"; ! return -1; ! } ! return 0; ! } ! Index: README =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/README,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** README 11 Nov 2004 07:57:58 -0000 1.4 --- README 24 Mar 2005 11:47:49 -0000 1.5 *************** *** 1,21 **** ! Some small test/example programs. These are primarily for streaming, and might not work on all platforms yet.. ! ! simple - Play the file bee.wav. The basic test from the tutorial. ! ! moving - Play the file bee.wav and moves it left/right (from the tutorial). ! ! testmic - Read from the default input device and play it to a source placed on (0,0,0). Stop when return is pressed. ! ! testsend - Load a file (gamebeginning.wav - not included) and send it through a socket, in packets of 1024 bytes. To be used in conjunction with teststream. ! ! multiple - Loads and plays and deletes several wav files. Tests the reference pointer deallocation ! ! teststream - Connect a socket to a source and play it. Run testsend directly after running this. ! ! ! ! More tests might be added in the future. The stranger tests that I used while developing have been removed as they would ! probably not be very interesting. ! ! /Anders Backman, VRlab, 2004 ! Tomas Hämälä, VRlab, 2002 --- 1,21 ---- ! Some small test/example programs. These are primarily for streaming, and might not work on all platforms yet.. ! ! simple - Play the file bee.wav. The basic test from the tutorial. ! ! moving - Play the file bee.wav and moves it left/right (from the tutorial). ! ! testmic - Read from the default input device and play it to a source placed on (0,0,0). Stop when return is pressed. ! ! testsend - Load a file (gamebeginning.wav - not included) and send it through a socket, in packets of 1024 bytes. To be used in conjunction with teststream. ! ! multiple - Loads and plays and deletes several wav files. Tests the reference pointer deallocation ! ! teststream - Connect a socket to a source and play it. Run testsend directly after running this. ! ! ! ! More tests might be added in the future. The stranger tests that I used while developing have been removed as they would ! probably not be very interesting. ! ! /Anders Backman, VRlab, 2004 ! Tomas Hämälä, VRlab, 2002 --- NEW FILE: test3.ogg --- (This appears to be a binary file; contents omitted.) Index: testsend.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/testsend.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** testsend.cpp 11 Nov 2004 07:57:58 -0000 1.9 --- testsend.cpp 24 Mar 2005 11:47:49 -0000 1.10 *************** *** 1,99 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where a soundfile is loaded using alutLoadWav and streamed over a ! * UDP socket to a receiver that will read the datastream and play it. ! * ! * Note about selecting rate, format and sending rate: ! * Rate is given in samples per second, and format gives the size of one ! * sample. This means that, for example: ! * If the format is Mono16, we have one channel with 16 bit per channel, i.e. ! * 16 bit or 2 bytes per sample. ! * Say we have a frequency of 44100 samples per second. 2 byte samples will ! * mean that we need to stream 88200 bytes per second. ! * If we can send (and receive) ten packets per second, each packet should be ! * at least 8820 bytes. ! * If we instead had a frequency of 11025, then it would be enough with 2205 ! * bytes per packet. ! * Of course it's a good idea to add a few hundred bytes to those numbers ;) ! */ ! ! #include <cc++/thread.h> ! #include <cc++/socket.h> ! #include <iostream> ! #include <stdlib.h> ! #include <AL/al.h> ! #include <AL/alut.h> ! #include "openalpp/windowsstuff.h" ! ! using namespace ost; ! ! int main(int argc,char **argv) { ! ALvoid *data; ! ALsizei bits,freq,size; ! ALenum format; ! ALboolean success; ! // Default packet size (in bytes) ! // Note that this doesn't necessarily have to have anything to do with the ! // buffer size of the receiver. Just set it to something appropriate ! // (depending on the connection), and the receiver will take care of the ! // playing the sound correctly... ! unsigned int packetsize=10000; ! const char defaultfile[]="bee.wav"; ! const char *filename; ! ! if(argc>1) ! filename=argv[1]; ! else ! filename=defaultfile; ! if(argc>2) ! packetsize=atoi(argv[2]); ! ! try { ! success=alutLoadWAV(filename,&data,&format,&size,&bits,&freq); ! std::cerr << "Bits: " << bits << " Freq: " << freq << std::endl; ! ! if(success==AL_FALSE) { ! std::cerr << "Error loading " << filename << "\n"; ! exit(1); ! } ! ! UDPSocket socket; ! socket.setPeer(InetHostAddress("127.0.0.1"),33333); ! ! int totalsent=0; ! while(totalsent<size) { ! // Send data in packets with a 60 ms delay between packets ! if((totalsent+packetsize)>size) ! packetsize=size-totalsent; ! totalsent+=socket.send((char *)data+totalsent,packetsize); ! ost::Thread::sleep(60); ! } ! ! free(data); ! } catch(...) { ! std::cerr << "Error caught!\n"; ! } ! ! return 0; ! } --- 1,99 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * CommonC++ (http://cplusplus.sourceforge.net/) ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example where a soundfile is loaded using alutLoadWav and streamed over a ! * UDP socket to a receiver that will read the datastream and play it. ! * ! * Note about selecting rate, format and sending rate: ! * Rate is given in samples per second, and format gives the size of one ! * sample. This means that, for example: ! * If the format is Mono16, we have one channel with 16 bit per channel, i.e. ! * 16 bit or 2 bytes per sample. ! * Say we have a frequency of 44100 samples per second. 2 byte samples will ! * mean that we need to stream 88200 bytes per second. ! * If we can send (and receive) ten packets per second, each packet should be ! * at least 8820 bytes. ! * If we instead had a frequency of 11025, then it would be enough with 2205 ! * bytes per packet. ! * Of course it's a good idea to add a few hundred bytes to those numbers ;) ! */ ! ! #include <cc++/thread.h> ! #include <cc++/socket.h> ! #include <iostream> ! #include <stdlib.h> ! #include <AL/al.h> ! #include <AL/alut.h> ! #include "openalpp/windowsstuff.h" ! ! using namespace ost; ! ! int main(int argc,char **argv) { ! ALvoid *data; ! ALsizei bits,freq,size; ! ALenum format; ! ALboolean success; ! // Default packet size (in bytes) ! // Note that this doesn't necessarily have to have anything to do with the ! // buffer size of the receiver. Just set it to something appropriate ! // (depending on the connection), and the receiver will take care of the ! // playing the sound correctly... ! unsigned int packetsize=10000; ! const char defaultfile[]="bee.wav"; ! const char *filename; ! ! if(argc>1) ! filename=argv[1]; ! else ! filename=defaultfile; ! if(argc>2) ! packetsize=atoi(argv[2]); ! ! try { ! success=alutLoadWAV(filename,&data,&format,&size,&bits,&freq); ! std::cerr << "Bits: " << bits << " Freq: " << freq << std::endl; ! ! if(success==AL_FALSE) { ! std::cerr << "Error loading " << filename << "\n"; ! exit(1); ! } ! ! UDPSocket socket; ! socket.setPeer(InetHostAddress("127.0.0.1"),33333); ! ! int totalsent=0; ! while(totalsent<size) { ! // Send data in packets with a 60 ms delay between packets ! if((totalsent+packetsize)>size) ! packetsize=size-totalsent; ! totalsent+=socket.send((char *)data+totalsent,packetsize); ! ost::Thread::sleep(60); ! } ! ! free(data); ! } catch(...) { ! std::cerr << "Error caught!\n"; ! } ! ! return 0; ! } Index: testfstream.cpp =================================================================== RCS file: /cvsroot/alpp/openalpp/tests/testfstream.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** testfstream.cpp 11 Nov 2004 07:57:58 -0000 1.7 --- testfstream.cpp 24 Mar 2005 11:47:49 -0000 1.8 *************** *** 1,72 **** ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example of streaming from a file. Only ogg files are supported at the ! * moment (2003-02-15). The program takes one argument; the name of the file ! * to stream data from. ! */ ! ! #include <openalpp/alpp.h> ! #include <iostream> ! ! using namespace openalpp; ! ! int main(int argc,char **argv) { ! if(argc<=1) { ! std::cerr << "Syntax:\n " << argv[0] << " <audiofile>\n"; ! return 1; ! } ! ! std::cout << argv[1] << "\n"; ! ! try { ! ! std::vector<openalpp::ref_ptr<Source> > vec; ! std::vector<openalpp::ref_ptr<FileStream> > fstream_vec; ! ! for(int i=0; i < 1; i++) { ! ! openalpp::ref_ptr<FileStream> stream = new FileStream(argv[1]); ! fstream_vec.push_back(stream); ! stream->setLooping(); // Remove this to play file once only. ! ! ! Source *source = new Source(*stream.get()); ! vec.push_back(source); ! source->setAmbient(); ! source->play(); ! ! } ! std::cerr << "Press return to stop " << std::endl; ! std::cin.get(); ! ! for(unsigned int i=0; i < vec.size(); i++) ! vec[i]->stop(); ! usleep(1000*1000); ! ! } catch(openalpp::Error e) { ! std::cerr << e << "\n"; ! } catch(...) { ! std::cerr << "Unknown error!\n"; ! } ! return 0; ! } --- 1,208 ---- ! /** ! * OpenAL++ - an object oriented toolkit for spatial sound ! * Copyright (C) 2002 VRlab, Umeå University ! * ! * OpenAL++ was created using the libraries: ! * OpenAL (http://www.openal.org), ! * PortAudio (http://www.portaudio.com/), and ! * ! * This library is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public ! * License as published by the Free Software Foundation; either ! * version 2.1 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 ! * Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this library; if not, write to the Free Software ! * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ! * ! * Example of streaming from a file. Only ogg files are supported at the ! * moment (2003-02-15). The program takes one argument; the name of the file ! * to stream data from. ! */ ! ! #include <openalpp/alpp.h> ! #include <iostream> ! ! ! #define CRTDBG_MAP_ALLOC ! #include <stdlib.h> ! #ifdef WIN32 ! #include <crtdbg.h> ! #endif ! ! ! ! using namespace openalpp; ! ! void WaitForPlaying(Source* source) ! { ! while (source->getState() != openalpp::Playing) ! { ! usleep(1000); ! int checkCount = 0; ! if (checkCount++ > 1000) ! { ! throw openalpp::Error("Timed out while waiting for stream to play"); ! } ! } ! } ! ! void WaitForStopped(Source* source) ! { ! while (source->getState() != openalpp::Stopped) ! { ! usleep(1000); ! int checkCount = 0; ! if (checkCount++ > 1000) ! { ! throw openalpp::Error("Timed out while waiting for stream to stop"); ! } ! } ! } ! ! void TestSeek() ! { ! std::string numbers("one_ten_b.ogg"); ! ! ! std::vector<float> seekPoints; ! seekPoints.push_back(7.0); ! seekPoints.push_back(5.0); ! seekPoints.push_back(2.0); ! seekPoints.push_back(3.0); ! ! try ! { ! openalpp::ref_ptr<Source> source = new Source; ! ! source->setSound(new FileStream(numbers)); ! source->setAmbient(); ! ! for (size_t k=0; k<seekPoints.size(); ++k) ! { ! fprintf(stdout, "%.0f ", seekPoints[k]); ! source->seek(seekPoints[k]); ! if (k==0) ! { ! source->play(); ! } ! usleep(500*1000); ! } ! fprintf(stdout, "\n"); ! ! source->stop(); ! ! WaitForStopped(source.get()); ! ! } ! catch(openalpp::Error e) ! { ! std::cerr << e << "\n"; ! } ! catch(...) ! { ! std::cerr << "Unknown error!\n"; ! } ! ! } ! ! ! ! int main(int argc,char **argv) { ! #ifdef WIN32 ! // MSVC memory leak detection ! _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // {,,msvcr71d.dll}_crtBreakAlloc ! #endif ! std::string file1("test1.ogg"); ! std::string file2("test2.ogg"); ! std::string file3("test3.ogg"); ! ! TestSeek(); ! usleep(500000); ! try ! { ! ! openalpp::ref_ptr<Source> source = new Source; ! ! source->setSound(new FileStream(file1)); ! source->setAmbient(); ! source->play(); ! ! // Test transition to audio file when first finishes ! std::cout << "Waiting for first audio file to stop" << std::endl; ! ! WaitForStopped(source.get()); ! ! std::cout << "Playing second audio file" << std::endl; ! ! // For now, the source has to be re-created for stable behavior ! source = new Source; ! ! source->setSound(new FileStream(file3)); ! source->setAmbient(); ! source->play(); ! ! // Test pause and resume ! std::cout << "Press return to pause audio file" << std::endl; ! std::cin.get(); ! ! source->pause(); ! ! std::cout << "Press return to resume audio file" << std::endl; ! std::cin.get(); ! ! source->play(); ! ! // Test switching between files mid-stream ! std::cout << "Press return to switch to next audio file" << std::endl; ! std::cin.get(); ! ! ! for (int nSwitch = 0; nSwitch < 2; nSwitch++) ! { ! source = new Source; ! ! source->setSound(new FileStream(file2)); ! source->setAmbient(); ! source->play(); ! ! std::cout << "Press return to switch to next audio file" << std::endl; ! std::cin.get(); ! ! source->stop(); ! WaitForStopped(source.get()); ! ! source = new Source; ! ! source->setSound(new FileStream(file1)); ! source->setAmbient(); ! source->play(); ! ! std::cout << "Press return to switch to next audio file" << std::endl; ! std::cin.get(); ! ! source->stop(); ! WaitForStopped(source.get()); ! ! } ! ! std::cout << "Press return to exit" << std::endl; ! std::cin.get(); ! } ! catch(openalpp::Error e) ! { ! std::cerr << e << "\n"; ! } ! catch(...) ! { ! std::cerr << "Unknown error!\n"; ! } ! ! ! return 0; ! } |