zoukankan      html  css  js  c++  java
  • 调用bios喇叭发声

    话不多说,上代码:

    #include <windows.h>
    #include <iostream>
    #include <map>
    using namespace std;
    
    const int DO = 261;
    const int RE = 293;
    const int MI = 329;
    const int FA = 349;
    const int SO = 392;
    const int LA = 440;
    const int TI = 493;
    
    const int DO_ = 130;
    const int RE_ = 147;
    const int MI_ = 165;
    const int FA_ = 174;
    const int SO_ = 186;
    const int LA_ = 220;
    const int TI_ = 247;
    
    int frequency(char note){
        static map<const char,int> table;
        
        if(table.size() == 0){
            table['1'] = DO;    
            table['2'] = RE;            
            table['3'] = MI;    
            table['4'] = FA;    
            table['5'] = SO;    
            table['6'] = LA;    
            table['7'] = TI;    
            
            table['c'] = DO_;    
            table['d'] = RE_;            
            table['e'] = MI_;    
            table['f'] = FA_;    
            table['g'] = SO_;    
            table['a'] = LA_;    
            table['b'] = TI_;    
        }
            
        return table.find(note) -> second;
    }
    
    class music{
        private:
            string notes;
            int tenuto;
        public:
            music(string &song , int tenuto_) { notes = song; tenuto = tenuto_; play(notes.end(),tenuto);}
            void play(string::iterator it,int duration );
    };
    void music::play(string::iterator it, int duration){
        char note = *it;
        
        if( it == notes.begin() )
            return;
        
        if( note == '-') 
            play( it - 1, duration + tenuto);
        else {
            if( isalnum(note) ) {
                play( it - 1, 0);
                
                Beep(frequency(note), tenuto + duration);
            } else
                play( it - 1, duration);
        }
        
    }
    
     string bee = "
     5 3 3 - | 4 2 2 - | 1 2 3 4 | 5 5 5 - | 
     5 3 3 - | 4 2 2 - | 1 3 5 5 | 3 3 3 - | 
     2 2 2 2 | 2 3 4 - | 3 3 3 3 | 3 4 5 - | 
     5 3 3 - | 4 2 2 - | 1 3 5 5 | 1 3 1 - |  
     ";
     
     string happynewyear = "
    						  1 1 1 - g - | 3 3 3 - 1 - | 1 3 5 - 5 - | 
    						  4 3 2 - - - | 2 3 4 - 4 - | 3 2 3 - 1 - | 
    						  1 3 2 - g - | b 2 1 - - - | 
    						  ";
     
     int main()
     {    
    	 music m(bee, 300);
    	 
    	 music m2(happynewyear, 200);
    	 
    	 return 0;
     }
     
     
    


     

  • 相关阅读:
    Android Studio AVD和SDK Manager灰色不能点击的问题。
    回溯:最佳调度问题
    回溯:八皇后问题(蒟蒻)
    usaco1.4.3等差数列
    单调队列练习题(oj p1157 p1158 p1159)
    OJP1147括号匹配加强版(栈)与P1153乱头发节(单调栈)
    NOIP2017游记......
    火柴棒等式c++
    潜伏者(noip09年t1)解题报告 C++
    2016noipday1t1玩具迷题结题报告
  • 原文地址:https://www.cnblogs.com/wangyaning/p/7854024.html
Copyright © 2011-2022 走看看