SlideShare une entreprise Scribd logo
1  sur  14
openFrameworks
     Sound
Sound
openFrameworks has some great support for
playing sounds. Using the ofSoundPlayer class you
call loadSound once to load the sound file (i.e.
mp3, wav) then call play to start playing.

Using ofSoundStream you can generate sounds or
use a microphone to get an input stream.
Playing sounds
Put a sound file into your data directory and use an
ofSoundPlayer to play the file.


testApp.h                           testApp.cpp
class testApp : public ofBaseApp{

 public:                            void testApp::setup(){

 
      ofSoundPlayer my_sound;     
 my_sound.loadSound("clong.mp3");

 
      ofSoundPlayer my_singer;    }
}


                                     void testApp::keyReleased(int key){
                                     
 my_sound.play();
                                     }
Multi play
A ofSoundPlayer can play the same sound object
multiple times simultaniously by setting the
multiplay flag. Call setMultiPlay(bool) to set
multiplay on or off. With the code below, try
pressing your space bar multiple times.

            void testApp::setup(){
            
 ofBackground(33,33,33);
            
 my_sound.loadSound("clong.mp3");
            
 my_singer.loadSound("violet.mp3");
            
            
 my_sound.setMultiPlay(true);
            
 my_singer.setMultiPlay(true);
            }


            void testApp::keyReleased(int key){
            
 my_sound.play();
            }
Volume and panning
To change the volume of a single sound use
my_sound.setVolume(float). A value of 0.0 means
no sound, 1.0 full volume. To pan the sound from
left to right use my_sound.setPan(float). A value of
-1.0 means play only left speaker, a value of 1.0
means play only right speaker.


          void testApp::mouseReleased(int x, int y, int button){
          
 if(button == 0) {
          
 
      my_sound.setPan(-1.0);
          
 }
          
 else {
          
 
      my_sound.setPan(1.0);
          
 }
          }
Pause
To temporarily stop a sound you call
my_sound.setPaused(bool).



             void testApp::keyReleased(int key){
             
 if(key == 'p') {
             
 
      my_sound.setPaused(true);
             
 }
             }
Loop
If you want the sound to repeat over an d over set
it to loop mode using my_sound.setLoop(bool).



              void testApp::keyReleased(int key){
              
 if(key == 'l') {
              
 
      my_sound.setLoop(true);
              
 }
              }
Changing the speed
With my_sound.setSpeed(float) you change how
fast the sound is played back. A value near 0.0 is
really slooooww and the higher the faster.



              void testApp::keyReleased(int key){
              
 if(key == 'n') {
              
 
      my_sound.setSpeed(0.1f);
              
 }
              
 else if(key == 'g') {
              
 
      my_sound.setSpeed(40.0f);
              
 }
              }
Set position
Using my_sound.setPosition(float) you can scrub
the playhead. A value of 0.0 brings you to the start
of the sound. Value 1.0 to the end.




         void testApp::update(){
         
 my_sound.setPosition((float)ofGetMouseX()/ofGetWidth());
         }
ofSoundPlayer
void loadSound(string fileName, bool stream = false)
void unloadSound()
void play()
void stop()
void setVolume(float vol)
void setPan(float vol)
void setSpeed(bool speed)
void setPaused(bool paused)
void setLoop(bool loop)
void setMultiPlay(bool mp)
void setPosition(float pos)
Helpers

These two functions operate on all sounds.



void ofSoundStopAll()

void ofSoundSetVolume(float vol)
Generating sounds
With the ofSoundStream class you can generate
sound or get sound from a microphone into your
application file.

Starting with OF-007 we have a new function in
our testApp called audioIn. This function is called
periodically with samples from the input device.
Generating sounds
To get input from a microphone you call setup(...)
and create an audioIn(..) function.


      testApp.h

      class testApp : public ofBaseApp{
      
 public:
      
 
      ofSoundStream my_sstream;
      
 
      void audioIn(float* input, int bufferSize, int nChannels);
      }


      testApp.cpp
      void testApp::setup(){
      
 my_sstream.setup(this, 0, 2, 44100, 256, 4);
      }
roxlu
www.roxlu.com

Contenu connexe

Tendances

Tendances (7)

Augeas
AugeasAugeas
Augeas
 
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.8 book - Part 55 of 202
 
Listing program
Listing programListing program
Listing program
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
Slicing
SlicingSlicing
Slicing
 
Basics
BasicsBasics
Basics
 
earthquake.gem
earthquake.gemearthquake.gem
earthquake.gem
 

Plus de roxlu

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - videoroxlu
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphicsroxlu
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
openFrameworks 007 - GL
openFrameworks 007 - GL openFrameworks 007 - GL
openFrameworks 007 - GL roxlu
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
ofxFlashCommunication
ofxFlashCommunicationofxFlashCommunication
ofxFlashCommunicationroxlu
 
