SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Mais 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
 

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

Último

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
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
 
[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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
#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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Último (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
[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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
#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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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); }

Notas do Editor

  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