openFrameworks freakDays S03E02 Tim Olden - Computational Candles
openFrameworks freakDays S03E02 Tim Olden - Computational CandlesopenFrameworks freakDays S03E02 Tim Olden - Computational Candles
openFrameworks freakDays S03E02 Tim Olden - Computational Candlesroxlu
 
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...roxlu
 

Plus de roxlu (9)

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - video
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
openFrameworks 007 - GL
openFrameworks 007 - GL openFrameworks 007 - GL
openFrameworks 007 - GL
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
ofxFlashCommunication
ofxFlashCommunicationofxFlashCommunication
ofxFlashCommunication
 
openFrameworks freakDays S03E02 Tim Olden - Computational Candles
openFrameworks freakDays S03E02 Tim Olden - Computational CandlesopenFrameworks freakDays S03E02 Tim Olden - Computational Candles
openFrameworks freakDays S03E02 Tim Olden - Computational Candles
 
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...
openFrameworks freakDay S03E02 Diederick Huijbers - C++/Physics/Cloth Animati...
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

openFrameworks 007 - sound

  • 2. Sound openFrameworks has some great support for playing sounds. Using the ofSoundPlayer class you call loadSound once to load the sound file (i.e. mp3, wav) then call play to start playing. Using ofSoundStream you can generate sounds or use a microphone to get an input stream.
  • 3. Playing sounds Put a sound file into your data directory and use an ofSoundPlayer to play the file. testApp.h testApp.cpp class testApp : public ofBaseApp{ public: void testApp::setup(){ ofSoundPlayer my_sound; my_sound.loadSound("clong.mp3"); ofSoundPlayer my_singer; } } void testApp::keyReleased(int key){ my_sound.play(); }
  • 4. Multi play A ofSoundPlayer can play the same sound object multiple times simultaniously by setting the multiplay flag. Call setMultiPlay(bool) to set multiplay on or off. With the code below, try pressing your space bar multiple times. void testApp::setup(){ ofBackground(33,33,33); my_sound.loadSound("clong.mp3"); my_singer.loadSound("violet.mp3"); my_sound.setMultiPlay(true); my_singer.setMultiPlay(true); } void testApp::keyReleased(int key){ my_sound.play(); }
  • 5. Volume and panning To change the volume of a single sound use my_sound.setVolume(float). A value of 0.0 means no sound, 1.0 full volume. To pan the sound from left to right use my_sound.setPan(float). A value of -1.0 means play only left speaker, a value of 1.0 means play only right speaker. void testApp::mouseReleased(int x, int y, int button){ if(button == 0) { my_sound.setPan(-1.0); } else { my_sound.setPan(1.0); } }
  • 6. Pause To temporarily stop a sound you call my_sound.setPaused(bool). void testApp::keyReleased(int key){ if(key == 'p') { my_sound.setPaused(true); } }
  • 7. Loop If you want the sound to repeat over an d over set it to loop mode using my_sound.setLoop(bool). void testApp::keyReleased(int key){ if(key == 'l') { my_sound.setLoop(true); } }
  • 8. Changing the speed With my_sound.setSpeed(float) you change how fast the sound is played back. A value near 0.0 is really slooooww and the higher the faster. void testApp::keyReleased(int key){ if(key == 'n') { my_sound.setSpeed(0.1f); } else if(key == 'g') { my_sound.setSpeed(40.0f); } }
  • 9. Set position Using my_sound.setPosition(float) you can scrub the playhead. A value of 0.0 brings you to the start of the sound. Value 1.0 to the end. void testApp::update(){ my_sound.setPosition((float)ofGetMouseX()/ofGetWidth()); }
  • 10. ofSoundPlayer void loadSound(string fileName, bool stream = false) void unloadSound() void play() void stop() void setVolume(float vol) void setPan(float vol) void setSpeed(bool speed) void setPaused(bool paused) void setLoop(bool loop) void setMultiPlay(bool mp) void setPosition(float pos)
  • 11. Helpers These two functions operate on all sounds. void ofSoundStopAll() void ofSoundSetVolume(float vol)
  • 12. Generating sounds With the ofSoundStream class you can generate sound or get sound from a microphone into your application file. Starting with OF-007 we have a new function in our testApp called audioIn. This function is called periodically with samples from the input device.
  • 13. Generating sounds To get input from a microphone you call setup(...) and create an audioIn(..) function. testApp.h class testApp : public ofBaseApp{ public: ofSoundStream my_sstream; void audioIn(float* input, int bufferSize, int nChannels); } testApp.cpp void testApp::setup(){ my_sstream.setup(this, 0, 2, 44100, 256, 4); }

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n